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

:root {
  /* Grayscale — the app's actual palette, Twitch-dark-theme style. Color
     only ever comes from the four --accent-* tones below, never mixed
     into these. */
  --bg:          #0e0e10;
  --surface:     #18181b;
  --surface2:    #1f1f23;
  --border:      #2d2d35;
  --border-hover:#3d3d46;

  /* Accent — the logo's four tones (#CECBF6/#7F77DD/#3C3489/#534AB7) live
     as raw hex in client/assets/logo.svg and favicon.svg, which can't read
     CSS custom properties. --accent-core is the one shade pulled into the
     app UI: active tab underline, sidebar active-state bar, primary
     buttons, input focus rings, the unread badge. Everything else
     (including hover states) stays grayscale. */
  --accent-core:  #534AB7;

  /* Glass surfaces — "milky glass": white mixed into the background rather
     than a dark or colored tint, so panels read as frosted/opal glass
     instead of tinted window glass. Alpha stays high enough (10-16%,
     combined with the dark page underneath) that text never drops below
     WCAG AA even where the backdrop blur picks up a bright blob. */
  --glass-bg:     rgba(255, 255, 255, 0.10);   /* cards */
  --glass-bg-2:   rgba(255, 255, 255, 0.14);   /* modals — a touch more opaque, they sit in front */
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-blur:   blur(24px) saturate(130%);

  /* Structural panels (navbar/sidebar/chat window) — same milky recipe,
     slightly less opaque since they're large surfaces. */
  --glass-bg-panel:    rgba(255, 255, 255, 0.08);
  --glass-border-panel:rgba(255, 255, 255, 0.16);
  --glass-blur-panel:  blur(26px) saturate(130%);

  --text:       #efeff1;
  --muted:      #adadb8;
  --danger:     #eb0400;
  --danger-soft:#eb040026;
  --warn:       #ff9900;
  --warn-soft:  #ff990026;
  --success:    #00b516;
  --success-soft:#00b51626;

  /* Type — system stack (no Inter, no external webfont) for UI chrome;
     a real monospace for chat content so usernames/timestamps line up and
     read like a log rather than prose. */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, "Liberation Mono", monospace;

  /* Spacing (4pt scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;

  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.5);
}

/* Flat, near-black backdrop — no gradient, no blobs. The app's visual
   identity comes from the milky glass panels and the accent color, not
   from the page background; a busy background reads as a template
   generator, not a work tool. */
body {
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

:focus-visible {
  outline: 2px solid var(--accent-core);
  outline-offset: 2px;
}

/* ── Login ──────────────────────────────────────────────────────────────── */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  height: 100vh;
}

#login-screen[hidden] {
  display: none;
}

.login-logo {
  width: 120px;
  height: auto;
  filter: drop-shadow(0 8px 24px rgba(83, 74, 183, .35)); /* = var(--accent-core) at 35% */
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6) var(--space-5);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.login-card h1 {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--text), var(--accent-core) 140%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
  margin-bottom: var(--space-1);
}

.login-card input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}

.login-card input:focus { border-color: var(--accent-core); }

.login-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn {
  display: inline-block;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; transform: scale(.97); }
.btn-primary { background: var(--accent-core); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warn { background: var(--warn); color: #000; }
.btn-sm { padding: 3px 8px; font-size: 11px; }

/* Second-click-to-confirm state for risky mod actions (ban/timeout) */
.btn.armed {
  animation: armed-pulse 0.9s ease-in-out infinite;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px currentColor;
}
@keyframes armed-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .55; }
}

#login-error { color: var(--danger); font-size: 12px; text-align: center; min-height: 16px; }

/* ── App shell ──────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--space-3);
  gap: var(--space-3);
}

#app[hidden] {
  display: none;
}

/* ── Nav bar ────────────────────────────────────────────────────────────── */

#navbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--glass-bg-panel);
  backdrop-filter: var(--glass-blur-panel);
  -webkit-backdrop-filter: var(--glass-blur-panel);
  border: 1px solid var(--glass-border-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  /* #navbar's own backdrop-filter creates a stacking context, which traps
     .profile-dropdown's z-index inside it — without this, the dropdown
     can never paint above the sibling #view-chat panels (which have their
     own backdrop-filter stacking context) no matter how high its z-index
     is, since it's escaping the navbar's box via position:absolute. z-index
     applies here without position:relative because #navbar is a flex item
     of #app. */
  z-index: 20;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #navbar { background: var(--surface); }
}

#navbar .logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--text);
  margin-right: var(--space-3);
  font-size: 15px;
}

.logo-icon {
  width: 30px;
  height: auto;
  flex-shrink: 0;
}

.nav-tab {
  position: relative;
  padding: 10px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
  transition: background .15s, color .15s;
}
.nav-tab:hover { background: var(--surface2); color: var(--text); }
.nav-tab.active { color: var(--text); }
.nav-tab.active::after {
  content: '';
  position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2px;
  background: var(--accent-core);
  border-radius: 2px;
}

#navbar .spacer { flex: 1; }
#navbar .nav-user { color: var(--muted); font-size: 12px; }

.profile-menu { position: relative; }

.profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--glass-border-panel);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.profile-avatar:hover { background: rgba(255,255,255,.14); border-color: var(--border-hover); }

.profile-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 170px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 2px;
  background: var(--glass-bg-panel);
  backdrop-filter: var(--glass-blur-panel);
  -webkit-backdrop-filter: var(--glass-blur-panel);
  border: 1px solid var(--glass-border-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.profile-dropdown[hidden] { display: none; }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .profile-dropdown { background: var(--surface2); }
}

.profile-dropdown button, .profile-dropdown a {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}
.profile-dropdown button:hover, .profile-dropdown a:hover { background: rgba(255,255,255,.08); }
.profile-dropdown a.linked { color: var(--success); }

/* ── Views ──────────────────────────────────────────────────────────────── */

.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* ── Accounts view ──────────────────────────────────────────────────────── */

#view-accounts {
  flex-direction: column;
  padding: var(--space-5);
  gap: var(--space-4);
  overflow-y: auto;
}

#view-accounts h2 { font-size: 16px; }

.account-list { display: flex; flex-direction: column; gap: var(--space-2); }

.account-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  transition: border-color .15s;
}
.account-row:hover { border-color: var(--border-hover); }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .account-row { background: var(--surface); }
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  text-transform: uppercase;
}

.account-row .name { font-weight: 600; flex: 1; }

.status-stack { display: flex; align-items: center; gap: var(--space-2); }
.status-slot[hidden] { display: none; }

.badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .02em; }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-expired { background: var(--danger-soft); color: var(--danger); }
.badge-disc { background: var(--warn-soft); color: var(--warn); }

/* ── Channels view ──────────────────────────────────────────────────────── */

#view-channels {
  flex-direction: column;
  padding: var(--space-5);
  gap: var(--space-4);
  overflow-y: auto;
}

#view-channels h2 { font-size: 16px; }

.channel-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  transition: border-color .15s;
}
.channel-card:hover { border-color: var(--border-hover); }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .channel-card { background: var(--surface); }
}

.channel-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.channel-card-header .cname { font-weight: 700; font-size: 14px; flex: 1; font-family: var(--font-mono); }

.account-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px 3px 8px;
  font-size: 11px;
}

.chip button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  margin-left: 2px;
}
.chip button:hover { color: var(--danger); }

.add-account-chip {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.add-account-chip:hover { border-color: var(--border-hover); color: var(--text); }

/* ── Chat view ──────────────────────────────────────────────────────────── */

#view-chat {
  flex-direction: row;
  gap: var(--space-3);
}

#channel-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--glass-bg-panel);
  backdrop-filter: var(--glass-blur-panel);
  -webkit-backdrop-filter: var(--glass-blur-panel);
  border: 1px solid var(--glass-border-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  padding: var(--space-2) 0;
  overflow-y: auto;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #channel-sidebar { background: var(--surface); }
}

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 4px 12px 6px;
}

.sidebar-channel {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--muted);
  border-radius: 4px;
  margin: 0 4px;
  transition: background .12s, color .12s;
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 12px;
}
.sidebar-channel:hover { background: var(--surface2); color: var(--text); }
.sidebar-channel.active {
  background: var(--surface2);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent-core);
}
.sidebar-channel::before { content: '#'; margin-right: 4px; color: var(--muted); }

.sidebar-channel .unread {
  margin-left: auto;
  background: var(--accent-core);
  color: #fff;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--glass-bg-panel);
  backdrop-filter: var(--glass-blur-panel);
  -webkit-backdrop-filter: var(--glass-blur-panel);
  border: 1px solid var(--glass-border-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden; /* clip header/messages/input-bar to the rounded corners */
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  #chat-main { background: var(--surface); }
}

#chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  height: 44px;
  border-bottom: 1px solid var(--glass-border-panel);
  flex-shrink: 0;
}

#chat-channel-name { font-weight: 700; font-size: 15px; font-family: var(--font-mono); }
#chat-header .spacer { flex: 1; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.msg-row {
  position: relative;
  padding: 3px 14px;
  line-height: 1.6;
  border-radius: 4px;
  margin: 0 4px;
}
.msg-row:hover { background: var(--surface); }
.msg-row:hover .msg-actions { display: flex; }

.msg-row.deleted { opacity: .4; text-decoration: line-through; }

.msg-time { color: var(--muted); font-size: 11px; margin-right: 6px; }

.msg-badges { display: inline-flex; align-items: center; gap: 3px; vertical-align: middle; }
.msg-badges:empty { display: none; }

.msg-badge {
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 4px;
}

.msg-username {
  font-weight: 700;
  cursor: pointer;
}
.msg-username:hover { text-decoration: underline; }

/* 7TV paint: stacked layers clipped to the username text. Each .paint-layer
   fills the same grid cell; whichever background (solid color / gradient /
   animated image) it carries shows through only where the glyphs are. */
.msg-username.paint {
  display: inline-grid;
  cursor: pointer;
}
.msg-username.paint:hover { text-decoration: underline; }
.msg-username.paint .paint-layer {
  grid-area: 1 / 1 / -1 / -1;
  -webkit-text-fill-color: transparent;
  background-color: currentColor;
  background-clip: text;
  -webkit-background-clip: text;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
@supports not ((background-clip: text) or (-webkit-background-clip: text)) {
  .msg-username.paint .paint-layer {
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
  }
  .msg-username.paint .paint-layer:not(:first-child) { display: none; }
}

.msg-text { word-break: break-word; font-family: var(--font-sans); }

.msg-emote {
  height: 24px;
  width: auto;
  vertical-align: middle;
  margin: -4px 1px;
}

.msg-actions {
  display: none;
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 4px;
  box-shadow: var(--shadow-md);
}
.msg-actions .btn { font-family: var(--font-sans); }

/* ── Chat input ─────────────────────────────────────────────────────────── */

#chat-input-bar {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--glass-border-panel);
  flex-shrink: 0;
  align-items: center;
}

#account-selector {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
  max-width: 140px;
  font-family: inherit;
}

#message-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
#message-input:focus { border-color: var(--accent-core); }

/* ── Modals ─────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--glass-bg-2);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .modal { background: var(--surface); }
}

.modal h3 { font-size: 15px; }

.modal .confirm-text { color: var(--muted); font-size: 13px; line-height: 1.5; }

.modal input, .modal select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
  width: 100%;
  outline: none;
  font-family: inherit;
}
.modal input:focus, .modal select:focus { border-color: var(--accent-core); }

.modal-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }

/* ── Toast ──────────────────────────────────────────────────────────────── */

/* Top-right, clear of any app chrome in every view (the old bottom-center
   spot sat right at the chat input bar's height in this near-full-viewport
   layout — not a stacking bug, just the wrong spot to begin with). #toast
   is a direct child of <body> with no filter/backdrop-filter ancestor in
   between, so position:fixed correctly resolves against the real
   viewport — this one shared element is already the app's one toast
   system; every toast(...) call reuses it. */
#toast {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: 320px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px 16px;
  font-size: 13px;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  transform: translateY(-4px);
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { border-color: var(--danger); color: var(--danger); }

/* ── Empty state ────────────────────────────────────────────────────────── */

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 20px;
  text-align: center;
}

/* ── Scrollbar ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
