/* =========================================================
   MLS STOCK — DESIGN SYSTEM
   Aesthetic: refined industrial. Generous whitespace,
   monospace numerics, single bold accent (#FF914D).
   ========================================================= */

:root {
    /* DARK (default) */
    --bg:           #0F0F10;
    --bg-elev:      #18181B;
    --bg-elev-2:    #1F1F23;
    --surface:      #232328;
    --border:       #2A2A30;
    --border-strong:#3A3A42;
    --text:         #F5F5F4;
    --text-dim:     #A1A1A6;
    --text-faint:   #6B6B73;
    --accent:       #FF914D;
    --accent-soft:  rgba(255, 145, 77, 0.12);
    --accent-glow:  rgba(255, 145, 77, 0.4);
    --success:      #4ADE80;
    --warning:      #FBBF24;
    --danger:       #F87171;
    --info:         #60A5FA;
    --shadow-sm:    0 1px 2px rgba(0,0,0,0.4);
    --shadow-md:    0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg:    0 24px 48px rgba(0,0,0,0.5);
    --radius:       12px;
    --radius-lg:    16px;
    --radius-sm:    8px;
}

[data-theme="light"] {
    --bg:           #FAFAF7;
    --bg-elev:      #FFFFFF;
    --bg-elev-2:    #FFFFFF;
    --surface:      #F4F4F0;
    --border:       #E7E5E0;
    --border-strong:#D4D2CC;
    --text:         #1A1A1C;
    --text-dim:     #57575E;
    --text-faint:   #8A8A92;
    --accent:       #E07A37;
    --accent-soft:  rgba(224, 122, 55, 0.10);
    --accent-glow:  rgba(224, 122, 55, 0.25);
    --success:      #15803D;
    --warning:      #B45309;
    --danger:       #B91C1C;
    --info:         #1D4ED8;
    --shadow-sm:    0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.06);
    --shadow-lg:    0 20px 40px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter Tight', -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overscroll-behavior: none;
}

body {
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -10%, var(--accent-soft), transparent 70%);
    background-attachment: fixed;
}

.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }

/* Monospace numerics */
.mono, .kpi-value, .stock-qty, .today-stat-value, .qty-pill, .hist-qty, .product-price {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
}

/* =========================================================
   LOGIN
   ========================================================= */
.auth-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.auth-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
}

.auth-mark {
    font-family: 'Fraunces', serif;
    font-weight: 700;
    font-size: 24px;
    letter-spacing: -0.02em;
    color: var(--accent);
}

.auth-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.15em;
    color: var(--text-faint);
}

.auth-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 36px;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 8px;
}

.auth-sub {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 32px;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.05em;
}

.dot {
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-glow);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* =========================================================
   FORM FIELDS
   ========================================================= */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
    font-size: 12px;
    color: var(--text-dim);
    font-weight: 500;
    letter-spacing: 0.02em;
}

input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-elev);
}

textarea { resize: vertical; min-height: 60px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.error-msg {
    color: var(--danger);
    font-size: 13px;
    min-height: 18px;
    text-align: center;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: all 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #1A0F08;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-primary:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.btn-danger-ghost {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--border);
}
.btn-danger-ghost:hover { background: var(--danger); color: white; border-color: var(--danger); }

.btn-block { width: 100%; padding: 14px; }
.btn-large { padding: 14px 24px; font-size: 15px; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }

/* Theme toggle icon swap */
[data-theme="dark"] .icon-sun, [data-theme="light"] .icon-moon { display: block; }
[data-theme="dark"] .icon-moon, [data-theme="light"] .icon-sun { display: none; }
:root:not([data-theme="light"]) .icon-moon { display: none; }
:root:not([data-theme="light"]) .icon-sun { display: block; }

/* =========================================================
   APP SHELL
   ========================================================= */
.app {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    padding-top: max(14px, env(safe-area-inset-top));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(20px);
    background: color-mix(in srgb, var(--bg) 85%, transparent);
}

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

.brand-logo {
    height: 32px;
    width: auto;
    display: block;
}

.auth-logo {
    height: 56px;
    width: auto;
    display: block;
    margin-bottom: 4px;
}

.brand-mark {
    font-family: 'Fraunces', serif;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.02em;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.brand-name {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 17px;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.brand-sub {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.1em;
    color: var(--text-faint);
}

.topbar-right { display: flex; gap: 4px; }

/* NAV — sidebar on desktop, bottom on mobile */
.nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 40;
    gap: 4px;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    border-radius: var(--radius-sm);
    color: var(--text-faint);
    transition: color 0.15s, background 0.15s;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.nav-btn svg { width: 20px; height: 20px; }
.nav-btn.active { color: var(--accent); background: var(--accent-soft); }
.nav-btn:hover:not(.active) { color: var(--text); }

.main {
    padding: 24px;
    padding-bottom: 100px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.view { display: none; animation: fadeUp 0.3s ease; }
.view.active { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.view-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.eyebrow {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.18em;
    color: var(--text-faint);
    margin-bottom: 6px;
}

.view-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 34px;
    letter-spacing: -0.025em;
    line-height: 1.1;
}

.view-title span {
    color: var(--accent);
    font-style: italic;
}

/* =========================================================
   KPI GRID
   ========================================================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.kpi {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
}

.kpi:hover { transform: translateY(-2px); border-color: var(--border-strong); }

.kpi-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.15em;
    color: var(--text-faint);
    margin-bottom: 12px;
}

.kpi-value {
    font-size: 36px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.03em;
    color: var(--text);
}

.kpi-meta {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 8px;
}

.kpi.accent .kpi-value { color: var(--accent); }
.kpi.warn   .kpi-value { color: var(--warning); }
.kpi.danger .kpi-value { color: var(--danger); }

.kpi-skeleton {
    background: linear-gradient(90deg, var(--surface), var(--bg-elev-2), var(--surface));
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
    height: 108px;
    border-color: transparent;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* =========================================================
   PANELS
   ========================================================= */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 760px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

.panel {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.panel-title {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 18px;
    letter-spacing: -0.02em;
}

.panel-meta {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.15em;
    color: var(--text-faint);
}

.today-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.today-stat-label { font-size: 11px; color: var(--text-faint); margin-bottom: 6px; letter-spacing: 0.05em; }
.today-stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }

/* SALES CHART (CSS bars) */
.chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 110px;
    padding-top: 12px;
}

.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
}

.chart-bar-fill {
    width: 100%;
    background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent));
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chart-bar-fill:hover::after {
    content: attr(data-val);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: var(--text);
    color: var(--bg);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.chart-bar-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: 0.05em;
}

/* ALERTS */
.alerts-list { display: flex; flex-direction: column; gap: 8px; }

.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--text-faint);
    transition: transform 0.15s;
}

.alert-item:hover { transform: translateX(2px); }
.alert-item.alert-out     { border-left-color: var(--danger); }
.alert-item.alert-reorder { border-left-color: var(--accent); }
.alert-item.alert-low_home { border-left-color: var(--warning); }

.alert-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.alert-name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-meta { font-size: 12px; color: var(--text-dim); }

.alert-status {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.1em;
    padding: 4px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.alert-status.s-out     { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.alert-status.s-reorder { background: var(--accent-soft); color: var(--accent); }
.alert-status.s-low_home { background: rgba(251, 191, 36, 0.15); color: var(--warning); }

.alerts-empty { text-align: center; padding: 32px; color: var(--text-faint); font-size: 14px; }

/* =========================================================
   LOG TRANSACTION VIEW
   ========================================================= */
.log-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.step {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding-bottom: 24px;
    margin-bottom: 24px;
    border-bottom: 1px dashed var(--border);
}
.step:last-of-type { border-bottom: none; padding-bottom: 0; margin-bottom: 16px; }

.step-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    padding-top: 2px;
}

.step-content { min-width: 0; }
.step-label { font-weight: 600; font-size: 15px; margin-bottom: 12px; }
.optional { color: var(--text-faint); font-weight: 400; font-size: 13px; }

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.action-tile {
    padding: 14px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: left;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.action-tile:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.action-tile.selected {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.action-tile.selected .action-tile-name { color: var(--accent); }

.action-tile-name { font-size: 13px; font-weight: 600; }
.action-tile-desc { font-size: 11px; color: var(--text-dim); line-height: 1.4; }

.product-picker { position: relative; }

.product-results {
    margin-top: 8px;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    display: none;
}

.product-results.visible { display: block; }

.product-result {
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.product-result:last-child { border-bottom: none; }
.product-result:hover { background: var(--bg-elev-2); }

.product-result-name { font-size: 14px; }
.product-result-qty {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

.selected-product {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.selected-product .sp-name { font-weight: 600; color: var(--accent); }
.selected-product .sp-qty {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-dim);
}

.qty-input-wrap {
    display: flex;
    align-items: center;
    gap: 0;
    max-width: 220px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}

.qty-step {
    width: 48px;
    height: 48px;
    font-size: 22px;
    font-weight: 500;
    color: var(--text-dim);
    transition: background 0.1s, color 0.1s;
}
.qty-step:hover { background: var(--bg-elev-2); color: var(--accent); }

.qty-input-wrap input {
    border: none;
    background: transparent;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 22px;
    font-weight: 600;
    height: 48px;
    padding: 0;
    width: 80px;
    -moz-appearance: textfield;
}
.qty-input-wrap input::-webkit-outer-spin-button,
.qty-input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.channel-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.channel-tile {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 12px;
    color: var(--text-dim);
    transition: all 0.15s;
}
.channel-tile:hover { color: var(--text); border-color: var(--border-strong); }
.channel-tile.selected {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.step-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* =========================================================
   STOCK VIEW
   ========================================================= */
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 12px;
    color: var(--text-dim);
    transition: all 0.15s;
    font-weight: 500;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); color: #1A0F08; border-color: var(--accent); }

.search-input {
    width: 100%;
    margin-bottom: 16px;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-size: 14px;
}

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

.stock-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, transform 0.15s;
}

.stock-row:hover { border-color: var(--border-strong); }

.stock-name { font-weight: 500; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stock-qty-group {
    display: flex;
    gap: 12px;
    align-items: center;
}

.stock-loc {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
}

.stock-loc-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    margin-bottom: 2px;
}

.stock-loc-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 600;
}

.stock-loc-value.zero { color: var(--text-faint); }

.stock-total {
    font-family: 'JetBrains Mono', monospace;
    font-size: 18px;
    font-weight: 700;
    min-width: 50px;
    text-align: right;
}

.stock-status {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 0.1em;
    min-width: 72px;
    text-align: center;
    text-transform: uppercase;
}

.stock-status.s-ok       { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.stock-status.s-out      { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.stock-status.s-reorder  { background: var(--accent-soft); color: var(--accent); }
.stock-status.s-low_home { background: rgba(251, 191, 36, 0.15); color: var(--warning); }

@media (max-width: 640px) {
    .stock-row {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "name status"
            "qtys total";
        gap: 8px;
    }
    .stock-name { grid-area: name; }
    .stock-status { grid-area: status; }
    .stock-qty-group { grid-area: qtys; gap: 16px; }
    .stock-total { grid-area: total; }
}

/* =========================================================
   HISTORY VIEW
   ========================================================= */
.history-list { display: flex; flex-direction: column; }

.hist-day-group { margin-bottom: 24px; }
.hist-day-head {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    letter-spacing: 0.2em;
    color: var(--text-faint);
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.hist-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
}

.hist-action-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.hist-action-icon svg { width: 16px; height: 16px; }

.hist-action-icon.sale          { background: rgba(96, 165, 250, 0.15); color: var(--info); }
.hist-action-icon.transfer      { background: var(--accent-soft); color: var(--accent); }
.hist-action-icon.restock       { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.hist-action-icon.adjust_plus   { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.hist-action-icon.adjust_minus  { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

.hist-body { min-width: 0; }
.hist-product { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta { font-size: 11px; color: var(--text-dim); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.hist-time { font-family: 'JetBrains Mono', monospace; }

.hist-qty {
    font-size: 15px;
    font-weight: 700;
    text-align: right;
    min-width: 60px;
}

.hist-qty.positive { color: var(--success); }
.hist-qty.positive::before { content: '+'; }
.hist-qty.negative { color: var(--danger); }
.hist-qty.negative::before { content: '−'; }
.hist-qty.neutral { color: var(--text-dim); }

/* =========================================================
   PRODUCTS VIEW
   ========================================================= */
.products-list { display: flex; flex-direction: column; gap: 6px; }

.product-row {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 16px;
    align-items: center;
    padding: 14px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.product-row:hover { border-color: var(--accent); transform: translateY(-1px); }

.product-name { font-weight: 500; font-size: 14px; }
.product-pricecell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    min-width: 80px;
}
.product-pricecell-label { font-size: 10px; color: var(--text-faint); letter-spacing: 0.05em; }
.product-price { font-size: 13px; font-weight: 600; }

@media (max-width: 640px) {
    .product-row {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "name name"
            "cost sale";
    }
    .product-name { grid-area: name; }
}

/* =========================================================
   TOAST
   ========================================================= */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: var(--bg);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 1000;
    max-width: calc(100vw - 32px);
    text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: white; }
.toast.success { background: var(--success); color: #052E16; }

/* =========================================================
   MODAL
   ========================================================= */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.2s;
}

.modal-card {
    position: relative;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-head h2 {
    font-family: 'Fraunces', serif;
    font-weight: 500;
    font-size: 22px;
    letter-spacing: -0.02em;
}

.modal-form { display: flex; flex-direction: column; gap: 16px; }

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (min-width: 900px) {
    .app {
        grid-template-columns: 220px 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "top top"
            "nav main";
    }
    .topbar { grid-area: top; }
    .nav {
        grid-area: nav;
        position: sticky;
        top: 66px;
        height: calc(100vh - 66px);
        flex-direction: column;
        border-top: none;
        border-right: 1px solid var(--border);
        padding: 16px;
        align-items: stretch;
        background: transparent;
    }
    .nav-btn {
        flex-direction: row;
        justify-content: flex-start;
        padding: 10px 14px;
        gap: 10px;
        font-size: 14px;
    }
    .nav-btn span { font-size: 14px; letter-spacing: -0.01em; }
    .nav-btn svg { width: 18px; height: 18px; }
    .main { grid-area: main; padding-bottom: 48px; }
    .toast { bottom: 24px; }
}

@media (max-width: 480px) {
    .view-title { font-size: 26px; }
    .main { padding: 16px; padding-bottom: 100px; }
    .auth-card { padding: 28px 24px; }
    .topbar { padding: 12px 16px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .kpi { padding: 16px; }
    .kpi-value { font-size: 26px; }
    .today-stats { grid-template-columns: 1fr; gap: 12px; }
    .today-stat-value { font-size: 22px; }
}


/* ============ NO-TOPBAR ADJUSTMENTS ============ */
.nav-spacer { display: none; }

/* Theme + Logout buttons in nav - subtle */
.nav-btn-icon {
    color: var(--text-faint);
}
.nav-btn-icon.active { background: none; color: var(--text-faint); }
.nav-btn-icon:hover { color: var(--text); background: var(--surface); }

/* Add safe-area to main since no topbar */
.main {
    padding-top: max(20px, env(safe-area-inset-top));
}

@media (min-width: 900px) {
    /* Desktop: just nav + main, no topbar row */
    .app {
        grid-template-columns: 220px 1fr;
        grid-template-rows: 1fr;
        grid-template-areas: "nav main";
    }
    .nav {
        position: sticky;
        top: 0;
        height: 100vh;
        flex-direction: column;
        border-top: none;
        border-right: 1px solid var(--border);
        padding: 24px 16px;
        align-items: stretch;
        background: transparent;
    }
    /* Spacer pushes theme + logout to the bottom */
    .nav-spacer { display: block; flex: 1; }
    .nav-btn-icon {
        opacity: 0.7;
    }
    .nav-btn-icon:hover { opacity: 1; }
    .main { padding-top: 24px; }
}

/* Mobile: allow nav to scroll horizontally if too many buttons */
@media (max-width: 899px) {
    .nav {
        overflow-x: auto;
        scrollbar-width: none;
    }
    .nav::-webkit-scrollbar { display: none; }
    .nav-btn { min-width: 60px; flex-shrink: 0; }
    .nav-spacer { display: none; }
    .nav-btn-icon span { font-size: 9px; }
}


/* ============ NAV CONTROLS (THEME + SIGNOUT) ============ */
.nav-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

@media (min-width: 900px) {
    .nav-controls {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 0;
        gap: 10px;
        border-top: 1px solid var(--border);
        margin-top: 12px;
    }
}

/* Theme pill toggle */
.theme-toggle {
    width: 100%;
}
.theme-toggle-track {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 3px;
    height: 36px;
    overflow: hidden;
}
.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    height: calc(100% - 6px);
    background: var(--accent);
    border-radius: 99px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(100%);
}
.theme-toggle-opt {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    border-radius: 99px;
    transition: color 0.2s;
    padding: 0;
}
.theme-toggle-opt svg { transition: stroke 0.2s; opacity: 0.8; }
[data-theme="light"] .theme-toggle-opt[data-theme="light"],
[data-theme="dark"]  .theme-toggle-opt[data-theme="dark"] {
    color: #1A0F08;
}
[data-theme="light"] .theme-toggle-opt[data-theme="light"] svg,
[data-theme="dark"]  .theme-toggle-opt[data-theme="dark"]  svg { opacity: 1; }

/* Sign out button */
.signout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
}
.signout-btn svg { width: 16px; height: 16px; }
.signout-btn:hover {
    background: rgba(248, 113, 113, 0.08);
    color: var(--danger);
    border-color: var(--danger);
}

/* Mobile: smaller controls fit alongside nav */
@media (max-width: 899px) {
    .nav-controls {
        gap: 6px;
        margin-left: auto;
        padding-left: 6px;
        border-left: 1px solid var(--border);
    }
    .theme-toggle-track {
        height: 32px;
        padding: 2px;
        width: 110px;
    }
    .theme-toggle-thumb {
        top: 2px;
        left: 2px;
        height: calc(100% - 4px);
        width: calc(50% - 2px);
    }
    .theme-toggle-opt span {
        display: none;
    }
    .theme-toggle-opt svg { width: 14px; height: 14px; }
    .signout-btn {
        padding: 8px 10px;
        width: auto;
    }
    .signout-btn span { display: none; }
}

/* ============ CONFIRMATION MODAL ============ */
.modal-card-sm { max-width: 380px; }

.modal-confirm {
    text-align: center;
    padding: 8px;
}
.modal-confirm-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-confirm h2 {
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.modal-confirm p {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 24px;
    line-height: 1.5;
}
.modal-confirm .modal-actions {
    border-top: none;
    padding-top: 0;
    justify-content: center;
    gap: 12px;
}
.modal-confirm .btn { flex: 1; }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(248, 113, 113, 0.35);
}


/* ============ MOBILE PADDING FIXES ============ */
@media (max-width: 899px) {
    .main {
        padding: 16px;
        padding-top: max(48px, calc(env(safe-area-inset-top) + 16px));
        padding-bottom: 110px;
    }

    /* Tighter view header on mobile */
    .view-header {
        margin-bottom: 20px;
        gap: 12px;
        align-items: flex-start;
    }

    .view-title {
        font-size: 28px;
        line-height: 1.2;
    }

    .eyebrow { margin-bottom: 4px; }

    /* Today's activity: stats in a row, not stacked vertically */
    .today-stats {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }
    .today-stat-label {
        font-size: 9px;
        letter-spacing: 0.06em;
    }
    .today-stat-value {
        font-size: 22px;
    }

    /* Panels: tighter padding */
    .panel { padding: 16px; }
    .panel-head { margin-bottom: 12px; }

    /* KPI tiles: smaller on phone */
    .kpi-grid { gap: 8px; }
    .kpi { padding: 14px 12px; }
    .kpi-label { font-size: 9px; margin-bottom: 8px; }
    .kpi-value { font-size: 24px; }
    .kpi-meta { font-size: 11px; }

    /* Sales chart: shorter, less wasted space */
    .chart { height: 90px; }

    /* Log activity button shouldn't dominate */
    .view-header .btn-primary {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* Smaller phones */
@media (max-width: 400px) {
    .view-title { font-size: 24px; }
    .kpi-value { font-size: 22px; }
    .today-stat-value { font-size: 20px; }
}


/* ============ MOBILE NAV - PROPER FIT ============ */
@media (max-width: 899px) {
    /* Use solid background, no transparency confusion */
    .nav {
        background: var(--bg-elev);
        padding: 6px 8px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
        gap: 2px;
        border-top: 1px solid var(--border);
    }

    /* Main nav buttons: smaller and tight */
    .nav-btn {
        padding: 6px 4px;
        font-size: 9px;
        min-width: 0;
    }
    .nav-btn svg { width: 18px; height: 18px; margin-bottom: 1px; }
    .nav-btn span {
        font-size: 9px;
        letter-spacing: 0.01em;
    }

    /* Theme pill: shrunk down */
    .nav-controls {
        gap: 4px;
        margin-left: 4px;
        padding-left: 4px;
        border-left: 1px solid var(--border);
        flex-direction: row;
    }
    .theme-toggle-track {
        height: 36px;
        width: 70px;
        padding: 3px;
    }
    .theme-toggle-thumb {
        top: 3px;
        left: 3px;
        height: calc(100% - 6px);
        width: calc(50% - 3px);
    }
    .theme-toggle-opt {
        gap: 0;
        padding: 0;
    }
    .theme-toggle-opt span { display: none; }
    .theme-toggle-opt svg { width: 14px; height: 14px; }

    .signout-btn {
        width: 36px;
        height: 36px;
        padding: 0;
        flex-shrink: 0;
        justify-content: center;
    }
    .signout-btn svg { width: 18px; height: 18px; }
    .signout-btn span { display: none; }
}

/* Very small phones */
@media (max-width: 380px) {
    .nav-btn { font-size: 8px; padding: 6px 2px; }
    .nav-btn svg { width: 16px; height: 16px; }
}


/* Final tight mobile nav adjustments */
@media (max-width: 899px) {
    /* Hide the theme pill's both options - just show current state icon-only */
    .theme-toggle {
        width: auto;
    }

    /* Make nav scrollable horizontally as safety net */
    .nav {
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .nav::-webkit-scrollbar { display: none; }
    .nav-btn {
        flex-shrink: 0;
        flex-basis: auto;
        min-width: 56px;
    }
    .nav-controls { flex-shrink: 0; }
}


/* ============ NUCLEAR PADDING FIX ============ */
/* These force adequate top padding regardless of other rules */
@media (max-width: 899px) {
    body { padding-top: 0 !important; }

    .main {
        padding-top: 60px !important;
        padding-top: max(60px, calc(env(safe-area-inset-top) + 20px)) !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
        padding-bottom: 120px !important;
    }

    /* Force today-stats into 3 columns on mobile */
    .today-stats {
        display: grid !important;
        grid-template-columns: 1fr 1fr 1fr !important;
        gap: 8px !important;
    }
    .today-stat-value { font-size: 20px !important; }
    .today-stat-label { font-size: 9px !important; }
}


/* ============ PWA STANDALONE MODE FIX (iOS Home Screen) ============ */
/* When launched from home screen, iOS doesn't auto-pad for status bar */
@media (display-mode: standalone) {
    .main {
        padding-top: max(70px, calc(env(safe-area-inset-top) + 24px)) !important;
    }
    /* Also on auth screen */
    .auth-screen {
        padding-top: max(40px, env(safe-area-inset-top)) !important;
    }
}

/* Belt and braces for old iOS */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 899px) {
        .main {
            padding-top: max(70px, calc(env(safe-area-inset-top) + 24px)) !important;
        }
    }
}
