: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;

    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);
        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; }
[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; }

/* ---------- 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 ---------- */
.shell { height: 100%; display: grid; grid-template-rows: var(--top-h) 1fr var(--nav-h); grid-template-columns: 1fr; }
.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; }
.bottom-nav a.active { color: var(--accent); font-weight: 600; }

@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; }

.veh-marker { position: relative; }
.veh-marker .dot {
    width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
    display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; background: currentColor;
}
.veh-marker .arrow { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid #fff; }
.veh-marker .label {
    position: absolute; top: 32px; 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 .dot { outline: 3px solid var(--accent); }

/* 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: 46%; display: flex; flex-direction: column;
    transition: max-height .2s ease;
}
.fleet-panel.collapsed { max-height: 54px; }
.fleet-panel .handle { padding: 8px 16px 6px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.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 .handle b { margin-top: 6px; }
.fleet-panel .rows { overflow: auto; padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.fleet-panel .item { padding: 10px; }
@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 { max-height: none; }
    .fleet-panel .handle::before { display: none; }
    .map-overlay { right: 360px; }
}

.vehicle-card { position: absolute; left: 10px; right: 10px; bottom: 64px; z-index: 5; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
@media (min-width: 900px) { .vehicle-card { left: 10px; right: auto; bottom: 10px; width: 360px; } }
.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; }
