:root {
  --bg: #070b12;
  --bg-2: #0d1422;
  --panel: #111a2b;
  --panel-2: #162338;
  --line: rgba(191, 219, 254, 0.10);
  --text: #e8f1ff;
  --muted: #8aa1c0;
  --cyan: #6ee7ff;
  --violet: #b38cff;
  --green: #5af0a6;
  --yellow: #ffd166;
  --red: #ff6b88;
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(110,231,255,.20), transparent 25%),
    radial-gradient(circle at 80% 10%, rgba(179,140,255,.16), transparent 22%),
    linear-gradient(180deg, #05070d 0%, var(--bg) 100%);
  font-family: "Courier New", Courier, ui-monospace, SFMono-Regular, monospace;
  overflow: hidden;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(rgba(255,255,255,0.025) 50%, rgba(0,0,0,0.08) 50%);
  background-size: 100% 4px;
  mix-blend-mode: soft-light;
  opacity: .25;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 330px;
  gap: 14px;
  padding: 14px;
  height: 100vh;
}

.sidebar, .center-column, .details-column {
  min-height: 0;
}

.sidebar, .panel, .office-card, .chat-card {
  background: linear-gradient(180deg, rgba(17,26,43,.94), rgba(9,14,25,.96));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 14px 40px var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);
}

.sidebar, .details-column {
  overflow: auto;
  padding: 16px;
}

.center-column {
  display: grid;
  grid-template-rows: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
  min-width: 0;
}

.office-card, .chat-card, .panel {
  overflow: hidden;
}

.avatar-panel {
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.avatar-panel h2 { margin: 0; font-size: 0.9rem; }

#avatarCanvas {
  width: 100%;
  max-width: 280px;
  height: 300px;
  border-radius: 12px;
  background: #05080f;
  display: block;
}

#avatarStatus {
  font-size: 0.75rem;
  text-align: center;
}

.office-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.card-head.compact { padding-bottom: 10px; }

h1, h2, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: .04em; }
h2 { font-size: 16px; letter-spacing: .03em; }
.eyebrow {
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: 10px;
  margin-bottom: 6px;
}
.muted { color: var(--muted); font-size: 12px; line-height: 1.4; }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.logo {
  width: 48px; height: 48px; display: grid; place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #0ff, #a855f7);
  color: #040810;
  font-weight: 900;
  box-shadow: 0 0 0 3px rgba(255,255,255,.06), 0 0 26px rgba(110,231,255,.20);
}
label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
select, textarea, button {
  width: 100%;
  border: 1px solid rgba(125, 154, 187, 0.18);
  border-radius: 14px;
  background: linear-gradient(180deg, #18263c, #101827);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
select { margin-bottom: 10px; }
textarea { resize: vertical; min-height: 86px; }
button {
  cursor: pointer;
  background: linear-gradient(180deg, #2a7bc9, #5f39d8);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.1);
}
button.secondary { background: linear-gradient(180deg, #1a2539, #111827); color: var(--cyan); }
button:hover { filter: brightness(1.08); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }

.session-tag, .pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 28px; padding: 0 10px; border-radius: 999px;
  background: #0c1320; border: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
}
.pill.idle { color: var(--muted); }
.pill.thinking, .pill.tool { color: #03121a; background: linear-gradient(180deg, #68e8ff, #3bc7f6); }
.pill.speaking { color: #062016; background: linear-gradient(180deg, #94f7c5, #39d98a); }
.pill.error { color: #24010a; background: linear-gradient(180deg, #ff8aa0, #ff5377); }
.office-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

#officeCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #09101d;
  image-rendering: pixelated;
}
.office-caption {
  padding: 10px 16px 14px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.chat-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}
.chat-log {
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.message {
  max-width: min(84%, 680px);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,.03);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03);
  white-space: pre-wrap;
  line-height: 1.45;
}
.message.user {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(54, 106, 180, .34), rgba(28, 43, 79, .38));
  border-color: rgba(110,231,255,.22);
}
.message.assistant {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(91, 68, 160, .28), rgba(20, 29, 52, .55));
  border-color: rgba(179,140,255,.20);
}
.message.error {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(255,107,136,.24), rgba(49, 14, 31, .48));
  border-color: rgba(255,107,136,.32);
}
.message .meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.composer {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(10,16,27,.84);
}
.composer button { margin-top: 0; }

.panel {
  padding: 14px;
  margin-bottom: 14px;
}
.panel:last-child { margin-bottom: 0; }
.crew-list { display: grid; gap: 10px; margin-top: 10px; }
.crew-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  cursor: pointer;
}
.crew-item.active { border-color: rgba(110,231,255,.35); box-shadow: 0 0 0 1px rgba(110,231,255,.14) inset; }
.crew-swatch {
  width: 18px; height: 18px; border-radius: 6px; border: 1px solid rgba(255,255,255,.2);
  box-shadow: 0 0 14px rgba(255,255,255,.06);
}
.crew-name { font-size: 13px; }
.crew-status { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.meta-box {
  margin-top: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  min-height: 80px;
  white-space: pre-line;
}
.timeline { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.timeline-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border-left: 3px solid var(--cyan);
}
.timeline-item.error { border-left-color: var(--red); }
.timeline-item small {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 10px;
}

@media (max-width: 1220px) {
  body { overflow: auto; }
  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 250px minmax(0, 1fr);
  }
  .details-column { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .panel { margin-bottom: 0; }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .details-column { grid-column: auto; grid-template-columns: 1fr; }
  .center-column { grid-template-rows: 460px minmax(420px, 1fr); }
}

@media (max-width: 680px) {
  .button-row, .composer { grid-template-columns: 1fr; }
  .office-meta { justify-content: flex-start; }
  .card-head { align-items: flex-start; flex-direction: column; }
  .center-column { grid-template-rows: 380px minmax(460px, 1fr); }
}
