:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --border: #dde2ea;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #1d4ed8;
    --accent-2: #dbe6ff;
    --on-accent: #ffffff;
    --danger: #b91c1c;
    --radius: 12px;
    --shadow: 0 6px 24px rgba(15, 23, 42, .12);
    --nav-h: 62px;
    --top-h: 52px;
    --side-w: 232px;

    /* araç durumları */
    --st-moving: #16a34a;
    --st-idle: #d97706;
    --st-stopped: #2563eb;
    --st-parked: #64748b;
    --st-stale: #ea580c;
    --st-offline: #dc2626;
    --st-nodata: #a3aab8;
    --map-bg: #f2f3f0; /* harita yüklenirken zemin (Positron) */

    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1120;
        --surface: #131c2e;
        --surface-2: #1b263b;
        --border: #2a364d;
        --text: #e5eaf3;
        --muted: #93a0b8;
        --accent: #4f83ff;
        --accent-2: #1d2e55;
        --danger: #f87171;
        --shadow: 0 6px 24px rgba(0, 0, 0, .45);
        --map-bg: #3a4a6b; /* Fiord yüklenirken */
        color-scheme: dark;
    }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; overscroll-behavior: none; }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 20px; margin: 8px 0; }
.spacer { flex: 1; }

/* ---------- düğmeler, formlar ---------- */
.btn {
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: 10px 14px; border-radius: 10px; font: inherit; cursor: pointer; min-height: 42px;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

input, select, textarea {
    font: inherit; color: var(--text); background: var(--surface); width: 100%;
    border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
label.check input { width: 20px; height: 20px; min-height: 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.form-actions .btn { flex: 1; }
/* iPhone, 16px'ten küçük yazılı kutuya dokununca sayfayı büyütür */
@media (max-width: 899px) { input, select, textarea { font-size: 16px; } }

/* ---------- giriş ---------- */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); padding: 28px 22px; border-radius: 18px; box-shadow: var(--shadow); }
.auth-logo { width: 56px; height: 56px; display: block; margin: 0 auto 8px; }
.auth-card h1 { text-align: center; font-size: 22px; margin: 4px 0; }
.auth-card > p.muted { text-align: center; margin: 0 0 18px; }

/* ---------- iskelet ---------- */
/* çentikli telefonlarda üst ve alt güvenli alan satır yüksekliğine eklenir */
.shell {
    height: 100%; display: grid; grid-template-columns: 1fr;
    grid-template-rows: calc(var(--top-h) + env(safe-area-inset-top)) 1fr calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.sidebar { display: none; }
.topbar {
    display: flex; align-items: center; gap: 10px; padding: 0 16px; padding-top: env(safe-area-inset-top);
    background: var(--surface); border-bottom: 1px solid var(--border); z-index: 5;
}
.topbar h1 { font-size: 17px; margin: 0; }
.view { overflow: auto; position: relative; }
.view.full { overflow: hidden; }
.page { padding: 16px; max-width: 980px; margin: 0 auto; padding-bottom: 32px; }

.bottom-nav {
    display: flex; background: var(--surface); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.bottom-nav a, .side-link {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--muted); text-decoration: none; font-size: 11px; padding: 6px 2px;
}
.bottom-nav a .ico { font-size: 20px; line-height: 1; padding: 3px 16px; border-radius: 999px; transition: background .15s; }
.bottom-nav a.active { color: var(--accent); font-weight: 600; }
.bottom-nav a.active .ico { background: var(--accent-2); }
.item:active, .btn:active, .chip:active, .fab:active, .card-actions .act:active { transform: scale(.98); }

@media (min-width: 900px) {
    .shell { grid-template-columns: var(--side-w) 1fr; grid-template-rows: var(--top-h) 1fr; }
    .sidebar {
        display: flex; flex-direction: column; grid-row: 1 / span 2; background: var(--surface);
        border-right: 1px solid var(--border); padding: 12px 10px;
    }
    .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 6px 8px 16px; }
    .brand img { width: 30px; height: 30px; }
    .side-link {
        flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14px; padding: 10px 12px;
        border-radius: 10px; margin-bottom: 2px; color: var(--text);
    }
    .side-link .ico { width: 22px; text-align: center; }
    .side-link:hover { background: var(--surface-2); }
    .side-link.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
    .side-footer { margin-top: auto; padding: 8px; }
    .bottom-nav { display: none; }
}

.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--st-nodata); }
.live-dot.on { background: var(--st-moving); box-shadow: 0 0 0 4px rgba(22, 163, 74, .18); }
.live-dot.off { background: var(--st-offline); }

/* ---------- kart, liste ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { flex: 1; min-width: 140px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
    display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px; cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
}
.item:hover { border-color: var(--accent); }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item .sub { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { text-align: right; font-size: 13px; color: var(--muted); white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
    font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.st-moving { color: var(--st-moving); } .st-idle { color: var(--st-idle); } .st-stopped { color: var(--st-stopped); }
.st-parked { color: var(--st-parked); } .st-stale { color: var(--st-stale); } .st-offline { color: var(--st-offline); }
.st-nodata { color: var(--st-nodata); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- harita ---------- */
.map-wrap { position: absolute; inset: 0; display: flex; }
.map { flex: 1; height: 100%; z-index: 1; }
.map-overlay { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 4; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.search { box-shadow: var(--shadow); border: 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
    padding: 6px 12px; font: inherit; font-size: 13px; white-space: nowrap; cursor: pointer; box-shadow: var(--shadow);
    display: inline-flex; gap: 6px; align-items: center;
}
.chip.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.chip .n { font-weight: 700; }

/* harita: üstten görünüm araç ikonu, gittiği yöne döner */
.veh-marker { position: relative; width: 44px; height: 44px; }
.veh-marker .body {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.55)); transition: transform .6s ease;
}
.veh-marker .badge-st {
    position: absolute; top: 0; right: 0; min-width: 17px; height: 17px; padding: 0 3px; border-radius: 9px;
    background: currentColor; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4);
    display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; line-height: 1;
}
.veh-marker .badge-st i { color: #fff; font-style: normal; }
.veh-marker .label {
    position: absolute; top: 42px; left: 50%; transform: translateX(-50%); background: var(--surface); color: var(--text);
    font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.veh-marker.selected::before {
    content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 3px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
}

/* araç listesi: telefonda alt panel, masaüstünde sağ panel */
.fleet-panel {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; background: var(--surface);
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow); max-height: 62%; display: flex; flex-direction: column;
    transition: max-height .22s ease;
}
.fleet-panel.collapsed { max-height: 56px; }
.fleet-panel .handle {
    position: relative; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 56px; padding: 12px 16px 8px;
    border: 0; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; touch-action: none;
}
.fleet-panel .handle::before { content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--border); }
.fleet-panel .toggle-text { color: var(--accent); font-size: 13px; font-weight: 600; }
.fleet-panel .rows { overflow: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.fleet-panel.collapsed .rows { display: none; }
.fleet-panel .item { padding: 10px; }

/* yüzen düğme (tüm araçları göster) */
.map-fabs { position: absolute; right: 12px; bottom: 104px; /* pusula ve telif satırının üstü */ z-index: 3; display: flex; flex-direction: column; gap: 8px; }
.fab {
    width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text);
    box-shadow: var(--shadow); font-size: 20px; cursor: pointer;
}
.map-wrap:not(.list-hidden) .map-fabs, .map-wrap.card-open .map-fabs { display: none; }

@media (min-width: 900px) {
    .fleet-panel { left: auto; top: 10px; right: 10px; bottom: 10px; width: 340px; max-height: none; border-radius: var(--radius); }
    .fleet-panel.collapsed { bottom: auto; width: auto; min-width: 200px; max-height: none; }
    .fleet-panel .handle { min-height: 48px; padding: 10px 14px; }
    .fleet-panel .handle::before { display: none; }
    .fleet-panel .handle:hover .toggle-text { text-decoration: underline; }
    .map-overlay { right: 360px; }
    .map-wrap.list-hidden .map-overlay { right: 230px; }
    /* yakınlaştırma ve yüzen düğme listenin altında kalmasın */
    .map-wrap:not(.list-hidden) .maplibregl-ctrl-bottom-right { margin-right: 350px; }
    .map-fabs, .map-wrap:not(.list-hidden) .map-fabs { display: flex; bottom: 150px; right: 10px; } /* yakınlaştırma + pusula + telif satırının üstü */
    .map-wrap:not(.list-hidden) .map-fabs { right: 360px; }
}

.vehicle-card {
    position: absolute; left: 8px; right: 8px; bottom: 64px; z-index: 5; background: var(--surface); border-radius: 16px;
    box-shadow: var(--shadow); padding: 14px; animation: card-in .18s ease-out;
}
@keyframes card-in { from { transform: translateY(16px); opacity: 0; } }
@media (min-width: 900px) { .vehicle-card { left: 10px; right: auto; bottom: 10px; width: 380px; } }
.card-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.card-actions .act {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px; padding: 6px 4px;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
    font: inherit; font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center;
}
.card-actions .act span { font-size: 19px; line-height: 1; }
.card-actions .act.on { border-color: var(--accent); background: var(--accent-2); color: var(--accent); }
.card-actions .act.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.vehicle-card .head { display: flex; align-items: center; gap: 8px; }
.vehicle-card .head b { font-size: 17px; }
.vehicle-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px; text-align: center; }
.stat .v { font-weight: 700; font-size: 16px; }
.stat .l { color: var(--muted); font-size: 11px; }

/* ---------- geçmiş ---------- */
.history { position: absolute; inset: 0; display: grid; grid-template-rows: auto 1fr auto; }
.history .controls { padding: 10px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.history .controls select, .history .controls input { flex: 1; min-width: 130px; }
.history .player { background: var(--surface); border-top: 1px solid var(--border); padding: 10px 14px; }
.history .player input[type=range] { padding: 0; min-height: 28px; }
.history .summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.speed-legend { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.speed-legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

/* ---------- alt sayfa ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 1000; }
.sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001; background: var(--surface); border-radius: 18px 18px 0 0;
    max-height: 92%; display: flex; flex-direction: column; box-shadow: var(--shadow); padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 700px) {
    .sheet { left: 50%; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 560px; border-radius: 18px; max-height: 88%; }
}
.sheet-head { display: flex; align-items: center; padding: 12px 12px 4px 18px; }
.sheet-head h2 { font-size: 17px; margin: 0; flex: 1; }
.sheet-body { overflow: auto; padding: 8px 18px 18px; }

.secret { font-family: Consolas, monospace; font-size: 18px; background: var(--surface-2); padding: 12px; border-radius: 10px; text-align: center; user-select: all; letter-spacing: 1px; }

.toast {
    position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%); z-index: 1100;
    background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; max-width: 90%;
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; font-weight: 600; }

/* ---------- alarmlar ve bölgeler (Faz 3) ---------- */
.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.seg a {
    flex: 1; text-align: center; padding: 8px 6px; border-radius: 9px; color: var(--muted); text-decoration: none;
    font-size: 14px; font-weight: 600; white-space: nowrap;
}
.seg a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.alert-ico { font-size: 22px; width: 32px; text-align: center; flex: none; }
.alert-item .sub { white-space: normal; }
.mini-map { height: 200px; border-radius: 12px; margin: 10px 0; z-index: 0; }
.check-list { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 0; margin-bottom: 12px; }
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 50%; flex: none; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.swatches input { display: none; }
.swatches input:checked + .swatch { box-shadow: 0 0 0 3px var(--accent); }
.draw-bar { margin: 0; box-shadow: var(--shadow); max-width: 420px; }
.fab.on { background: var(--accent-2); color: var(--accent); }

/* okunmamış alarm sayısı */
.nav-badge {
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff;
    font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; font-style: normal;
}
.bottom-nav .ico { position: relative; }
.bottom-nav .nav-badge { position: absolute; top: -4px; right: 4px; }
.side-link .nav-badge { margin-left: auto; }

/* ---------- raporlar (Faz 2) ---------- */
.seg-scroll { overflow-x: auto; scrollbar-width: none; }
.seg-scroll::-webkit-scrollbar { display: none; }
.report-filters .form-row { gap: 0 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stats-grid .stat { background: var(--surface); border: 1px solid var(--border); }
.timeline .stop-item { cursor: default; background: var(--surface-2); border-style: dashed; }
.timeline .stop-item:hover { border-color: var(--border); }
.timeline .sub { white-space: normal; }
.report-table td, .report-table th { white-space: nowrap; }
.report-table .num { text-align: right; }
.report-table tbody tr[data-v] { cursor: pointer; }
.report-table tbody tr:hover { background: var(--surface-2); }
.report-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.bar-cell { position: relative; display: flex; align-items: center; gap: 8px; }
.bar-cell .bar { display: block; height: 10px; border-radius: 5px; background: var(--accent); flex: none; }
.print-only { display: none; }

/* Yazdır / PDF: yalnızca rapor */
@media print {
    @page { margin: 12mm; }
    body { background: #fff; color: #000; overflow: visible; }
    .shell { display: block; height: auto; }
    .sidebar, .topbar, .bottom-nav, .no-print, .toast, .sheet, .sheet-backdrop { display: none !important; }
    .view { overflow: visible; }
    .page { max-width: none; padding: 0; }
    .print-only { display: block; }
    .report-head { font-size: 16px; margin-bottom: 10px; }
    .card, .stat, .item { box-shadow: none; break-inside: avoid; }
    .table-wrap { overflow: visible; }
    .report-table { font-size: 11px; }
    .report-table td, .report-table th { padding: 4px 6px; }
    a { color: inherit; text-decoration: none; }
}

/* ---------- yolcu paylaşımı (Faz 4) ---------- */
.card-actions.wrap { grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); }
.share-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; margin: 12px 0; }
.share-actions .act {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 64px;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
    font: inherit; font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.share-actions .act span { font-size: 22px; line-height: 1; }

/* ---------- MapLibre harita (geo.js) ---------- */
.map, .mini-map { background: var(--map-bg); }
.g-marker { cursor: pointer; }
.g-marker:hover { z-index: 1000 !important; }
.g-tooltip .maplibregl-popup-content { padding: 4px 8px; font-size: 12px; font-weight: 600; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.g-tooltip .maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-attrib { font-size: 10px; }
@media (max-width: 899px) { #fleetMap .maplibregl-ctrl-bottom-right { bottom: 58px; } } /* alt çekmecenin üstünde */

/* ---------- bakım (Faz 5) ---------- */
h2.sec { font-size: 15px; margin: 18px 0 8px; }
.bar-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; font-size: 14px; }
.bar-row:last-child { border-bottom: 0; }
.bar-row > span:first-child { font-weight: 600; }
.maint .item .sub { white-space: normal; }
