:root {
  --bg: #171d2e;
  --panel: #1f2a44;
  --panel-2: #26335200;
  --line: #34446a;
  --ink: #f2f4f1;
  --muted: #a9b4cc;
  --pandan: #1e7a5a;
  --pandan-hi: #2fa37a;
  --kunyit: #e0a21b;
  --bata: #c65a3e;
  --kertas: #f2f4f1;
  --shadow: 4px 4px 0 rgba(0, 0, 0, .35);
  --pixel: "Silkscreen", ui-monospace, monospace;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(900px 500px at 15% -10%, rgba(224, 162, 27, .10), transparent 60%), var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
}
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

.pixel-title { font: 20px/1.2 var(--pixel); letter-spacing: .5px; }
.pixel-sub { font: 14px/1.3 var(--pixel); letter-spacing: .5px; color: var(--kunyit); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  font: 13px var(--pixel);
  border: 2px solid #0d1322;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--ink);
  background: var(--panel);
}
.btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 rgba(0, 0, 0, .35); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--pandan); }
.btn-primary:hover:not(:disabled) { background: var(--pandan-hi); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.btn-ghost:hover { border-color: var(--kunyit); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--kunyit); outline-offset: 2px; }

.chip { font: 12px var(--pixel); padding: 4px 8px; border: 2px solid currentColor; }
.chip-ok { color: #6ee3a8; }
.chip-wait { color: var(--kunyit); }
.chip-bad { color: #ff8b73; }

.card, .floor-card, .chat-card, .log-card {
  background: var(--panel);
  border: 2px solid #0d1322;
  box-shadow: var(--shadow);
}

/* ── Login ───────────────────────────────────────────────────────────── */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px 24px; background: var(--panel); border: 2px solid #0d1322; box-shadow: 6px 6px 0 rgba(0, 0, 0, .4); text-align: center; }
.login-art { width: 100%; max-width: 240px; image-rendering: pixelated; margin: 0 auto 14px; display: block; }
.login-card .muted { margin: 6px 0 18px; }
.login-form { display: grid; gap: 12px; text-align: left; }
.login-form label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.login-form input, .composer textarea {
  width: 100%;
  font: 15px var(--sans);
  color: var(--ink);
  background: #141b2c;
  border: 2px solid var(--line);
  padding: 10px 12px;
}
.error { color: #ff8b73; font-size: 14px; }

/* ── App layout ──────────────────────────────────────────────────────── */
.app { max-width: 1320px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 28px; height: 28px; background: var(--pandan); box-shadow: inset -6px -6px 0 #145c43, 3px 3px 0 #0d1322; }
.topbar-right { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 1fr);
  grid-template-areas: "floor chat" "log chat";
}
.floor-card { grid-area: floor; padding: 14px; }
.chat-card { grid-area: chat; display: flex; flex-direction: column; min-height: 560px; max-height: calc(100vh - 110px); }
.log-card { grid-area: log; padding: 14px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "floor" "chat" "log"; }
  .chat-card { max-height: none; min-height: 460px; }
}

/* ── Floor ───────────────────────────────────────────────────────────── */
.floor-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.floor { width: 100%; display: block; image-rendering: pixelated; border: 2px solid #0d1322; }
.wall { fill: #33405f; }
.wall-trim { fill: #4a3b6b; }
.window { fill: #8fc7e8; }
.window-bar { fill: #e8e2d4; }
.board { fill: #e8e2d4; }
.board-text { font: 5px var(--pixel); fill: #1e7a5a; }
.board-sub { font: 3px var(--pixel); fill: #4a3b6b; }
.floor-wood { fill: #8a5a3c; }
.floor-lines rect { fill: #7a4e33; }
.aisle { fill: #1e7a5a; opacity: .55; }
.pot { fill: #c65a3e; }
.leaf { fill: #2fa37a; }

.desk { cursor: pointer; outline: none; }
.chair { fill: #3b3b4f; }
.skin { fill: #f2c79b; }
.eye { fill: #141414; }
.collar { fill: #f4f1ea; }
.headset { fill: #141414; }
.desk-top { fill: #c2894f; }
.desk-front { fill: #a8733f; }
.desk-leg { fill: #6b4430; }
.monitor { fill: #1d2b3a; }
.screen { fill: #0f1a14; }
.code { fill: #2c8f75; }
.keyboard { fill: #d9d4c7; }
.paper { fill: #f4f1ea; }
.phone { fill: #e0a21b; }
.plate { fill: #1f2a44; }
.plate-text { font: 3.6px var(--pixel); fill: #f2f4f1; letter-spacing: .1px; }
.glow { fill: transparent; stroke: transparent; stroke-width: 1; }
.desk:hover .glow { stroke: #a9b4cc; stroke-dasharray: 1 2; }
.desk.selected .glow, .desk:focus-visible .glow { stroke: #e0a21b; stroke-dasharray: 2 2; animation: march 1s linear infinite; }
.desk.selected .plate { fill: #e0a21b; }
.desk.selected .plate-text { fill: #1f2a44; }
.desk .person { animation: idle 3s steps(2) infinite; }
.desk.working .screen { fill: #0f2a20; }
.desk.working .code { fill: #6ef3c5; animation: blink .8s steps(1) infinite; }
.desk.working .person { animation: type .4s steps(1) infinite; }
.bubble, .donecheck { display: none; }
.desk.working .bubble { display: inline; }
.desk.done:not(.working) .donecheck { display: inline; }
.bubble-bg { fill: #f4f1ea; }
.dot { fill: #1f2a44; animation: dot 1.2s steps(1) infinite; }
.d2 { animation-delay: .2s; }
.d3 { animation-delay: .4s; }
.check-box { fill: #f4f1ea; }
.check { fill: #1e7a5a; }

.roster { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 0; padding: 0; }
.roster button {
  width: 100%;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 2px 8px;
  align-items: center;
  text-align: left;
  padding: 7px 9px;
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--line);
  cursor: pointer;
  font: 600 13px var(--sans);
}
.roster button:hover { border-color: var(--muted); }
.roster button.active { border-color: var(--kunyit); background: rgba(224, 162, 27, .08); }
.roster .pip { width: 10px; height: 10px; grid-row: span 2; box-shadow: 0 0 0 1px var(--muted); }
.roster .r-state { font: 11px var(--pixel); }
@media (max-width: 620px) { .roster { grid-template-columns: repeat(2, 1fr); } }

/* ── Chat ────────────────────────────────────────────────────────────── */
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 2px solid #0d1322; }
.thread { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #1a2338; }
.empty { margin: auto; text-align: center; max-width: 320px; display: grid; gap: 8px; }
.msg { max-width: 88%; display: grid; gap: 4px; }
.msg-user { align-self: flex-end; }
.msg-assistant { align-self: flex-start; }
.msg-who { font: 11px var(--pixel); color: var(--muted); }
.msg-user .msg-who { text-align: right; }
.msg-body { padding: 10px 12px; border: 2px solid #0d1322; overflow-wrap: anywhere; }
.msg-user .msg-body { background: var(--pandan); }
.msg-assistant .msg-body { background: #2a3858; }
.msg-error .msg-body { background: #4a2a2a; color: #ffd0c4; }
.streaming .msg-body::after { content: "▌"; animation: blink 1s steps(1) infinite; color: var(--kunyit); }
.msg-body pre { margin: 8px 0; padding: 8px; background: #0f1520; overflow-x: auto; font: 13px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.msg-body code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; background: rgba(0, 0, 0, .25); padding: 0 3px; }
.msg-body pre code { background: none; padding: 0; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 2px solid #0d1322; align-items: flex-end; }
.composer textarea { resize: none; min-height: 52px; }
.composer .btn { height: 52px; }
.cs-panel { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 14px; background: #1a2338; }
.cs-panel .btn { align-self: flex-start; text-decoration: none; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0; }
.stats div { padding: 10px; background: var(--panel); border: 2px solid #0d1322; }
.stats dt { font: 11px var(--pixel); color: var(--muted); }
.stats dd { margin: 4px 0 0; font: 700 20px var(--sans); }

/* ── Log ─────────────────────────────────────────────────────────────── */
.log { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 6px 8px; background: #1a2338; border-left: 3px solid var(--line); font-size: 13px; }
.log li time { color: var(--muted); font: 11px var(--pixel); grid-row: span 2; align-self: center; }
.log li span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log .log-task { border-left-color: var(--kunyit); }
.log .log-done { border-left-color: var(--pandan-hi); }
.log .log-error { border-left-color: var(--bata); }
.log .log-security { border-left-color: #6c7a92; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes march { to { stroke-dashoffset: -4; } }
@keyframes step { 50% { transform: translateY(-1px); } }
@keyframes idle { 50% { transform: translateY(-.5px); } }
@keyframes type { 50% { transform: translateY(.5px); } }
@keyframes dot { 0%, 66% { opacity: 1; } 33% { opacity: .2; } }

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