/* ═══════════════════════════════════════════════════
   AgentChat SPA Shell — CSS Grid Layout
   5-area grid: topbar, sidebar, view-host, rpanel, statusbar
   ═══════════════════════════════════════════════════ */

/* ── Global: ensure [hidden] always works ─────────── */
[hidden] { display: none !important; }

/* ── CSS Custom Properties ────────────────────────── */
:root {
  /* Layout sizing — resizable via drag handles, persisted in localStorage */
  --sidebar-w: 240px;
  --rpanel-w: 260px;
  --topbar-h: 44px;
  --statusbar-h: 24px; /* match prod value to avoid mobile regressions */

  /* Backgrounds */
  --bg: #1a1a2e;
  --bg-primary: #1a1a2e;
  --bg-surface: #16213e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-message-hover: rgba(255, 255, 255, 0.02);
  --bg-input: #0d2d55;
  --bg-login-card: #16213e;
  --bg-server-bar: #0e1525;

  /* Text */
  --text: #e8e8e8;
  --text-primary: #e8e8e8;
  --text-secondary: #8e9aaf;
  --text-muted: #9ca3af;
  --text-link: #53a8b6;

  /* Accent */
  --accent: #53a8b6;
  --accent-hover: #6bc4d2;
  --accent-dim: rgba(83, 168, 182, 0.15);

  /* Borders */
  --border: #1e3054;
  --border-light: #2a3f5f;

  /* Semantic */
  --success: #43b581;
  --warning: #faa61a;
  --error: #f04747;
  --danger: #f04747;
  --online: #43b581;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);

  /* Typography */
  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-main);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════════════ */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-login-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-logo h1 {
  font-size: 1.3rem;
  margin-top: 0.5rem;
  color: var(--text-primary);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.form-group input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-field {
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.btn-primary {
  width: 100%;
  padding: 0.7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-text {
  color: var(--error);
  font-size: 0.85rem;
  margin-top: 0.5rem;
  text-align: center;
}

.login-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1.5rem;
}

/* ═══════════════════════════════════════════════════
   APP SHELL — 5-AREA CSS GRID
   ═══════════════════════════════════════════════════ */

.app-shell {
  display: grid;
  height: 100dvh; /* dvh excludes Android soft nav bar; fallback to 100vh for older browsers */
  height: 100vh; /* fallback for browsers without dvh */
  grid-template-columns: var(--sidebar-w) 1fr var(--rpanel-w);
  grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  grid-template-areas:
    "topbar   topbar    topbar"
    "sidebar  viewhost  rpanel"
    "status   status    status";
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@supports (height: 100dvh) {
  .app-shell { height: 100dvh; }
}

/* Sidebar collapsed */
.app-shell.sidebar-collapsed {
  grid-template-columns: 0px 1fr var(--rpanel-w);
}
.app-shell.sidebar-collapsed .sidebar {
  display: none;
}

/* Right panel collapsed */
.app-shell.rpanel-collapsed {
  grid-template-columns: var(--sidebar-w) 1fr 0px;
}
.app-shell.rpanel-collapsed .rpanel {
  display: none;
}

/* Both collapsed */
.app-shell.sidebar-collapsed.rpanel-collapsed {
  grid-template-columns: 0px 1fr 0px;
}
/* Old 80px compact rules removed — see clean rules below */


/* ── TOPBAR ────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  background: var(--bg-server-bar);
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
  z-index: 100;
  min-height: var(--topbar-h);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.topbar-brand-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.topbar-brand-link:hover { opacity: 0.85; }

.topbar-brand-url {
  font-size: 0.6rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.topbar-view-title {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 400;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-user {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.connection-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background var(--transition-fast);
}
.connection-dot.online { background: var(--online); }
.connection-dot.offline { background: var(--error); }
.connection-dot.connecting { background: var(--warning); }

/* ── SIDEBAR ───────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  min-width: 0;
}

.sidebar-nav {
  padding: 0.5rem 0;
}

.nav-section {
  margin-bottom: 0.5rem;
}

.nav-section-title {
  padding: 0.4rem 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.nav-list {
  list-style: none;
}

.channel-filter {
  display: block;
  width: calc(100% - 1.6rem);
  margin: 2px 0.8rem 4px;
  padding: 3px 7px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-input, #0d2d55);
  border: 1px solid var(--border, #1e3054);
  border-radius: var(--radius-sm, 3px);
  color: var(--text-primary, #e8e8e8);
  outline: none;
  box-sizing: border-box;
}
.channel-filter:focus-visible { border-color: var(--accent, #53a8b6); }
.channel-filter::placeholder { color: var(--text-muted, #9ca3af); }
.app-shell.sidebar-compact .channel-filter { display: none; }

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.35rem 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  margin: 0 0.4rem;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  overflow: visible;
}
/* Tighter left inset for the RPanel Chat Tools list — Dan 2026-04-21 19:41
   flagged excess left padding on those rows. Icon + label snug to the edge. */
#rpanel .rpanel-content-pinned .nav-list { margin: 0; padding-left: 0; }
#rpanel .rpanel-content-pinned .nav-link { padding-left: 0.4rem; padding-right: 0.4rem; margin-left: 0; margin-right: 0; }
#rpanel .rpanel-content-pinned .nav-section-title { padding-left: 0.4rem; }
.nav-link .channel-name,
.nav-link .dm-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.nav-link .unread-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: 9999px;
  margin-left: auto;
  min-width: 16px;
  text-align: center;
  flex-shrink: 0;
}

/* ── VIEW HOST ─────────────────────────────────────── */
.view-host {
  grid-area: viewhost;
  background: var(--bg-primary);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.view-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── RIGHT PANEL ───────────────────────────────────── */
.rpanel {
  grid-area: rpanel;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  position: relative;
  min-width: 0;
}

.rpanel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-primary);
}

.rpanel-content {
  padding: 0.75rem;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── STATUSBAR — always-visible, 1-icon tall ───────── */
/* Transparent background, in grid flow (grid-area: status), pushes
   content up so nothing is obscured. Health icons far left, mixer
   volume icon far right. No auto-hide, no dock, no translate tricks. */
.statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
  background: transparent;
  border: none;
  min-height: var(--statusbar-h);
  overflow: visible; /* pulse auras extend beyond */
}

.statusbar .statusbar-spacer { flex: 1; min-width: 6px; }

/* Legacy rule — kept for backwards compat */
.status-ws { margin-left: auto; }

/* ── FOOTER HEALTH CLUSTER ─────────────────────────── */
/* Always-visible, transparent, overflow visible for pulse auras. */
.statusbar .health-cluster {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 2px;
  user-select: none;
  min-width: 0;
  flex: 1;
  overflow-x: auto;
  overflow-y: visible;
  border: none;
  background: none;
  scrollbar-width: none; /* hide scrollbar, just swipe */
}
.statusbar .health-cluster::-webkit-scrollbar { display: none; }
.statusbar .health-cluster .cluster-empty {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
  padding: 0 4px;
  white-space: nowrap;
  opacity: 0.6;
}

.statusbar .health-stat {
  position: relative;
  min-width: 18px;
  height: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: help;
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1;
}
.statusbar .health-stat .emoji {
  position: relative;
  z-index: 1;
  display: inline-block;
  transition: filter 0.15s, transform 0.15s;
}
/* Gentle scale on hover for inspection */
.statusbar .health-stat {
  transition: transform 0.15s ease;
}
.statusbar .health-stat:hover {
  transform: scale(1.3);
  z-index: 10;
}

.statusbar .health-stat::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  z-index: 0;
  box-shadow: 0 0 0 0 currentColor;
  pointer-events: none;
}
.statusbar .health-stat.healthy { color: var(--success, #4ade80); }
.statusbar .health-stat.healthy .emoji { filter: drop-shadow(0 0 2px var(--success, #4ade80)); }
.statusbar .health-stat.healthy::before { animation: fm-pulse-slow 2.6s ease-out infinite; }
.statusbar .health-stat.unhealthy { color: var(--error, #ff6b6b); }
.statusbar .health-stat.unhealthy .emoji { filter: drop-shadow(0 0 3px var(--error, #ff6b6b)); }
.statusbar .health-stat.unhealthy::before { animation: fm-pulse-fast 0.9s ease-out infinite; }
.statusbar .health-stat.degraded { color: var(--warning, #ffb84a); }
.statusbar .health-stat.degraded .emoji { filter: drop-shadow(0 0 2px var(--warning, #ffb84a)); }
.statusbar .health-stat.degraded::before { animation: fm-pulse-med 1.6s ease-out infinite; }
.statusbar .health-stat.unknown { color: var(--text-muted); opacity: 0.5; }
.statusbar .health-stat.unknown::before { animation: none; }

.statusbar .health-stat[data-label]::after {
  content: attr(data-label) " · " attr(data-state);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
  border: 1px solid var(--border);
  z-index: 100;
}
.statusbar .health-stat:hover::after { opacity: 1; }

@keyframes fm-pulse-slow {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes fm-pulse-med {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes fm-pulse-fast {
  0%   { box-shadow: 0 0 0 0 currentColor; }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── FOOTER AUDIO MIXER ────────────────────────────── */
/* card 12d7fdba — volume icon only in the bar (with subtle backdrop shade).
   Click opens the full flyout above with master + 5 channels. */
.statusbar .mixer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  user-select: none;
  flex-shrink: 0;
  height: 24px;
  border: none;
  background: none;
}
/* Volume icon with shade backdrop for visibility on transparent bar */
.statusbar .mixer .volume-icon {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s;
}
.statusbar .mixer .volume-icon:hover {
  background: rgba(0, 0, 0, 0.55);
}
.statusbar .mixer .volume-icon svg {
  width: 13px;
  height: 13px;
}
.statusbar .mixer .master-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  margin: 0;
}
.statusbar .mixer .master-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-server-bar);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}
.statusbar .mixer .master-slider::-webkit-slider-thumb:hover { background: var(--accent-hover, var(--accent)); }
.statusbar .mixer .master-slider::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-server-bar);
  cursor: pointer;
}
.statusbar .mixer .master-readout {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
}
.statusbar .mixer .btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s, transform 0.15s;
  font-family: inherit;
}
.statusbar .mixer .btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.statusbar .mixer .btn-icon svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.statusbar .mixer.muted .master-slider { opacity: 0.35; }
.statusbar .mixer.muted .master-readout { text-decoration: line-through; }
.statusbar .mixer.muted .mute-btn { color: var(--error, #ff6b6b); }
.statusbar .mixer .expand-arrow { transition: transform 0.2s; }
.statusbar .mixer[aria-expanded="true"] .expand-arrow { transform: rotate(180deg); }

/* Flyout panel — always viewport-anchored so zoom can't push it off-screen */
.statusbar .mixer .flyout {
  position: fixed;
  right: 4px;
  bottom: calc(var(--statusbar-h) + 4px);
  width: min(175px, calc(100vw - 8px));
  max-height: min(400px, calc(100vh - var(--statusbar-h) - 50px));
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 4px;
  font-size: 9px;
  line-height: 1.2;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transform-origin: bottom right;
  transform: translateY(6px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
  z-index: 200;
}
.statusbar .mixer .flyout.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}
.statusbar .mixer .flyout-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1px;
}
.statusbar .mixer .flyout-title {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}
.statusbar .mixer .info-btn {
  width: 1.3em;
  height: 1.3em;
  min-width: 12px;
  min-height: 12px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 7px;
  font-style: italic;
  font-family: serif;
  cursor: help;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.statusbar .mixer .info-btn:hover { border-color: var(--accent); color: var(--text-primary); }

/* Single-column stack — tall and thin, horizontal dividers */
.statusbar .mixer .mixer-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.statusbar .mixer .mixer-card {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 1px 0 2px;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  cursor: pointer;
  transition: opacity 0.15s;
  user-select: none;
}
.statusbar .mixer .mixer-card:last-child { border-bottom: none; }
/* Fix 345e27d5: voice_in active indicator when STT is listening */
.statusbar .mixer .mixer-card.active { box-shadow: 0 0 0 2px var(--accent, #53a8b6); }
/* Muted state: no opacity dim — mute is shown by emoji swap on the thumb (🔊→🔇) */
.statusbar .mixer .mixer-card .card-label {
  font-size: 8px;
  line-height: 1;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin: 0;
  padding: 0;
}
/* no visual change on label when muted — the thumb emoji swap is the indicator */
/* Slider row with -/+ volume indicators */
.statusbar .mixer .mixer-card .slider-row {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 14px;
}
.statusbar .mixer .mixer-card .vol-indicator {
  font-size: 8px;
  color: var(--text-muted);
  flex-shrink: 0;
  line-height: 1;
  opacity: 0.6;
}
/* Card slider styling — force transparent input box, visible track via pseudo */
.statusbar .mixer .mixer-card input[type=range] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 14px; /* match thumb height so no extra space */
  background: transparent !important;
  border: none;
  outline: none;
  cursor: pointer;
  margin: 0;
  padding: 0;
  display: block;
}
.statusbar .mixer .mixer-card input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  border: none;
}
.statusbar .mixer .mixer-card input[type=range]::-moz-range-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  border: none;
}
.statusbar .mixer .mixer-card input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px; /* center 14px thumb on 4px track */
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
  cursor: pointer;
  /* 🔊 emoji rendered via text on a pseudo-overlay — can't use pseudo on input,
     so we rely on JS to swap a data attribute for the mute indicator */
}
/* Muted thumb — red tint instead of accent color */
.statusbar .mixer .mixer-card.muted input[type=range]::-webkit-slider-thumb {
  background: var(--error, #f44336);
}
.statusbar .mixer .mixer-card input[type=range]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M5 9v6h4l5 4V5L9 9H5zm11.5 3a4.5 4.5 0 0 0-2.5-4.03v8.05A4.5 4.5 0 0 0 16.5 12z'/%3E%3C/svg%3E") center/10px no-repeat;
  border: none;
  cursor: pointer;
}
/* END FOOTER AUDIO MIXER */

/* ── Mobile scaling ── */
@media (max-width: 420px) {
  .statusbar { padding: 0 2px; gap: 2px; }
  .statusbar .health-cluster { gap: 1px; }
  .statusbar .health-stat { min-width: 14px; height: 14px; font-size: 9px; }
  .statusbar .mixer .volume-icon { width: 16px; height: 16px; }
  .statusbar .mixer .volume-icon svg { width: 11px; height: 11px; }
  /* Flyout is position:fixed with min() width — adapts to any viewport/zoom */
}

/* ── DRAG HANDLES ──────────────────────────────────── */
.drag-handle {
  position: absolute;
  z-index: 50;
  background: transparent;
  transition: background var(--transition-fast);
}

.drag-handle:hover {
  background: var(--accent, #53a8b6);
  opacity: 0.4;
}
.drag-handle.dragging {
  background: var(--accent, #53a8b6);
  opacity: 0.8;
}

/* Vertical drag handle (col-resize) — fixed to viewport so it stays visible
   even when sidebar scrolls. Width 8px for easier targeting. */
.drag-handle-vertical {
  position: fixed;
  top: var(--topbar-h, 44px);
  bottom: var(--statusbar-h, 24px);
  width: 8px;
  cursor: col-resize;
  z-index: 60;
  /* Visual indicator on hover */
}
.drag-handle-vertical::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 32px;
  background: var(--border, #2a2a4a);
  border-radius: 1px;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.15s;
}
.drag-handle-vertical:hover::before { opacity: 1; }

#sidebar-drag.drag-handle-vertical {
  left: var(--sidebar-w, 240px);
  margin-left: -4px;
}
.drag-handle-vertical.drag-handle-left,
#rpanel-drag.drag-handle-vertical {
  right: var(--rpanel-w, 260px);
  left: auto;
  margin-right: -4px;
}

/* Hide drag handles when corresponding panel is collapsed/compact */
.app-shell.sidebar-collapsed #sidebar-drag,
.app-shell.sidebar-compact #sidebar-drag { display: none; }
.app-shell.rpanel-collapsed #rpanel-drag,
.app-shell.rpanel-compact #rpanel-drag { display: none; }

/* ═══════════════════════════════════════════════════
   CHAT VIEW STYLES (view-specific, scoped to .chat-view)
   ═══════════════════════════════════════════════════ */

.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-header-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.chat-header-topic {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 1rem;
}

.chat-message {
  display: flex;
  gap: 0.6rem;
  padding: 0.3rem 0;
  transition: background var(--transition-fast);
}

.chat-message[data-zebra="1"] {
  background: var(--bg-message-zebra, rgba(255, 255, 255, 0.022));
}

.chat-message:hover,
.chat-message[data-zebra="1"]:hover {
  background: var(--bg-message-hover);
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.chat-msg-author {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.chat-msg-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chat-msg-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.45;
}

.chat-msg-text code {
  background: var(--bg-tertiary);
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85em;
}

.chat-composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.9rem;
  line-height: 1.4;
  max-height: 150px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.chat-composer textarea:focus {
  border-color: var(--accent);
}

.chat-composer button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.chat-composer button:hover {
  background: var(--accent-hover);
}

.typing-indicator {
  padding: 0.2rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  min-height: 1.2rem;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════
   SETTINGS VIEW
   ═══════════════════════════════════════════════════ */

.settings-view {
  padding: 2rem;
  overflow-y: auto;
  height: 100%;
}

.settings-view h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.settings-view .setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-view .setting-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.settings-view .setting-value {
  color: var(--text-primary);
  font-size: 0.9rem;
}

/* ═══════════════════════════════════════════════════
   PLACEHOLDER / EMPTY VIEW
   ═══════════════════════════════════════════════════ */

.placeholder-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 1.1rem;
  flex-direction: column;
  gap: 0.5rem;
}

.placeholder-view .placeholder-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

/* ═══════════════════════════════════════════════════
   MEMBER LIST (right panel content for chat)
   ═══════════════════════════════════════════════════ */

.member-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 0 0.25rem;
  letter-spacing: 0.05em;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  position: relative;
}

.member-presence {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

/* ═══════════════════════════════════════════════════
   SCROLLBAR STYLING
   ═══════════════════════════════════════════════════ */

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

/* ═══════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: 2.5rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
}

.toast {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: #fff;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.25s ease;
  max-width: 360px;
}

.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); color: #000; }
.toast.error { background: var(--error); }
.toast.info { background: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════
   SPA Overrides — ensure SPA grid layout wins
   ═══════════════════════════════════════════════════ */

/* Tool view content inherits full height */
.tool-view-content {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Ensure tool pages that have their own .app class don't break the grid */
.view-host .app {
  display: block !important;
  height: 100%;
}
/* Tool pages' .app-shell should fill the view host but keep their flex layout */
.view-host .app-shell {
  display: flex !important;
  flex-direction: column !important;
  height: 100% !important;
  overflow-y: auto !important;
}

/* Tool pages that embed their own login screen - hide them (SPA handles auth) */
.view-host .login-screen {
  display: none !important;
}

/* Tool pages that embed their own sidebar - hide them (SPA has the sidebar) */
.view-host .sidebar {
  display: none !important;
}

/* Tool pages' main content should fill the view host */
.view-host .main-content,
.view-host .content-area {
  width: 100% !important;
  margin: 0 !important;
}

/* Nav link with tool icon alignment */
.nav-link .forge-tool-icon {
  margin-right: 0.4rem;
  display: inline-block;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════
   Compact Sidebar (2026-04-04)
   ═══════════════════════════════════════════════════ */

/* Sidebar width: grid var matches style.css --sidebar-width (240px) */
/* Note: --sidebar-w was previously set to 190px here causing grid/sidebar mismatch */

/* Tighter nav padding */
.sidebar-nav { padding: 0.25rem 0; }
.nav-section { margin-bottom: 0.25rem; }
.nav-section-title { padding: 0.25rem 0.75rem; font-size: 0.65rem; }
.nav-link { padding: 0.2rem 0.6rem; font-size: 0.82rem; margin: 0 0.25rem; }
.nav-link .forge-tool-icon { font-size: 1.1rem !important; min-width: 22px; margin-right: 0.25rem; }

/* Ensure sidebar scrolls and doesn't clip */
.sidebar { overflow-y: auto; overflow-x: hidden; }

/* Right panel: start visible by default (remove rpanel-collapsed) */
/* Show gear toggle more prominently */
#rpanel-toggle { font-size: 1.1rem; }

/* Force-hide auth overlays from injected tool pages */
.view-host .auth-overlay,
.view-host #authOverlay {
  display: none !important;
}

/* ═══════════════════════════════════════════════════
   Collapsible Sections (2026-04-04)
   ═══════════════════════════════════════════════════ */
.nav-section-title {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.nav-section-title::before {
  content: '▾';
  font-size: 0.6rem;
  transition: transform var(--transition-fast);
  display: inline-block;
  width: 0.8rem;
}
.nav-section.collapsed .nav-section-title::before {
  transform: rotate(-90deg);
}
.nav-section.collapsed .nav-list {
  display: none;
}

/* ═══════════════════════════════════════════════════
   DM List (sidebar)
   ═══════════════════════════════════════════════════ */

.dm-entry {
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
}

.dm-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.dm-empty {
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════
   Channel Descriptions + Online Count
   ═══════════════════════════════════════════════════ */

.channel-link {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0;
  line-height: 1.3;
}
.channel-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.channel-link .unread-badge {
  flex-shrink: 0;
  margin-left: 6px;
  align-self: center;
}

.channel-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-topic {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.7;
  line-height: 1.2;
}

.online-count {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--online, #43b581);
  margin-left: 0.3rem;
}

/* ═══════════════════════════════════════════════════
   Cmd+K Quick Search Modal
   ═══════════════════════════════════════════════════ */

.qsearch-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.qsearch-modal {
  background: var(--bg-secondary, #16213e);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

.qsearch-input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--bg-primary, #1a1a2e);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
}

.qsearch-input::placeholder {
  color: var(--text-muted);
}

.qsearch-results {
  list-style: none;
  max-height: 300px;
  overflow-y: auto;
  padding: 0.25rem 0;
}

.qsearch-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast, 150ms ease);
}

.qsearch-item:hover,
.qsearch-item.selected {
  background: var(--accent-dim, rgba(83, 168, 182, 0.15));
  color: var(--text-primary);
}

.qsearch-badge {
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 22px;
  text-align: center;
}

.qsearch-badge-channel { background: var(--accent-dim); color: var(--accent); }
.qsearch-badge-dm { background: rgba(224, 128, 255, 0.15); color: #e080ff; }
.qsearch-badge-tool { background: rgba(250, 166, 26, 0.15); color: var(--warning); }

.qsearch-hint {
  padding: 0.4rem 1rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  text-align: center;
}

/* ═══════════════════════════════════════════════════
   Channel Info (right panel)
   ═══════════════════════════════════════════════════ */

.rpanel-channel-info {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
}

.ci-header {
  margin-bottom: 0.3rem;
}

.ci-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.ci-topic-row {
  display: flex;
  align-items: flex-start;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}

.ci-topic {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.3;
  flex: 1;
}

.ci-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  opacity: 0.5;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.ci-edit-btn:hover { opacity: 1; }

.ci-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.ci-topic-edit {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.3rem;
  align-items: center;
}

.ci-topic-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  font-family: inherit;
  outline: none;
}

.ci-topic-input:focus { border-color: var(--accent); }

.ci-save-btn,
.ci-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
}

.ci-save-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.ci-cancel-btn:hover { background: var(--bg-hover); }

.ci-actions {
  margin-top: 0.4rem;
}

.ci-archive-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  width: 100%;
  text-align: left;
  transition: all var(--transition-fast);
}

.ci-archive-btn:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(240, 71, 71, 0.05);
}

.ci-archive-confirm {
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: rgba(240, 71, 71, 0.08);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ci-archive-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.3rem;
}

.ci-archive-yes {
  background: var(--error);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
}

.ci-archive-yes:hover { opacity: 0.85; }
.ci-archive-yes:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════════════════════════════════════════════
   Pinned Messages (right panel)
   ═══════════════════════════════════════════════════ */

.rpanel-pins {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}

.pins-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.3rem;
}

.pins-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.pin-item {
  padding: 0.35rem 0.5rem;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.pin-item:hover {
  background: var(--accent-dim);
}

.pin-author {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
}

.pin-time {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
}

.pin-content {
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
  margin-top: 0.1rem;
}

/* ═══════════════════════════════════════════════════
   Nav Section Action Button (+ create)
   ═══════════════════════════════════════════════════ */

.nav-section-action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  padding: 0 0.3rem;
  margin-left: auto;
  border-radius: var(--radius-sm);
  line-height: 1;
  opacity: 0.5;
  transition: opacity var(--transition-fast), color var(--transition-fast);
}

.nav-section-action:hover {
  opacity: 1;
  color: var(--accent);
}

.nav-section-title {
  position: relative;
  z-index: 2;
}

/* ═══════════════════════════════════════════════════
   Modal (reusable)
   ═══════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: var(--bg-secondary, #16213e);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.2rem 0.4rem;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: 1rem;
}

.modal-field {
  margin-bottom: 0.75rem;
}

.modal-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.modal-field input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.modal-field input:focus { border-color: var(--accent); }

.modal-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  display: block;
}

.modal-error {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.modal-btn-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.modal-btn-cancel:hover { background: var(--bg-hover); }

.modal-btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
}

.modal-btn-primary:hover { opacity: 0.85; }
.modal-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════════════════════════════════════════════
   Notification Bell
   ═══════════════════════════════════════════════════ */

.notif-bell {
  position: relative;
}

.notif-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--error);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0px 4px;
  border-radius: 8px;
  min-width: 14px;
  text-align: center;
  line-height: 1.4;
}

.notif-dropdown {
  position: fixed;
  z-index: 9998;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  width: 320px;
  max-width: calc(100vw - 8px);
  max-height: 400px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.notif-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.notif-mark-all {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0.2rem 0.4rem;
}

.notif-mark-all:hover { text-decoration: underline; }

.notif-list {
  overflow-y: auto;
  max-height: 340px;
}

.notif-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.notif-item:hover { background: var(--bg-hover); }

.notif-item.unread {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

.notif-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.notif-body { flex: 1; min-width: 0; }

.notif-preview {
  font-size: 0.8rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notif-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.notif-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Tablet (≤900px): keep panels but narrower ── */
@media (max-width: 900px) and (min-width: 769px) {
  .app-shell {
    --sidebar-w: 200px;
    --rpanel-w: 220px;
  }
}

/* ── Mobile responsive — collapse panels by default, allow drawer on toggle ── */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 0px 1fr 0px !important;
    grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
  }
  .app-shell .sidebar,
  .app-shell .rpanel {
    display: none;
  }

  /* Drawer mode: when toggled visible, slide in as overlay (override the display:none above) */
  .app-shell.sidebar-visible .sidebar {
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    top: 44px !important;
    left: 0 !important;
    right: auto !important;
    bottom: 24px !important;
    width: 85vw !important;
    max-width: 280px !important;
    min-width: 200px !important;
    height: auto !important;
    z-index: 9999 !important;
    background: var(--bg-secondary, #1e1e2e) !important;
    box-shadow: 2px 0 16px rgba(0,0,0,0.5);
    border-right: 1px solid var(--border);
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transform: none !important;
  }
  .app-shell.rpanel-visible .rpanel {
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    top: 44px !important;
    right: 0 !important;
    left: auto !important;
    bottom: 24px !important;
    width: 85vw !important;
    max-width: 300px !important;
    min-width: 200px !important;
    height: auto !important;
    z-index: 9999 !important;
    background: var(--bg-secondary, #1e1e2e) !important;
    box-shadow: -2px 0 16px rgba(0,0,0,0.5);
    border-left: 1px solid var(--border);
    overflow-y: auto !important;
    overflow-x: hidden !important;
    transform: none !important;
  }

  /* Subtle backdrop ONLY behind the drawer, doesn't block clicks elsewhere.
     Click handler in shell.js handles outside-click dismiss. */
  .app-shell.sidebar-visible::after,
  .app-shell.rpanel-visible::after {
    content: '';
    position: fixed;
    top: var(--topbar-h, 44px);
    left: 0; right: 0; bottom: var(--statusbar-h, 24px);
    background: rgba(0,0,0,0.35);
    z-index: 150;
    pointer-events: none; /* clicks pass through to underlying app-shell */
  }

  /* 3d9847da: when rpanel covers full viewport, raise edge toggle above it so users
     can close it (rpanel is z-index:9999, toggle needs to be above that). */
  .app-shell.rpanel-visible .panel-edge-toggle-right {
    z-index: 10001;
    opacity: 1;
    min-width: 44px;
  }

  /* Edge toggles always visible on mobile, position at edges */
  .panel-edge-toggle-left { left: 0 !important; }
  .panel-edge-toggle-right { right: 0 !important; }

  /* Hide the drag handles on mobile — touch can't easily grab 4px */
  #sidebar-drag, #rpanel-drag { display: none !important; }

  /* Show mobile hamburger toggles in topbar */
  #mobile-sidebar-toggle.mobile-only,
  #mobile-rpanel-toggle.mobile-only {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Make topbar more compact */
  .topbar { padding: 0 0.5rem; gap: 0.25rem; }
  .topbar-brand-url { display: none; }
}

/* ── Narrow phone (≤480px) ── */
@media (max-width: 480px) {
  .topbar-brand strong {
    font-size: 0.85rem;
  }
  .topbar-view-title {
    display: none;
  }
  /* Even smaller topbar buttons */
  .topbar-btn { padding: 4px 6px; font-size: 12px; }
  .logout-btn { padding: 3px 6px; font-size: 0.7rem; }
  /* Drawers fill more of screen */
  .app-shell.sidebar-visible .sidebar,
  .app-shell.rpanel-visible .rpanel {
    width: min(92vw, 260px);
  }
}

/* ── Ultra-narrow (≤360px - Z Flip portrait) ── */
@media (max-width: 360px) {
  .topbar { padding: 0 0.25rem; }
  .topbar-brand strong { font-size: 0.78rem; }
  .topbar-actions { gap: 2px; }
  .topbar-btn { padding: 3px 5px; }
  .topbar-user { display: none; }
  .app-shell.sidebar-visible .sidebar,
  .app-shell.rpanel-visible .rpanel {
    width: 100vw;
  }
}

/* Logout button — distinct from other topbar buttons */
.logout-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin-left: 0.3rem;
}
.logout-btn:hover {
  background: var(--error, #f04747);
  color: #fff;
  border-color: var(--error, #f04747);
}

/* Topbar user display — make it visible */
.topbar-user:not(:empty) {
  padding: 0.2rem 0.5rem;
  background: var(--bg-hover, rgba(255,255,255,0.06));
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--text-primary);
}


/* ═══════════════════════════════════════════════════
   PANEL SYSTEM: LPanel + RPanel
   3 states: normal, compact (48px icons), collapsed (0px)
   Floating edge toggle buttons outside panels
   Pinned bottom sections (Tools in LPanel, Chat Tools in RPanel)
   ═══════════════════════════════════════════════════ */

/* --- Pinned bottom sections --- */
.sidebar { display: flex; flex-direction: column; }
.sidebar-nav { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.sidebar-nav-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.sidebar-nav-pinned { flex-shrink: 0; border-top: 1px solid var(--border); padding-top: 0.25rem; }

.rpanel { display: flex; flex-direction: column; }
.rpanel-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
/* Snug-to-left RPanel per Dan 2026-04-21 20:28 — kill all left padding on
   container AND nav-link inside so every row sits flush against the panel
   edge. Children can add 2-4px for visual breathing room. */
.rpanel-content-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; padding: 0.5rem 0 0.5rem 0; }
.rpanel-content-pinned { flex-shrink: 0; border-top: 1px solid var(--border); padding: 0.4rem 0 0.4rem 0; }
#rpanel .nav-link { padding-left: 0.25rem; margin-left: 0; }
#rpanel .nav-section-title { padding-left: 0.25rem; }
#rpanel .nav-list { padding-left: 0; margin: 0; }

/* --- Floating edge toggle buttons --- */
.panel-edge-toggle {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 100;
  width: 18px; height: 48px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; padding: 0; opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}
.panel-edge-toggle:hover {
  opacity: 1; background: var(--bg-tertiary, var(--surface)); color: var(--text-primary, var(--fg));
}
.panel-edge-toggle-left { left: var(--sidebar-w, 240px); border-radius: 0 4px 4px 0; border-left: none; }
.panel-edge-toggle-right { right: var(--rpanel-w, 260px); border-radius: 4px 0 0 4px; border-right: none; }

/* --- Collapsed state (overrides the originals at lines ~207-227) --- */
.app-shell.sidebar-collapsed .panel-edge-toggle-left { left: 0; }
.app-shell.rpanel-collapsed .panel-edge-toggle-right { right: 0; }

/* --- Compact state (48px, icon-only) --- */
.app-shell.sidebar-compact { grid-template-columns: 48px 1fr var(--rpanel-w); }
.app-shell.sidebar-compact .sidebar { width: 48px; min-width: 48px; overflow: hidden; }
.app-shell.sidebar-compact .panel-edge-toggle-left { left: 48px; }

.app-shell.rpanel-compact { grid-template-columns: var(--sidebar-w) 1fr 48px; }
.app-shell.rpanel-compact .rpanel { width: 48px; min-width: 48px; overflow: hidden; }
.app-shell.rpanel-compact .panel-edge-toggle-right { right: 48px; }

.app-shell.sidebar-compact.rpanel-compact { grid-template-columns: 48px 1fr 48px; }
.app-shell.sidebar-collapsed.rpanel-compact { grid-template-columns: 0px 1fr 48px; }
.app-shell.sidebar-compact.rpanel-collapsed { grid-template-columns: 48px 1fr 0px; }


/* ═══════════════════════════════════════════════════
   COMPACT MODE — Clean consolidated rules
   LPanel: .app-shell.sidebar-compact #sidebar ...
   RPanel: .app-shell.rpanel-compact #rpanel ...
   ═══════════════════════════════════════════════════ */

/* ── Shared compact behavior ── */
.app-shell.sidebar-compact #sidebar-drag,
.app-shell.rpanel-compact #rpanel-drag { display: none; }

/* ── LPanel compact: icon-only navigation ── */
.app-shell.sidebar-compact #sidebar .nav-section-title { font-size: 0; padding: 2px; height: 8px; overflow: hidden; border-bottom: 1px solid var(--border); }
.app-shell.sidebar-compact #sidebar .nav-section-action,
.app-shell.sidebar-compact #sidebar .online-count { display: none; }

.app-shell.sidebar-compact #sidebar .nav-link {
  font-size: 0; line-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px 4px; width: 100%;
  overflow: hidden; white-space: nowrap;
}
.app-shell.sidebar-compact #sidebar .nav-link .forge-tool-icon {
  font-size: 1.3rem; line-height: 1.2;
}
.app-shell.sidebar-compact #sidebar .nav-link .dm-avatar {
  font-size: 11px; line-height: 24px; width: 24px; height: 24px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
}

.app-shell.sidebar-compact #sidebar .channel-item {
  font-size: 0; padding: 6px 8px; width: 100%;
  overflow: hidden; white-space: nowrap;
}
.app-shell.sidebar-compact #sidebar .channel-item .ch-icon { font-size: 14px; }
.app-shell.sidebar-compact #sidebar .ch-unread { font-size: 8px; }

.app-shell.sidebar-compact #sidebar .member-name,
.app-shell.sidebar-compact #sidebar .bot-badge { display: none; }
.app-shell.sidebar-compact #sidebar .member-role-group-header { font-size: 0; padding: 2px; height: 12px; overflow: hidden; }

/* Hide channel topic text in compact */
.app-shell.sidebar-compact #sidebar .channel-topic { display: none; }

/* ── RPanel compact: icon-only Chat Tools ── */
.app-shell.rpanel-compact #rpanel .nav-section-title { font-size: 0; padding: 2px; height: 8px; overflow: hidden; border-bottom: 1px solid var(--border); }


.app-shell.rpanel-compact #rpanel .rpanel-content { width: 100%; }
.app-shell.rpanel-compact #rpanel .rpanel-content-pinned {
  flex: 1; border-top: none; padding-top: 0.5rem; width: 100%;
}
.app-shell.rpanel-compact #rpanel .rpanel-content-pinned .nav-section,
.app-shell.rpanel-compact #rpanel .rpanel-content-pinned .nav-list { width: 100%; padding: 0; }

.app-shell.rpanel-compact #rpanel .nav-link {
  font-size: 0; line-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px 4px; width: 100%;
  overflow: hidden; white-space: nowrap;
}
.app-shell.rpanel-compact #rpanel .nav-link .forge-tool-icon {
  font-size: 1.3rem; line-height: 1.2;
}

/* === FIX: Compact RPanel icons centered and large === */
.app-shell.rpanel-compact .rpanel .rpanel-content-pinned {
  padding: 0 !important;
  margin: 0;
}
.app-shell.rpanel-compact .rpanel .rpanel-content-pinned .nav-section {
  padding: 0;
  margin: 0;
}
.app-shell.rpanel-compact .rpanel .rpanel-content-pinned .nav-list {
  padding: 0;
  margin: 0;
  list-style: none;
}
.app-shell.rpanel-compact .rpanel .rpanel-content-pinned .nav-list li {
  display: flex;
  justify-content: center;
  padding: 0;
  margin: 0;
}
.app-shell.rpanel-compact .rpanel .nav-link {
  font-size: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 48px !important;
  height: 40px !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box;
}
.app-shell.rpanel-compact .rpanel .nav-link .forge-tool-icon {
  font-size: 1.4rem !important;
  line-height: 1 !important;
  display: block !important;
  text-align: center !important;
}
/* Same fix for LPanel compact */
.app-shell.sidebar-compact .sidebar .nav-link {
  font-size: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 48px !important;
  height: 36px !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box;
}
.app-shell.sidebar-compact .sidebar .nav-link .forge-tool-icon {
  font-size: 1.4rem !important;
  line-height: 1 !important;
  display: block !important;
  text-align: center !important;
}

/* === RPanel compact: all content visible, just compacted === */
/* Scroll area stays visible with compact content */
.app-shell.rpanel-compact .rpanel .rpanel-content-scroll {
  display: block !important;
  flex: 1 !important;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px !important;
}
/* Mini-chat compact: just show the chat icon/toggle */
.app-shell.rpanel-compact .rpanel #rpanel-chat {
  display: block !important;
  overflow: hidden;
  max-height: 32px;
}
/* Members compact: show avatars only */
.app-shell.rpanel-compact .rpanel #rpanel-members {
  display: block !important;
}
.app-shell.rpanel-compact .rpanel .member-role-group-header {
  font-size: 0 !important;
  padding: 2px !important;
  height: 12px;
  overflow: hidden;
}
.app-shell.rpanel-compact .rpanel .member-name,
.app-shell.rpanel-compact .rpanel .bot-badge {
  display: none !important;
}
.app-shell.rpanel-compact .rpanel .member-item {
  padding: 2px 4px !important;
  justify-content: center;
}
.app-shell.rpanel-compact .rpanel .member-avatar {
  margin: 0 auto;
}
/* Chat Tools: pinned to bottom in compact */
.app-shell.rpanel-compact .rpanel .rpanel-content-pinned {
  flex: none !important;
  flex-shrink: 0 !important;
  border-top: 1px solid var(--border);
}

/* ── RPanel compact: mini-chat + members as icons ── */
.app-shell.rpanel-compact #rpanel-chat { overflow: hidden; max-height: 40px; border-bottom: 1px solid var(--border); }
.app-shell.rpanel-compact #rpanel-chat .rpc-body { display: none; }
.app-shell.rpanel-compact #rpanel-chat .rpc-toggle { padding: 8px; justify-content: center; }
.app-shell.rpanel-compact #rpanel-chat .rpc-toggle-right { display: none; }
.app-shell.rpanel-compact #rpanel-chat .rpc-toggle-left { font-size: 0; }
.app-shell.rpanel-compact #rpanel-chat .rpc-toggle-left::before { content: '💬'; font-size: 1.3rem; }

.app-shell.rpanel-compact #rpanel-members { overflow: hidden; }
.app-shell.rpanel-compact #rpanel-members .member-name,
.app-shell.rpanel-compact #rpanel-members .bot-badge,
.app-shell.rpanel-compact #rpanel-members .member-group-label,
.app-shell.rpanel-compact #rpanel-members .member-group-count,
.app-shell.rpanel-compact #rpanel-members .online-count { display: none; }
.app-shell.rpanel-compact #rpanel-members .member-role-group-header { font-size: 0; padding: 4px; justify-content: center; }
.app-shell.rpanel-compact #rpanel-members .member-role-group-header .member-group-icon { font-size: 1.2rem; }
.app-shell.rpanel-compact #rpanel-members .member-item { padding: 2px 8px; justify-content: center; }
.app-shell.rpanel-compact #rpanel-members .member-avatar { margin: 0 auto; }

/* ── Unread badges ── */
.ch-unread {
  margin-left: 0; margin-right: 4px; order: -1;
  background: var(--error, #f04747);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* RPanel overlay mode for mobile */
@media (max-width: 768px) {
  .app-shell.rpanel-visible .rpanel {
    display: block;
    position: fixed;
    top: var(--topbar-h, 44px);
    right: 0;
    bottom: var(--statusbar-h, 24px);
    width: 260px;
    z-index: 100;
    background: var(--bg-secondary, #1e1e2e);
    box-shadow: -2px 0 8px rgba(0,0,0,0.3);
  }
}

/* ── RPanel DMs ── */
.rpanel-dms { border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.rpanel-dms .presence-dot.online { background: var(--success, #43b581); }
.rpanel-dms .presence-dot.away { background: var(--warning, #faa61a); }
.rpanel-dms .presence-dot.dnd { background: var(--error, #f04747); }
.rpanel-dms .presence-dot.offline { background: var(--text-muted, #6a6a80); }

/* Global presence-dot defaults for sidebar DM list, etc. */
.presence-dot.online { background: var(--success, #43b581); }
.presence-dot.away { background: var(--warning, #faa61a); }
.presence-dot.dnd { background: var(--error, #f04747); }
.presence-dot.offline { background: var(--text-muted, #6a6a80); }


/* ── Touch target minimums (iOS HIG / Material) ───────────────────────
   Ensure nav links, buttons, and toggle elements meet 44px tap target.
   Only applied on coarse-pointer (touch) devices.                    */
@media (pointer: coarse) {
  .nav-link,
  .topbar-btn,
  .mobile-only,
  .sidebar-section-header,
  button.tab-label,
  .settings-tab label {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .nav-list .nav-link {
    padding-top: 10px;
    padding-bottom: 10px;
  }
  /* Prevent accidental horizontal scroll on touch */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
}

@media (pointer: coarse) {
  .topbar-btn { min-width: 44px; }       /* c796dba2 */
  .panel-edge-toggle { min-width: 44px; } /* cd6241ee */
}

/* Channel list li as flex row — badge is sibling of nav-link, not inside it */
#channel-list li {
  display: flex;
  align-items: center;
  list-style: none;
}
#channel-list li .nav-link {
  flex: 1;
  min-width: 0;
}
#channel-list li > .unread-badge {
  flex-shrink: 0;
  margin-right: 8px;
  background: var(--error, #f04747);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 9px;
  min-width: 14px;
  text-align: center;
}

/* Channel list item layout — flex for inline badge */
.channel-item {
  display: flex;
  align-items: center;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin: 0 0.3rem;
  transition: background 0.12s;
  gap: 4px;
}
.channel-item:hover { background: var(--bg-hover); }
.channel-item.active { background: var(--accent-dim); }
.channel-item .channel-hash-icon { flex-shrink: 0; }
.channel-item .channel-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item .unread-badge {
  background: var(--error, #f04747);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 9px;
  min-width: 14px;
  text-align: center;
  flex-shrink: 0;
  margin-left: auto;
}
.channel-item .channel-voice-join-btn { flex-shrink: 0; margin-left: auto; }

/* a11y: visible keyboard focus ring (WCAG 2.4.7). Several rules set outline:none */
/* which hid focus for keyboard users; :focus-visible shows only on keyboard nav.  */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible,
.nav-link:focus-visible,
.channel-link:focus-visible,
.member-item:focus-visible,
.btn-primary:focus-visible,
.btn-icon:focus-visible {
  outline: 2px solid var(--accent) !important;
  outline-offset: 2px !important;
  border-radius: 3px;
  /* a11y WCAG 1.4.11: theme-agnostic dual-tone focus ring. dark halo carries light themes, accent outline carries dark. */
  box-shadow: 0 0 0 4px rgba(0,0,0,.55) !important;
}
