:root {
    --bg: #eef3f8;
    --bg-alt: linear-gradient(180deg, #f7f9fc 0%, #edf2f7 100%);
    --panel: rgba(255, 255, 255, 0.94);
    --panel-strong: #ffffff;
    --surface-muted: #f7f9fc;
    --text: #17212f;
    --muted: #5f6f86;
    --border: rgba(31, 52, 84, 0.12);
    --brand: #c49644;
    --brand-strong: #8a6223;
    --accent: #1f4b7a;
    --danger: #c2413b;
    --warning: #d98c10;
    --shadow: 0 18px 40px rgba(19, 38, 68, 0.09);
}

[data-theme="dark"] {
    --bg: #0f1722;
    --bg-alt: radial-gradient(circle at top, #18314f 0%, #0f1722 58%);
    --panel: rgba(18, 27, 39, 0.94);
    --panel-strong: #162131;
    --surface-muted: #111b29;
    --text: #edf3ff;
    --muted: #a3b2c7;
    --border: rgba(203, 216, 236, 0.12);
    --brand: #ddb173;
    --brand-strong: #f0cf9a;
    --accent: #7fb1eb;
    --danger: #f97066;
    --warning: #fdb022;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: var(--bg-alt);
    color: var(--text);
}
a { color: inherit; text-decoration: none; }
a:focus-visible,
button:focus-visible,
.primary-btn:focus-visible,
.ghost-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(31, 75, 122, 0.24);
    outline-offset: 2px;
}
code { background: rgba(0,0,0,0.08); padding: 0.15rem 0.35rem; border-radius: 6px; }
img { max-width: 100%; display: block; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
    padding: 1.5rem;
    background: linear-gradient(180deg, rgba(16, 28, 44, 0.98), rgba(12, 21, 33, 0.98));
    color: #ecf5f7;
    border-right: 1px solid rgba(255,255,255,0.08);
}
.brand-block { display: flex; gap: 14px; align-items: flex-start; padding-bottom: 1rem; border-bottom: 1px solid rgba(255,255,255,0.08); }
.brand-mark {
    width: 62px;
    min-width: 62px;
    height: 62px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.18);
}
.brand-mark img { width: 100%; height: auto; object-fit: contain; }
.brand-copy h1 { font-size: 1.18rem; margin: 0.2rem 0; }
.brand-copy p { margin: 0; }
.brand-copy small { display: block; margin-top: 0.35rem; line-height: 1.45; }
.brand-block p, .nav-label, .eyebrow, .muted, small { color: var(--muted); }
.sidebar .eyebrow, .sidebar .nav-label, .sidebar p, .sidebar small { color: rgba(236,245,247,0.74); }
.nav-group { margin-top: 1.6rem; display: grid; gap: 0.35rem; }
.nav-group a {
    padding: 0.62rem 0.82rem;
    border-radius: 10px;
    color: #f0fbff;
    border: 1px solid transparent;
}
.nav-group a:hover, .nav-group a.active { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.06); }

.content { padding: 1.5rem 1.7rem 2.25rem; }
.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.4rem;
}
.topbar-title { font-size: 1.55rem; font-weight: 700; }
.topbar-copy p { margin: 0.35rem 0 0; color: var(--muted); max-width: 54rem; }
.topbar-actions { display: flex; align-items: center; gap: 0.8rem; }
.user-chip {
    display: flex;
    flex-direction: column;
    padding: 0.65rem 0.8rem;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
}
.hero-card, .panel, .stat-card, .delivery-card, .login-panel {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}
.hero-card::before, .panel::before, .stat-card::before, .delivery-card::before, .login-panel::before {
    content: "";
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--brand), var(--accent));
}
.page-intro {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 1.25rem 1.35rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(196,150,68,0.08), rgba(31,75,122,0.04));
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.page-intro h3 { margin: 0.2rem 0 0.45rem; }
.page-intro p { margin: 0.4rem 0 0; color: var(--muted); line-height: 1.6; max-width: 60rem; }
.hero-card {
    padding: 1.4rem;
    border-radius: 18px;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1.25rem;
}
.compact-hero { margin-bottom: 1rem; }
.hero-card h2, .panel h3 { margin: 0.2rem 0 0.45rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.primary-btn, .ghost-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    padding: 0.78rem 1rem;
    border: 1px solid var(--border);
    cursor: pointer;
    font-weight: 600;
}
.primary-btn { background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: white; border: none; }
.ghost-btn { background: var(--panel-strong); color: var(--text); }

.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 1.2rem; }
.stat-card {
    padding: 1rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.stat-card strong { font-size: 2rem; }
.stat-card.alert strong { color: var(--danger); }

.page-grid, .split-layout, .three-col { display: grid; gap: 1rem; }
.page-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.split-layout { grid-template-columns: 1.55fr 1fr; }
.split-layout.wide { grid-template-columns: 1.8fr 1.2fr; }
.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.full-span { grid-column: 1 / -1; }
.narrow { max-width: 720px; }
.panel { border-radius: 18px; padding: 1.15rem; overflow: hidden; }
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 1rem;
    margin-bottom: 0.9rem;
}

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 0.8rem 0.72rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.data-table th {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.78rem;
}
.data-table td strong, .data-table td small { display: block; }
.data-table.dense th, .data-table.dense td { padding: 0.6rem; }

.stack-form { display: grid; gap: 0.8rem; }
.stack-form.compact { margin-top: 1rem; }
.stack-form label { display: grid; gap: 0.35rem; font-weight: 600; }
input, select, textarea {
    width: 100%;
    padding: 0.72rem 0.82rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel-strong);
    color: var(--text);
    font: inherit;
}
textarea { min-height: 92px; resize: vertical; }
button:disabled,
.primary-btn:disabled,
.ghost-btn:disabled {
    opacity: 0.62;
    cursor: not-allowed;
}

.badge {
    display: inline-flex;
    padding: 0.35rem 0.72rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(31, 75, 122, 0.12);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 700;
}
.badge.delayed, .badge.missed { background: rgba(178, 68, 68, 0.16); color: var(--danger); }
.badge.partial { background: rgba(213, 138, 0, 0.16); color: var(--warning); }
.badge.completed, .badge.on-track, .badge.on_track { background: rgba(196, 150, 68, 0.16); color: var(--brand-strong); }

.progress-shell { display: flex; align-items: center; gap: 0.7rem; min-width: 170px; }
.progress-bar {
    width: 100%;
    height: 10px;
    background: rgba(128, 140, 161, 0.18);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(135deg, var(--brand), var(--brand-strong));
}

.list-stack, .timeline { display: grid; gap: 0.75rem; }
.list-item, .timeline-item, .inline-card {
    display: grid;
    gap: 0.18rem;
    padding: 0.9rem;
    border-radius: 14px;
    background: var(--surface-muted);
}
.inline-card a,
.list-item a {
    color: var(--accent);
    font-weight: 700;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 1rem; }
.delivery-card { border-radius: 16px; padding: 1rem; }
.delivery-head { display: flex; justify-content: space-between; gap: 0.75rem; }
.delivery-head span, .delivery-meta { color: var(--muted); }
.carry-chip {
    display: inline-block;
    margin: 0.8rem 0;
    padding: 0.5rem 0.7rem;
    border-radius: 12px;
    background: rgba(213, 138, 0, 0.15);
    color: var(--warning);
    font-weight: 600;
}

.filter-row, .weekday-grid, .triple, .pill-stack { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.inline-toggle { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; }
.inline-toggle input { width: auto; }
.subgrid-rows { display: grid; gap: 0.85rem; }
.triple > * { flex: 1; }

.flash-stack { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.flash {
    padding: 0.85rem 1rem;
    border-radius: 14px;
    background: rgba(13, 107, 95, 0.12);
    border: 1px solid var(--border);
}
.flash.error { background: rgba(178, 68, 68, 0.15); }

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}
.login-panel {
    width: min(520px, 100%);
    padding: 2rem;
    border-radius: 22px;
}
.login-brand { width: 92px; margin-bottom: 1rem; }
.login-note { margin-top: 1rem; color: var(--muted); }

@media (max-width: 1180px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .split-layout, .split-layout.wide, .three-col, .page-grid { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { padding-bottom: 0.75rem; }
    .content { padding: 1rem; }
    .topbar, .hero-card, .page-intro { flex-direction: column; align-items: stretch; }
    .stat-grid { grid-template-columns: 1fr; }
}
