:root {
  --bg: #020617;
  --floor: #0F172A;
  --panel: #0B1226;
  --line: #1E293B;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --green: #22C55E;
  --amber: #F59E0B;
  --red: #EF4444;
  --cyan: #38BDF8;
  --z-panel: 30;
  --z-drawer: 40;
  --z-login: 50;
  --z-toast: 60;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 20px;
  line-height: 1.5;
}
.pixel-title {
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--green);
  text-shadow: 0 0 8px rgba(34, 197, 94, 0.55);
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; z-index: var(--z-login);
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #071127 0%, var(--bg) 70%);
}
.login-box {
  display: flex; flex-direction: column; gap: 10px;
  padding: 32px; min-width: 300px;
  background: var(--panel); border: 2px solid var(--line);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.15);
}
.login-sub { color: var(--muted); margin: 0 0 10px; }
.login-box label { color: var(--muted); }
.login-box input {
  background: #020a1a; border: 2px solid var(--line); color: var(--text);
  padding: 10px; font: inherit; min-height: 44px;
}
.login-box input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.login-box button {
  min-height: 44px; margin-top: 6px;
  background: var(--green); color: #04140a; border: none;
  font-family: 'Press Start 2P', monospace; font-size: 12px;
  transition: background-color 200ms;
}
.login-box button:hover { background: #4ade80; }
.login-box button:disabled { opacity: 0.6; cursor: wait; }
.login-error { color: var(--red); min-height: 24px; margin: 0; }

/* ---------- layout ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px; border-bottom: 2px solid var(--line);
  background: var(--panel); flex-wrap: wrap;
}
.top-stat { color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.top-spacer { flex: 1; }
.led {
  width: 10px; height: 10px; display: inline-block;
  background: var(--red); box-shadow: 0 0 6px var(--red);
}
.led.up { background: var(--green); box-shadow: 0 0 6px var(--green); }
.topbtn {
  background: transparent; border: 2px solid var(--line); color: var(--text);
  padding: 8px 14px; min-height: 44px; min-width: 44px;
  transition: border-color 200ms, color 200ms;
}
.topbtn:hover { border-color: var(--green); color: var(--green); }
.topbtn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ---------- office ---------- */
.office {
  position: relative; flex: 1; overflow: auto;
  background:
    linear-gradient(rgba(30, 41, 59, 0.35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30, 41, 59, 0.35) 1px, transparent 1px),
    linear-gradient(180deg, #04102b 0%, var(--floor) 100%);
  background-size: 40px 40px, 40px 40px, 100% 100%;
}
.scanlines {
  pointer-events: none; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.16) 0 1px, transparent 1px 3px);
  mix-blend-mode: multiply;
}
.desks {
  display: grid; gap: 28px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  max-width: 1200px; margin: 0 auto; padding: 40px 24px 60px;
}
.station {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 68px 12px 12px;
  border: 2px solid transparent;
  transition: border-color 200ms, background-color 200ms;
  cursor: pointer;
  background: transparent;
  color: inherit; font: inherit; text-align: center;
}
.station:hover, .station:focus-visible {
  border-color: var(--line); background: rgba(15, 23, 42, 0.6); outline: none;
}
.station:focus-visible { border-color: var(--green); }
.station svg { width: 170px; height: 150px; image-rendering: pixelated; }
.nameplate {
  margin-top: 6px; display: inline-flex; align-items: center; gap: 8px;
  color: var(--text); letter-spacing: 1px;
}
.status-word { color: var(--muted); font-size: 16px; }
.station.working .status-word { color: var(--green); }
.station.thinking .status-word { color: var(--cyan); }
.station.error .status-word { color: var(--red); }

/* speech bubble */
.bubble {
  position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  max-width: 220px; padding: 6px 10px;
  background: var(--text); color: #0b1226;
  font-size: 16px; line-height: 1.3; text-align: left;
  border: 2px solid #0b1226;
  opacity: 0; transition: opacity 300ms;
  pointer-events: none;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}
.bubble.show { opacity: 1; }
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -6px;
  border: 6px solid transparent; border-top-color: var(--text);
}

/* character animation hooks (SVG groups) */
.arm-l, .arm-r { transform-box: fill-box; transform-origin: top center; }
.station.working .arm-l { animation: type 240ms steps(2) infinite; }
.station.working .arm-r { animation: type 240ms steps(2) infinite 120ms; }
@keyframes type { 0% { transform: translateY(0); } 100% { transform: translateY(2px); } }
.eyes { animation: blink 4.4s steps(1) infinite; }
@keyframes blink { 0%, 92%, 100% { opacity: 1; } 94%, 98% { opacity: 0; } }
.monitor-glow { opacity: 0.25; transition: opacity 300ms; }
.station.working .monitor-glow, .station.thinking .monitor-glow { opacity: 1; }
.station.working .monitor-glow { animation: flicker 900ms steps(3) infinite; }
@keyframes flicker { 0% { opacity: 1; } 50% { opacity: 0.75; } 100% { opacity: 0.95; } }
.think-dots { opacity: 0; }
.station.thinking .think-dots { opacity: 1; animation: think 1.2s steps(3) infinite; }
@keyframes think { 0% { transform: translateY(0); } 100% { transform: translateY(-2px); } }
.err-mark { opacity: 0; fill: var(--red); }
.station.error .err-mark { opacity: 1; animation: errblink 800ms steps(1) infinite; }
@keyframes errblink { 50% { opacity: 0.2; } }
.station.offline svg { filter: grayscale(0.9) brightness(0.5); }
.desk-led { fill: var(--muted); }
.station.working .desk-led, .station.thinking .desk-led { fill: var(--green); }
.station.error .desk-led { fill: var(--red); }

/* idle sway so the office never looks frozen */
.station .body { transform-box: fill-box; transform-origin: bottom center; }
.station.idle .body { animation: sway 5s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(1.5px); } }

/* bubble variants: real agent-to-agent talk vs ambient flavor */
.bubble.talk { background: var(--cyan); border-color: #06364f; }
.bubble.talk::after { border-top-color: var(--cyan); }
.bubble.ambient { background: rgba(148, 163, 184, 0.85); font-style: italic; color: #1e293b; }
.bubble.ambient::after { border-top-color: rgba(148, 163, 184, 0.85); }

/* office chat feed */
.office-chat {
  position: sticky; bottom: 0; z-index: 4;
  max-width: 1200px; margin: 0 auto; padding: 8px 14px 10px;
  background: rgba(2, 6, 23, 0.92); border: 2px solid var(--line); border-bottom: none;
}
.oc-title {
  font-family: 'Press Start 2P', monospace; font-size: 10px;
  color: var(--cyan); letter-spacing: 1px; margin-bottom: 4px;
}
.oc-log { max-height: 130px; overflow-y: auto; font-size: 17px; line-height: 1.4; }
.oc-line { color: var(--text); }
.oc-who { color: var(--cyan); letter-spacing: 1px; margin-right: 6px; }
.oc-time { color: var(--muted); font-size: 14px; margin-left: 6px; }

.power-cut {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, 0.88); color: var(--muted); gap: 8px;
}
.power-cut .pixel-title { color: var(--red); text-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }

/* ---------- panel & drawer ---------- */
.panel, .drawer {
  position: fixed; background: var(--panel); border: 2px solid var(--line);
  display: flex; flex-direction: column;
}
.panel {
  top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: var(--z-panel);
  border-width: 0 0 0 2px;
}
.drawer {
  left: 0; right: 0; bottom: 0; height: min(60vh, 560px); z-index: var(--z-drawer);
  border-width: 2px 0 0 0;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 2px solid var(--line);
}
.panel-title { font-family: 'Press Start 2P', monospace; font-size: 12px; color: var(--cyan); }
.tabs { display: flex; border-bottom: 2px solid var(--line); }
.tab {
  flex: 1; background: transparent; border: none; color: var(--muted);
  padding: 10px; min-height: 44px; font: inherit; letter-spacing: 1px;
  transition: color 200ms, background-color 200ms;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--green); background: rgba(34, 197, 94, 0.08); box-shadow: inset 0 -2px 0 var(--green); }
.tab:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.tabpane { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px; overflow: auto; }
.hint { color: var(--muted); font-size: 16px; margin: 0 0 8px; }

/* chat */
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 92%; padding: 8px 10px; border: 2px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: rgba(56, 189, 248, 0.12); border-color: rgba(56, 189, 248, 0.4); }
.msg.assistant { align-self: flex-start; background: rgba(34, 197, 94, 0.08); }
.msg.streaming { border-style: dashed; }
.msg .who { display: block; font-size: 14px; color: var(--muted); margin-bottom: 2px; letter-spacing: 1px; }
.chat-form { display: flex; gap: 8px; padding-top: 8px; }
.chat-form input, #task-input {
  flex: 1; background: #020a1a; border: 2px solid var(--line); color: var(--text);
  padding: 10px; font: inherit; min-height: 44px;
}
.chat-form input:focus, #task-input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.chat-form button, #task-send {
  background: var(--green); border: none; color: #04140a; padding: 0 16px; min-height: 44px;
  transition: background-color 200ms;
}
.chat-form button:hover, #task-send:hover { background: #4ade80; }
#chat-stop { background: var(--red); color: #fff; }
#chat-stop:hover { background: #f87171; }
#task-input { width: 100%; resize: vertical; }
#task-send { margin-top: 10px; padding: 12px 18px; }

/* history & drawer lists */
.history-list, .drawer-pane { gap: 8px; }
.rowitem {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 2px solid var(--line); padding: 8px 10px; margin-bottom: 8px;
}
.rowitem .grow { flex: 1; min-width: 140px; word-break: break-all; }
.rowitem .sub { color: var(--muted); font-size: 15px; display: block; }
.minibtn {
  background: transparent; border: 2px solid var(--line); color: var(--text);
  padding: 6px 10px; min-height: 36px; font: inherit; font-size: 15px;
  transition: border-color 200ms, color 200ms;
}
.minibtn:hover { border-color: var(--cyan); color: var(--cyan); }
.minibtn.danger:hover { border-color: var(--red); color: var(--red); }
.ok { color: var(--green); }
.bad { color: var(--red); }
.log-view { font-size: 14px; line-height: 1.35; white-space: pre-wrap; word-break: break-all; margin: 0; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--panel); border: 2px solid var(--red); color: var(--text); padding: 10px 14px; max-width: 340px; }
.toast.good { border-color: var(--green); }

@media (max-width: 700px) {
  .desks { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 20px 10px 40px; }
  .station svg { width: 130px; height: 116px; }
  .topbar { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
