:root {
  --bg: #0A1628;
  --panel: #0F2139;
  --screen: #071120;
  --line: #1E3556;
  --grid: rgba(98, 198, 255, 0.06);
  --accent: #D9B45A;
  --accent-ink: #14213A;
  --text: #EAF0F7;
  --muted: #9DB0C9;
  --act: #FF5D73;
  --watch: #F5B841;
  --good: #3DDC97;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: #F0CF7E; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 20px 20px 40px; display: flex; flex-direction: column; gap: 16px; }

/* Top bar and view switch */
.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.brand { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.switch { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.tab { display: flex; flex-direction: column; justify-content: center; min-height: 44px; padding: 6px 18px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 15px; line-height: 1.2; }
.tab span { font-size: 12px; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.tab:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Mode labels */
.mode { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding: 10px 16px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }
.mode strong { text-transform: uppercase; letter-spacing: 0.12em; font-size: 13px; }
.mode-mockup { border: 1px dashed var(--accent); color: var(--muted); }
.mode-mockup strong { color: var(--accent); }
.mode-live { border: 1px solid var(--good); color: var(--muted); }
.mode-live strong { color: var(--good); }
.mode-sample { border: 1px dashed var(--watch); color: var(--muted); }
.mode-sample strong { color: var(--watch); }
.mode-paused { border: 1px solid var(--watch); color: var(--text); }
.mode-paused strong { color: var(--watch); }
.mode-offline { border: 1px solid var(--line); color: var(--muted); }
.mode-offline strong { color: var(--muted); }
.btn { min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
.btn:hover { background: #F0CF7E; }
.placeholder .actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }

.placeholder { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.placeholder h2 { margin: 0 0 8px; font-size: 20px; }
.placeholder p { margin: 0 0 8px; color: var(--muted); max-width: 640px; line-height: 1.5; }

/* Monitor */
.monitor { display: flex; flex-direction: column; gap: 16px; }
.mon-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.mon-head h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
.mon-head .sub { font-size: 16px; font-weight: 500; color: var(--muted); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 14px; color: var(--muted); }
.crumbs button { background: none; border: none; padding: 10px 2px; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.crumbs .here { color: var(--text); font-weight: 600; padding: 10px 2px; }
.crumbs .sep { padding: 0 4px; }
.mon-meta { font-size: 13px; color: var(--muted); }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--good); background: rgba(61, 220, 151, 0.07); }
.banner.watch { border-color: var(--watch); background: rgba(245, 184, 65, 0.10); }
.banner.act { border-color: var(--act); background: rgba(255, 93, 115, 0.12); }
.banner-label { font-weight: 700; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--good); }
.banner.watch .banner-label { color: var(--watch); }
.banner.act .banner-label { color: var(--act); }
.banner-text { flex: 1 1 260px; font-size: 15px; }
.banner-go { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid currentColor; background: transparent; font-weight: 600; cursor: pointer; }
.banner.act .banner-go { border-color: var(--act); }
.banner.watch .banner-go { border-color: var(--watch); }

.screen { background: var(--screen); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.lane { display: flex; flex-wrap: wrap; align-items: stretch; border-bottom: 1px solid var(--line); }
.lane-label { flex: 0 0 150px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.lane-name { font-size: 13px; font-weight: 700; letter-spacing: 0.12em; }
.lane-desc { font-size: 12px; color: var(--muted); line-height: 1.35; }
.trace { flex: 999 1 420px; min-width: 0; height: 116px; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 29px, 40px 100%; }
.trace svg { width: 100%; height: 100%; display: block; }
.trace path { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.trace .p-good { stroke: var(--good); stroke-width: 2.25px; }
.trace .p-watch { stroke: var(--watch); stroke-width: 2.5px; }
.trace .p-act { stroke: var(--act); stroke-width: 2.75px; }
.trace .cursor { stroke: var(--accent); stroke-opacity: 0.4; stroke-width: 1px; vector-effect: non-scaling-stroke; }
.readout { flex: 0 0 200px; padding: 12px 18px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.value { font-family: var(--mono); font-size: 38px; font-weight: 600; line-height: 1; }
.unit { font-size: 12px; color: var(--muted); }
.state { align-self: flex-start; margin-top: 4px; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; border: 1px solid currentColor; color: var(--muted); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 10px 16px; font-size: 12px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .note { margin-left: auto; }

.bottom { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.machines { flex: 1 1 100%; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.sec-head h2, .panel h2 { margin: 0; font-size: 16px; font-weight: 700; }
.sec-head span { font-size: 13px; color: var(--muted); }
.clusters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.cluster { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; }
.cluster:hover { border-color: var(--muted); }
.cluster.sel { border-color: var(--accent); background: rgba(217, 180, 90, 0.10); }
.cluster.alarm { border-color: var(--act); }
.cluster { gap: 4px; }
.cluster-stats { font-size: 12px; color: var(--muted); }
.cluster-name { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.detail { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 12px; border: 1px solid var(--accent); background: var(--panel); }
.detail.flat { padding: 0; border: none; background: none; }
.detail h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--accent); }
.link-btn { background: none; border: none; padding: 10px 2px; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; text-align: left; }
.card.sel { border-color: var(--accent); background: rgba(217, 180, 90, 0.10); }
.card.alarm { border-color: var(--act); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; }
.card-name { font-weight: 600; font-family: var(--mono); font-size: 14px; }
.card-status { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.card-role, .card-stats { font-size: 12px; color: var(--muted); }
.card-stats { font-family: var(--mono); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.panel h2 { margin-bottom: 4px; }
.panel p { margin: 0; font-size: 13px; color: var(--muted); }
.activity { flex: 1 1 100%; min-width: 0; }
.rows { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px 16px; }
@media (min-width: 960px) {
  /* newest first, reading down the left column then the right */
  .rows { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, auto); grid-auto-flow: column; }
}
.row { display: grid; grid-template-columns: 86px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; border: 1px solid transparent; background: transparent; text-align: left; cursor: pointer; }
.row:hover { border-color: var(--line); }
.row .t, .row .m { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.row .body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.row .x { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { justify-self: end; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }

/* Situation strip */
.situations { display: flex; flex-wrap: wrap; align-items: stretch; gap: 12px 20px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--accent); background: rgba(217, 180, 90, 0.06); }
.sit-intro { flex: 0 0 170px; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.sit-intro h2 { margin: 0; font-size: 17px; font-weight: 700; color: var(--accent); }
.sit-intro p { margin: 0; font-size: 13px; color: var(--muted); }
.sit-buttons { flex: 1 1 600px; min-width: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.scen { display: flex; flex-direction: column; justify-content: flex-start; gap: 2px; min-height: 44px; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; }
.scen:hover { border-color: var(--muted); }
.scen b { font-size: 14px; }
.scen span { font-size: 12px; color: var(--muted); line-height: 1.35; }
.scen[aria-pressed="true"] { border-color: var(--accent); background: rgba(217, 180, 90, 0.16); }
.scen[aria-pressed="true"] b { color: var(--accent); }

.pulse { animation: vsPulse 1.6s ease-in-out infinite; }
@keyframes vsPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 93, 115, 0); } 50% { box-shadow: 0 0 0 5px rgba(255, 93, 115, 0.35); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

@media (max-width: 640px) {
  .lane-label, .readout { flex-basis: 50%; }
  .trace { order: 3; flex-basis: 100%; border-left: none; border-right: none; border-top: 1px solid var(--line); }
  .legend .note { margin-left: 0; }
  .row { grid-template-columns: 76px minmax(0, 1fr); gap: 4px 10px; }
  .row .badge { grid-column: 2; justify-self: start; }
  .row .x { white-space: normal; }
}
