:root {
    --bg: #F8F4EC;
    --surface: #FFFFFF;
    --line: #E8E0D2;
    --fill: #F0EADD;
    --ink: #3B2A22;
    --muted: #7A6A5C;
    --faint: #A99A87;
    --red: #C2262A;
    --red-dark: #9A1B20;
    --red-tint: #F9E9E7;
    --amber: #8A6009;
    --amber-tint: #FBF3E0;
    --font-body: 'Public Sans', system-ui, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-display: 'Bricolage Grotesque', 'Public Sans', system-ui, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --radius: 12px;
    --radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.45;
}

h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.01em; margin: 0 0 0.5rem 0; }
h1 { font-size: 1.6rem; } h3 { font-size: 1.35rem; } h4 { font-size: 1.05rem; }
a { color: var(--red); } a:hover { color: var(--red-dark); }
label { font-size: 0.85rem; font-weight: 600; color: var(--muted); display: inline-flex; flex-direction: column; gap: 0.3rem; }
/* Checkbox labels lay out inline (checkbox beside text), not stacked like input labels. */
label:has(> input[type=checkbox]) { flex-direction: row; align-items: center; gap: 0.45rem; }

/* ---- shared components ---- */
.page-head { margin: 0 0 1rem 0; }

/* Filter/edit control rows (shared by most pages; a bottom alignment keeps
   44px inputs, stacked labels, buttons, and checkbox labels on one baseline). */
.controls { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem; align-items: flex-end; }
.controls label:has(> input[type=checkbox]) { min-height: 44px; }
.sub { color: var(--muted); font-size: 0.9rem; }

.card {
    background: var(--surface);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 0.85rem;
}

.pill {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    white-space: nowrap;
}
.pill-neutral { background: var(--fill); color: var(--muted); }
.pill-active { background: var(--red-tint); color: var(--red-dark); }
.pill-warn { background: var(--amber-tint); color: var(--amber); }

button, .btn {
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    min-height: 44px;
    padding: 0 1.1rem;
    border-radius: var(--radius);
    border: 1.5px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
.btn-primary, button[type=submit] { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled), button[type=submit]:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-outline { background: transparent; border-color: var(--red); color: var(--red); }

input, select, .field {
    font-family: var(--font-body);
    font-size: 1rem;
    min-height: 44px;
    padding: 0 0.75rem;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
}
/* Inline warning row (e.g. missing UoM conversion on the item page). */
.conv-warn { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
    background: var(--amber-tint); border: 1.5px solid var(--amber); border-radius: var(--radius);
    padding: 0.5rem 0.75rem; font-size: 0.92rem; }
.conv-warn button { min-height: 36px; padding: 0 0.7rem; font-size: 0.85rem; }

/* Checkboxes must not inherit the 44px text-input frame. */
input[type=checkbox] { min-height: 0; width: 1.2rem; height: 1.2rem; padding: 0; margin: 0; accent-color: var(--red); }
input:focus, select:focus { outline: 2px solid var(--red); outline-offset: -1px; border-color: var(--red); }

.table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th { background: var(--bg); color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; text-align: left; padding: 0.7rem 0.85rem; border-bottom: 1.5px solid var(--line); }
.table td { padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--fill); font-size: 0.92rem; }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.name-zh { color: var(--muted); margin-left: 0.35em; }

/* ---- Blazor-required rules (kept from template) ---- */
h1:focus { outline: none; }
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid var(--red); }
.validation-message { color: var(--red); }
.darker-border-checkbox.form-check-input { border-color: #929292; }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred."
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}

/* Toasts */
.toast-stack { position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 1000; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: 0 6px 24px rgba(59,42,34,.18);
  font-size: 15px; cursor: pointer; animation: toast-in .2s ease-out; }
.toast-icon { display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; font-weight: 700; flex: none; }
.toast-success { border-color: #BFDCC4; background: #EFF7F0; }
.toast-success .toast-icon { background: #2E7D43; color: #fff; }
.toast-error { border-color: #E9B8B6; background: #FBEFEE; }
.toast-error .toast-icon { background: var(--red); color: #fff; }
.toast-info { border-color: #E8D9B8; background: var(--amber-tint); }
.toast-info .toast-icon { background: var(--amber); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
/* Two live regions share the stack (polite + assertive); an empty one must not add a gap. */
.toast-region { display: flex; flex-direction: column; gap: 8px; }
.toast-region:empty { display: none; }
/* Errors never expire on a timer, so they get a real dismiss control instead of
   "click anywhere on the toast", which is undiscoverable and easy to trigger by accident. */
.toast-sticky { cursor: default; }
.toast-dismiss { flex: none; min-height: 28px; width: 28px; padding: 0; margin-left: auto;
    border: none; background: none; color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; }
.toast-dismiss:hover { color: var(--ink); }
@media (max-width: 768px) { .toast-stack { top: 12px; } }

/* In-flight indicator for slow actions (see Components/BusyTracker.cs). */
.spinner {
    display: inline-block; width: 1rem; height: 1rem; border-radius: 50%; flex: none;
    border: 2px solid var(--fill); border-top-color: var(--red);
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Inline "what is happening" note beside a busy button. */
.busy-note { display: inline-flex; align-items: center; gap: 0.5rem; margin-left: 0.75rem;
    color: var(--muted); font-size: 0.85rem; }

/* Two-step confirm (Components/Shared/ConfirmButton.razor). */
.confirm-wrap { display: inline-flex; align-items: center; gap: 0.35rem; }
.confirm-yes { background: var(--red); border-color: var(--red); color: #fff; }
.confirm-yes:hover:not(:disabled) { background: var(--red-dark); border-color: var(--red-dark); }
.confirm-no { background: none; border-color: var(--line); color: var(--muted); }

/* Inline "Saved HH:mm:ss" note. Orders and the stock take page each define this in their
   own scoped stylesheet, where it cannot reach any other component — so any page that
   writes a .save-note without one of its own used to render it as bare unstyled text.
   This is the shared fallback; the scoped rules still win where they exist. */
.save-note { color: var(--muted); font-size: 0.85rem; }

/* One-time reveal of a freshly minted API token (Components/Pages/Tokens.razor).
   The secret is 68 characters and shown exactly once, so it gets a full-width field
   the user can select in one gesture rather than a <code> run they must drag across. */
.token-reveal { border-color: var(--amber); background: var(--amber-tint); }
.token-reveal-field { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.6rem 0 0.85rem 0; width: 100%; }
.token-reveal-field .field-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.token-value { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.95rem; background: var(--surface); }
.token-reveal-actions { margin-bottom: 0; }

/* ---- narrow screens ----
   The app is used on phones on the shop floor. Control rows stop being a flex row and
   become a stack, tables keep their own horizontal scroller (never the page body), and
   the long token field wraps instead of forcing the layout wide. */
@media (max-width: 640px) {
    body { overflow-x: hidden; }
    .controls { flex-direction: column; align-items: stretch; gap: 0.6rem; }
    .controls > label, .controls > button, .controls > .confirm-wrap { width: 100%; }
    /* Inline widths set per page (style="width:16em") must not win on a 360px screen. */
    .controls label > input, .controls label > select,
    .controls > input, .controls > select { width: 100% !important; }
    .controls label:has(> input[type=checkbox]) { width: auto; }
    .table-wrap { -webkit-overflow-scrolling: touch; }
    .table th, .table td { padding: 0.55rem 0.6rem; }
    .toast-stack { width: calc(100vw - 24px); }
    .token-value { font-size: 0.85rem; }
    .token-reveal-actions { flex-direction: column; }
}

/* Listings: the pager under every list, and the text-styled buttons in filter bars. */
.pager { display: flex; align-items: center; gap: 0.75rem; margin: 1rem 0; }
.pager-range { color: var(--muted); }
.link-btn { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; min-height: 44px; }
.list-row-link { text-decoration: none; }
