:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1d2330;
    --muted: #667085;
    --border: #dfe3ea;
    --accent: #1f5fbf;
    --accent-text: #ffffff;
    --sidebar: #172033;
    --sidebar-text: #c9d2e3;
    --sidebar-active: #ffffff;
    --danger: #c0262d;
    --danger-bg: #fdecec;
    --warn: #9a5b00;
    --warn-bg: #fff4dc;
    --hot-bg: #fff1f0;
    --done: #8a93a3;
    --radius: 6px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f141d;
        --surface: #171e2a;
        --surface-2: #1d2533;
        --text: #e4e8ef;
        --muted: #8e98aa;
        --border: #2a3344;
        --accent: #5b9bff;
        --accent-text: #0b1220;
        --sidebar: #0b1019;
        --sidebar-text: #9aa6bb;
        --danger: #ff7b7b;
        --danger-bg: #3a1a1c;
        --warn: #f0b44c;
        --warn-bg: #3a2c12;
        --hot-bg: #2e1a1a;
        --done: #5f687a;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
h1:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: .92em; }
.nowrap { white-space: nowrap; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 200px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1rem .75rem;
    gap: 1.25rem;
}

.brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: 0 .5rem; }
.brand span, .login-card h1 span { font-weight: 400; opacity: .75; margin-left: .15rem; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { text-transform: uppercase; font-size: .72rem; letter-spacing: .06em; padding: 0 .5rem .25rem; opacity: .7; }
.nav-group a { color: var(--sidebar-text); padding: .4rem .5rem; border-radius: var(--radius); }
.nav-group a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav-group a.active { background: rgba(255,255,255,.12); color: var(--sidebar-active); }

.nav-user { margin-top: auto; padding: 0 .5rem; font-size: .88rem; }
.nav-user-name { color: #fff; margin-bottom: .25rem; }
.link-button { background: none; border: 0; padding: 0; color: var(--sidebar-text); cursor: pointer; font: inherit; text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .5rem 1rem; gap: .5rem 1rem; }
    .nav-group { flex-direction: row; gap: .25rem; }
    .nav-label { display: none; }
    .nav-user { margin: 0 0 0 auto; display: flex; gap: .75rem; align-items: center; }
    .nav-user-name { margin: 0; }
    .content { padding: 1rem; }
}

/* ---- page head / toolbar ---- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head .toolbar { margin-bottom: 0; }

input, select, button {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .38rem .6rem;
}
input.wide { width: min(480px, 100%); }
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .6; cursor: default; }
button.primary, a.button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
a.button { display: inline-block; padding: .45rem .9rem; border-radius: var(--radius); }
a.button:hover { text-decoration: none; }

.check { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }
.check input { padding: 0; }

.segmented { display: inline-flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.segmented button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.segmented button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.alert { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: 1rem; }

/* ---- grids ---- */
.table-wrap {
    overflow: auto;
    max-height: calc(100vh - 150px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table.grid { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.grid th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    text-align: left;
    font-weight: 600;
    padding: .45rem .6rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    z-index: 1;
}
table.grid td { padding: .38rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tr.clickable { cursor: pointer; }
table.grid td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grid td.notes { max-width: 280px; color: var(--muted); }
table.grid td.empty { text-align: center; color: var(--muted); padding: 2rem; }

tr.row-hot { background: var(--hot-bg); }
tr.row-done td { color: var(--done); }
tr.row-oos td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.exp-past { color: var(--danger); font-weight: 600; }
.exp-soon { color: var(--warn); font-weight: 600; }

.badge {
    display: inline-block;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .03em;
    padding: 1px 5px;
    margin-left: 4px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    vertical-align: middle;
}
.badge.hot { background: var(--danger); color: #fff; border-color: var(--danger); }
.status { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* ---- order detail ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
dl.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem 1.25rem; margin: 0; }
.field dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field dd { margin: .1rem 0 0; }
.notes-block { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.notes-block p { margin: .25rem 0 0; white-space: pre-wrap; }

/* ---- login / error ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
    width: min(360px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.login-card h1 { margin-bottom: .25rem; }
.login-card label { font-size: .85rem; color: var(--muted); margin-top: .35rem; }
.login-card button { margin-top: .75rem; padding: .55rem; }
.login-card p { margin: 0 0 .25rem; }

/* ---- Blazor error bar ---- */
#blazor-error-ui {
    background: var(--warn-bg);
    color: var(--text);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
