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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-elev: #232734;
    --border: #2a2d3a;
    --text: #e4e4e7;
    --text-muted: #9ca3af;
    --text-faint: #6b7280;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --warehouse: #38bdf8;
    --warehouse-rgb: 56, 189, 248;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 14px;
    --pad: 16px;
}

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
    font: inherit;
    color: inherit;
    -webkit-appearance: none;
    appearance: none;
}
button { cursor: pointer; }

/* ─── Topbar ───────────────────────────────────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) var(--pad) 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-logo {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--warehouse);
    color: var(--bg);
    border-radius: 9px;
    font-weight: 700;
    font-size: 18px;
}

.topbar h1 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.topbar-pill {
    background: rgba(var(--warehouse-rgb), 0.13);
    color: var(--warehouse);
    border: 1px solid rgba(var(--warehouse-rgb), 0.32);
    padding: 5px 11px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ─── Views ────────────────────────────────────────── */
.view { display: none; padding: var(--pad); }
.view.active { display: block; }

/* ─── Today feed ───────────────────────────────────── */
.feed {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.action-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.1s;
}

.action-card.urgent {
    border-color: rgba(239, 68, 68, 0.5);
    background:
        linear-gradient(135deg, rgba(239, 68, 68, 0.10) 0%, transparent 60%),
        var(--surface);
}

.action-card.attention {
    border-color: rgba(245, 158, 11, 0.42);
    background:
        linear-gradient(135deg, rgba(245, 158, 11, 0.07) 0%, transparent 60%),
        var(--surface);
}

.action-card.suggest {
    border-color: var(--border);
}

.action-card.info {
    background:
        linear-gradient(135deg, rgba(34, 197, 94, 0.05) 0%, transparent 60%),
        var(--surface);
    border-color: rgba(34, 197, 94, 0.22);
}

.action-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.action-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
    flex-shrink: 0;
}

.action-icon.icon-urgent    { background: rgba(239, 68, 68, 0.18); color: var(--danger); }
.action-icon.icon-attention { background: rgba(245, 158, 11, 0.18); color: var(--warning); }
.action-icon.icon-suggest   { background: rgba(99, 102, 241, 0.18); color: var(--accent); }
.action-icon.icon-info      { background: rgba(34, 197, 94, 0.18); color: var(--success); }

.action-title {
    font-size: 1.02rem;
    font-weight: 600;
    line-height: 1.3;
    flex: 1;
    padding-top: 2px;
}

.action-meta {
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

.action-cta {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 13px 16px;
    font-weight: 600;
    font-size: 0.95rem;
    width: 100%;
    min-height: 48px;
    text-align: center;
    transition: background 0.15s, transform 0.1s;
}

.action-card.urgent .action-cta {
    background: var(--danger);
}

.action-card.urgent .action-cta:active { background: #dc2626; }
.action-cta:active { transform: scale(0.98); background: var(--accent-hover); }

.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-muted);
}
.empty-state .big {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: 16px;
    color: var(--success);
}
.empty-state h3 {
    font-size: 1.3rem;
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 600;
}

/* ─── Stock view ───────────────────────────────────── */
.search-wrap { margin-bottom: 14px; }

#stock-search,
#receive-search {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    color: var(--text);
    font-size: 16px; /* iOS no-zoom */
}

#stock-search:focus,
#receive-search:focus {
    outline: none;
    border-color: var(--warehouse);
}

/* Mode toggle (Browse / Stock check) */
.stock-mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 14px;
}

.stock-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 14px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
    min-height: 42px;
}
.stock-mode-btn.active {
    background: var(--warehouse);
    color: var(--bg);
}
.stock-mode-btn:not(.active):active {
    background: rgba(255, 255, 255, 0.04);
}

/* Sticky check banner */
.stock-check-banner {
    background:
        linear-gradient(135deg, rgba(var(--warehouse-rgb), 0.12) 0%, transparent 70%),
        var(--surface);
    border: 1px solid rgba(var(--warehouse-rgb), 0.42);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 14px;
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 64px);
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}
.stock-check-banner.hidden { display: none; }

.check-banner-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.check-banner-meta strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 4px;
}
.check-banner-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.check-banner-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.btn-discard {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 9px 14px;
    border-radius: 9px;
    font-weight: 600;
    font-size: 0.88rem;
    min-height: 40px;
}
.btn-discard:active { background: rgba(255, 255, 255, 0.04); }

.btn-save {
    background: var(--success);
    border: none;
    color: white;
    padding: 9px 16px;
    border-radius: 9px;
    font-weight: 700;
    font-size: 0.9rem;
    min-height: 40px;
}
.btn-save:disabled {
    background: var(--surface-elev);
    color: var(--text-faint);
    cursor: not-allowed;
}
.btn-save:not(:disabled):active { background: #16a34a; transform: scale(0.98); }

.stock-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ─── Stock-check row ─────────────────────────────────────────────── */
.check-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.check-row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.check-row-body {
    display: flex;
    align-items: stretch;
    gap: 12px;
}

.check-expected {
    flex: 1;
    background: var(--surface-elev);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.check-expected-label {
    font-size: 0.66rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 2px;
}
.check-expected-qty {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
}

.check-count-wrap {
    flex: 1;
    background: rgba(var(--warehouse-rgb), 0.06);
    border: 1px solid rgba(var(--warehouse-rgb), 0.3);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.check-count-label {
    font-size: 0.66rem;
    color: var(--warehouse);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    margin-bottom: 2px;
}
.check-count-input {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.35rem;
    font-weight: 700;
    width: 100%;
    padding: 0;
    -moz-appearance: textfield;
}
.check-count-input::-webkit-outer-spin-button,
.check-count-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.check-count-input:focus { outline: none; }
.check-count-input::placeholder { color: var(--text-faint); font-weight: 500; }

/* Variance pill */
.variance-pill {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    white-space: nowrap;
}
.variance-pill.pending { background: var(--surface-elev); color: var(--text-faint); }
.variance-pill.ok      { background: rgba(34, 197, 94, 0.18);  color: var(--success); }
.variance-pill.over    { background: rgba(34, 197, 94, 0.18);  color: var(--success); }
.variance-pill.short   { background: rgba(239, 68, 68, 0.18);  color: var(--danger); }

/* Audit toggle + content */
.check-audit-toggle {
    background: transparent;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    padding: 10px 0 0;
    font-size: 0.82rem;
    font-weight: 500;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    width: 100%;
}
.check-audit-toggle:active { color: var(--text); }
.audit-chevron {
    font-size: 0.7rem;
    color: var(--text-faint);
    transition: transform 0.15s;
}

.audit-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
    margin-top: 4px;
}
.audit-content.hidden { display: none; }

.audit-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    line-height: 1.4;
}
.audit-key { color: var(--text-muted); }
.audit-val {
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", monospace;
    color: var(--text);
}
.audit-val.pos { color: var(--success); }
.audit-val.neg { color: var(--text-muted); }

.audit-line.audit-total {
    border-top: 1px solid var(--border);
    padding-top: 6px;
    margin-top: 4px;
}
.audit-line.audit-total .audit-key { color: var(--text); font-weight: 600; }
.audit-line.audit-total .audit-val { font-size: 0.95rem; }

.audit-line.audit-system .audit-val { color: var(--success); }

.stock-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: background 0.15s;
}
.stock-row:active { background: var(--surface-elev); }

.stock-row-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.stock-name {
    font-weight: 600;
    flex: 1;
    line-height: 1.3;
    font-size: 0.98rem;
}

.status-pill {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    white-space: nowrap;
}

.status-pill.critical { background: rgba(239, 68, 68, 0.18); color: var(--danger); }
.status-pill.low      { background: rgba(245, 158, 11, 0.18); color: var(--warning); }
.status-pill.ok       { background: rgba(34, 197, 94, 0.16); color: var(--success); }
.status-pill.cancelled { background: rgba(107, 114, 128, 0.22); color: var(--text-muted); }

.tier-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.tier-cell {
    background: var(--surface-elev);
    border-radius: 9px;
    padding: 8px 4px;
    text-align: center;
    border: 1px solid transparent;
}

.tier-cell.tier-out {
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.07);
}
.tier-cell.tier-low {
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.05);
}

.tier-label {
    font-size: 0.63rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    display: block;
    margin-bottom: 3px;
    font-weight: 600;
}

.tier-qty {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.tier-cell.tier-out .tier-qty { color: var(--danger); }
.tier-cell.tier-low .tier-qty { color: var(--warning); }

/* ─── Releases ─────────────────────────────────────── */
.release-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.release-section-label {
    font-size: 0.72rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    padding: 8px 4px 2px;
}

.release-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.release-card.pending { border-left: 3px solid var(--warning); }
.release-card.received { border-left: 3px solid var(--success); }
.release-card.cancelled { border-left: 3px solid var(--text-faint); opacity: 0.75; }

.release-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.release-route {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.release-dsp {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", monospace;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.release-arrow {
    color: var(--text-faint);
    font-size: 0.9rem;
    flex-shrink: 0;
}

.release-dest {
    color: var(--text);
    font-weight: 500;
    font-size: 0.95rem;
}

.release-stats {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.release-when {
    color: var(--text-faint);
    font-size: 0.8rem;
}

/* ─── FAB ──────────────────────────────────────────── */
.fab {
    position: fixed;
    right: 16px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    background: var(--warehouse);
    color: var(--bg);
    border: none;
    border-radius: 28px;
    height: 56px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    box-shadow: 0 8px 22px rgba(var(--warehouse-rgb), 0.35), 0 2px 6px rgba(0, 0, 0, 0.4);
    z-index: 50;
    transition: transform 0.1s;
}
.fab:active { transform: scale(0.96); }

.fab-plus {
    font-size: 1.5rem;
    line-height: 1;
    margin-right: -2px;
}

/* ─── Receive view ─────────────────────────────────── */
#view-receive { padding-bottom: 90px; } /* clear the sticky action bar */

.receive-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.receive-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color 0.15s, background 0.15s;
}
.receive-row.has-qty {
    border-color: rgba(var(--warehouse-rgb), 0.5);
    background:
        linear-gradient(135deg, rgba(var(--warehouse-rgb), 0.08) 0%, transparent 60%),
        var(--surface);
}

.receive-row-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.receive-current {
    color: var(--text-muted);
    font-size: 0.78rem;
    flex-shrink: 0;
    white-space: nowrap;
}

/* Qty stepper — matches qa-dispatch-stock pattern: ▲ left / input / ▼ right */
.qty-stepper {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg);
    min-height: 48px;
    align-self: flex-end;
}
.qty-stepper:focus-within { border-color: var(--warehouse); }

.qty-btn {
    background: var(--surface-elev);
    border: none;
    color: var(--text);
    width: 50px;
    min-width: 50px;
    padding: 0;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 0;
    transition: background 0.1s, color 0.1s;
}
.qty-btn:active { background: var(--warehouse); color: var(--bg); }

.receive-qty-input {
    width: 80px;
    border: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    text-align: center;
    background: transparent;
    color: var(--text);
    padding: 0 6px;
    font-size: 1.1rem;
    font-weight: 700;
    -moz-appearance: textfield;
}
.receive-qty-input::-webkit-outer-spin-button,
.receive-qty-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.receive-qty-input:focus { outline: none; }

/* Sticky action bar (Receive tab only) */
.receive-action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 60px); /* sit above tabbar */
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    z-index: 45;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}
.receive-action-bar.hidden { display: none; }

.receive-summary {
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
}

.receive-submit {
    background: var(--warehouse);
    color: var(--bg);
    border: none;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.95rem;
    min-height: 48px;
    flex-shrink: 0;
    transition: transform 0.1s, background 0.15s;
}
.receive-submit:disabled {
    background: var(--surface-elev);
    color: var(--text-faint);
    cursor: not-allowed;
}
.receive-submit:not(:disabled):active { transform: scale(0.97); }

/* ─── Tab bar ──────────────────────────────────────── */
.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 40;
}

.tab {
    background: transparent;
    border: none;
    color: var(--text-faint);
    padding: 10px 8px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: color 0.15s, background 0.15s;
}
.tab.active { color: var(--warehouse); }
.tab:active { background: rgba(255, 255, 255, 0.04); }

.tab-icon { font-size: 1.25rem; line-height: 1; }
.tab-label { font-size: 0.74rem; font-weight: 600; }

/* ─── Utility ──────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Auth screen ──────────────────────────────────── */
.auth-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
}

.auth-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px;
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: var(--warehouse);
    color: var(--bg);
    border-radius: 14px;
    font-weight: 700;
    font-size: 28px;
    margin-bottom: 14px;
}

.auth-container h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}

.auth-container > p {
    color: var(--text-muted);
    font-size: 0.92rem;
    margin-bottom: 22px;
}

#login-form { display: flex; flex-direction: column; gap: 10px; }

#login-form input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 13px 14px;
    color: var(--text);
    font-size: 16px; /* >= 16px stops iOS auto-zoom */
}
#login-form input:focus {
    outline: none;
    border-color: var(--warehouse);
}

#login-form button {
    background: var(--warehouse);
    color: var(--bg);
    border: none;
    border-radius: 10px;
    padding: 13px 14px;
    font-size: 1rem;
    font-weight: 700;
    margin-top: 6px;
}
#login-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.error {
    color: var(--danger);
    font-size: 0.88rem;
    margin-top: 12px;
    min-height: 1.2em;
}

/* ─── Topbar logout ────────────────────────────────── */
.topbar-right { display: flex; align-items: center; gap: 10px; }

.topbar-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.topbar-logout:active { background: rgba(255, 255, 255, 0.04); }

/* ─── Stock-tier "missing in this tier" cell ───────── */
.tier-cell.tier-missing { opacity: 0.45; }
.tier-cell.tier-missing .tier-qty { color: var(--text-faint); }
