/* FightClub design system: calm slate surfaces, one green accent, high contrast, touch-first.
   System font stack only. Tokens first; components below use tokens, never raw colours. */
:root {
  --bg: #f1f5f9; --fg: #0f172a; --muted: #475569; --card: #fff; --line: #cbd5e1;
  --accent: #15803d; --on-accent: #fff; --ok: #166534; --bad: #b91c1c; --focus: #1d4ed8;
  --nav-bg: #fff; --nav-active: #dcfce7;
  --radius: 12px; --radius-sm: 8px;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px;
  --target: 44px; --tabs-h: 60px; --side-w: 248px; --content-w: 960px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --dur: 150ms;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px); --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --fg: #f8fafc; --muted: #94a3b8; --card: #1b2336; --line: #3b475c;
    --accent: #22c55e; --on-accent: #0f172a; --ok: #4ade80; --bad: #f87171; --focus: #93c5fd;
    --nav-bg: #131c30; --nav-active: #163a2a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 16px/1.5 var(--font); background: var(--bg); color: var(--fg);
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip {
  position: absolute; left: var(--space-2); top: -100px; z-index: 20; padding: var(--space-3);
  background: var(--card); color: var(--fg); border: 2px solid var(--focus);
  border-radius: var(--radius-sm);
}
.skip:focus { top: calc(var(--safe-top) + var(--space-2)); }

/* Shell: phone = top bar + tab bar; desktop = sidebar. */
.shell { min-height: 100vh; min-height: 100dvh; }
.bar {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: var(--safe-top) var(--space-4) 0; min-height: calc(52px + var(--safe-top));
  border-bottom: 1px solid var(--line); background: var(--nav-bg);
  position: sticky; top: 0; z-index: 10;
}
.bar nav { display: flex; gap: var(--space-4); align-items: center; }
.brand {
  font-weight: 800; letter-spacing: .01em; color: var(--accent); text-decoration: none;
  display: inline-flex; align-items: center; min-height: var(--target);
}
.side { display: none; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--nav-bg); border-top: 1px solid var(--line);
  padding: 0 var(--safe-left) var(--safe-bottom) var(--safe-right);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tabs-h); min-width: var(--target); font-size: .75rem;
  color: var(--muted); text-decoration: none; font-weight: 600;
  transition: background var(--dur), color var(--dur);
}
.tabs a[aria-current="page"], .side a[aria-current="page"] {
  color: var(--fg); background: var(--nav-active);
}
.tabs a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--accent); }
.nav-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
main {
  max-width: var(--content-w); margin: 0 auto; padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
}
.has-tabs main { padding-bottom: calc(var(--tabs-h) + var(--safe-bottom) + var(--space-5)); }
@media (min-width: 900px) {
  .has-nav { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .has-nav .bar, .tabs { display: none; }
  .has-tabs main { padding-bottom: var(--space-5); }
  .side {
    display: flex; flex-direction: column; gap: var(--space-1); position: sticky; top: 0;
    height: 100vh; height: 100dvh; padding: var(--space-4) var(--space-3);
    background: var(--nav-bg); border-right: 1px solid var(--line); overflow-y: auto;
  }
  .side .brand { font-size: 1.25rem; padding: 0 var(--space-3) var(--space-3); }
  .side a {
    display: flex; align-items: center; gap: var(--space-3); min-height: var(--target);
    padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--muted);
    text-decoration: none; font-weight: 600;
  }
  .side a:hover { background: var(--bg); color: var(--fg); }
  .side h2 { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted); margin: var(--space-4) var(--space-3) var(--space-1); }
  .side .signout { margin-top: auto; }
  main { padding: var(--space-5); }
}

/* Surfaces and type. */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--space-4) var(--space-5); margin-bottom: var(--space-4);
}
.narrow { max-width: 380px; margin: 48px auto; }
h1 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 var(--space-3); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin: 20px 0 var(--space-2); color: var(--muted); }
.muted, .help { color: var(--muted); font-size: .875rem; }
.error { color: var(--bad); }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.notice { color: var(--ok); border-left: 3px solid var(--ok); padding: var(--space-1) var(--space-3); }
.tag {
  font-style: normal; font-size: .75rem; border: 1px solid var(--line); border-radius: 6px;
  padding: 0 6px; color: var(--muted);
}

/* Forms and buttons. */
label { display: block; margin-bottom: var(--space-3); }
input, select, textarea {
  display: block; width: 100%; min-height: var(--target); padding: 10px var(--space-3);
  margin-top: var(--space-1); font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
button { font: inherit; cursor: pointer; min-height: var(--target); }
button:disabled { cursor: not-allowed; opacity: .6; }
.primary, a.button {
  background: var(--accent); color: var(--on-accent); border: 0; font-weight: 600;
  border-radius: var(--radius-sm); padding: 10px 18px;
}
a.button { display: inline-flex; align-items: center; text-decoration: none; min-height: var(--target); }
.link {
  background: none; border: 0; color: var(--accent); padding: 0 var(--space-2);
  min-height: var(--target); text-decoration: underline;
}
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.check { display: inline-flex; gap: 6px; align-items: center; margin: 0 var(--space-3) 0 0; min-height: var(--target); }
.check input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-1) var(--space-4); align-items: end;
}
.grid .wide, .grid button { grid-column: 1 / -1; }
.grid button { justify-self: start; }
.actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.actions button {
  border: 1px solid var(--line); background: var(--card); color: inherit;
  border-radius: var(--radius-sm); padding: var(--space-2) 14px;
}
.actions .danger, .danger { color: var(--bad); border-color: var(--bad); }

/* Tables. */
table.status, table.list { width: 100%; border-collapse: collapse; }
table.status { font-size: .95rem; }
.status th, .status td { text-align: left; padding: 6px var(--space-2); border-bottom: 1px solid var(--line); vertical-align: top; }
.list th, .list td { text-align: left; padding: var(--space-2); border-bottom: 1px solid var(--line); vertical-align: top; }
@media (max-width: 600px) { .status td:nth-child(4), .status th:nth-child(4) { display: none; } }
.setting .key { font-family: var(--mono); font-size: .9rem; }
.setting .help { display: block; margin-top: 2px; }

/* Home. */
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
.quick a {
  display: flex; align-items: center; gap: var(--space-2); min-height: var(--target);
  padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg); text-decoration: none; font-weight: 600;
}
.quick a:hover { border-color: var(--accent); }
.hint { border-left: 3px solid var(--accent); padding: var(--space-1) var(--space-3); }

/* Chat: phone shows one screen (rooms, room or thread); desktop shows them side by side. */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
main:has(> .chat) { max-width: none; padding: 0; }
.has-tabs main:has(> .chat) { padding-bottom: 0; }
.chat {
  --chat-h: calc(100vh - 52px - var(--safe-top) - var(--tabs-h) - var(--safe-bottom));
  display: flex; flex-direction: column; height: var(--chat-h); background: var(--bg);
}
@supports (height: 100dvh) {
  .chat { --chat-h: calc(100dvh - 52px - var(--safe-top) - var(--tabs-h) - var(--safe-bottom)); }
}
.chat [hidden] { display: none !important; }
.chat-status {
  margin: 0; padding: var(--space-2) var(--space-4); background: var(--nav-active);
  border-bottom: 1px solid var(--line); font-size: .875rem; flex: none;
}
.chat-rooms, .chat-room, .chat-thread {
  display: none; flex-direction: column; flex: 1; min-height: 0; min-width: 0;
  background: var(--card);
}
.chat[data-screen="list"] .chat-rooms,
.chat[data-screen="room"] .chat-room,
.chat[data-screen="thread"] .chat-thread { display: flex; }
.chat-rooms h1 { padding: var(--space-3) var(--space-4) 0; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.chat-group {
  padding: var(--space-3) var(--space-4) var(--space-1); font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.chat-room-item {
  display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  width: 100%; min-height: var(--target); padding: var(--space-2) var(--space-4);
  background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--fg);
  text-align: left; font-weight: 600;
}
.chat-room-item:hover { background: var(--bg); }
.chat-room-item[aria-current="true"] { background: var(--nav-active); box-shadow: inset 3px 0 0 var(--accent); }
.chat-badge {
  min-width: 24px; padding: 0 var(--space-2); border-radius: 12px; text-align: center;
  background: var(--accent); color: var(--on-accent); font-size: .8rem; font-weight: 700;
}
.chat-head {
  display: flex; align-items: center; gap: var(--space-2); flex: none; min-height: 52px;
  padding: 0 var(--space-3); border-bottom: 1px solid var(--line);
}
.chat-head h2 { margin: 0; font-size: 1.05rem; }
.chat-back, .chat-composer button:not(.primary) {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: var(--target); background: none; border: 0; color: var(--fg);
  border-radius: var(--radius-sm);
}
.chat-back:hover, .chat-composer button:not(.primary):hover { background: var(--bg); }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-3) var(--space-4); overscroll-behavior: contain; }
.chat-inline { max-height: 420px; padding: 0; }
.chat-earlier { align-self: center; }
.chat-day { text-align: center; margin: var(--space-3) 0; font-size: .75rem; color: var(--muted); }
.chat-day span { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 2px var(--space-3); }
.chat-empty { text-align: center; padding: var(--space-4); }
.msg { margin: 0 0 var(--space-3); max-width: 46rem; }
.msg-head { display: flex; gap: var(--space-2); align-items: baseline; font-size: .875rem; }
.msg.own .msg-head strong { color: var(--accent); }
.msg-body { overflow-wrap: anywhere; }
.msg-body p, .msg-body ul, .msg-body ol, .msg-body blockquote, .msg-body pre { margin: var(--space-1) 0; }
.msg-body blockquote { border-left: 3px solid var(--line); padding-left: var(--space-3); color: var(--muted); }
.msg-body code { font-family: var(--mono); font-size: .9em; background: var(--bg); padding: 0 4px; border-radius: 4px; }
.msg-body pre { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); overflow-x: auto; }
.msg-body pre code { padding: 0; background: none; }
.msg-image img { display: block; max-width: min(100%, 360px); height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); }
.msg-image { display: inline-block; min-height: var(--target); }
.msg-video { max-width: 100%; }
.msg-audio { display: flex; flex-direction: column; gap: var(--space-1); }
.msg-audio audio { width: min(100%, 320px); min-height: var(--target); }
.msg-file {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--fg); padding: var(--space-2) var(--space-3); text-align: left;
}
.msg-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.msg-actions button {
  background: none; border: 0; color: var(--muted); font-size: .8rem; text-decoration: underline;
  min-height: var(--target); padding: 0 var(--space-2);
}
.msg-actions button:hover { color: var(--accent); }
.chat-composer {
  display: flex; align-items: flex-end; gap: var(--space-1); flex: none;
  padding: var(--space-2) var(--space-3); border-top: 1px solid var(--line); background: var(--card);
}
.chat-composer textarea { flex: 1; margin: 0; resize: none; max-height: 160px; min-width: 0; }
.chat-composer .primary { padding: 0 var(--space-4); }
.chat-composer .recording { background: var(--bad); color: #fff; }
@media (min-width: 900px) {
  .chat { --chat-h: 100vh; height: var(--chat-h); display: grid; grid-template-rows: auto minmax(0, 1fr);
    grid-template-columns: 300px minmax(0, 1fr); }
  @supports (height: 100dvh) { .chat { --chat-h: 100dvh; } }
  .chat.has-thread { grid-template-columns: 300px minmax(0, 1fr) 340px; }
  .chat-status { grid-column: 1 / -1; grid-row: 1; }
  .chat-rooms, .chat-room, .chat-thread { display: flex; grid-row: 2; border-right: 1px solid var(--line); }
  .chat-room:not([hidden]) ~ .chat-thread { border-right: 0; }
  #chat-back { display: none; }
  .chat[data-screen="list"] .chat-room { display: none; }
  .chat[data-screen="list"]::after {
    content: "Pick a room"; grid-column: 2; grid-row: 2; align-self: center; justify-self: center; color: var(--muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line, #e2e8f0); }
ul.plain li:last-child { border-bottom: 0; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photos img { width: 160px; height: 120px; object-fit: cover; border-radius: 8px; }
