:root {
    --primary: #0a84ff;
    --bg: #000000;
    --card: #1c1c1e;
    --text: #ffffff;
    --text2: #8e8e93;
    --separator: #38383a;
    --danger: #ff453a;

    --buy-bg: #0d3320;       --buy-fg: #32d74b;
    --sell-bg: #001f4d;      --sell-fg: #0a84ff;
    --repair-bg: #3d1f00;    --repair-fg: #ff9f0a;
    --fuel-bg: #3d2e00;      --fuel-fg: #ffd60a;
    --tax-bg: #3d0a08;       --tax-fg: #ff453a;
    --insurance-bg: #2c1a4d; --insurance-fg: #bf5af2;

    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    font-size: 16px;
    line-height: 1.4;
}

/* ── Navigation ──────────────────────────────── */
.nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(28,28,30,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--separator);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) 16px 0;
    height: calc(56px + env(safe-area-inset-top));
}

.nav-title {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    flex: 1;
}

.nav-left, .nav-right {
    min-width: 64px;
    display: flex;
    align-items: center;
}

.nav-right { justify-content: flex-end; }

.nav-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 17px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

/* ── Content ─────────────────────────────────── */
.content {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 96px;
}

/* ── Section label ───────────────────────────── */
.section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0 4px 8px;
}

/* ── Cards ───────────────────────────────────── */
.card {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ── Car list item ───────────────────────────── */
.car-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
    gap: 12px;
    border-bottom: 1px solid var(--separator);
}

.car-item:last-child { border-bottom: none; }

.car-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

.car-info { flex: 1; min-width: 0; }

.car-plate {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.car-name {
    font-size: 14px;
    color: var(--text2);
    margin-top: 2px;
}

.car-meta {
    font-size: 14px;
    color: var(--text2);
    text-align: right;
    flex-shrink: 0;
}

.car-km { font-weight: 600; color: var(--text); }

.chevron {
    color: var(--text2);
    font-size: 14px;
    margin-left: 4px;
}

/* ── Stats grid ──────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--card);
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.stat-label {
    font-size: 12px;
    color: var(--text2);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-value.highlight { color: var(--primary); }
.stat-value.small { font-size: 16px; }

/* ── Entry cards ─────────────────────────────── */
.entry-card {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.entry-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 10px;
    border-bottom: 1px solid var(--separator);
}

.type-badge {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}

.type-buy       { background: var(--buy-bg);        color: var(--buy-fg); }
.type-sell      { background: var(--sell-bg);       color: var(--sell-fg); }
.type-repair    { background: var(--repair-bg);     color: var(--repair-fg); }
.type-fuel      { background: var(--fuel-bg);       color: var(--fuel-fg); }
.type-tax       { background: var(--tax-bg);        color: var(--tax-fg); }
.type-insurance { background: var(--insurance-bg);  color: var(--insurance-fg); }

.entry-mileage {
    font-size: 15px;
    font-weight: 600;
    flex: 1;
}

.entry-date {
    font-size: 13px;
    color: var(--text2);
}

.entry-body {
    padding: 10px 16px;
}

.entry-cost {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.entry-fuel-details {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 4px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.entry-fuel-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.entry-notes {
    font-size: 14px;
    color: var(--text2);
    font-style: italic;
    margin-top: 4px;
}

.entry-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0 16px 10px;
}

.btn-delete {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 13px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 6px;
    min-height: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-delete:active { background: #ffd5d3; }

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    min-height: 50px;
    transition: opacity 0.15s;
}

.btn:active { opacity: 0.75; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
}

.btn-secondary {
    background: var(--separator);
    color: var(--text);
    width: 100%;
}

/* FAB */
.fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: var(--primary);
    color: #fff;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(0,122,255,0.4);
    transition: transform 0.15s;
    z-index: 50;
}

.fab:active { transform: scale(0.93); }

/* ── Forms ───────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 13px 14px;
    font-size: 17px;
    border: 1.5px solid var(--separator);
    border-radius: 10px;
    background: #2c2c2e;
    color: var(--text);
    appearance: none;
    -webkit-appearance: none;
    font-family: inherit;
    color-scheme: dark;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

textarea {
    min-height: 80px;
    resize: vertical;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    background: #2c2c2e;
    border-radius: 10px;
    border: 1.5px solid var(--separator);
}

.checkbox-row label {
    margin: 0;
    font-size: 17px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    flex: 1;
}

input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--primary);
    flex-shrink: 0;
}

/* ── Add Car form ─────────────────────────────── */
.add-car-form {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    margin-top: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.add-car-form h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 14px;
}

/* ── Empty state ─────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text2);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.empty-sub { font-size: 15px; }

/* ── Car detail header ───────────────────────── */
.car-header-card {
    background: var(--card);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 14px;
}

.car-header-icon { font-size: 40px; line-height: 1; }

.car-header-plate {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.car-header-name {
    font-size: 15px;
    color: var(--text2);
    margin-top: 2px;
}

/* ── Error banner ────────────────────────────── */
.error-banner {
    background: #ffd5d3;
    color: #aa1a14;
    border: 1.5px solid #ffb3b0;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 16px;
    line-height: 1.4;
}


/* ── Edit / action buttons on entries ───────── */
.entry-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 16px 10px;
    justify-content: flex-end;
}

.btn-edit {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 13px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 6px;
    min-height: 36px;
    display: flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
}

.btn-edit:active { background: rgba(0,122,255,0.1); }

/* ── Service intervals ───────────────────────── */
.interval-card {
    background: var(--card);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-left: 4px solid #34c759;
}

.interval-card.interval-warn    { border-left-color: #ff9500; }
.interval-card.interval-overdue { border-left-color: #ff3b30; }

.interval-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.interval-name {
    font-size: 16px;
    font-weight: 600;
}

.interval-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.badge-ok      { background: #d1f5dc; color: #1a7a3a; }
.badge-warn    { background: #ffe8c2; color: #a85800; }
.badge-overdue { background: #ffd5d3; color: #aa1a14; }

.interval-bar-bg {
    height: 6px;
    background: var(--separator);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.interval-bar {
    height: 100%;
    background: #34c759;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.interval-bar.bar-warn    { background: #ff9500; }
.interval-bar.bar-overdue { background: #ff3b30; }

.interval-meta {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 10px;
}

.interval-actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    min-height: 32px;
}

.btn-small-primary {
    background: var(--primary);
    color: #fff;
}

.btn-small-ghost {
    background: var(--separator);
    color: var(--text2);
}

/* ── Add details (collapsible form) ─────────── */
.add-details {
    background: var(--card);
    border-radius: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}

.add-details > summary {
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.add-details > summary::-webkit-details-marker { display: none; }
.add-details[open] > summary { border-bottom: 1px solid var(--separator); }

.add-details-form {
    padding: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ── Chart ───────────────────────────────────── */
.chart-card {
    padding: 16px;
    margin-bottom: 16px;
}

/* ── Annual breakdown table ──────────────────── */
.annual-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.annual-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.annual-table th {
    text-align: right;
    padding: 8px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text2);
    border-bottom: 1px solid var(--separator);
}

.annual-table th:first-child,
.annual-table td:first-child { text-align: left; }

.annual-table td {
    text-align: right;
    padding: 8px 6px;
    border-bottom: 1px solid var(--separator);
    white-space: nowrap;
}

.annual-table tbody tr:last-child td { border-bottom: none; }

.annual-year { font-weight: 700; }
.annual-total { font-weight: 700; color: var(--primary); }

.btn-delete:active { background: #3d0a08; }

.error-banner {
    background: #3d0a08;
    color: #ff6b6b;
    border-color: #5c1512;
}

.fab {
    box-shadow: 0 4px 14px rgba(10, 132, 255, 0.35);
}

.card,
.stat-card,
.entry-card,
.car-header-card,
.add-car-form,
.interval-card,
.add-details {
    box-shadow: none;
}

.badge-ok      { background: #0d3320; color: #32d74b; }
.badge-warn    { background: #3d1f00; color: #ff9f0a; }
.badge-overdue { background: #3d0a08; color: #ff453a; }

.btn-small-ghost { background: #2c2c2e; color: var(--text2); }
