/**
 * Moom Core CSS — Design System Bridge
 *
 * Source of truth: moom-brand.css (design system mode)
 * This file bridges legacy token names (--moom-green, --font-body) to
 * design system tokens (--accent-camel, --font-base) so existing viewers
 * continue working while new/rebuilt viewers use standard tokens directly.
 *
 * Migration: viewers being rebuilt should use --accent-camel, --font-base, etc.
 * Legacy: --moom-green, --font-body still resolve correctly via aliases below.
 */

:root {
    /* ===== DESIGN SYSTEM TOKENS (canonical — from moom-brand.css) ===== */

    /* Typography — Moom brand fonts with free fallbacks */
    --font-display: 'Reckless Neue', 'Newsreader', Georgia, serif;
    --font-base: 'Maison Neue', 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Maison Neue Mono', 'JetBrains Mono', 'SF Mono', Monaco, monospace;

    /* Elevation — warm gray family from Moom brand */
    --bg-base: #f4f1ed;
    --bg-surface: #faf8f6;
    --bg-raised: #e9e5df;
    --bg-elevated: #fdfcfa;

    /* Text hierarchy — warm neutrals */
    --text-primary: #1c1b18;
    --text-secondary: #5a5548;
    --text-tertiary: #908880;
    --text-muted: #b8b0a5;
    --text-inverse: #FFFFFF;

    /* Accent — Moom Green (primary) */
    --accent-camel: #005330;
    --accent-camel-hover: #003d22;
    --accent-camel-subtle: #dff0e7;

    /* Accent — Apricot (secondary) */
    --accent-terra: #c07830;
    --accent-terra-hover: #a86820;
    --accent-terra-subtle: #fff3e6;

    /* Accent — Sundrop (pop) */
    --accent-pop: #d4b000;
    --accent-pop-hover: #b89800;
    --accent-pop-subtle: #fef8e0;

    /* Semantic */
    --semantic-success: #1a7a48;
    --semantic-warning: #b07830;
    --semantic-error: #c03030;

    /* Borders — warm gray */
    --border-subtle: #dfd9d1;
    --border-default: #cec7bc;
    --border-emphasis: #b8b0a4;

    /* Shadows — warm-tinted */
    --shadow-sm: 0 1px 2px rgba(28, 27, 24, 0.06),
                 0 1px 3px rgba(28, 27, 24, 0.04);
    --shadow-md: 0 4px 8px rgba(28, 27, 24, 0.08),
                 0 2px 4px rgba(28, 27, 24, 0.05);
    --shadow-lg: 0 12px 28px rgba(28, 27, 24, 0.12),
                 0 8px 12px rgba(28, 27, 24, 0.06);

    /* Accent glows */
    --shadow-glow-camel: 0 0 20px rgba(0, 83, 48, 0.15);
    --shadow-glow-terra: 0 0 20px rgba(192, 120, 48, 0.14);
    --shadow-glow-pop: 0 0 20px rgba(251, 222, 64, 0.25);
    --shadow-glow-success: 0 0 10px rgba(26, 122, 72, 0.15);

    /* Chart palette — from Moom brand secondary colors */
    --chart-1: #005330;
    --chart-2: #A7C6ED;
    --chart-3: #F58132;
    --chart-4: #8B84D7;
    --chart-5: #BAD479;
    --chart-6: #F58E8E;
    --chart-7: #758CC0;
    --chart-8: #FBDE40;

    /* Typography scale (required by components.css) */
    --text-xs: 10px;
    --text-sm: 12px;
    --text-base: 14px;
    --text-lg: 18px;
    --text-xl: 24px;

    /* Spacing scale */
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;

    /* Radius scale */
    --radius-sm: 4px; --radius-md: 6px; --radius-lg: 8px; --radius-xl: 12px;

    /* ===== DESIGN SYSTEM ALIASES (maps Moom tokens → components.css tokens) ===== */
    --accent-primary: var(--accent-camel);
    --accent-primary-hover: var(--accent-camel-hover);
    --accent-primary-subtle: var(--accent-camel-subtle);
    --accent-secondary: var(--accent-terra);
    --accent-secondary-hover: var(--accent-terra-hover);
    --accent-secondary-subtle: var(--accent-terra-subtle);

    /* ===== LEGACY ALIASES (bridge — remove when all viewers migrated) ===== */
    --font-body: var(--font-base);
    --moom-green: var(--accent-camel);
    --moom-green-light: #006940;
    --moom-green-hover: var(--accent-camel-hover);
    --accent-warning: var(--semantic-warning);
    --accent-error: var(--semantic-error);
    --accent-success: var(--semantic-success);
    --accent-info: #2980b9;
    --accent-purple: #7c3aed;

    /* ===== STATUS COLORS (Moom-specific, not in base design system) ===== */
    --status-ok: #1a7a48;
    --status-ok-bg: #e0f5e8;
    --status-low: var(--semantic-warning);
    --status-low-bg: #fff3e0;
    --status-critical: var(--semantic-error);
    --status-critical-bg: #fde8e8;
    --status-overdue: #8e44ad;
    --status-overdue-bg: #f3e8fd;
    --status-no-sales: #6a6a6a;
    --status-no-sales-bg: #f0f0f0;

    /* ===== MARKET COLORS ===== */
    --market-sg: var(--accent-camel);
    --market-my: #FFB673;
    --market-hk: #A7A4E0;
}

/* ===== BASE RESET ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

select, option, input, button, textarea {
    font-family: var(--font-base);
}

body {
    font-family: var(--font-base);
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ===== HEADER COMPONENT ===== */
.moom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.moom-header h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 400;
    color: var(--accent-camel);
    letter-spacing: -0.025em;
}

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

.moom-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== BUTTON COMPONENT ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-family: var(--font-base);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-camel), var(--accent-camel-hover));
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-camel-hover), var(--accent-camel));
    box-shadow: var(--shadow-md), var(--shadow-glow-camel);
}

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

.btn-secondary:hover {
    border-color: var(--accent-camel);
    color: var(--text-primary);
}

.btn-warning {
    background: var(--accent-warning);
    color: white;
}

.btn-warning:hover {
    background: var(--accent-terra-hover);
}

.btn-warning:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== LABEL COMPONENT ===== */
.sidebar-label,
.section-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-camel);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ===== NAVIGATION (for shell) ===== */
.moom-nav {
    display: flex;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    padding: 0 24px;
    gap: 4px;
    align-items: stretch;
}

.moom-nav-item {
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--duration-fast) var(--ease-default);
    margin-bottom: -1px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.moom-nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-raised);
}

.moom-nav-item.active {
    color: var(--accent-camel);
    border-bottom-color: var(--accent-camel);
    background: transparent;
}

.moom-nav-item .icon {
    font-size: 16px;
}

/* ===== DROPDOWN ===== */
.dropdown {
    position: relative;
}

.dropdown-toggle {
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--duration-fast) var(--ease-default);
    margin-bottom: -1px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    font-family: var(--font-base);
}

.dropdown-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-raised);
}

.dropdown-toggle .icon {
    font-size: 16px;
}

.dropdown-toggle .arrow {
    font-size: 10px;
    transition: transform var(--duration-normal) var(--ease-default);
}

.dropdown.open .dropdown-toggle .arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    display: none;
    overflow: hidden;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background var(--duration-fast) var(--ease-default);
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--bg-raised);
}

.dropdown-item .icon {
    font-size: 16px;
    opacity: 0.7;
}

.dropdown-item .label {
    flex: 1;
}

/* ===== IFRAME PANEL ===== */
.iframe-panel {
    height: calc(100vh - 110px);
    padding: 0;
}

.iframe-panel iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ===== TABLE STYLES ===== */
.moom-table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.moom-table {
    width: 100%;
    border-collapse: collapse;
}

.moom-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--bg-raised);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}

.moom-table td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.moom-table tr:last-child td {
    border-bottom: none;
}

.moom-table tr:hover {
    background: var(--bg-raised);
}

/* ===== STATUS BADGES ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.status-badge.ok {
    background: var(--status-ok-bg);
    color: var(--status-ok);
}

.status-badge.low {
    background: var(--status-low-bg);
    color: var(--status-low);
}

.status-badge.critical {
    background: var(--status-critical-bg);
    color: var(--status-critical);
}

.status-badge.overdue {
    background: var(--status-overdue-bg);
    color: var(--status-overdue);
}

.status-badge.no-sales {
    background: var(--status-no-sales-bg);
    color: var(--status-no-sales);
}

/* ===== STAT CARDS (canonical) ===== */
.stat-cards {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 140px;
    padding: 16px 20px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-camel);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Clickable stat cards (for filtering) */
.stat-card.clickable {
    cursor: pointer;
    transition: border-color var(--duration-normal) var(--ease-default);
}

.stat-card.clickable:hover {
    border-color: var(--border-default);
}

.stat-card.active-filter {
    border-left: 3px solid var(--accent-camel);
    padding-left: 17px;
}

/* ===== UTILITY CLASSES ===== */
.code {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-secondary);
}

.num {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.num.positive { color: var(--status-ok); }
.num.negative { color: var(--status-critical); }

/* ===== LOADING STATE ===== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--text-muted);
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-default);
    border-top-color: var(--accent-camel);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ===== LOT/BATCH TRACKING ===== */

/* Expiry status colors */
.lot-expired { --lot-color: var(--accent-error); }
.lot-expiring-soon { --lot-color: var(--accent-warning); }
.lot-good { --lot-color: var(--accent-success); }
.lot-no-expiry { --lot-color: var(--text-muted); }

/* Lot indicator badge (compact, inline) */
.lot-indicator {
    display: inline-block;
    font-size: 11px;
    font-family: var(--font-mono);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--lot-color);
    background: color-mix(in srgb, var(--lot-color) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--lot-color) 20%, transparent);
    cursor: pointer;
    white-space: nowrap;
}
.lot-indicator:hover {
    background: color-mix(in srgb, var(--lot-color) 15%, transparent);
}

/* Expiry badge (inline label) */
.lot-expiry-badge {
    font-size: 11px;
    font-weight: 500;
    color: var(--lot-color);
}

/* Batch number monospace */
.lot-batch {
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 1px 4px;
    background: var(--bg-raised);
    border-radius: 3px;
}

/* Lot breakdown table (expandable detail) */
.lot-breakdown {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px;
}
.lot-breakdown th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-tertiary);
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-default);
}
.lot-breakdown td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-subtle);
}
.lot-breakdown tr.lot-expired td {
    opacity: 0.6;
}

/* Lot consumption summary (used in transfer detail, batch import, etc.) */
.lot-consumption-details {
    margin-top: 12px;
}
.lot-consumption-toggle {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    padding: 4px 0;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.lot-consumption-toggle::before {
    content: '\25B6';
    font-size: 8px;
    transition: transform var(--duration-fast) var(--ease-default);
}
.lot-consumption-details[open] > .lot-consumption-toggle::before {
    transform: rotate(90deg);
}
.lot-consumption-toggle::-webkit-details-marker { display: none; }
.lot-consumption-group {
    margin-top: 8px;
}
.lot-consumption-group-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 13px;
}
.lot-consumption-total {
    color: var(--text-muted);
    font-size: 12px;
}
.lot-consumption-table-wrap {
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    overflow: hidden;
}
.lot-consumption-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.lot-consumption-table th {
    background: var(--bg-raised);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-default);
}
.lot-consumption-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
.lot-consumption-table tr:last-child td {
    border-bottom: none;
}
.lot-consumption-table tr.lot-expired td {
    opacity: 0.6;
}

/* Lot picker widget (interactive form) */
.lot-alloc-input {
    font-family: var(--font-mono);
    font-size: 12px;
    width: 56px;
    padding: 1px 4px;
    border: 1px solid var(--border-default);
    border-radius: 2px;
    text-align: right;
    background: var(--bg-surface);
}
.lot-alloc-input:focus {
    outline: none;
    border-color: var(--accent-info);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-info) 20%, transparent);
}

/* ===== FILTER BAR EXTENSION (text inputs — not in components.css) ===== */
.ds-filter-bar__input {
    background: var(--bg-base);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 4px 8px;
    font-family: var(--font-base);
    font-size: var(--text-sm);
    color: var(--text-primary);
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.15);
}

.ds-filter-bar__input:hover {
    border-color: var(--border-emphasis);
}

.ds-filter-bar__input:focus {
    border-color: var(--accent-primary);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.15), 0 0 0 2px var(--accent-primary-subtle);
}

/* Legacy .filter-bar aliases REMOVED — all viewers now use ds-filter-bar from components.css */
