/* Tahona WMS - legacy variable names.
   Every name here predates the token system and is still used by pages across the app, so each
   one is kept as an ALIAS of a token in tokens.css. Never put a literal color here: a literal is
   a value the light theme cannot override, and CssVariablesDefinedTests fails the build for it.
   New code uses the token names (--bg, --surface, --text, --accent, ...) directly. */

:root {
    --bg-primary: var(--bg);
    --bg-secondary: var(--bg-2);
    --bg-tertiary: var(--surface);
    --bg-hover: var(--surface-2);

    /* The old palette was seven pastels used decoratively. They now map onto the fixed status
       colors and the accent, so a page that reached for "pastel-yellow" to mean "caution" still
       reads as caution in both themes. */
    --pastel-blue: var(--info);
    --pastel-purple: var(--accent);
    --pastel-teal: var(--accent);
    --pastel-pink: var(--serious);
    --pastel-green: var(--good);
    --pastel-yellow: var(--warn);
    --pastel-orange: var(--serious);

    --text-primary: var(--text);
    --text-secondary: var(--text-2);
    --text-muted: var(--text-3);
    --text-disabled: var(--text-3);

    --success: var(--good);
    --warning: var(--warn);
    --error: var(--crit);

    /* --border-primary was the VISIBLE border and --border-secondary the quieter one; the token
       names invert that reading, so the mapping is deliberately crossed. */
    --border-primary: var(--border-2);
    --border-secondary: var(--border);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: var(--shadow-overlay);
    --shadow-xl: var(--shadow-overlay);

    --spacing-1: 4px;
    --spacing-2: 8px;
    --spacing-3: 12px;
    --spacing-4: 16px;
    --spacing-6: 24px;
    --spacing-8: 32px;
    --spacing-12: 48px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    font-feature-settings: "tnum" 1;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-4);
}

h1 { font-size: 32px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
h4 { font-size: 18px; }
h5 { font-size: 16px; }
h6 { font-size: 14px; }

p {
    margin-bottom: var(--spacing-4);
    color: var(--text-secondary);
}

/* Links */
a {
    color: var(--accent-fg);
    text-decoration: none;
    transition: color 150ms ease;
}

a:hover {
    color: var(--text);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 150ms ease;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

/* A dead button must look dead. Without this, a disabled .btn keeps its full colour and
   pointer cursor, and clicking it teaches an operator nothing — "nothing happens" was the
   whole bug report from the first demo walkthrough. Wins over the variant :hover rules by
   source order + the :disabled match, so a dead button also stops reacting to the mouse. */
.btn:disabled,
.btn:disabled:hover,
.btn:disabled:active {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* .btn-secondary:hover moves background and border-color, which the rule above does not
   declare — so a dead secondary button still reacted to the mouse. pointer-events: none
   would be simpler but it also suppresses the title tooltip, and the tooltip is the whole
   point of a dead button here. */
.btn-secondary:disabled:hover {
    background: var(--bg-secondary);
    border-color: var(--border-primary);
}

/* The primary action is the ONE place the accent appears as a fill. Flat, not a gradient: a
   tenant accent (Phase 3) has to stay legible against --accent-ink, and a two-stop gradient has
   no single contrast ratio to check. */
.btn-primary {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 4px 12px color-mix(in oklab, var(--accent) 35%, transparent);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
}

/* The destructive twin of .btn-primary (Confirm cancel on /orders). */
.btn-danger {
    background: var(--error);
    color: var(--bg-primary);
    font-weight: 600;
}

.btn-danger:hover {
    opacity: 0.9;
    box-shadow: 0 4px 12px color-mix(in oklab, var(--crit) 35%, transparent);
}

.btn-sm {
    padding: var(--spacing-2) var(--spacing-3);
    font-size: 13px;
}

/* Action controls inside a table row (e.g. Allocate / Cancel on /orders).
   .btn is inline-flex with no margin, so sibling buttons in a narrow cell sit flush
   against each other and wrap onto separate lines. This keeps them on one line with
   real space between, still wrapping gracefully when the column gets tight, and lines
   up any status badges shown instead of a button. */
.row-actions {
    display: flex;
    /* nowrap is load-bearing, not cosmetic: with wrapping allowed the flex container's
       min-content width is a single button, so the table hands this column too little
       room and the actions stack. Refusing to wrap makes the column claim the width the
       controls actually need, which is what keeps Allocate and Cancel on one line. The
       table already scrolls horizontally on narrow viewports. */
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--spacing-2);
}

.btn-lg {
    padding: var(--spacing-4) var(--spacing-6);
    font-size: 16px;
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-4);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-2);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea,
.form-control {
    width: 100%;
    padding: var(--spacing-3) var(--spacing-4);
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    transition: all 150ms ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-primary);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-input::placeholder,
.form-control::placeholder {
    color: var(--text-muted);
}

/* The compact size, on .btn-sm's scale, so an inline prompt's inputs and buttons read as one row. */
.form-control-sm {
    padding: var(--spacing-2) var(--spacing-3);
    font-size: 13px;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    color: var(--text-secondary);
}

.form-checkbox input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* Activity log filter bar */
.activity-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--spacing-3);
    align-items: end;
}

.activity-filters-actions {
    display: flex;
    gap: var(--spacing-2);
}

.activity-when {
    display: block;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--text-secondary);
}

/* A select in a table cell must never shrink to a bare arrow: on a phone the Members table
   squeezed the role control to nothing (live walk 2026-09-09). The card scrolls sideways
   instead, which the operator can see. */
.table select.form-input {
    min-width: 8.5rem;
}

/* A name is one token to a reader; "Andrew" over "Ewing" read as two people. */
.activity-actor {
    white-space: nowrap;
}

.activity-ago {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--spacing-6);
    margin-bottom: var(--spacing-6);
    box-shadow: var(--shadow-sm);
    transition: all 150ms ease;
}

.card:hover {
    border-color: var(--border-secondary);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-4);
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: var(--spacing-1);
}

.card-body {
    color: var(--text-secondary);
    /* Tablet/narrow viewports: let wide tables scroll inside the card instead of
       overflowing it and clipping trailing action columns past the viewport edge
       (uxqa j-003 receiving inventory, j-011 configured printers). On desktop the
       tables fit, so no scrollbar appears. position:relative makes this the
       containing block for absolutely-positioned descendants (e.g. .sr-only header
       text in action columns) so they are clipped by this scroll region rather than
       escaping to widen the page. */
    position: relative;
    overflow-x: auto;
    /* Scroll cue (UX evaluation 2026-10, finding 8): at handheld width the trailing action
       column (Picking's Open, Members' Remove, Printers, API keys) sat past the right edge with
       nothing to say so. Two shadow gradients are pinned to the box's edges (attachment: scroll)
       under two covers the colour of the card that move with the content (attachment: local).
       With no overflow the covers sit on the shadows and nothing shows; scrolled content slides
       a cover away and the shadow on that side appears. No script, no measuring. A row with its
       own opaque background (the table header) paints over the cue; the body rows show it. */
    background:
        linear-gradient(to right, var(--bg-secondary) 40%, transparent) left / 48px 100% no-repeat local,
        linear-gradient(to left, var(--bg-secondary) 40%, transparent) right / 48px 100% no-repeat local,
        linear-gradient(to right, color-mix(in oklab, var(--text-primary) 28%, transparent), transparent) left / 16px 100% no-repeat scroll,
        linear-gradient(to left, color-mix(in oklab, var(--text-primary) 28%, transparent), transparent) right / 16px 100% no-repeat scroll;
}

.card-footer {
    margin-top: var(--spacing-4);
    padding-top: var(--spacing-4);
    border-top: 1px solid var(--border-primary);
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table thead {
    background: var(--bg-tertiary);
}

/* 12px horizontal, not 16: eleven columns of 16px padding cost the Orders table 88px at
   1440 wide, which is what pushed its Actions column past the card edge with the horizontal
   scrollbar 48 rows below the fold — an operator saw "Ca" and no way to Cancel. */
.table th {
    padding: var(--spacing-3) var(--spacing-3);
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-primary);
}

.table td {
    padding: var(--spacing-3) var(--spacing-3);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Badges and alerts.
   The ground is a NEUTRAL surface, not a tint of the status colour. Tinting with the ink means
   the ground moves with the text: darkening the ink darkened the tint too, and the ratio stayed
   pinned around 4:1 in every direction. A neutral ground with a status-coloured border keeps the
   colour signal and lets the text clear 4.5:1. (Status is still never colour-alone — every badge
   and alert carries its own words.) */

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
}

.badge-primary {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--info) 45%, transparent);
    color: var(--info);
}

.badge-success {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--good) 45%, transparent);
    color: var(--pastel-green);
}

.badge-warning {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--warn) 45%, transparent);
    color: var(--pastel-yellow);
}

.badge-error {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--crit) 45%, transparent);
    color: var(--error);
}

/* Neutral badge for a state that is a SETTING, not an outcome — e.g. the Orders list's
   "Off" when a store has tracking push-back switched off. Deliberately the quietest badge
   on the page (nothing is wrong), but still readable: it uses --text-secondary rather than
   --text-muted, so an operator can tell it apart from an empty cell at a glance. */
.badge-muted {
    background: var(--surface-2);
    color: var(--text-secondary);
}

/* Progress Bar */
.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--spacing-4);
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: var(--radius-full);
    transition: width 300ms ease;
}

/* Alerts */
.alert {
    padding: var(--spacing-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-4);
}

.alert-info {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--info) 45%, transparent);
    color: var(--info);
}

.alert-success {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--good) 45%, transparent);
    color: var(--pastel-green);
}

.alert-warning {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--warn) 45%, transparent);
    color: var(--pastel-yellow);
}

.alert-error {
    background: var(--surface-2);
    border: 1px solid color-mix(in oklab, var(--crit) 45%, transparent);
    color: var(--error);
}

/* Utilities */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }

.mt-1 { margin-top: var(--spacing-1); }
.mt-2 { margin-top: var(--spacing-2); }
.mt-3 { margin-top: var(--spacing-3); }
.mt-4 { margin-top: var(--spacing-4); }
.mt-6 { margin-top: var(--spacing-6); }
.mt-8 { margin-top: var(--spacing-8); }

.mb-1 { margin-bottom: var(--spacing-1); }
.mb-2 { margin-bottom: var(--spacing-2); }
.mb-3 { margin-bottom: var(--spacing-3); }
.mb-4 { margin-bottom: var(--spacing-4); }
.mb-6 { margin-bottom: var(--spacing-6); }
.mb-8 { margin-bottom: var(--spacing-8); }

.p-1 { padding: var(--spacing-1); }
.p-2 { padding: var(--spacing-2); }
.p-3 { padding: var(--spacing-3); }
.p-4 { padding: var(--spacing-4); }
.p-6 { padding: var(--spacing-6); }
.p-8 { padding: var(--spacing-8); }

/* Layout utilities. Declared after .alert and the form rules so an inline prompt
   (.alert.d-flex) lays out as a row and .w-auto overrides .form-control's width: 100%. */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.gap-2 { gap: var(--spacing-2); }
.w-auto { width: auto; }

.hidden { display: none !important; }

/* Two or more buttons side by side, with air between them. Without a rule like this adjacent
   .btn elements are inline-blocks separated only by whitespace collapse, which puts a primary
   and a secondary action close enough to mis-click. Wraps rather than overflowing on narrow
   screens — a warehouse tablet must not lose the second button off the edge. */
.btn-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-3);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.fade-in {
    animation: fadeIn 300ms ease;
}

.slide-in {
    animation: slideIn 300ms ease;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        font-size: 13px;
    }

    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }

    .card {
        padding: var(--spacing-4);
    }

    /* When a card table scrolls sideways (the .card-body cue), the first column — the order
       number, the receipt, the member's name — stays put so a row is never a bare set of numbers
       (UX evaluation 2026-10, finding 8's polish). Opt-in per table (.table-sticky-first): the
       Waves table's first column is a checkbox and Stock's is the client, neither worth pinning.
       Opaque so the scrolled cells pass under it, with an edge so the seam is visible. */
    .card-body .table.table-sticky-first th:first-child,
    .card-body .table.table-sticky-first td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: var(--bg-secondary);
        box-shadow: inset -1px 0 0 var(--border-primary);
    }

    .card-body .table.table-sticky-first thead th:first-child {
        background: var(--bg-tertiary);
    }
}
