:root {
  --chassis: #14161c;
  --face: #1c2029;
  --strip: #222734;
  --strip-armed: #252c3d;
  --hairline: #3a4154;
  --tungsten: #f0b429;
  --talk: #4f8cff;
  --danger: #e85d4c;
  --ok: #5dcaa5;
  --mute: #8b93a7;
  --ink: #e8eaef;
  --recess: #0d0f14;
  --font-ui: "Familjen Grotesk", "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--chassis); color: var(--ink); font-family: var(--font-ui); }
body { background-image: radial-gradient(1200px 500px at 10% -10%, #1d2433 0%, transparent 55%); }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--talk); text-decoration: none; }
code { font-family: var(--font-data); font-size: 0.85em; }

.chassis { max-width: 1180px; margin: 0 auto; padding: 28px 20px 48px; }
.faceplate {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 20px;
  align-items: center;
  background: linear-gradient(180deg, #262b38, var(--face));
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 16px 18px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 12px 40px rgba(0,0,0,0.35);
}
.brand { display: flex; gap: 14px; align-items: center; }
.eyebrow { margin: 0; color: var(--mute); font-family: var(--font-data); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: 28px; letter-spacing: -0.03em; font-weight: 700; }
.screw {
  width: 14px; height: 14px; border-radius: 50%;
  background: conic-gradient(from 40deg, #6a7184, #2c313c, #8a91a3, #2c313c);
  box-shadow: inset 0 0 0 2px #1a1d24;
}
.nav { display: flex; gap: 8px; }
.nav a {
  color: var(--mute); padding: 8px 12px; border: 1px solid transparent; border-radius: 4px;
  font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; font-size: 12px;
}
.nav a:hover, .nav a.active { color: var(--ink); border-color: var(--hairline); background: var(--recess); }
.meters { display: flex; gap: 16px; }
.meter { text-align: right; }
.meter span { display: block; font-family: var(--font-data); font-size: 22px; color: var(--tungsten); }
.meter label { color: var(--mute); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 18px; color: var(--mute); font-size: 13px; align-items: center; }
.legend .hint { margin-left: auto; }
.led { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #555; box-shadow: 0 0 0 2px #111; }
.led.live { background: var(--tungsten); box-shadow: 0 0 8px var(--tungsten); }
.led.idle { background: #5a6274; }
.led.armed { background: var(--talk); box-shadow: 0 0 8px #4f8cff88; }

.rack { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; }
.strip {
  display: grid;
  grid-template-columns: 28px 1.6fr 1.2fr 90px 88px 110px;
  gap: 12px;
  align-items: center;
  background: var(--strip);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 12px 14px;
  min-height: 76px;
}
.strip.armed { background: var(--strip-armed); border-color: #4f8cff55; }
.strip:hover { border-color: #5b6580; }
.channel-index { font-family: var(--font-data); color: var(--mute); font-size: 12px; }
.title { margin: 0; font-size: 17px; font-weight: 600; }
.meta, .turn { margin: 4px 0 0; color: var(--mute); font-size: 12px; font-family: var(--font-data); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn { color: #c6cbd6; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pid { font-family: var(--font-data); font-size: 12px; color: var(--mute); }
.resume-cmd {
  display: block;
  margin-top: 6px;
  width: 100%;
  text-align: left;
  background: var(--recess);
  border: 1px dashed var(--hairline);
  color: var(--tungsten);
  font-family: var(--font-data);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0;
  padding: 6px 8px;
  border-radius: 3px;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
}
.resume-cmd:hover { border-color: var(--tungsten); color: var(--ink); }
.resume-cmd.copied { border-style: solid; border-color: var(--ok); color: var(--ok); }
.resume-cmd.copied::after { content: "  copied"; color: var(--ok); }
.chat-head .resume-cmd {
  flex: 1 1 100%;
  width: auto;
}
.arm {
  appearance: none; border: 1px solid var(--hairline); background: var(--recess);
  padding: 8px 10px; border-radius: 3px; cursor: pointer; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; font-size: 11px; color: var(--mute);
}
.strip.armed .arm { color: var(--talk); border-color: #4f8cff88; }
.talk {
  background: var(--talk); color: #081018; border: 0; padding: 8px 10px; border-radius: 3px;
  font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 11px; cursor: pointer;
}
.talk:disabled { opacity: 0.35; cursor: not-allowed; }

.unlock, .panel {
  margin-top: 28px; background: var(--face); border: 1px solid var(--hairline); border-radius: 6px; padding: 28px;
}
.unlock h2, .panel h2 { margin: 0 0 8px; }
.unlock p, .panel p { color: var(--mute); }
.row { display: flex; gap: 10px; margin-top: 16px; }
input[type="text"], input[type="password"], textarea {
  background: var(--recess); border: 1px solid var(--hairline); border-radius: 4px; padding: 10px 12px; width: 100%;
  font-family: var(--font-data); font-size: 13px;
}
textarea { min-height: 120px; resize: vertical; }
.primary {
  background: var(--tungsten); color: #1a1406; border: 0; padding: 10px 16px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase; cursor: pointer; border-radius: 3px;
}
.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); padding: 8px 12px; cursor: pointer; border-radius: 3px; }
.err { color: var(--danger); font-family: var(--font-data); font-size: 13px; }
.ok { color: var(--ok); }
.session-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-top: 22px; }
.job { margin-top: 16px; background: var(--recess); border: 1px solid var(--hairline); padding: 14px; font-family: var(--font-data); font-size: 12px; white-space: pre-wrap; }
.audit { list-style: none; padding: 0; margin: 12px 0 0; }
.audit li { font-family: var(--font-data); font-size: 12px; color: var(--mute); border-top: 1px solid var(--hairline); padding: 8px 0; }
.pre { font-family: var(--font-data); font-size: 12px; background: var(--recess); padding: 14px; border-radius: 4px; overflow: auto; }
.empty { margin-top: 32px; color: var(--mute); }
.tape { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.take {
  background: var(--recess);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--talk);
  padding: 12px 14px;
}
.take header {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-family: var(--font-data); font-size: 11px; color: var(--mute); margin-bottom: 8px;
}
.take .prompt, .take .reply { margin: 6px 0 0; white-space: pre-wrap; font-size: 14px; }
.take .prompt strong { color: var(--tungsten); margin-right: 8px; }
.take .reply strong { color: var(--talk); margin-right: 8px; }

.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.viewbar { display: flex; border: 1px solid var(--hairline); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.viewbar button {
  background: transparent; border: 0; color: var(--mute); padding: 8px 16px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer;
}
.viewbar button.on { background: var(--recess); color: var(--ink); }

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: min(70vh, 720px);
  overflow: auto;
  padding: 16px 12px 20px;
  background:
    radial-gradient(circle at 20% 0%, #1a2230 0%, transparent 50%),
    var(--recess);
  border: 1px solid var(--hairline);
  border-radius: 12px;
}
.stamp {
  align-self: center;
  font-family: var(--font-data);
  font-size: 10px;
  color: var(--mute);
  letter-spacing: 0.04em;
  margin: 6px 0 2px;
}
.msg { display: flex; flex-direction: column; max-width: min(78%, 36rem); }
.msg .who { font-size: 11px; color: var(--mute); margin: 0 10px 4px; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.them { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}
.bubble.bot {
  background: #3b82f6;
  color: #f8fbff;
  border-radius: 18px 18px 4px 18px;
}
.bubble.local {
  background: #2c3344;
  color: var(--ink);
  border-radius: 18px 18px 18px 4px;
}
.bubble.local.qwen {
  background: #2f2a1d;
  color: #f6e7c1;
  box-shadow: inset 0 0 0 1px #f0b42944;
}
.bubble.bad { background: #5a2a28; color: #ffd4d0; }
.bubble.local.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  min-height: 72px;
}
.activity-sprite {
  display: inline-block;
  width: 96px;
  height: 96px;
  flex-shrink: 0;
  background-image: url("/assets/activity/local-grok-reply-sheet.png");
  background-repeat: no-repeat;
  background-size: 576px 96px;
  animation: local-grok-typing 0.66s steps(6) infinite;
}
.typing-label {
  color: var(--mute);
  font-size: 13px;
  letter-spacing: 0.04em;
}
.take .reply.waiting {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.take .reply.waiting .activity-sprite {
  width: 72px;
  height: 72px;
  background-size: 432px 72px;
  animation-name: local-grok-typing-sm;
}
@keyframes local-grok-typing {
  from { background-position: 0 0; }
  to { background-position: -576px 0; }
}
@keyframes local-grok-typing-sm {
  from { background-position: 0 0; }
  to { background-position: -432px 0; }
}
.conv.working strong::after {
  content: " · working";
  color: var(--tungsten);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
@media (max-width: 720px) {
  .activity-sprite {
    width: 72px;
    height: 72px;
    background-size: 432px 72px;
    animation-name: local-grok-typing-sm;
  }
}
@media (prefers-reduced-motion: reduce) {
  .activity-sprite {
    animation: none;
    background-position: 0 0;
  }
}

body.chat-layout,
body.chat-layout html {
  height: 100%;
  overflow: hidden;
}
body.chat-layout .chassis {
  height: 100vh;
  max-width: 1180px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 12px;
}
body.chat-layout #app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.chat-layout #app .panel {
  flex: 0 0 auto;
}
body.chat-layout .legend {
  flex-shrink: 0;
  margin-top: 8px;
}

.inbox {
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  flex: 1;
  min-height: 0;
  height: min(72vh, 760px);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  overflow: hidden;
  background: var(--face);
  margin-top: 12px;
}
body.chat-layout .inbox {
  height: auto;
}
.inbox-list {
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  height: 100%;
  border-right: 1px solid var(--hairline);
  background: #191c24;
}
.conv {
  display: block;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
  color: inherit;
}
.conv strong { display: block; font-size: 14px; }
.conv .meta { display: block; margin-top: 4px; font-size: 12px; color: var(--mute); }
.conv:hover { background: #222734; }
.conv.on {
  background: #243044;
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.25);
}
.conv.armed strong::before,
.conv.live strong::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  margin-right: 8px;
}
.conv.armed strong::before {
  background: var(--talk);
  box-shadow: 0 0 8px #4f8cff88;
}
.conv.live strong::before {
  background: var(--tungsten);
  box-shadow: 0 0 8px var(--tungsten);
}
.conv.llm strong::before {
  background: #c084fc;
  box-shadow: 0 0 8px #c084fc88;
}
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--hairline);
  background: var(--face);
  flex-shrink: 0;
}
.composer textarea {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 72px;
  resize: vertical;
  background: var(--recess);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
}
.composer .primary { justify-self: end; }
.composer .action-msg { color: var(--mute); font-size: 12px; align-self: center; }
.strip.llm { border-color: #c084fc55; }
.qwen-jump {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 0;
  padding: 14px 16px;
  border: 1px solid #c084fc88;
  border-radius: 8px;
  background: #241c33;
  color: inherit;
}
.qwen-jump strong { font-size: 18px; }
.qwen-jump span { color: var(--mute); font-family: var(--font-data); font-size: 12px; }
.qwen-jump:hover { border-color: #c084fc; }

.inbox.qwen-solo,
body.qwen-solo .inbox {
  grid-template-columns: 1fr;
  height: auto;
  min-height: 0;
  flex: 1;
}
body.qwen-solo .inbox-list { display: none; }
body.qwen-solo #app .panel { display: none; }

.inbox-chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.chat-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  flex-shrink: 0;
  background: var(--face);
}
.chat-head strong { flex: 1 1 auto; }
.rename {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--mute);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.rename:hover { color: var(--ink); border-color: var(--talk); }
.inbox-chat .tape {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.inbox-chat .thread {
  flex: 1;
  min-height: 0;
  max-height: none;
  height: auto;
  overflow-y: auto;
  overflow-x: hidden;
  border: 0;
  border-radius: 0;
}
.fold-btn {
  align-self: center;
  position: sticky;
  top: 0;
  z-index: 2;
  background: #2a3142;
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  margin: 4px 0 10px;
}
.fold-btn:hover { border-color: var(--talk); color: var(--talk); }
.bay-filter { margin: 16px 0 10px; }
.qr-slot img {
  width: 96px;
  height: 96px;
  background: #fff;
  padding: 6px;
  border-radius: 8px;
  display: block;
}

@media (max-width: 900px) {
  .msg { max-width: 88%; }
  .faceplate { grid-template-columns: 1fr; }
  .strip { grid-template-columns: 1fr 1fr; }
  .legend .hint { margin-left: 0; }
  .inbox {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 28vh) 1fr;
  }
  .inbox-list {
    height: auto;
    max-height: 28vh;
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
  }
  .nav a { padding: 8px 8px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .led.live { box-shadow: none; }
}
