:root {
  --bg: #090C11;
  --accent: #2E6AF5;
  --accent-ui: #5B8CFF;
  --accent-soft: rgba(46, 106, 245, 0.18);
  --accent-glow: rgba(46, 106, 245, 0.4);
  --glass: rgba(12, 16, 24, 0.78);
  --glass-border: rgba(255, 255, 255, 0.16);
  --text: #F4F7FB;
  --muted: #A8B0BE;
  --ok: #16A374;
  --warn: #C97A0E;
  --bad: #DC4B36;
  --panel-r: 12px;
  --font: "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

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

html, body, #app {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

#c {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  outline: none;
  z-index: 0;
}

#intro-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 40;
  background: linear-gradient(180deg, rgba(9,12,17,0.55) 0%, transparent 32%, transparent 72%, rgba(9,12,17,0.4) 100%);
  transition: opacity 0.8s ease;
}
#intro-overlay.fade { opacity: 0; }
#intro-overlay.gone { display: none; }

.intro-brand {
  position: absolute; top: 14%; left: 50%;
  transform: translateX(-50%);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.intro-mark {
  width: 84px; height: 84px; object-fit: contain;
  filter: drop-shadow(0 4px 28px rgba(91,140,255,0.4));
}
.intro-wordmark {
  width: min(320px, 55vw); height: auto; object-fit: contain;
  filter: drop-shadow(0 2px 18px rgba(0,0,0,0.55));
}
.intro-sub {
  font-size: 11px; letter-spacing: 0.32em; color: #c5ccd8; font-weight: 500;
  text-shadow: 0 1px 8px rgba(0,0,0,0.6);
}
#skip-intro {
  pointer-events: auto;
  position: absolute; bottom: 48px; right: 48px;
  background: rgba(238,241,245,0.1);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font: 500 12px var(--font);
  letter-spacing: 0.06em;
}
#skip-intro:hover { background: var(--accent-soft); border-color: var(--accent-ui); }

.ui-hidden { opacity: 0; pointer-events: none !important; transform: translateY(8px); }
#topbar, #dashboard, #bottombar {
  transition: opacity 0.7s ease, transform 0.7s ease;
}
#topbar:not(.ui-hidden), #dashboard:not(.ui-hidden), #bottombar:not(.ui-hidden) {
  opacity: 1; pointer-events: auto; transform: none;
}

#topbar {
  position: absolute; top: 12px; left: 12px; right: 12px;
  height: 48px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px 0 10px;
  background: rgba(12, 16, 24, 0.92);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--panel-r);
  z-index: 30;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.1);
  isolation: isolate;
  transform: translateZ(0);
}
.tb-left, .tb-center, .tb-right {
  display: flex; align-items: center; gap: 10px;
}
.tb-mark { width: 26px; height: 26px; object-fit: contain; display: block; filter: drop-shadow(0 0 6px rgba(255,255,255,0.25)); }
.tb-wordmark { height: 15px; width: auto; object-fit: contain; display: block; filter: drop-shadow(0 1px 4px rgba(0,0,0,0.5)); }
.plant-name {
  font-weight: 600; letter-spacing: 0.16em; font-size: 10px; color: #c5ccd8;
}
.loc { letter-spacing: 0.1em; font-size: 10px; color: #c5ccd8; }
#sim-datetime { font-family: var(--mono); font-size: 11px; color: #F4F7FB; font-weight: 500; }
.divider { width: 1px; height: 16px; background: rgba(255,255,255,0.2); }
.shift {
  font-size: 9px; font-weight: 600; letter-spacing: 0.1em;
  padding: 4px 9px; border-radius: 999px;
}
.shift.day { background: rgba(201,122,14,0.22); color: #F0C87A; }
.shift.night { background: rgba(91,140,255,0.28); color: #B8D0FF; }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: pulse 1.6s ease infinite;
}
.tb-right { font-size: 10px; letter-spacing: 0.1em; color: #c5ccd8; gap: 8px; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Compact scrollable dashboard — fits 1280x800 & 1440x900 */
#dashboard {
  position: absolute; top: 66px; right: 10px; bottom: 66px;
  width: 260px;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column; gap: 5px;
  z-index: 30;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.panel {
  background: rgba(14, 18, 28, 0.94);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: var(--panel-r);
  padding: 7px 9px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06);
  flex-shrink: 0;
  isolation: isolate;
  transform: translateZ(0);
  min-height: 1px;
}
.panel h3 {
  font-size: 9px; font-weight: 600; letter-spacing: 0.16em;
  color: #A8B0BE; margin-bottom: 6px;
}
.big-stat { display: flex; align-items: baseline; gap: 5px; margin-bottom: 4px; }
.big-stat .num {
  font-size: 26px; font-weight: 700; font-family: var(--mono);
  letter-spacing: -0.02em; color: #fff;
}
.big-stat .unit { font-size: 10px; color: var(--muted); }
.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1px 0; color: var(--muted); font-size: 11px;
}
.stat-row span:last-child { color: var(--text); font-family: var(--mono); font-size: 11px; }
.up { color: var(--ok) !important; }
.down { color: var(--bad) !important; }
.muted { color: var(--muted); font-size: 11px; }
.hidden { display: none !important; }

.progress {
  height: 3px; background: rgba(255,255,255,0.08);
  border-radius: 2px; margin: 5px 0; overflow: hidden;
}
.progress .bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ui));
  border-radius: 2px; transition: width 0.15s linear;
}
.sel-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }

.mix-row {
  display: grid; grid-template-columns: 78px 1fr 32px;
  align-items: center; gap: 5px; margin-bottom: 4px;
  font-size: 10px; color: var(--muted);
}
.mix-bar {
  height: 5px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden;
}
.mix-bar i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-ui));
  border-radius: 3px;
}
.mix-row span:last-child { font-family: var(--mono); color: var(--text); text-align: right; }

#alerts { list-style: none; max-height: 72px; overflow-y: auto; }
#alerts li {
  font-size: 10px; padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  color: var(--muted);
  display: flex; gap: 5px; align-items: flex-start;
}
#alerts li::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent-ui); margin-top: 3px; flex-shrink: 0;
}
#alerts li.warn::before { background: var(--warn); }
#alerts li.bad::before { background: var(--bad); }
#alerts li.ok::before { background: var(--ok); }

.action-btn {
  width: 100%; margin-bottom: 5px;
  background: var(--accent-soft);
  border: 1px solid rgba(91,140,255,0.45);
  color: #A8C5FF;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: 500 11px var(--font);
}
.action-btn:hover { background: rgba(46,106,245,0.32); border-color: var(--accent-ui); }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#bottombar {
  position: absolute; left: 12px; right: 282px; bottom: 12px;
  height: 48px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: rgba(12, 16, 24, 0.94);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--panel-r);
  z-index: 30;
  box-shadow: 0 8px 32px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.1);
  isolation: isolate;
  transform: translateZ(0);
  overflow: visible;
  min-width: 0;
}
.ctrl { display: flex; align-items: center; gap: 7px; }
.ctrl label {
  font-size: 9px; font-weight: 600; letter-spacing: 0.12em; color: #A8B0BE;
}
.ctrl input[type="range"] {
  width: 80px; accent-color: var(--accent-ui); cursor: pointer;
}
.ctrl span { font-family: var(--mono); font-size: 11px; min-width: 30px; color: #F4F7FB; }
.toggle-btn, .icon-btn {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.16);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  font: 500 10px var(--font);
  letter-spacing: 0.06em;
}
.toggle-btn:hover, .icon-btn:hover { background: rgba(255,255,255,0.12); }
.toggle-btn.active {
  background: rgba(46,106,245,0.32);
  border-color: var(--accent-ui);
  color: #C5D8FF;
}
.icon-btn { font-size: 13px; padding: 3px 9px; }
.cam-modes { margin-left: auto; }

canvas#chart-output, canvas#chart-revenue {
  width: 100%; display: block; margin: 4px 0 2px;
  border-radius: 4px;
}
canvas#chart-output { height: 40px; }
canvas#chart-revenue { height: 48px; }

.expand-panel .stat-row { margin-top: 2px; }

@media (max-height: 820px) {
  .panel { padding: 6px 9px; }
  .big-stat .num { font-size: 22px; }
  #alerts { max-height: 52px; }
  canvas#chart-output { height: 32px; }
  canvas#chart-revenue { height: 40px; }
  .action-btn { padding: 6px 8px; }
}
@media (max-width: 1280px) {
  #dashboard { width: 248px; }
  #bottombar { right: 268px; }
}


/* v5 additions */
.intro-hint {
  position: absolute; bottom: 100px; right: 48px;
  font-size: 11px; letter-spacing: 0.08em; color: #A8B0BE;
}
.product-tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.ptab {
  flex: 1; background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted); padding: 4px 6px; border-radius: 6px;
  cursor: pointer; font: 500 10px var(--font); letter-spacing: 0.04em;
}
.ptab.active, .ptab:hover {
  background: rgba(46,106,245,0.28); border-color: var(--accent-ui); color: #C5D8FF;
}
#product-preview {
  width: 100%; height: 140px; display: block;
  border-radius: 8px; background: rgba(8,12,20,0.85);
  margin-bottom: 6px; border: 1px solid rgba(255,255,255,0.08);
}
.prod-name { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.prod-tag { font-size: 10px; color: var(--muted); margin-bottom: 6px; line-height: 1.35; }
.prod-specs {
  display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px;
}
.prod-specs span {
  font-size: 9px; font-family: var(--mono);
  padding: 2px 6px; border-radius: 4px;
  background: rgba(91,140,255,0.15); color: #B8D0FF;
  border: 1px solid rgba(91,140,255,0.25);
}
.wh-row {
  display: grid; grid-template-columns: 78px 1fr 36px;
  align-items: center; gap: 5px; margin-bottom: 4px;
  font-size: 10px; color: var(--muted);
}
.wh-row span:last-child { font-family: var(--mono); color: var(--text); text-align: right; }
.wh-row .mix-bar i { background: linear-gradient(90deg, #1a5c3a, var(--accent-ui)); }
#wh-raw { background: linear-gradient(90deg, var(--accent), var(--accent-ui)) !important; }
#wh-components { background: linear-gradient(90deg, #3a7aef, #74a6ff) !important; }
#wh-wip { background: linear-gradient(90deg, #8a5a10, var(--warn)) !important; }
#wh-finished { background: linear-gradient(90deg, #0d7a52, var(--ok)) !important; }
.quality-modes { gap: 4px; }
.fps {
  font-family: var(--mono); font-size: 10px; color: #A8B0BE;
  min-width: 52px; margin-left: 4px;
}
@media (max-width: 1400px) {
  .quality-modes label { display: none; }
  #bottombar { gap: 8px; }
  .ctrl input[type="range"] { width: 60px; }
}


/* v52: UI fit at 1280×800 / wrap quality row */
@media (max-width: 1400px) {
  #bottombar { gap: 6px; padding: 0 8px; flex-wrap: nowrap; }
  .quality-modes label { display: none; }
  .ctrl input[type="range"] { width: 56px; }
  .fps { min-width: 44px; font-size: 9px; }
  .toggle-btn, .icon-btn { padding: 4px 7px; font-size: 9px; }
}
@media (max-height: 800px) {
  #dashboard { top: 60px; bottom: 58px; }
  #bottombar { height: 44px; bottom: 8px; }
  #topbar { height: 42px; top: 8px; }
  #product-preview { height: 110px; }
}
