:root {
    color-scheme: light;
    --ink: #202c27;
    --muted: #52645a;
    --line: #d6ded8;
    --paper: #fff;
    --surface: #f4f6f2;
    --accent: #245b46;
    --accent-hover: #184733;
    --danger: #923c32;
    font: 16px/1.5 system-ui, "PingFang TC", "Microsoft JhengHei", sans-serif;
    color: var(--ink);
    background: var(--surface);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-underline-offset: .18em; }
button, input, textarea, select { font: inherit; }
button, input, textarea, select { min-height: 44px; border-radius: .45rem; }
input, textarea, select {
    display: block;
    padding: .5rem .65rem;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border: 1px solid #a5b2a8;
    color: var(--ink);
    background: var(--paper);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 3px solid #528b70;
    outline-offset: 2px;
}
label { display: block; font-size: .94rem; font-weight: 620; }
label input, label select, label textarea { margin-top: .25rem; font-weight: 400; }
button {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: white;
    padding: .46rem 1rem;
    cursor: pointer;
    font-weight: 650;
}
button:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); border-color: var(--danger); }
h1, h2, h3, p { margin: 0 0 .75rem; }
h1 { font-size: clamp(1.5rem, 3vw, 2.05rem); line-height: 1.25; margin-bottom: 1.25rem; letter-spacing: -.03em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.workbench {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: start;
    gap: clamp(1rem, 2.2vw, 2rem);
    width: min(1460px, calc(100% - 3rem));
    margin: 0 auto;
    padding: 1.6rem 0 3rem;
}
.workspace-sidebar {
    position: sticky;
    top: 1.6rem;
    display: grid;
    gap: 1rem;
    max-height: calc(100dvh - 3.2rem);
    overflow: auto;
    padding: 1rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: .65rem;
}
.brand { color: var(--ink); display: inline-flex; align-items: center; gap: .55rem; text-decoration: none; font-weight: 750; width: fit-content; }
.brand b, .wordmark { color: var(--accent); font-size: 1.5rem; letter-spacing: -.055em; }
.workspace-nav { display: grid; gap: .25rem; }
.workspace-nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: .5rem .65rem;
    border-radius: .4rem;
    color: var(--muted);
    font-size: .93rem;
    text-decoration: none;
}
.workspace-nav a:hover { color: var(--accent); background: var(--surface); }
.workspace-nav a[aria-current="page"] {
    color: var(--accent);
    background: #e5f1ea;
    font-weight: 750;
    box-shadow: inset 3px 0 var(--accent);
}
.account {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .32rem .9rem;
    padding-top: .75rem;
    border-top: 1px solid var(--line);
    font-size: .85rem;
    color: var(--muted);
}
.account span { flex: 0 0 100%; overflow-wrap: anywhere; }
.workspace { min-width: 0; }
.batch-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    margin-bottom: .9rem;
    border-bottom: 1px solid var(--line);
}
.batch-tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: .5rem .75rem;
    border-radius: .4rem .4rem 0 0;
    color: var(--muted);
    font-size: .9rem;
    text-decoration: none;
}
.batch-tabs a:hover { background: var(--paper); color: var(--accent); }
.batch-tabs a[aria-current="page"] {
    background: #e5f1ea;
    color: var(--accent);
    font-weight: 750;
    box-shadow: inset 0 -3px var(--accent);
}
.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: .65rem;
    padding: 1rem 1.15rem;
    margin-bottom: .9rem;
}
.panel > :last-child, .panel > form:last-child > :last-child { margin-bottom: 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); align-items: end; gap: .75rem; }
.fields > button { justify-self: start; }
form:not(.fields) .fields, details[open] > form { margin-top: .75rem; }
.heading, .actions, .pager { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; margin-bottom: .55rem; }
.actions, .pager { margin-top: .85rem; }
.heading h2 { margin: 0; }
.badge { font-size: .82rem; color: #285442; background: #e5f1ea; padding: .18rem .5rem; border-radius: .3rem; }
.table-wrap { overflow: auto; }
.mobile-cell-label { display: none; }
table { border-collapse: collapse; text-align: left; width: 100%; min-width: 35rem; font-size: .92rem; }
th, td { padding: .52rem .65rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
th { color: #35483b; background: #edf2ed; font-size: .85rem; }
tr:last-child td { border-bottom: 0; }
td:nth-child(1) { font-variant-numeric: tabular-nums; }
.stock-overview-heading { justify-content: space-between; }
.stock-overview {
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.stock-overview th, .stock-overview td { vertical-align: top; border-right: 1px solid var(--line); }
.stock-overview th:last-child, .stock-overview td:last-child { border-right: 0; }
.stock-overview th:first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    min-width: 3.8rem;
    white-space: nowrap;
}
.stock-overview td { min-width: 9rem; }
.stock-overview-item {
    display: grid;
    gap: .1rem;
    min-height: 44px;
    padding: .25rem .35rem;
    border-radius: .35rem;
    text-decoration: none;
}
.stock-overview-item + .stock-overview-item { margin-top: .3rem; border-top: 1px solid var(--line); }
.stock-overview-item:hover { background: var(--surface); }
.stock-overview-item:hover strong { text-decoration: underline; }
.stock-overview-item > span { display: flex; justify-content: space-between; gap: .35rem; color: var(--muted); font-size: .83rem; }
.stock-overview-item b { color: var(--ink); font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .55rem 1rem; margin: .8rem 0; }
dt { color: var(--muted); font-size: .84rem; }
dd { margin: 0; overflow-wrap: anywhere; }
.muted, .empty { color: var(--muted); }
.notice { color: #624b1e; background: #f9f0d5; border-radius: .45rem; padding: .75rem .85rem; margin: .6rem 0 .9rem; overflow-wrap: anywhere; }
.notice.error { background: #f9e8e6; color: #792d26; }
.notice.success { background: #e7f3ea; color: #244f39; }
summary { cursor: pointer; font-weight: 700; }
details[open] > summary { margin-bottom: .6rem; }
.history { border-top: 1px solid var(--line); padding: .6rem 0; }
.history summary { font-weight: 550; }
.history .table-wrap { margin-top: .5rem; }
.unit-list { border: 1px solid var(--line); border-radius: .45rem; max-height: 20rem; overflow: auto; margin: .65rem 0; }
.check { display: flex; align-items: center; min-height: 44px; gap: .45rem; }
.check input { width: 1.08rem; min-height: 1.08rem; margin: 0; flex: none; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.15rem; }
.login-panel { width: min(100%, 400px); padding: clamp(1.25rem, 6vw, 2.35rem); border: 1px solid var(--line); background: var(--paper); border-radius: .8rem; }
.login-panel .wordmark { font-weight: 800; margin-bottom: .65rem; }
.login-panel form { display: grid; gap: .85rem; }
.login-panel button { margin-top: .25rem; }
.reset-link { display: inline-block; font-size: .88rem; margin-top: 1rem; }
@media (max-width: 850px) {
    .workbench {
        grid-template-columns: minmax(0, 1fr);
        width: calc(100% - 1.5rem);
        padding-top: .75rem;
    }
    .workspace-sidebar {
        position: static;
        grid-template-columns: minmax(0, 1fr) minmax(0, auto);
        align-items: center;
        gap: .5rem .75rem;
        max-height: none;
        overflow: visible;
        padding: .7rem;
    }
    .workspace-nav {
        grid-column: 1 / -1;
        grid-row: 2;
        display: flex;
        flex-wrap: wrap;
    }
    .account {
        grid-column: 2;
        grid-row: 1;
        max-width: 12rem;
        justify-content: flex-end;
        text-align: right;
        padding: 0;
        border: 0;
    }
}
@media (max-width: 600px) {
    .workbench { width: calc(100% - 1.25rem); }
    .workspace-nav a { padding: .4rem .5rem; font-size: .85rem; }
    .panel { padding: .75rem; }
    .stock-table { min-width: 0; }
    .stock-table thead { clip-path: inset(50%); position: absolute; width: 1px; height: 1px; overflow: hidden; }
    .stock-table, .stock-table tbody { display: block; }
    .stock-table tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .55rem .8rem;
        padding: .7rem 0;
        border-bottom: 1px solid var(--line);
    }
    .stock-table tr:last-child { border-bottom: 0; }
    .stock-table td { display: block; padding: 0; border: 0; }
    .stock-table td:first-child { font-weight: 750; }
    .stock-table td:last-child { grid-column: 1 / -1; }
    .stock-table td:has(.cell-value:empty) { display: none; }
    .stock-table .mobile-cell-label { display: block; font-size: .8rem; font-weight: 500; color: var(--muted); }
}

.purchase-header { grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.purchase-items { min-width: 0; margin: 1rem 0 0; padding: .75rem; border: 1px solid var(--line); border-radius: .45rem; }
.purchase-items legend { padding: 0 .3rem; font-weight: 700; }
.purchase-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(7.5rem, 10rem) auto;
    align-items: end;
    gap: .65rem;
    margin-bottom: .65rem;
}
button.secondary { color: var(--accent); background: var(--paper); border-color: var(--line); }
button.secondary:hover { background: #e5f1ea; }
button.secondary:disabled { color: var(--muted); background: var(--surface); opacity: .65; cursor: default; }

@media (max-width: 600px) {
    .purchase-item { grid-template-columns: minmax(0, 1fr) auto; }
    .purchase-item label:first-child { grid-column: 1 / -1; }
}

.purchase-code { grid-column: 1 / -1; color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.purchase-code output { margin-left: .4rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.purchase-cutoff { grid-column: 1 / -1; }
.purchase-cutoff[hidden] { display: none; }
.batch-code { display: block; color: var(--muted); font-size: .85rem; }
