/* Sjallabais IRC web client — theme port of docs/irc-client-theme.md.
   Dark-only (ADR 0047 upstream). Green is an accent, not a fill. */

/* --- §2 Fonts: self-hosted Geist variable fonts, no font CDN (ADR 0009). --- */
@font-face {
  font-family: "Geist";
  src: url("/assets/fonts/Geist-Variable.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/assets/fonts/GeistMono-Variable.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* --- §1 Drop-in tokens --- */
:root {
  color-scheme: only dark;

  /* Surfaces (darkest → lightest) */
  --bg: #05080b;
  --bg-soft: #0a1016;
  --surface: #101820;
  --surface-2: #131f29;
  --surface-3: #172631;

  /* Text */
  --ink: #edf7f3;
  --muted: #8fa39a;
  --muted-2: #60746d;

  /* Brand (the "heartbeat" green) */
  --brand: #2ddf8e;
  --brand-strong: #22c77d;
  --heartbeat: #2ddf8e;
  --heartbeat-dim: rgba(45, 223, 142, 0.14);
  --heartbeat-glow: rgba(45, 223, 142, 0.42);

  /* Lines */
  --border: rgba(143, 163, 154, 0.16);
  --border-strong: rgba(45, 223, 142, 0.34);

  /* Status */
  --danger: #ff6b6b;
  --success: #49d17d;
  --amber: #f5a524;

  /* Depth */
  --shadow-soft: 0 14px 42px rgba(0, 0, 0, 0.28);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;

  /* Type */
  --font-sans: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    monospace;

  /* Nick-color palette — 14 hand-picked hues, each measured against
     --bg-soft (#0a1016). Every ratio clears WCAG-AA 4.5:1; brand green is
     deliberately excluded so it stays reserved for you / active state. */
  --nick-0: #f37168; /* red      6.71:1 */
  --nick-1: #f59166; /* coral    8.31:1 */
  --nick-2: #f5a447; /* orange   9.36:1 */
  --nick-3: #f5c73d; /* amber   11.94:1 */
  --nick-4: #f0e34c; /* yellow  14.38:1 */
  --nick-5: #9ee25a; /* lime    12.27:1 */
  --nick-6: #49dfd2; /* teal    11.62:1 */
  --nick-7: #49cee9; /* cyan    10.28:1 */
  --nick-8: #5fb5f2; /* sky      8.54:1 */
  --nick-9: #77a2f8; /* blue     7.56:1 */
  --nick-10: #9d94f9; /* indigo  7.32:1 */
  --nick-11: #be8ef6; /* violet  7.64:1 */
  --nick-12: #f17ef1; /* magenta 8.19:1 */
  --nick-13: #f679b8; /* pink    7.60:1 */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* --- The canvas: top glow + faint terminal grid (§1). --- */
html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--ink);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  background:
    linear-gradient(180deg, rgba(19, 31, 41, 0.54) 0%, rgba(5, 8, 11, 0) 430px),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(143, 163, 154, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 163, 154, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.74), transparent 72%);
}

/* --- §4 Interactive states: one focus treatment everywhere. --- */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* --- App shell: full viewport, page body never scrolls. --- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.app-shell { width: min(1160px, calc(100% - 32px)); margin: 0 auto 32px; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  height: 48px;
  flex: 0 0 auto;
  background: rgba(5, 8, 11, 0.75);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
}

.brand-logo {
  display: block;
}

a.brand {
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--brand);
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.app-main {
  flex: 1 1 auto;
  min-height: 0;
}

/* View switching. Each view controls its own display when visible. */
.view {
  display: none;
  height: 100%;
}
.view-login.visible {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
}
.view-chat.visible {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  min-height: 0;
}

/* --- §5 Panels --- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
}

/* --- §4 Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: 36px;
  padding: 0 0.875rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}
.btn-sm {
  height: 32px;
  padding: 0 0.625rem;
}
.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--brand);
  color: var(--bg);
  font-weight: 600;
}
.btn-primary:hover,
.btn-primary:active {
  background: var(--brand-strong);
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.btn-secondary:active {
  background: var(--surface-3);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.btn-ghost:active {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--danger);
  color: var(--bg);
  font-weight: 600;
}
.btn-danger:hover {
  background: rgba(255, 107, 107, 0.9);
}
.btn-danger:active {
  background: rgba(255, 107, 107, 0.8);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

/* --- §4 Inputs --- */
.control {
  width: 100%;
  height: 36px;
  padding: 0 0.625rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
}
.control::placeholder {
  color: var(--muted-2);
}
.control:focus {
  border-color: var(--border-strong);
  outline: none;
  box-shadow: 0 0 0 4px rgba(45, 223, 142, 0.15);
}
.control[aria-invalid="true"] {
  border-color: var(--danger);
}

/* --- Login card --- */
.login-card {
  width: min(380px, 100%);
  box-shadow: var(--shadow-soft);
}
.login-title {
  margin: 0 0 1rem;
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
  letter-spacing: -0.025em;
}
.field-group {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.field {
  display: grid;
  gap: 0.35rem;
}
.field-label {
  font-size: 12px;
  color: var(--muted);
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 13px;
}
.checkbox-label input {
  accent-color: var(--brand);
}

/* Segmented control (credential form switch) */
.segmented {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
}
.seg {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
}
.seg:hover {
  color: var(--ink);
}
.seg.active {
  background: var(--surface-2);
  color: var(--brand);
  font-weight: 600;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 1.2rem;
  margin: 0.75rem 0 0;
}

/* --- §6 Channel rail --- */
.channel-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0.75rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.rail-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: 0.25rem 0.625rem 0.5rem;
}
.channel-list {
  display: grid;
  gap: 0.125rem;
  flex: 1 1 auto;
}
.channel-button {
  position: relative;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  cursor: pointer;
}
.channel-button:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.channel-button.active {
  background: var(--surface-2);
  color: var(--ink);
  border-left-color: var(--brand);
}
.channel-button.unjoined {
  color: var(--muted-2);
}
.channel-tag {
  font-family: var(--font-sans);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--amber);
  margin-left: 0.4rem;
}
.rail-logout {
  margin-top: 0.5rem;
  flex: 0 0 auto;
}

/* --- Chat main column --- */
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.chat-topic {
  flex: 0 0 auto;
  padding: 0.625rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.topic-name {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/* --- §6 Message log: recessed, mono, single-line rows. --- */
.message-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
  background: var(--bg-soft);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
}

.msg {
  display: grid;
  grid-template-columns: max-content max-content 1fr;
  gap: 0 0.625rem;
  padding: 0.05rem 1rem;
  border-left: 2px solid transparent;
}
.msg:hover {
  background: var(--surface-3);
}
.msg-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  align-self: baseline;
  padding-top: 0.05rem;
}
.msg-nick {
  font-weight: 600;
  white-space: nowrap;
  align-self: baseline;
}
.msg-nick.is-you {
  color: var(--brand);
}
.msg-text {
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* Rows that mention you get a brand left-marker (§6). */
.msg.mention {
  border-left-color: var(--brand);
}

/* System / local lines: one muted line spanning the text column, no nick. */
.msg.system {
  grid-template-columns: max-content 1fr;
}
.msg.system .msg-text {
  color: var(--muted-2);
  white-space: pre-wrap;
}
.msg.system.error .msg-text {
  color: var(--danger);
}

/* Nick color palette classes (see --nick-* tokens above). */
.nick-0 { color: var(--nick-0); }
.nick-1 { color: var(--nick-1); }
.nick-2 { color: var(--nick-2); }
.nick-3 { color: var(--nick-3); }
.nick-4 { color: var(--nick-4); }
.nick-5 { color: var(--nick-5); }
.nick-6 { color: var(--nick-6); }
.nick-7 { color: var(--nick-7); }
.nick-8 { color: var(--nick-8); }
.nick-9 { color: var(--nick-9); }
.nick-10 { color: var(--nick-10); }
.nick-11 { color: var(--nick-11); }
.nick-12 { color: var(--nick-12); }
.nick-13 { color: var(--nick-13); }

/* --- Composer --- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer-input {
  flex: 1 1 auto;
  font-family: var(--font-mono);
}
.char-counter {
  flex: 0 0 auto;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.char-counter.over {
  color: var(--danger);
  font-weight: 600;
}

/* --- §6 / §7 Connection dot + popover --- */
.conn {
  position: relative;
}
.conn-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
}
.conn-dot-glyph {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted-2);
}
.conn-dot.connected .conn-dot-glyph {
  background: var(--success);
  box-shadow: 0 0 0 0 var(--heartbeat-glow);
  animation: conn-pulse 2.4s ease-out infinite;
}
.conn-dot.connecting .conn-dot-glyph,
.conn-dot.reconnecting .conn-dot-glyph {
  background: var(--amber);
}
.conn-dot.disconnected .conn-dot-glyph {
  background: var(--danger);
}

/* §7 heartbeat: a quiet glow-ring pulse on the connected dot only. */
@keyframes conn-pulse {
  0% {
    box-shadow: 0 0 0 0 var(--heartbeat-glow);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(45, 223, 142, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(45, 223, 142, 0);
  }
}

.conn-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(280px, calc(100vw - 2rem));
  display: grid;
  gap: 0.5rem;
  padding: 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.conn-popover[hidden] {
  display: none;
}
.conn-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  font-size: 13px;
}
.conn-key {
  color: var(--muted);
}
.conn-val {
  color: var(--ink);
  text-align: right;
  overflow-wrap: anywhere;
}
.conn-val.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}
.conn-note {
  margin: 0;
  font-size: 12px;
  color: var(--amber);
}
.conn-note[hidden] {
  display: none;
}
.mono {
  font-family: var(--font-mono);
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 600; letter-spacing: -0.02em; }
.brand img { flex-shrink: 0; }
.brand-context { color: var(--muted); font-weight: 400; margin-left: 4px; }
h1, h2 { font-weight: 600; letter-spacing: -0.025em; }
h1 { font-size: 28px; margin: 0 0 12px; }
h2 { font-size: 20px; margin: 0 0 16px; }
.intro { color: var(--muted); margin: 0 0 24px; }
.status-pill { font: 12px "Geist Mono", monospace; padding: 6px 10px; border: 1px solid var(--card-border); border-radius: 6px; background: var(--bg-soft); }
.view { display: none; }
.view.visible { display: block; }
#view-login { max-width: 480px; margin: 72px auto; }
.panel { border: 1px solid var(--card-border); border-radius: 8px; padding: 20px; background: var(--card); }
label { display: block; margin-bottom: 16px; font-weight: 500; }
input { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--card-border); background: var(--bg-soft); color: var(--text); font: inherit; }
input::placeholder { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
button { border: 1px solid transparent; border-radius: 6px; padding: 9px 14px; background: var(--accent); color: var(--bg); font: 600 13px "Geist", system-ui, sans-serif; cursor: pointer; }
button:hover { background: var(--accent-strong); }
button[type="button"] { color: var(--text); background: var(--bg-soft); border-color: var(--card-border); }
button[type="button"]:hover { border-color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.message-list { min-height: 45vh; max-height: 55vh; overflow-y: auto; overflow-wrap: anywhere; }
.chat-layout { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-main { min-width: 0; }
#message-form { margin-top: 16px; }
.panel-title { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.channel-list { display: grid; gap: 6px; }
.channel-button { width: 100%; text-align: left; overflow-wrap: anywhere; }
.channel-button.active, .channel-button.active:hover { background: var(--accent); color: var(--bg); border-color: transparent; }
.channel-button.unjoined { color: var(--muted); }
.message-item.local { color: var(--muted); }
.message-item.error { color: var(--danger); }
.message-item { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--card-border); }
.message-meta { color: var(--muted); font: 12px/1.5 "Geist Mono", monospace; margin-bottom: 4px; }
.error-text { color: var(--danger); min-height: 20px; }
.connected { color: var(--ok); }
.reconnecting, .connecting { color: #f5a524; }
.disconnected { color: var(--danger); }
.status-grid { display: grid; gap: 12px; overflow-wrap: anywhere; }

/* --- §8 Reduced motion: freeze all decorative motion. --- */
@media (prefers-reduced-motion: reduce) {
  .conn-dot.connected .conn-dot-glyph {
    animation: none;
    box-shadow: none;
  }
}

/* --- Responsive: clean 390px → 1440px. --- */
@media (max-width: 640px) {
  .view-chat.visible {
    grid-template-columns: minmax(120px, 150px) minmax(0, 1fr);
  }
  .app-header {
    padding: 0 0.75rem;
  }
  .msg {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}
