/* =====================================================================
   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 { 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;
  height: 100dvh;
  overflow: hidden;
}
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);
  flex-shrink: 0; background: var(--bg);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--accent-text); font: 600 13px/1 var(--font-body);
  min-height: 44px;
}
.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);
  flex-shrink: 0;
}
.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;
  overflow: hidden;
}

.rooms {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 16px 20px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  overflow: hidden;
}
.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; min-height: 0; }
.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; overflow: hidden;
}
.chat__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat__head h2 { font-size: 18px; }
.presence { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

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

.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;
  padding-block: 12px; min-height: 44px;
  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 12px; border-top: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg);
}
.composer #hint, .composer .hint, .composer .turnstile { 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;
  min-height: 32px;
}
.turnstile { max-width: 100%; overflow: auto; }

.foot {
  padding: 12px 20px 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted);
  flex-shrink: 0;
}
.foot a { color: var(--text); padding-block: 12px; display: inline-block; min-height: 44px; }
.foot a:hover { color: var(--accent-text); }

.shows {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}
.shows--bar {
  padding: 0.7rem 1rem;
  background: rgba(194, 65, 12, 0.08);
  border-bottom: 1px solid rgba(194, 65, 12, 0.28);
}
.shows__k {
  margin-right: 0.45rem;
  font-family: "JetBrains Mono", ui-monospace, Menlo, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c2410c;
}

@media (max-width: 800px) {
  .topbar { grid-template-columns: 1fr; height: auto; padding: 10px 12px; gap: 8px; }
  .topbar__title { grid-column: 1; }
  .topbar__title p { display: none; }
  .topbar__actions { grid-column: 1; width: 100%; justify-content: flex-start; }
  .topbar__actions > a.btn-ghost { display: none; }
  .you { flex: 1 1 8rem; min-width: 0; }
  .you span { display: none; }
  .you input { width: 100%; min-width: 0; height: 44px; font-size: 16px; }
  .layout { grid-template-columns: 1fr; }
  .rooms {
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: none; padding: 10px 12px;
    gap: 8px;
  }
  .rooms__hint { display: none; }
  .room-list {
    flex-direction: row; overflow-x: auto; overflow-y: hidden;
    flex: none; gap: 8px; padding-bottom: 2px;
  }
  .room-list li { flex: 0 0 auto; }
  .room-btn { width: auto; min-height: 44px; white-space: nowrap; padding: 8px 12px; }
  .room-btn__preview { display: none; }
  .messages { padding: 12px; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .join input, .composer input[type="text"] { height: 44px; }
  .shows--bar {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .strip { min-height: 0; padding: 6px 12px; font-size: 12px; }
  .foot { display: none; }
}

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

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
textarea,
select {
  font-size: 16px;
}

@media (max-width: 900px) {
  .btn,
  a.btn,
  .btn-primary,
  .btn-ghost,
  .room-btn {
    min-height: 44px;
  }
  .btn-icon {
    min-width: 44px;
    width: 44px;
    height: 44px;
  }
  .topbar {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .topbar__actions { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; }
  .join input { min-width: 0; max-width: 100%; }
}
