/* =====================================================================
   EdgeChat slice — Graphite & Ember
   Tokens mirror theserverless.dev and the hub. One flat ember accent.
   ===================================================================== */

:root {
  --ember: #c2410c;
  --ember-2: #e2622e;
  --ember-rgb: 194, 65, 12;
  --font-heading: "Bricolage Grotesque", "Space Grotesk", system-ui, sans-serif;
  --font-body: "Hanken Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --radius-sm: 6px;
  --radius: 10px;
  --fast: 0.16s cubic-bezier(0.4, 0, 0.2, 1);
  --topbar-h: 59px;
  --strip-h: 37px;
  --rooms-w: 280px;
}

:root, [data-theme="dark"] {
  --bg: #0e0e11;
  --surface: #141418;
  --surface-2: #1b1b20;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #c9c9c4;
  --text-strong: #e8e8e4;
  --muted: #8a8a85;
  --accent-text: #e2622e;
  --ok: #5aa877;
  --ok-soft: rgba(90, 168, 119, 0.12);
  --warn: #d19a2a;
  --warn-soft: rgba(209, 154, 42, 0.1);
  --danger: #d0533f;
  --mine: rgba(194, 65, 12, 0.12);
}

[data-theme="light"] {
  --ember: #b23a0a;
  --ember-2: #c2410c;
  --ember-rgb: 178, 58, 10;
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f3f1eb;
  --border: rgba(23, 23, 26, 0.1);
  --border-strong: rgba(23, 23, 26, 0.2);
  --text: #3d3a34;
  --text-strong: #17171a;
  --muted: #6b675e;
  --accent-text: #b23a0a;
  --ok: #2f7d4f;
  --ok-soft: rgba(47, 125, 79, 0.1);
  --warn: #a86f0a;
  --warn-soft: rgba(168, 111, 10, 0.1);
  --danger: #b43d2b;
  --mine: rgba(178, 58, 10, 0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
h1, h2 { font-family: var(--font-heading); color: var(--text-strong); letter-spacing: -0.02em; line-height: 1.15; }
a { color: var(--text-strong); text-decoration: none; }
a:hover { color: var(--accent-text); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
.icon { width: 18px; height: 18px; flex-shrink: 0; display: block; }
:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  height: 34px; padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  color: var(--text-strong);
  font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: border-color var(--fast), background-color var(--fast), color var(--fast);
}
.btn:hover { border-color: rgba(var(--ember-rgb), 0.6); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--ember); border-color: var(--ember); color: #fff; }
.btn-primary:hover { background: var(--ember-2); border-color: var(--ember-2); }
.btn-ghost { border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-icon { width: 34px; padding: 0; }

.eyebrow {
  font: 600 11px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.hint { font-size: 12px; color: var(--muted); min-height: 1.5em; }
.hint[data-tone="error"] { color: var(--danger); }
.hint[data-tone="ok"] { color: var(--ok); }

.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  height: var(--topbar-h); padding: 0 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--accent-text); font: 600 13px/1 var(--font-body); }
.brand span { color: var(--text); }
.brand__mark { display: block; color: var(--accent-text); }
.topbar__title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.topbar__title h1 { font-size: 20px; font-weight: 700; white-space: nowrap; }
.topbar__title p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__actions { display: flex; align-items: center; gap: 6px; }
.you { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.you input {
  width: 140px; height: 34px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.strip {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--strip-h); padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; color: var(--text);
  background: var(--surface);
}
.strip__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.strip[data-state="live"] { background: var(--ok-soft); }
.strip[data-state="live"] .strip__dot { background: var(--ok); }
.strip[data-state="off"] { background: var(--warn-soft); }
.strip[data-state="off"] .strip__dot { background: var(--warn); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--rooms-w) 1fr;
  min-height: 0;
}

.rooms {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 16px 20px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.rooms__head { display: flex; align-items: baseline; justify-content: space-between; }
.rooms__head h2 { font-size: 16px; }
.count {
  font-family: var(--font-mono); font-size: 12px; color: var(--muted);
}
.join { display: flex; gap: 6px; }
.join input, .composer input[type="text"] {
  flex: 1; min-width: 0; height: 34px; padding: 0 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.room-list { list-style: none; overflow: auto; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.room-btn {
  width: 100%; text-align: left; padding: 10px 12px;
  border-radius: var(--radius); border: 1px solid transparent;
  color: var(--text);
}
.room-btn:hover { background: var(--surface-2); }
.room-btn.is-on { border-color: rgba(var(--ember-rgb), 0.45); background: var(--mine); color: var(--text-strong); }
.room-btn__name { display: block; font-weight: 600; }
.room-btn__preview { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rooms__hint { margin-top: auto; }

.chat {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.chat__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.chat__head h2 { font-size: 18px; }
.presence { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

.messages {
  list-style: none; flex: 1; overflow: auto; padding: 16px 20px 8px;
  display: flex; flex-direction: column; gap: 10px;
}
.empty { padding: 24px 20px; color: var(--muted); }

.msg {
  max-width: min(640px, 92%);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.msg.is-mine { align-self: flex-end; background: var(--mine); border-color: rgba(var(--ember-rgb), 0.25); }
.msg__meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.msg__author { font-weight: 600; color: var(--text-strong); font-size: 13px; }
.msg__time { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.msg__body { white-space: pre-wrap; word-break: break-word; }
.msg__file {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 8px;
  font-size: 13px; color: var(--accent-text);
}
.msg__img {
  display: block; margin-top: 8px; max-width: min(360px, 100%);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

.composer {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 20px 4px; border-top: 1px solid var(--border);
}
.composer #hint { flex-basis: 100%; }
.attach { position: relative; }
.attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filechip {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  border: 1px dashed var(--border-strong); border-radius: 999px; padding: 4px 10px;
}
.composer .hint { padding: 0 20px 12px; }

.foot {
  padding: 12px 20px 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
}
.foot a { color: var(--text); }
.foot a:hover { color: var(--accent-text); }

@media (max-width: 800px) {
  .topbar { grid-template-columns: 1fr auto; height: auto; padding: 10px 12px; gap: 8px; }
  .topbar__title { grid-column: 1 / -1; }
  .topbar__title p { display: none; }
  .you span { display: none; }
  .you input { width: 110px; }
  .layout { grid-template-columns: 1fr; }
  .rooms { border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
  .messages { padding: 12px; }
  .composer { padding: 10px 12px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
