:root {
    color-scheme: light;
    --bg: #e7f0f0;
    --ink: #14262b;
    --muted: #5d7178;
    --line: #d3e0e2;
    --card: #ffffff;
    --teal: #0c6b6b;
    --teal-dark: #0c3d3d;
    --teal-soft: #e5f3f3;
    --amber: #8a5a00;
    --amber-bg: #fff4dc;
    --red: #9f1d1d;
    --red-bg: #fdecea;
    --green: #0f6b45;
    --green-bg: #e5f6ee;
    --orange: #c46b2d;
    --shadow: 0 12px 32px rgba(12, 61, 61, 0.08);
    --radius: 18px;
    --nav-h: 68px;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--ink);
    min-height: 100dvh;
}
a { color: var(--teal-dark); }
img { max-width: 100%; }

.sidebar { display: none; }
.shell { min-height: 100dvh; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-end;
    background: var(--teal-dark);
    color: white;
    padding: calc(12px + env(safe-area-inset-top)) 16px 14px;
}
.topbar h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.03em; }
.eyebrow { margin: 0 0 2px; font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.75; }
.who {
    margin: 0;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
    opacity: 0.9;
}
main { padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); }
.bare-main {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px 16px;
}

.auth-card, .panel, .form-card, .rowcard, .tile, .table-wrap, .chart-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.auth-card, .form-card { padding: 22px 18px; }
.auth-card { width: min(440px, 100%); margin: 0 auto; }
.brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand-lockup h1 { margin: 0; }
.brand-mark, .brand .brand-mark {
    display: inline-grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--teal);
    color: white;
    font-weight: 800;
    letter-spacing: 0.04em;
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.7rem; }
.lead { color: var(--muted); margin: 0 0 18px; line-height: 1.45; }
.form-card { max-width: 680px; }
.form-card h2, .panel h2 { margin: 0 0 12px; font-size: 1.15rem; }

label { display: block; font-size: 0.92rem; font-weight: 700; margin: 14px 0 6px; }
input, select, textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    color: inherit;
    background: white;
}
textarea { min-height: 96px; resize: vertical; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; line-height: 1.4; }
.check { display: flex; align-items: center; gap: 10px; margin: 16px 0; font-weight: 650; }
.check input { width: 22px; height: 22px; min-height: 0; }

.button, button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 14px;
    border: 0;
    background: var(--teal);
    color: white;
    font: inherit;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}
.button.full { width: 100%; margin-top: 16px; }
.button.ghost { background: transparent; color: var(--teal-dark); box-shadow: inset 0 0 0 1.5px var(--teal); }
.button.danger { background: var(--red); }
.button.small, a.mini {
    min-height: 40px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 0.92rem;
}
a.mini {
    display: inline-flex;
    align-items: center;
    background: var(--teal);
    color: white;
    text-decoration: none;
    font-weight: 700;
}
a.mini.ghost { background: transparent; color: var(--teal-dark); box-shadow: inset 0 0 0 1.5px var(--teal); }
.text-link { font-weight: 700; }

.alert {
    border-radius: 14px;
    padding: 12px 14px;
    margin: 0 0 14px;
    line-height: 1.4;
}
.alert.ok { background: var(--green-bg); color: var(--green); }
.alert.warn { background: var(--amber-bg); color: var(--amber); }
.alert.bad { background: var(--red-bg); color: var(--red); }
a.alert { display: block; text-decoration: none; font-weight: 700; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.tile {
    display: block;
    padding: 14px;
    text-decoration: none;
    color: inherit;
    border: 2px solid transparent;
}
.tile strong { display: block; font-size: 1.6rem; letter-spacing: -0.04em; }
.tile span { color: var(--muted); font-size: 0.88rem; }
.tile.active { border-color: var(--teal); background: var(--teal-soft); }
.tile.neg strong { color: var(--red); }
.tile.low strong { color: var(--amber); }
.tile.zero strong { color: var(--muted); }

.search { margin: 4px 0 14px; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin: 8px 0; }
.muted { color: var(--muted); }
.actions-row { display: none; gap: 10px; margin-bottom: 14px; }

.stack { display: grid; gap: 10px; }
.rowcard { padding: 14px; border-left: 5px solid var(--teal); }
.rowcard.is-low { border-left-color: #e0a100; background: #fffaf0; }
.rowcard.is-zero { border-left-color: #b7c4c8; background: #f7f9f9; }
.rowcard.is-neg { border-left-color: var(--red); background: var(--red-bg); }
.rowcard header, .card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rowcard h2, .card-top h2 { margin: 0; font-size: 1.05rem; line-height: 1.3; }
.rowcard h2 a, .name-link { color: inherit; text-decoration: none; }
.stocknum { margin: 8px 0 0; font-size: 1.45rem; font-weight: 800; letter-spacing: -0.04em; }
.stocknum small { display: block; font-size: 0.95rem; font-weight: 650; color: var(--muted); margin-top: 2px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }
.badge {
    flex: none;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 800;
    background: var(--teal-soft);
    color: var(--teal-dark);
}
.badge.low { background: var(--amber-bg); color: var(--amber); }
.badge.zero { background: #e8eeef; color: #607077; }
.badge.neg { background: #f8d2ce; color: var(--red); }
.badge.review { background: var(--amber-bg); color: var(--amber); }
.meta { margin: 6px 0 0; color: var(--muted); font-size: 0.88rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
tr.is-low td { background: #fffaf0; }
tr.is-zero td { background: #f7f9f9; }
tr.is-neg td { background: #fff6f5; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.only-desktop { display: none; }

.picker { position: relative; }
.picker-panel {
    position: absolute;
    z-index: 15;
    left: 0;
    right: 0;
    top: calc(100% - 4px);
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    max-height: 260px;
    overflow: auto;
    box-shadow: var(--shadow);
}
.picker-option {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-height: 46px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: white;
    text-align: left;
    padding: 8px 12px;
    font: inherit;
    cursor: pointer;
}
.picker-option small { color: var(--muted); }
.picker-stock { min-height: 1.2em; margin: 8px 0 0; font-weight: 700; }
.picker-stock.low { color: var(--amber); }
.picker-stock.neg { color: var(--red); }
.picker-create { display: inline-block; margin-top: 8px; font-weight: 750; }
.filters { display: grid; gap: 10px; margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi {
    background: white;
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}
.kpi span { display: block; color: var(--muted); font-size: 0.82rem; }
.kpi strong { display: block; margin-top: 4px; font-size: 1.45rem; letter-spacing: -0.04em; }
.kpi em { font-style: normal; color: var(--muted); font-size: 0.85rem; }
.chart-card, .panel { padding: 14px; margin-bottom: 14px; }
.chart { display: flex; align-items: flex-end; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.chart .col { min-width: 52px; text-align: center; }
.chart .bars { height: 140px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart .bar { width: 14px; border-radius: 8px 8px 3px 3px; min-height: 0; }
.chart .bar.in { background: var(--teal); }
.chart .bar.out { background: var(--orange); }
.chart .label { display: block; margin-top: 6px; font-size: 0.72rem; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 0.85rem; color: var(--muted); margin: 0 0 8px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 99px; margin-right: 4px; }
.swatch.in { background: var(--teal); }
.swatch.out { background: var(--orange); }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; }
.user-card { padding: 14px; }
.user-card p { margin: 4px 0; }
.split { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.bottom-nav {
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    background: white;
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav > a, .bottom-nav summary {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    text-align: center;
    text-decoration: none;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 750;
    border-radius: 12px;
    list-style: none;
    cursor: pointer;
}
.bottom-nav > a.active, .bottom-nav details[open] summary { background: var(--teal-soft); color: var(--teal-dark); }
.bottom-nav summary::-webkit-details-marker { display: none; }
.more { position: relative; }
.more-panel {
    position: absolute;
    right: 0;
    bottom: 52px;
    width: 210px;
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 8px;
    display: flex;
    flex-direction: column;
}
.more-panel a { padding: 12px; border-radius: 10px; text-decoration: none; font-weight: 700; }
:focus-visible { outline: 3px solid #e2a20c; outline-offset: 2px; }

@media (min-width: 900px) {
    .sidebar {
        display: flex;
        flex-direction: column;
        position: fixed;
        inset: 0 auto 0 0;
        width: 240px;
        background: var(--teal-dark);
        color: #e7f4f4;
        padding: 22px 14px;
    }
    .brand { display: flex; align-items: center; gap: 10px; color: white; text-decoration: none; font-weight: 800; font-size: 1.15rem; }
    .side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 28px; }
    .side-nav a { color: inherit; text-decoration: none; padding: 12px 12px; border-radius: 12px; font-weight: 700; }
    .side-nav a.active, .side-nav a:hover { background: rgba(255, 255, 255, 0.12); }
    .side-user { margin-top: auto; padding: 12px; }
    .side-user p { margin: 0 0 8px; font-size: 0.92rem; }
    .side-user a { color: white; }
    .shell { margin-left: 240px; }
    .topbar { padding: 22px 28px 8px; background: transparent; color: var(--ink); position: static; }
    .eyebrow { color: var(--teal); opacity: 1; }
    .who { display: none; }
    .topbar h1 { font-size: 2rem; }
    main { padding: 8px 28px 48px; }
    .bottom-nav { display: none; }
    .only-mobile { display: none; }
    .only-desktop { display: block; }
    table.only-desktop { display: table; }
    .actions-row { display: flex; }
    .tiles, .kpis { grid-template-columns: repeat(4, 1fr); }
    .filters { grid-template-columns: 1.5fr repeat(4, minmax(120px, 1fr)) auto; align-items: end; }
    .filters button { margin-top: 0; }
}

@media print {
    .sidebar, .bottom-nav, .actions-row, .card-actions, .search, .filters { display: none !important; }
    .shell { margin: 0; }
    body, .topbar { background: white; color: black; }
    main { padding: 0; }
}
