/* CORE TRIAGE SYSTEM */
:root {
    /* Base: Cool, receding slate tones to reduce eye strain and provide contrast */
    --bg-deep: #0D1117;
    --panel-bg: #161B22;
    --panel-border: #30363D;
    
    /* Psychological Color Theory */
    --accent-optimal: #3FB950; /* Calming Green: Safe, Flowing, Optimal */
    --accent-warning: #D29922; /* Advancing Amber: Monitor, Needs Attention */
    --accent-critical: #F85149; /* Urgent Red: Stop, Action Required, Incident */
    --accent-info: #58A6FF;    /* Cool Blue: Neutral Business Data, Context */
    
    /* Legacy aliases mapped to new theory */
    --accent-green: var(--accent-optimal);
    --accent-orange: var(--accent-warning);
    --accent-cyan: var(--accent-info);
    --accent-red: var(--accent-critical);
    
    --text-primary: #E6EDF3;
    --text-muted: #8B949E;
    
    --font-ui: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    background-color: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    overflow: hidden;
}

.mono { font-family: var(--font-mono); }
.bold { font-weight: 700; }
.cyan { color: var(--accent-cyan); }

/* GRID LAYOUT */
.bento-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-rows: min-content;
    gap: 16px;
    height: calc(100vh - 32px);
    padding: 16px;
    overflow-y: auto;
}

/* WIDGET PANELS */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
    border-radius: 16px;
}

.widget {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.bento-box {
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    max-height: 250px; /* Collapsed state height limit */
    justify-content: flex-start; /* align top to allow expansion */
}

.bento-box:hover {
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.bento-box.expanded {
    grid-column: 1 / -1;
    max-height: 800px;
    cursor: default;
    border-color: var(--accent-cyan);
    z-index: 10;
}
@media (min-width: 801px) {
    .bento-box.expanded {
        grid-row: span 2;
    }
}

.bento-detail {
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 20px;
    animation: fadeDetail 0.4s ease forwards;
}

@keyframes fadeDetail {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.bento-box.expanded .stock-list-preview,
.bento-box.expanded .bento-hint {
    display: none !important;
}

.clickable { cursor: pointer; }
.clickable:hover { 
    transform: translateY(-2px); 
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.widget h2 {
    position: absolute;
    top: 16px;
    left: 20px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 600;
}

/* HEADER */
.venue-header {
    grid-column: span 2;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: clamp(0.9rem, 1.5vw, 1.1rem); font-weight: 400; color: var(--text-muted); }
.brand .accent { color: var(--text-primary); font-weight: 800; letter-spacing: 0.05em; }

.header-right { display: flex; align-items: center; gap: 20px; }

.sys-pulse {
    width: 12px; height: 12px; border-radius: 50%;
    animation: pulse 2s infinite;
}
.sys-pulse.green { background: var(--accent-green); box-shadow: 0 0 10px var(--accent-green); }

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.8;}
    50% { transform: scale(1.1); opacity: 1;}
    100% { transform: scale(0.95); opacity: 0.8;}
}

.clock { font-size: 1.2rem; color: var(--text-muted); }

/* MEGA METRICS (Rows 1 & 2) */
.mega-metric {
    font-size: clamp(4rem, 8vw, 7rem);
    font-weight: 800;
    line-height: 1;
    text-align: center;
    margin-top: 10px;
}
.large-metric {
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 800;
    text-align: center;
    margin-top: 20px;
}
.medium-metric {
    font-size: clamp(2rem, 4vw, 3.5rem);
    font-weight: 700;
    text-align: center;
    margin-top: 20px;
    color: var(--text-muted); /* Dims it down inherently */
}

.metric-subtext {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cap { font-size: 2.5rem; color: var(--text-muted); font-weight: 400; }
.cap-small { font-size: 1.5rem; color: rgba(139, 148, 158, 0.5); font-weight: 400; }

/* DYNAMIC COLORS CAUGHT BY JS */
.state-ok { color: var(--accent-optimal); border-color: rgba(63, 185, 80, 0.2); }
.state-warn { color: var(--accent-warning); border-color: rgba(210, 153, 34, 0.4); }
.state-crit { color: var(--accent-critical); border-color: var(--accent-critical); box-shadow: 0 0 12px rgba(248, 81, 73, 0.15); background: rgba(248, 81, 73, 0.05); }

/* ALERTS & LISTS */
.widget-alerts {
    grid-column: span 2;
    justify-content: flex-start;
    padding: 0;
}

.alert-header {
    background: rgba(255,0,60,0.1);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,0,60,0.2);
}
.alert-header h2 { position: static; color: var(--accent-red); margin: 0; font-weight: 800;}

.badge-red {
    background: var(--accent-red); color: white;
    padding: 4px 12px; border-radius: 12px; font-weight: 800;
}

.pulse { animation: red-pulse 1s infinite alternate; }
@keyframes red-pulse { 0% { opacity: 1; } 100% { opacity: 0.5; } }

.alert-feed {
    padding: 16px;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 8px;
    height: 100%;
}

.alert-row {
    background: rgba(255,0,60,0.05);
    border-left: 3px solid var(--accent-red);
    padding: 12px; border-radius: 4px;
    font-size: 0.9rem;
    display: flex; gap: 16px;
    animation: slide-in 0.3s ease;
}
@keyframes slide-in { from { transform: translateX(-10px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.alert-time { font-family: var(--font-mono); color: var(--accent-red); min-width: 80px;}

.alert-body { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; }
.alert-loc { color: var(--text-muted); }
.btn-snapshot { background: rgba(88, 166, 255, 0.1); border: 1px solid rgba(88, 166, 255, 0.3); color: var(--accent-info); padding: 4px 8px; border-radius: 4px; font-family: var(--font-ui); font-size: 0.75rem; cursor: pointer; align-self: flex-start; margin-top: 4px; transition: all 0.2s;}
.btn-snapshot:hover { background: var(--accent-info); color: var(--bg-deep); }

.bg-dim { background: rgba(0,0,0,0.4); }

/* STOCK PREVIEW */
.stock-list-preview {
    margin-top: 30px;
    display: flex; flex-direction: column; gap: 8px;
    max-height: 150px; overflow-y: hidden;
}

.inv-row {
    display: flex; justify-content: space-between;
    padding: 8px; border-radius: 4px; background: rgba(255,255,255,0.03);
    font-size: 0.85rem; font-family: var(--font-mono);
}
.inv-state-flow { color: var(--accent-green); }
.inv-state-drop { color: var(--accent-red); font-weight: bold; background: rgba(255,0,60,0.1); }
.inv-state-dorm { color: var(--text-muted); }

/* MODALS */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-content {
    width: 600px; max-width: 90%;
    padding: 32px;
    position: relative;
    transform: scale(0.95); transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content { transform: scale(1); }

.close-btn {
    position: absolute; top: 16px; right: 24px;
    background: transparent; border: none;
    color: var(--text-muted); font-size: 2rem;
    cursor: pointer;
}
.close-btn:hover { color: white; }

.modal-content h2 { color: var(--text-muted); text-transform: uppercase; margin-bottom: 24px; border-bottom: 1px solid var(--panel-border); padding-bottom: 12px;}

/* ZONE BARS */
.zone-row { display: flex; justify-content: space-between; font-size: 0.95rem; margin-bottom: 8px;}
.zone-bar { height: 8px; background: rgba(255,255,255,0.05); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; transition: width 0.5s ease; background: var(--accent-info); }
.fill.cyan { background: var(--accent-info); }
.fill.dim { background: var(--text-muted); }
.fill.green { background: var(--accent-optimal); }
.mt-2 { margin-top: 24px; }
.mt-1 { margin-top: 8px; }

/* SALES TOGGLES & L4L */
.widget-header-row { display: flex; justify-content: space-between; align-items: center; position: absolute; top: 16px; left: 20px; right: 20px; }
.widget-header-row h2 { position: static; }
.time-toggles { display: flex; background: rgba(0,0,0,0.5); border-radius: 12px; overflow: hidden; border: 1px solid var(--panel-border);}
.btn-toggle { background: transparent; border: none; color: var(--text-muted); padding: 4px 10px; font-size: 0.75rem; font-weight: bold; cursor: pointer; transition: background 0.2s;}
.btn-toggle.active { background: var(--accent-cyan); color: var(--bg-deep); }
.btn-toggle:hover:not(.active) { background: rgba(255,255,255,0.1); }
.l4l-container { margin-top: 4px; }
.l4l-positive { color: var(--accent-green); }
.l4l-negative { color: var(--accent-red); }

/* BASKET AND ORDERING */
.basket-btn { background: rgba(255,255,255,0.1); border: 1px solid var(--panel-border); color: white; padding: 6px 16px; border-radius: 20px; font-family: var(--font-ui); font-size: 0.9rem; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: background 0.2s; }
.basket-btn:hover { background: rgba(255,255,255,0.2); }
.badge { background: var(--accent-cyan); color: var(--bg-deep); font-weight: bold; font-family: var(--font-mono); padding: 2px 6px; border-radius: 10px; font-size: 0.75rem; }

.btn-order { background: rgba(255,255,255,0.05); border: 1px solid var(--panel-border); color: white; padding: 4px 12px; border-radius: 4px; font-family: var(--font-ui); font-size: 0.75rem; cursor: pointer; }
.btn-order:hover { background: var(--accent-cyan); color: var(--bg-deep); border-color: var(--accent-cyan); }
.btn-order:disabled { opacity: 0.5; cursor: default; background: rgba(255,255,255,0.05); color: var(--text-muted); border-color: transparent;}

.basket-list { max-height: 400px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; padding-right: 8px;}
.basket-footer { border-top: 1px solid var(--panel-border); padding-top: 16px; display: flex; justify-content: flex-end; }
.btn-submit { background: var(--accent-green); color: var(--bg-deep); border: none; padding: 12px 24px; border-radius: 8px; font-weight: bold; font-family: var(--font-ui); cursor: pointer; font-size: 1rem; }
.btn-submit:hover { filter: brightness(1.2); }

.supplier-header { font-size: 0.8rem; color: var(--accent-info); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 16px; margin-bottom: 4px; border-bottom: 1px solid rgba(88, 166, 255, 0.2); padding-bottom: 4px;}
.supplier-item { margin-left: 8px; border-left: 2px solid rgba(255,255,255,0.05); border-radius: 0 4px 4px 0;}

/* STOCK LIST FULL */
.stock-full-list { max-height: 400px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;}
.stock-full-list .inv-row { padding: 12px; align-items: center; }
.inv-name-col { flex: 1; }
.inv-state-col { min-width: 150px; text-align: right; margin-right: 16px; }

/* RESPONSIVE LAYOUT ENFORCEMENT */
@media screen and (max-width: 1024px) and (orientation: portrait) {
    .bento-grid {
        grid-template-columns: 1fr;
        grid-auto-rows: min-content;
    }
    .venue-header { grid-column: 1; }
    .widget-alerts { grid-column: 1; }
}

@media screen and (max-height: 700px) {
    .mega-metric { font-size: clamp(3rem, 6vw, 5rem); margin-top: 5px; }
    .large-metric { font-size: clamp(2rem, 4vw, 3rem); margin-top: 10px; }
    .widget { padding: 16px; }
    .bento-grid { gap: 8px; padding: 8px; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
