/* ===========================================================================
   SIEMAG Mileage Tracker
   Built on the shared SIEMAG design system (navy/blue, Barlow), with a
   mobile-first layer on top - this app is used from a phone most of the time.
   =========================================================================== */
:root {
    --bg:      #f4f6f9;
    --bg2:     #ffffff;
    --accent:  #1a5c9e;
    --accent2: #2272c3;
    --navy:    #1a2332;
    --text:    #1a2332;
    --muted:   #5a6a7a;
    --border:  #d0d7e0;
    --danger:  #c0392b;
    --success: #1e8449;
    --warn:    #c8820a;
    --zero:    #b8c2ce;
    --shadow:  0 1px 3px rgba(0,0,0,0.08);
    --nav-h:   64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Barlow', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---- Nav ---- */
nav {
    background: var(--navy);
    border-bottom: 3px solid var(--accent);
    display: flex; align-items: stretch; padding: 0; min-height: var(--nav-h);
    position: sticky; top: 0; z-index: 50;
}
.nav-brand {
    display: flex; align-items: center; gap: 14px;
    padding: 10px 24px; background: #ffffff;
    border-right: 3px solid var(--accent); text-decoration: none; flex: none;
}
.nav-brand:hover { text-decoration: none; }
.nav-brand img { height: 42px; width: auto; display: block; }
.nav-brand-text {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.95rem; font-weight: 700; color: var(--navy);
    letter-spacing: 0.08em; text-transform: uppercase;
}
.nav-links { display: flex; align-items: stretch; flex: 1; min-width: 0; }
nav a.nav-link {
    color: #ffffff; text-decoration: none; padding: 0 20px;
    font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em;
    text-transform: uppercase; transition: color 0.15s, background 0.15s;
    border-right: 1px solid #2e3d55; display: flex; align-items: center;
    white-space: nowrap;
}
nav a.nav-link:hover, nav a.nav-link.active {
    color: #ffffff; background: var(--accent2); text-decoration: none;
}
nav a.nav-out { margin-left: auto; border-right: none; color: #aeb9c7; }

.container { max-width: 1800px; margin: 0 auto; padding: 28px 24px; }

/* ---- Page header ---- */
.page-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    margin-bottom: 24px; padding-bottom: 16px; border-bottom: 2px solid var(--border);
    flex-wrap: wrap; gap: 16px;
}
.page-title {
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.8rem;
    font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text);
}
.page-title span { color: var(--accent); }
.page-sub { color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.page-sub strong { color: var(--text); }
.head-actions { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 18px; border: none; border-radius: 4px;
    font-family: 'Barlow', sans-serif; font-size: 0.85rem; font-weight: 500;
    letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer;
    text-decoration: none; transition: all 0.15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); color: #fff; text-decoration: none; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: #f0f5fc; text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e74c3c; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
/* The primary phone action - big enough to hit with a thumb. */
.btn-big { padding: 15px 28px; font-size: 1rem; font-weight: 600; width: 100%; max-width: 320px; }

.icon-btn {
    border: none; background: none; cursor: pointer; font-size: 15px;
    padding: 8px 10px; border-radius: 4px; color: var(--muted); line-height: 1;
}
.icon-btn:hover { background: #f0f5fc; color: var(--accent); text-decoration: none; }
.del-btn:hover { background: #fdf0ee; color: var(--danger); }

/* ---- Alerts ---- */
.alert { padding: 12px 18px; border-radius: 4px; margin-bottom: 20px; font-size: 0.9rem; border-left: 4px solid; }
.alert-success { background: #eafaf1; border-color: var(--success); color: #1a6e3c; }
.alert-warning { background: #fef9ec; border-color: var(--warn); color: #7d5a00; }
.alert-error,
.alert-danger { background: #fdf0ee; border-color: var(--danger); color: #922b21; }
.alert-info { background: #eaf4fb; border-color: #2980b9; color: #1a5276; }

/* ---- Stat pills ---- */
.stat-row { display: flex; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-pill {
    flex: 1; min-width: 130px;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    padding: 14px 20px; font-family: 'Barlow Condensed', sans-serif; box-shadow: var(--shadow);
}
.stat-pill.accent { background: var(--navy); border-color: var(--navy); }
.stat-pill.accent .stat-num { color: #fff; }
.stat-pill.accent .stat-lbl { color: #aeb9c7; }
.stat-num { font-size: 1.8rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-num.small { font-size: 1.35rem; }
.stat-lbl { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-top: 4px; }
.stat-row-compact .stat-pill { padding: 11px 16px; min-width: 100px; }
.stat-row-compact .stat-num { font-size: 1.45rem; }

/* ---- Filter bar / sort labels ---- */
.filter-bar {
    display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px;
}
.sort-label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.sort-label select {
    display: block; margin-top: 6px; padding: 9px 12px; background: #fff; color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    font-family: 'Barlow', sans-serif; font-size: 0.9rem; cursor: pointer;
}

/* ---- Table ---- */
/* No overflow wrapper on wide screens, so the sticky header resolves against
   the viewport (native sticky breaks inside an overflow-x container). */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); }
@media (max-width: 1200px) { .table-wrap { overflow-x: auto; } }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.grid thead tr { background: #f8f9fb; }
table.grid th {
    padding: 12px 14px; text-align: left; font-family: 'Barlow Condensed', sans-serif;
    font-size: 1rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--navy); border-bottom: 2px solid var(--border);
    white-space: nowrap; position: sticky; top: 67px; background: #f8f9fb; z-index: 20;
}
table.grid td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover td { background: #f0f5fc; }
table.grid td.company { font-weight: 500; }
.zero { color: var(--zero); }
table.grid tfoot td {
    border-top: 2px solid var(--navy); background: #f8f9fb;
    font-variant-numeric: tabular-nums; font-weight: 700;
}
.actions-col { text-align: center; width: 84px; }

/* ---- Cards ---- */
/* Deliberately NO `overflow` here. An overflow ancestor becomes the containing
   block for position:sticky, which would make the table headers below stick
   67px down INSIDE the card - landing on top of the first data row - instead of
   against the viewport. Corner clipping is handled per-corner further down. */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); }
.card-header {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    font-family: 'Barlow Condensed', sans-serif; font-size: 0.9rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
    background: #f8f9fb;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 20px; }
.entry-card { border-top: 4px solid var(--accent); }
.card > .card-header:first-child { border-radius: 6px 6px 0 0; }

/* A table nested in a card: the card already draws the frame, so drop the
   wrapper's own border/shadow and let the last row round off the card. */
.card > .table-wrap {
    border: none; border-radius: 0 0 6px 6px; box-shadow: none; background: transparent;
}
.card > .table-wrap table.grid tbody tr:last-child td,
.card > .table-wrap table.grid tfoot tr:last-child td { border-bottom: none; }

/* Two side-by-side cards that stack on narrow screens. */
.report-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 22px; }
.field-wide { grid-column: 1 / -1; }
.field { display: block; }
.field-label {
    display: block; margin-bottom: 6px; font-size: 0.78rem; font-weight: 600;
    letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.field-label em { font-style: normal; font-weight: 400; text-transform: none; letter-spacing: 0; }
.field input, .field select, .modal input.minput {
    width: 100%; padding: 11px 13px; background: #fff; color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    font-family: 'Barlow', sans-serif; font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .modal input.minput:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,92,158,0.12);
}
/* The mileage box is the number you glance at before hitting Save. */
.miles-input { font-size: 1.35rem !important; font-weight: 600; font-variant-numeric: tabular-nums; }
.field-hint { display: block; margin-top: 6px; font-size: 0.8rem; color: var(--muted); line-height: 1.45; }
.field-hint.ok { color: var(--success); }
.field-hint.warn { color: var(--warn); }

/* The "+ Somewhere new..." name box that drops out of the To picker. */
.new-loc {
    margin-top: 10px; padding: 12px 14px;
    background: #f0f5fc; border: 1px solid var(--border);
    border-left: 3px solid var(--accent); border-radius: 4px;
}
.new-loc input {
    width: 100%; padding: 11px 13px; background: #fff; color: var(--text);
    border: 1px solid var(--border); border-radius: 4px;
    font-family: 'Barlow', sans-serif; font-size: 0.95rem;
}
.new-loc input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,92,158,0.12); }
.new-loc .field-hint { margin-top: 8px; }
.opt-new { font-weight: 600; color: var(--accent); }

.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 0.9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }

.inline-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 160px; }
.field-narrow { flex: 0 0 130px !important; min-width: 110px !important; }
.edit-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---- Tags ---- */
.tag {
    display: inline-block; padding: 2px 9px; border-radius: 11px;
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
}
.tag-on   { background: #eafaf1; color: #1a6e3c; }
.tag-off  { background: #eef1f5; color: var(--muted); }
.tag-home { background: #eaf4fb; color: #1a5276; margin-left: 8px; }

/* ---- Modal ---- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(26,35,50,.55);
    align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff; border-radius: 6px; width: 100%; max-width: 540px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3); border-top: 4px solid var(--accent);
    max-height: 92vh; overflow-y: auto;
}
.modal-head {
    padding: 16px 22px; border-bottom: 1px solid var(--border);
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.15rem; font-weight: 700;
    letter-spacing: 0.05em; text-transform: uppercase; color: var(--text);
}
.modal-body { padding: 22px; }
.modal-body .field { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ---- Login ---- */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 20px; background: var(--bg);
}
.login-card {
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    border-top: 4px solid var(--accent); box-shadow: 0 6px 24px rgba(0,0,0,.10);
    padding: 34px 32px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo { height: 46px; width: auto; margin: 0 auto 14px; display: block; }
.login-title {
    font-family: 'Barlow Condensed', sans-serif; font-size: 1.15rem; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase; color: var(--navy);
    margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.login-hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 12px; }
.login-card input {
    width: 100%; padding: 13px 14px; border: 1px solid var(--border); border-radius: 5px;
    font-size: 1rem; margin-bottom: 16px; text-align: center; letter-spacing: 3px;
    font-family: 'Barlow', sans-serif;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(26,92,158,0.12); }
.login-card .btn { width: 100%; justify-content: center; padding: 13px; font-size: 0.95rem; }
.login-card .alert { text-align: left; }

/* ---- Footer ---- */
.foot {
    display: flex; justify-content: space-between; align-items: center;
    max-width: 1800px; margin: 20px auto 0; padding: 20px 24px 30px;
    border-top: 1px solid var(--border); color: var(--muted); font-size: 0.8rem;
}
.foot .mono { font-family: 'Barlow Condensed', sans-serif; letter-spacing: 0.05em; text-transform: uppercase; }

/* ===========================================================================
   MOBILE. Most entries happen on a phone, so this is the case that matters.
   =========================================================================== */
@media (max-width: 1000px) {
    .report-cols { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    :root { --nav-h: 56px; }

    /* Brand row on top, nav links in a swipeable strip beneath it. */
    nav { flex-direction: column; padding: 0; }
    .nav-brand { padding: 8px 16px; border-right: none; width: 100%; gap: 10px; }
    .nav-brand img { height: 32px; }
    .nav-brand-text { font-size: 0.85rem; }
    .nav-links {
        width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; background: var(--navy);
    }
    .nav-links::-webkit-scrollbar { display: none; }
    nav a.nav-link { padding: 13px 16px; font-size: 0.78rem; }
    nav a.nav-out { margin-left: 0; }

    .container { padding: 18px 14px; }

    .page-header { margin-bottom: 18px; align-items: flex-start; }
    .page-title { font-size: 1.45rem; }
    .head-actions { width: 100%; }
    .head-actions .btn { flex: 1; }

    /* One field per row - no side-by-side inputs on a phone. */
    .form-grid { grid-template-columns: 1fr; gap: 16px; }
    .inline-form { flex-direction: column; align-items: stretch; }
    .inline-form .field, .field-narrow { flex: 1 1 auto !important; min-width: 0 !important; }
    .inline-form .btn { width: 100%; }
    .btn-big { max-width: none; }

    /* 16px minimum stops iOS Safari zooming in when a field is focused. */
    .field input, .field select, .sort-label select, .login-card input,
    .new-loc input { font-size: 16px; }
    .miles-input { font-size: 1.5rem !important; }

    .filter-bar { gap: 12px; }
    .filter-bar .sort-label { flex: 1; min-width: 140px; }

    /* Secondary columns are dropped rather than squeezed; the full record is
       always one tap away on the edit page. */
    .hide-sm { display: none !important; }
    table.grid { font-size: 0.85rem; }
    table.grid th { position: static; font-size: 0.85rem; padding: 10px; }
    table.grid td { padding: 12px 10px; }
    .actions-col { width: 60px; }

    .stat-row { gap: 10px; }
    .stat-pill { min-width: 0; padding: 12px 14px; }
    .stat-row-compact .stat-num { font-size: 1.25rem; }
    .stat-num.small { font-size: 1.05rem; }

    .card-body { padding: 16px; }
    .modal-actions .btn { flex: 1; }
    .foot { flex-direction: column; gap: 6px; text-align: center; }
}
