:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --border: #262b35;
  --text: #e7eaf0;
  --muted: #8a93a4;
  --accent: #1db954;
  --accent-2: #1ed760;
  --user: #2a3450;
  --assistant: #1c2129;
  --rec: #ff4757;
  --ok: #2ecc71;
  --warn: #f0c419;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}

html, body {
  height: 100vh;
  height: 100dvh;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
  flex: 0 0 auto;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 rgba(0,0,0,0);
  transition: background 200ms ease, box-shadow 200ms ease;
}

/* Connection status sets the base color. */
.dot[data-conn="connected"]    { background: var(--ok); }
.dot[data-conn="connecting"]   { background: var(--warn); animation: pulse 900ms ease-in-out infinite; }
.dot[data-conn="disconnected"] { background: var(--rec); }

/* Pipeline state overrides the color while the assistant is working — only
   meaningful while the SSE channel is connected. */
.dot[data-conn="connected"][data-state="listening"]    { background: var(--rec); animation: pulse 900ms ease-in-out infinite; }
.dot[data-conn="connected"][data-state="transcribing"] { background: var(--warn); animation: pulse 900ms ease-in-out infinite; }
.dot[data-conn="connected"][data-state="thinking"]     { background: var(--accent); animation: pulse 900ms ease-in-out infinite; }
.dot[data-conn="connected"][data-state="speaking"]     { background: var(--accent-2); animation: pulse 900ms ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.0); }
  50%      { box-shadow: 0 0 0 6px rgba(255,255,255,0.08); }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
}

/* Old `.wakelock` styles replaced — the wake-lock icon now uses the same
   `.hw-indicator` markup as the mic/speaker indicators. States are mapped
   in the shared rule block below. */

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-height: 0; /* allows children to shrink so inner scroll works in flex parent */
  overflow: hidden;
}

/* Mobile-only top tab bar — switches between chat, Spotify, and lights.
   Hidden on desktop; shown below 700px where the split-view grid is too
   cramped to be useful. The three panels then become mutually exclusive,
   driven by `body[data-mobile-tab]`. */
.mobile-tabs { display: none; }

@media (max-width: 700px) {
  .mobile-tabs {
    display: flex;
    flex: 0 0 auto;
    background: rgba(15, 17, 21, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 4;
    padding: 0;
    gap: 0;
  }
  .mobile-tab {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 8px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
  }
  .mobile-tab:hover { color: var(--text); background: var(--panel-2); }
  .mobile-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
  }
  .mobile-tab.active[data-mobile-tab="spotify"] {
    color: #1db954;
    border-bottom-color: #1db954;
  }
  .mobile-tab.active[data-mobile-tab="lights"] {
    color: var(--warn);
    border-bottom-color: var(--warn);
  }
  .mobile-tab.active[data-mobile-tab="rohlik"] {
    color: #eb5c1e;
    border-bottom-color: #eb5c1e;
  }
  .mobile-tab-icon { flex: 0 0 auto; display: inline-flex; align-items: center; }
  .mobile-tab-emoji { font-size: 16px; }

  /* Single panel visible at a time — no more top/bottom split. */
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }
  /* Hide the inner Spotify/Lights sub-tabs header — the outer mobile bar
     now handles panel choice, so the inline sub-tabs would be redundant. */
  .panel-header.tabs-header { display: none; }

  /* Drive panel visibility from the body attribute. `!important` so the
     `.tab-panel[hidden]` display:none rule (set by internal tab switching
     for Spotify vs Lights) doesn't leak across — if the user picked
     "lights" on mobile, we force-show it via `[data-mobile-tab="lights"]`
     regardless of the internal state. */
  body[data-mobile-tab="chat"] .right-stack { display: none; }
  body[data-mobile-tab="spotify"] .conversation,
  body[data-mobile-tab="lights"]  .conversation,
  body[data-mobile-tab="rohlik"]  .conversation { display: none; }
  body[data-mobile-tab="spotify"] #panel-spotify { display: flex !important; }
  body[data-mobile-tab="spotify"] #panel-lights  { display: none  !important; }
  body[data-mobile-tab="spotify"] #panel-rohlik  { display: none  !important; }
  body[data-mobile-tab="lights"]  #panel-lights  { display: flex !important; }
  body[data-mobile-tab="lights"]  #panel-spotify { display: none  !important; }
  body[data-mobile-tab="lights"]  #panel-rohlik  { display: none  !important; }
  body[data-mobile-tab="rohlik"]  #panel-rohlik  { display: flex !important; }
  body[data-mobile-tab="rohlik"]  #panel-spotify { display: none  !important; }
  body[data-mobile-tab="rohlik"]  #panel-lights  { display: none  !important; }
}

/* The sidebar is always a slide-over drawer, triggered from the hamburger
   button in the topbar. Hidden off-screen by default on every viewport so
   the chat gets the full horizontal space when the list isn't needed. */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 320px;
  max-width: 82vw;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform 220ms ease;
  border-radius: 0;
  border-top: none;
  border-bottom: none;
  border-left: none;
  box-shadow: 8px 0 28px rgba(0, 0, 0, 0.4);
}
.sidebar.open { transform: translateX(0); }

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 25;
  opacity: 0;
  transition: opacity 220ms ease;
}
.sidebar-scrim.open { opacity: 1; }
.sidebar-scrim[hidden] { display: none; }

.sidebar-toggle { display: inline-flex; }

/* Right-hand stack: the tabbed panel (Spotify + Světla) fills the full
   height of the column. */
.right-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
.right-stack .panel.right-panel { flex: 1 1 auto; min-height: 0; }

/* --- Right-panel tabs (Spotify / Světla) --- */
/* Compound selector so we outrank `.panel-header`, which is defined later in
   this stylesheet and would otherwise win on source order. */
.panel-header.tabs-header {
  padding: 0;
  gap: 0;
  justify-content: flex-start;
  /* Match the sibling `.conversation` panel's header height so the two
     panels sit on a shared baseline. */
  min-height: 56px;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  /* Align with the chat header — see `.panel-header` min-height. */
  height: 56px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
}
.tab-btn:hover { color: var(--text); background: var(--panel-2); }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: transparent;
}
.tab-btn.active[data-tab="spotify"] { color: #1db954; border-bottom-color: #1db954; }
.tab-btn.active[data-tab="lights"]  { color: var(--warn); border-bottom-color: var(--warn); }
.tab-btn.active[data-tab="rohlik"]  { color: #eb5c1e; border-bottom-color: #eb5c1e; }
.tab-icon { flex: 0 0 auto; display: inline-flex; align-items: center; }
.tab-emoji { font-size: 16px; }

.tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tab-panel[hidden] { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 56px;
  flex: 0 0 auto;
}

.panel-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.hint { font-size: 12px; color: var(--muted); }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-gutter: stable;
}

.composer { flex: 0 0 auto; }
.panel-header { flex: 0 0 auto; }
.display-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Custom scrollbar — narrower & themed so it doesn't look like a plain page scrollbar. */
.messages::-webkit-scrollbar,
.display-body::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb,
.display-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover,
.display-body::-webkit-scrollbar-thumb:hover {
  background: #3a4051;
}
.messages, .display-body { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 15px;
  animation: fadeIn 180ms ease-out;
}

.bubble .meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

/* User bubbles render on the left, assistant on the right — opposite of
   most chat UIs but the user explicitly preferred this layout. */
.bubble.user {
  background: var(--user);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.assistant {
  background: var(--assistant);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border);
}
.bubble.pending {
  opacity: 0.7;
  font-style: italic;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* Inline progress entries — "searching the internet", "calling tool ..." */
.progress {
  align-self: stretch;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 10px;
  margin: 2px 0 2px 6px;
  font-size: 13px;
  color: var(--muted);
  border-left: 2px solid var(--border);
  animation: fadeIn 180ms ease-out;
}
.progress .progress-icon {
  font-size: 12px;
  flex: 0 0 auto;
  opacity: 0.85;
}
.progress .progress-label {
  font-style: italic;
}
.progress .progress-detail {
  color: var(--text);
  opacity: 0.85;
  font-style: normal;
  word-break: break-word;
  min-width: 0;
}
.progress .progress-detail::before {
  content: "— ";
  color: var(--muted);
}
.progress.kind-web-search { border-left-color: var(--accent); }
.progress.kind-web-fetch  { border-left-color: var(--accent-2); }
.progress.kind-tool       { border-left-color: var(--warn); }
.progress.kind-thinking   { border-left-color: var(--accent-2); }

.composer {
  display: flex;
  gap: 8px;
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
  flex: 0 0 auto;
  min-height: 76px;
  align-items: center;
}

.composer input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 48px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.composer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 185, 84, 0.2);
}

.composer button.primary {
  height: 48px;
  padding: 0 20px;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  /* Kill iOS double-tap zoom on every button and shave the old 300ms click
     delay — the viewport meta handles the rest, this is belt-and-suspenders. */
  touch-action: manipulation;
}
button:disabled { cursor: not-allowed; opacity: 0.5; }

/* Same treatment for anything else a finger might land on: conversation
   rows, bubbles, sliders, composer input. */
.conv-item,
.bubble,
.composer input,
input[type="range"] { touch-action: manipulation; }

button.primary {
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background 120ms ease;
}
button.primary:hover:not(:disabled) { background: var(--accent-2); }

button.ghost {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 120ms ease, color 120ms ease;
}
button.ghost:hover { background: var(--panel-2); color: var(--text); }

.display-body .empty {
  color: var(--muted);
  text-align: center;
  margin-top: 40px;
  font-style: italic;
}

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  animation: fadeIn 180ms ease-out;
}

.card h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 600;
}

.card .body {
  font-size: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.card .data {
  margin-top: 12px;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  font-size: 13px;
  color: var(--muted);
}
.card .data .k { font-weight: 600; }
.card .data .v { color: var(--text); }

.card.kind-error  { border-color: rgba(255, 71, 87, 0.4); }
.card.kind-error h3 { color: var(--rec); }
.card.kind-spotify h3 { color: #1db954; }
.card.kind-light h3, .card.kind-outlet h3 { color: var(--warn); }
.card.kind-time h3, .card.kind-timer h3 { color: var(--accent-2); }

/* --- Spotify widget --- */

.spotify-logo { flex: 0 0 auto; }

.spotify-body {
  display: grid;
  grid-template-columns: 80px 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "art  meta"
    "queue queue"
    "controls controls";
  column-gap: 14px;
  row-gap: 0;
  padding: 16px 16px 0;
  align-items: center;
  flex: 1 1 auto;
  min-height: 0;
}
/* Reinstate the visual gap between the art/meta row and the queue, since
   row-gap was set to 0 to let the queue scrollbar meet the controls bar. */
.spotify-lists { margin-top: 14px; }

.spotify-art {
  grid-area: art;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1db954;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.spotify-art.has-art > svg { display: none; }

.spotify-meta {
  grid-area: meta;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: center;
  position: relative; /* anchor for the absolutely-positioned radio button */
}

.spotify-track {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotify-artist {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotify-progress {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.spotify-progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.spotify-progress-fill {
  height: 100%;
  background: #1db954;
  width: 0%;
  transition: width 250ms linear;
}

.spotify-progress-times {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.spotify-controls {
  grid-area: controls;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 12px;
  padding: 14px 12px;
  margin: 0 -16px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  min-height: 76px;
}
.spotify-controls-buttons {
  grid-column: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
/* Radio trigger floats at the top-right corner of the meta column —
   absolute positioning so it doesn't compete for flex space with the
   track title / artist (which would shrink them otherwise). */
.spotify-btn.spotify-radio-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 28px;
  height: 28px;
  color: var(--muted);
  z-index: 1;
}
.spotify-btn.spotify-radio-btn svg { width: 20px; height: 20px; }
.spotify-radio-btn:not(:disabled):hover { color: var(--text); }
/* Reserve space at the end of the title so long names don't slide under
   the icon; padding-only (no layout flex) means the artist row below
   still spans the full meta width. */
.spotify-meta .spotify-track { padding-right: 32px; }
/* In the empty state there's nothing to radio-from — hide the button. */
.spotify-body[data-state="empty"] .spotify-radio-btn { visibility: hidden; }
.spotify-body[data-state="empty"] .spotify-meta .spotify-track { padding-right: 0; }
.spotify-device {
  grid-column: 3;
  justify-self: end;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 4px;
  color: var(--muted);
  opacity: 0.75;
}

.spotify-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 120ms ease, transform 80ms ease;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
}
.spotify-btn svg { width: 24px; height: 24px; }
.spotify-btn:hover:not(:disabled) { background: var(--panel); }
.spotify-btn:active:not(:disabled) { transform: scale(0.94); }
.spotify-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.spotify-btn.primary {
  width: 48px;
  height: 48px;
  background: #1db954;
  color: #0c1812;
}
.spotify-btn.primary svg { width: 28px; height: 28px; }
.spotify-btn.primary:hover:not(:disabled) { background: #1ed760; }

.spotify-body[data-state="empty"] .spotify-progress,
.spotify-body[data-state="empty"] .spotify-artist { visibility: hidden; }
.spotify-body[data-state="empty"] .spotify-track { color: var(--muted); font-weight: 400; }

/* Unified list panel — one scrollable list with a tab bar to switch
   between the current queue, recently-played, and top tracks. Fills the
   remaining panel height so the Spotify box reads as a real "now playing"
   view, not a widget. */
.spotify-lists {
  grid-area: queue;
  align-self: stretch;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 6px;
  overflow: hidden;
}

.spotify-list-tabs {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  padding: 0 2px 4px;
}
.spotify-list-tab {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.spotify-list-tab:hover { background: var(--panel-2); color: var(--text); }
.spotify-list-tab.active { background: var(--panel-2); color: var(--text); }
.spotify-list-tab[hidden] { display: none; }
.spotify-list-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.spotify-queue-list {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.spotify-queue-list::-webkit-scrollbar { width: 8px; }
.spotify-queue-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.spotify-queue-list::-webkit-scrollbar-thumb:hover { background: #3a4051; }

.spotify-queue-list:empty + .spotify-queue-empty { display: block; }
.spotify-queue-list:not(:empty) + .spotify-queue-empty { display: none; }
.spotify-queue-empty { padding: 8px 2px; color: var(--muted); font-style: italic; }

.spotify-queue-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 6px 4px;
  border-radius: 6px;
  min-width: 0;
  touch-action: manipulation;
  transition: background 120ms ease;
}
.spotify-queue-item + .spotify-queue-item { border-top: 1px solid rgba(255, 255, 255, 0.03); }
.spotify-queue-item[data-uri] { cursor: pointer; }
.spotify-queue-item[data-uri]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (hover: hover) {
  .spotify-queue-item[data-uri]:hover { background: var(--panel-2); }
}
.spotify-queue-item[data-uri]:active { background: var(--panel-2); }

/* Click-in-flight feedback: the clicked row gets an accent bar + pulse,
   siblings dim so attention stays on the target. The `busy` class on the
   <ul> blocks further pointer interaction while a skip-next sequence is
   running so rapid taps don't stack. */
.spotify-queue-list.busy { pointer-events: none; }
.spotify-queue-list.busy .spotify-queue-item { opacity: 0.45; transition: opacity 160ms ease; }
.spotify-queue-list.busy .spotify-queue-item.loading {
  opacity: 1;
  background: var(--panel-2);
  box-shadow: inset 3px 0 0 var(--accent);
  animation: queue-loading-pulse 900ms ease-in-out infinite;
}
@keyframes queue-loading-pulse {
  0%, 100% { background-color: var(--panel-2); }
  50%      { background-color: rgba(29, 185, 84, 0.18); }
}

.spotify-queue-art {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: var(--panel-2);
  background-size: cover;
  background-position: center;
  flex: 0 0 auto;
}

.spotify-queue-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.spotify-queue-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.spotify-queue-artist {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotify-queue-dur {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}


.ptt-bar {
  flex: 0 0 auto;
  /* Three-column grid keeps the Mluvit button geometrically centered
     regardless of how wide the volume pill on the right is (the empty
     left slot mirrors it). */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 5;
}
.ptt-slot { min-width: 0; display: flex; align-items: center; }
.ptt-slot-left { justify-content: flex-start; }
.ptt-slot-right { justify-content: flex-end; }

/* On phones the full volume pill would force a second row, so we collapse
   it into a single round icon next to Mluvit. The pill itself becomes a
   popover anchored above that icon — absolutely positioned so it never
   contributes to layout. */
@media (max-width: 640px) {
  .ptt-bar {
    /* Switch to flex + absolute-positioned right slot so the Mluvit button
       sits dead-center regardless of the toggle's width, and the volume
       popover can anchor relative to the whole bar without breaking layout. */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    position: relative;
  }
  /* Mirror the right slot's absolute positioning so the Mluvit button stays
     perfectly centered while the mic-source toggle hangs off the left edge. */
  .ptt-slot-left {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
  }
  .ptt-slot-right {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
  }
  /* Slightly compact on phones — leaves breathing room next to the volume
     toggle and stops the button from dominating the footer. */
  .ptt-btn {
    height: 44px;
    min-width: 0;
    padding: 0 18px;
    font-size: 14px;
    gap: 8px;
  }
  .ptt-btn .ptt-icon svg { width: 22px; height: 22px; }
}

/* Status indicators in the topbar — mic, speaker, wake-lock all share the
   same round-icon visual. Color reflects state (green = good, yellow =
   muted/disabled, red = bad, muted-gray = neutral). They're interactive
   toggles, so they behave like buttons (hover / active). */
.hw-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 80ms ease;
}
.hw-indicator:hover { filter: brightness(1.15); }
.hw-indicator:active { transform: scale(0.92); }
/* mic/speaker: `connected` / `disconnected`  -- wake-lock: `on` / `off` /
   `unavailable` / `error`. Map semantically similar states to the same
   visual style so the three icons behave consistently. */
.hw-indicator[data-state="connected"],
.hw-indicator[data-state="on"] {
  color: var(--ok);
  border-color: rgba(46, 204, 113, 0.4);
  background: rgba(46, 204, 113, 0.08);
  box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.12);
}
.hw-indicator[data-state="disconnected"],
.hw-indicator[data-state="error"] {
  color: var(--rec);
  border-color: rgba(255, 71, 87, 0.45);
  background: rgba(255, 71, 87, 0.08);
  box-shadow: 0 0 0 2px rgba(255, 71, 87, 0.12);
}
.hw-indicator[data-state="unknown"],
.hw-indicator[data-state="off"],
.hw-indicator[data-state="unavailable"] {
  color: var(--muted);
  opacity: 0.6;
}
/* Muted = user-disabled but hardware is still present. Orange/warning
   color so it reads as "intentionally off" rather than "broken". */
.hw-indicator[data-state="muted"] {
  color: var(--warn);
  border-color: rgba(240, 196, 25, 0.45);
  background: rgba(240, 196, 25, 0.08);
  box-shadow: 0 0 0 2px rgba(240, 196, 25, 0.12);
}

/* Mic-source toggle — sits to the left of the Mluvit button. Shows a single
   icon + short label indicating the currently-selected source; click flips
   the source. Device (browser mic) is the default when supported; Pi source
   falls back to the Pi's hardware mic via /api/wakeword. The two icons share
   the same slot — CSS shows exactly one based on [data-source]. */
.mic-source-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  /* Match .volume-pill height so both pills sit on the same footer baseline. */
  height: 60px;
  padding: 0 18px;
  max-width: 260px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, transform 80ms ease;
}
.mic-source-btn .mic-source-icon { width: 20px; height: 20px; }
.mic-source-btn .mic-source-label {
  /* Truncate long device names ("Default - MacBook Pro Microphone (Built-in)")
     so the pill doesn't stretch across the whole footer. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.mic-source-btn:hover { filter: brightness(1.15); }
.mic-source-btn:active { transform: scale(0.95); }
.mic-source-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.mic-source-btn[data-source="device"] {
  color: var(--accent);
  border-color: rgba(29, 185, 84, 0.45);
  background: rgba(29, 185, 84, 0.08);
}
.mic-source-btn[data-source="pi"] {
  color: var(--warn);
  border-color: rgba(240, 196, 25, 0.45);
  background: rgba(240, 196, 25, 0.08);
}
/* Show exactly one icon depending on the selected source. */
.mic-source-btn .mic-source-icon { flex: 0 0 auto; }
.mic-source-btn[data-source="device"] .mic-source-icon-pi,
.mic-source-btn[data-source="pi"] .mic-source-icon-device { display: none; }

/* Mobile: collapse the pill into a 44×44 round icon that mirrors the
   volume toggle. Must come AFTER the base rules (equal specificity) so
   height/width/padding actually win. */
@media (max-width: 640px) {
  .mic-source-btn {
    width: 44px;
    height: 44px;
    max-width: none;
    padding: 0;
    gap: 0;
    border-radius: 50%;
    box-shadow: none;
  }
  .mic-source-btn .mic-source-label { display: none; }
  .mic-source-btn .mic-source-icon { width: 22px; height: 22px; }
}

.ptt-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Match the volume-pill height so the footer sits on a single baseline. */
  height: 60px;
  padding: 0 28px;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 80ms ease, background 120ms ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-width: 220px;
  justify-content: center;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  border: none;
}

.ptt-btn * { pointer-events: none; }
.ptt-btn:focus { outline: none; }
.ptt-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 3px;
}
.ptt-btn:active { transform: scale(0.98); }

.ptt-btn[data-state="recording"] {
  background: var(--rec);
}

.ptt-btn[data-state="processing"] {
  background: var(--panel-2);
  color: var(--muted);
  cursor: progress;
  animation: none;
}

.ptt-btn[data-state="error"] {
  background: var(--rec);
  cursor: not-allowed;
}

.ptt-icon { display: flex; align-items: center; }

/* --- Sidebar (conversation list) --- */

.sidebar {
  min-height: 0;
  background: var(--panel);
}

.sidebar .panel-header {
  padding: 12px 14px;
}

.panel-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.conv-list::-webkit-scrollbar { width: 8px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-list:empty + .conv-empty { display: block; }
.conv-list:not(:empty) + .conv-empty { display: none; }
.conv-empty { padding: 12px 16px; }

/* User footer at the bottom of the sidebar — sits below the conversation
   list (which has flex: 1 1 auto) so it stays pinned to the bottom of the
   drawer. Filled in by app.js from /auth/whoami. */
.sidebar-user {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.sidebar-user[hidden] { display: none; }

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}
.sidebar-user-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
}
.sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.sidebar-user-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-user-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.sidebar-logout-btn:hover {
  color: var(--text);
  border-color: var(--rec);
  background: rgba(255, 71, 87, 0.08);
}
.sidebar-logout-btn span { line-height: 1; }

.conv-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 10px 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  gap: 8px;
  transition: background 120ms ease;
  touch-action: manipulation;
}
@media (hover: hover) {
  .conv-item:hover { background: var(--panel-2); }
}
.conv-item.active {
  background: var(--user);
  /* Thin accent strip on the left signals which conversation is the one
     voice turns & SSE replay attach to. */
  box-shadow: inset 3px 0 0 var(--accent);
}

.conv-item .conv-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.conv-item .conv-preview {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.conv-item .conv-time {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.conv-item .conv-delete {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: opacity 120ms ease, background 120ms ease, color 120ms ease;
  grid-row: 1;
  grid-column: 2;
}
.conv-item.active .conv-delete,
.conv-item:focus-within .conv-delete { opacity: 1; }
@media (hover: hover) {
  .conv-item:hover .conv-delete { opacity: 1; }
  .conv-item .conv-delete:hover { background: rgba(255, 71, 87, 0.15); color: var(--rec); }
}
@media (hover: none) {
  /* On touch devices, keep the delete button reachable without hover. */
  .conv-item .conv-delete { opacity: 0.6; }
}

.conv-item.renaming {
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.conv-item .conv-rename-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  outline: none;
}
.conv-item .conv-rename-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 185, 84, 0.2);
}

/* Icon buttons (topbar hamburger + "new conversation" plus) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  transition: background 120ms ease, color 120ms ease, transform 80ms ease, box-shadow 120ms ease;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

/* "New conversation" plus buttons — accent-colored so they read as a
   primary action rather than a subtle toggle. */
#new-conv-btn,
#header-new-conv-btn {
  background: var(--accent);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
#new-conv-btn:hover,
#header-new-conv-btn:hover {
  background: var(--accent-2);
  color: white;
}

/* --- Status panel (mic / speaker / volume) --- */

.status-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  overflow-y: auto;
  min-height: 0;
}

/* Compact volume pill in the footer — icon + slider + value, all in one
   rounded bar. Sized for comfortable touch control on iPad: generous
   padding, wide slider, bigger thumb (see #status-volume-slider overrides
   below). Only rendered when a Bluetooth speaker is connected; the server
   decides, we just toggle `hidden`. */
.volume-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  /* Height aligned with .ptt-btn so the footer reads as one tidy row. */
  height: 60px;
  padding: 0 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  min-width: 340px;
  max-width: 440px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
/* `!important` so the availability toggle wins over the mobile
   `[data-open="true"]` popover rule below (equal specificity otherwise). */
.volume-pill[hidden] { display: none !important; }

/* Desktop: toggle never shows — the full pill is always present instead. */
.volume-toggle-btn { display: none; }

/* Mobile-only popover mode: toggle becomes a round icon button, the pill
   turns into an absolutely-positioned bubble above it, opened via
   `data-open="true"` on the pill (synced with `aria-expanded` on the
   toggle). */
@media (max-width: 640px) {
  .volume-toggle-btn[hidden] { display: none; }
  .volume-toggle-btn:not([hidden]) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: var(--muted);
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 0;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: color 160ms ease, background 160ms ease, border-color 160ms ease, transform 80ms ease;
  }
  .volume-toggle-btn:hover { filter: brightness(1.15); }
  .volume-toggle-btn:active { transform: scale(0.92); }
  .volume-toggle-btn[data-state="muted"] {
    color: var(--warn);
    background: rgba(240, 196, 25, 0.1);
    border-color: rgba(240, 196, 25, 0.45);
  }
  .volume-toggle-btn[aria-expanded="true"] {
    color: var(--text);
    background: var(--panel-2);
  }

  /* Pill becomes a floating bubble anchored above the toggle button. */
  .volume-pill {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    min-width: 0;
    width: min(320px, calc(100vw - 24px));
    height: 56px;
    padding: 0 14px;
    gap: 6px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    /* Default closed; `data-open="true"` (set from JS) flips it open. */
    display: none;
    animation: volume-pill-pop 140ms ease-out;
  }
  .volume-pill[data-open="true"] { display: inline-flex; }
  /* On a narrow popover, shrink the secondary controls a little so the
     slider still has room to breathe. */
  .volume-pill .volume-pill-step { width: 28px; height: 28px; }
  .volume-pill .volume-pill-icon { width: 32px; height: 32px; }
  .volume-pill .volume-pill-icon svg { width: 20px; height: 20px; }
}
@keyframes volume-pill-pop {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* The speaker icon inside the pill doubles as a mute toggle — styled like
   a flat round button with a clear hover/active state, mirrors the mute
   state via a data-state attribute. */
.volume-pill-icon {
  color: var(--muted);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: color 160ms ease, background 160ms ease, transform 80ms ease;
}
.volume-pill-icon:hover { background: var(--panel-2); color: var(--text); }
.volume-pill-icon:active { transform: scale(0.92); }
.volume-pill-icon[data-state="muted"] {
  color: var(--warn);
  background: rgba(240, 196, 25, 0.1);
}
.volume-pill-icon svg { width: 22px; height: 22px; }

/* +/- step buttons — same shape as the mute toggle, slightly smaller.
   Clicking steps the volume by 2% (see VOLUME_STEP_PCT in app.js). */
.volume-pill-step {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: color 160ms ease, background 160ms ease, transform 80ms ease;
}
.volume-pill-step:hover { background: var(--panel-2); color: var(--text); }
.volume-pill-step:active { transform: scale(0.9); }
.volume-pill-step:disabled { opacity: 0.35; cursor: not-allowed; }
.volume-pill-slider {
  flex: 1 1 auto;
  min-width: 0;
  /* Taller track so it reads as a primary control rather than an afterthought. */
  height: 10px !important;
}
.volume-pill-value {
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 3.6ch;
  text-align: right;
  flex: 0 0 auto;
  color: var(--text);
}

.status-volume {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.status-volume[hidden] { display: none; }
.status-volume-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Range slider — left side of the thumb is filled with the accent color.
   Chrome/Safari: linear-gradient on the track driven by `--fill` (set from
   JS on input). Firefox: `::-moz-range-progress` handles it natively.
   Sized for touch: 10px track, 26px thumb (Apple's HIG recommends ~44px hit
   targets; the slider itself gets the full padding of its container too). */
#status-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  background: transparent;
  border-radius: 5px;
  outline: none;
  cursor: pointer;
  --fill: 0%;
  /* Vertical padding in the tap zone without visually enlarging the track. */
  padding: 8px 0;
  touch-action: none; /* prevents the browser from eating horizontal drags as scrolls */
}
#status-volume-slider::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill),
    var(--bg) var(--fill),
    var(--bg) 100%
  );
}
#status-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--panel);
  cursor: pointer;
  margin-top: -8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: background 120ms ease, transform 80ms ease;
}
#status-volume-slider::-webkit-slider-thumb:hover { background: var(--accent-2); }
#status-volume-slider::-webkit-slider-thumb:active { transform: scale(1.12); }
#status-volume-slider::-moz-range-track {
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
}
#status-volume-slider::-moz-range-progress {
  height: 10px;
  background: var(--accent);
  border-radius: 5px;
}
#status-volume-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--panel);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
#status-volume-slider:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Lights panel (IKEA DIRIGERA) --- */

.lights-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 16px;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.lights-body::-webkit-scrollbar { width: 8px; }
.lights-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.lights-empty {
  padding: 16px 4px;
  font-style: italic;
}
.lights-empty[hidden] { display: none; }

.lights-room {
  margin-top: 14px;
}
.lights-room:first-child { margin-top: 4px; }
.lights-room-name {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 0 4px 6px;
}

.lights-device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lights-device {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto auto;
  grid-template-areas:
    "icon  name    toggle"
    "icon  dim     dim";
  column-gap: 10px;
  row-gap: 6px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 160ms ease, background 160ms ease;
}
.lights-device.on { border-color: rgba(240, 196, 25, 0.45); background: rgba(240, 196, 25, 0.06); }
.lights-device.unreachable { opacity: 0.55; }
.lights-device.no-dim {
  grid-template-areas:
    "icon  name    toggle"
    "icon  sub     sub";
}

.lights-device-icon {
  grid-area: icon;
  font-size: 22px;
  line-height: 1;
  text-align: center;
  user-select: none;
  filter: grayscale(1) brightness(0.7);
  transition: filter 160ms ease;
}
.lights-device.on .lights-device-icon { filter: none; }

.lights-device-name {
  grid-area: name;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.lights-device-sub {
  grid-area: sub;
  font-size: 11px;
  color: var(--muted);
}

.lights-device-dim {
  grid-area: dim;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 10px;
}
.lights-device-level {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: transparent;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  --fill: 0%;
  padding: 6px 0;
  touch-action: none;
}
.lights-device-level::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--warn) 0%,
    var(--warn) var(--fill),
    var(--bg) var(--fill),
    var(--bg) 100%
  );
}
.lights-device-level::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid var(--panel);
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.lights-device-level::-moz-range-track { height: 6px; background: var(--bg); border-radius: 3px; }
.lights-device-level::-moz-range-progress { height: 6px; background: var(--warn); border-radius: 3px; }
.lights-device-level::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--warn); border: 2px solid var(--panel); cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.lights-device-level:disabled { opacity: 0.4; cursor: not-allowed; }
.lights-device-level-value {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 3.4ch;
  text-align: right;
  color: var(--muted);
}

/* On-off switch — CSS-only toggle built on a hidden checkbox. */
.lights-toggle {
  grid-area: toggle;
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}
.lights-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.lights-toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 160ms ease;
}
.lights-toggle .slider::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--text);
  border-radius: 50%;
  transition: transform 160ms ease, background 160ms ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.lights-toggle input:checked + .slider { background: var(--accent); }
.lights-toggle input:checked + .slider::before { transform: translateX(20px); background: white; }
.lights-toggle input:disabled + .slider { cursor: not-allowed; opacity: 0.45; }

/* --- Rohlík panel (mcp.rohlik.cz bridge) --- */

.rohlik-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}
.rohlik-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(235, 92, 30, 0.08), transparent);
}
.rohlik-summary-count, .rohlik-summary-total {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rohlik-summary-total { text-align: right; }
.rohlik-summary-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.rohlik-summary-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.rohlik-items {
  list-style: none;
  margin: 0;
  padding: 8px 14px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
}
.rohlik-items::-webkit-scrollbar { width: 8px; }
.rohlik-items::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
/* UA `[hidden] { display:none }` has lower specificity than the class
   rule above, so hiding one of the two lists via `.hidden = true` did
   nothing — both were visible. Force it. */
.rohlik-items[hidden] { display: none; }

.rohlik-empty {
  padding: 16px 18px;
  font-style: italic;
}
.rohlik-empty[hidden] { display: none; }

.rohlik-item {
  display: grid;
  /* Two-column grid: image + main (name/sub stacked) with a single
     action cell spanning both rows on the right. The action cell holds
     either the quantity controls stack (cart / fav-in-cart) or a single
     "Přidej" button (fav not in cart). Fixed action column width keeps
     rows visually aligned. */
  grid-template-columns: 44px 1fr auto;
  grid-template-areas:
    "img  name    action"
    "img  sub     action";
  column-gap: 10px;
  row-gap: 2px;
  align-items: center;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.rohlik-item-img {
  grid-area: img;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
}
.rohlik-item-img.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--muted);
}
.rohlik-item-name {
  grid-area: name;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  /* Two-line clamp with ellipsis on overflow — long Rohlík names like
     "Kitchin Passata di pomodoro – loupaná pasírovaná rajčata" need two
     lines to be readable without truncating key words. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  min-width: 0;
}
.rohlik-item-sub {
  grid-area: sub;
  font-size: 11px;
  color: var(--muted);
}
/* Sale styling inside the sub label — crossed-out original followed by the
   current (discounted) price in the Rohlík accent color. */
.rohlik-item-sub .rohlik-strike {
  text-decoration: line-through;
  color: var(--muted);
  opacity: 0.7;
  margin-right: 4px;
}
.rohlik-item-sub .rohlik-sale {
  color: #eb5c1e;
  font-weight: 600;
}
/* Right-hand action column — spans both rows of the item grid. Holds the
   qty controls (cart / fav-in-cart) OR the Add button (fav not in cart),
   with a price+delete row underneath when applicable. */
.rohlik-item-action {
  grid-area: action;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 104px;
  justify-self: end;
}

.rohlik-qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}
.rohlik-qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  transition: background 120ms ease, color 120ms ease;
}
.rohlik-qty-btn:hover { background: rgba(235, 92, 30, 0.18); color: #eb5c1e; }
.rohlik-qty-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.rohlik-qty-val {
  min-width: 24px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #eb5c1e;
  user-select: none;
}

.rohlik-item-footer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.rohlik-item-price {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rohlik-item-del {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  transition: background 120ms ease, color 120ms ease;
}
.rohlik-item-del:hover { background: rgba(255, 80, 80, 0.15); color: #ff6a6a; }
.rohlik-item-del:disabled { opacity: 0.35; cursor: not-allowed; }

.rohlik-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  background: rgba(235, 92, 30, 0.14);
  color: #eb5c1e;
  border: 1px solid rgba(235, 92, 30, 0.35);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background 120ms ease, border-color 120ms ease;
}
.rohlik-add-btn:hover { background: rgba(235, 92, 30, 0.25); border-color: #eb5c1e; }
.rohlik-add-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.rohlik-item.out-of-stock { opacity: 0.55; }
.rohlik-item.pending { outline: 1px solid rgba(235, 92, 30, 0.45); }

/* --- Inner sub-tabs (Košík / Oblíbené) --- */
.rohlik-sub-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px 0;
  border-bottom: 1px solid var(--border);
}
.rohlik-sub-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  appearance: none;
  -webkit-appearance: none;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.rohlik-sub-tab:hover { color: var(--text); background: var(--panel-2); }
.rohlik-sub-tab.active {
  color: #eb5c1e;
  border-bottom-color: #eb5c1e;
}

/* --- Past-order header (Minulá tab) --- */
.rohlik-order-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "meta   total"
    "repeat repeat";
  gap: 4px 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(235, 92, 30, 0.05), transparent);
}
.rohlik-order-header[hidden] { display: none; }
.rohlik-order-meta {
  grid-area: meta;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.rohlik-order-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.rohlik-order-state {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.rohlik-order-total {
  grid-area: total;
  align-self: start;
  font-size: 16px;
  font-weight: 600;
  color: #eb5c1e;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rohlik-repeat-btn {
  grid-area: repeat;
  margin-top: 6px;
  height: 34px;
  background: #eb5c1e;
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background 120ms ease;
}
.rohlik-repeat-btn:hover:not(:disabled) { background: #c94d18; }
.rohlik-repeat-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Active conversation title in the center panel header. */
.panel.conversation .panel-header h2 {
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1 1 auto;
}

/* ────────────── Login page (and OAuth error fallback rendered by auth.ts) ─────────── */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  background: radial-gradient(circle at top, #1a1f2b 0%, var(--bg) 65%);
}

.auth-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  text-align: center;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}
.auth-brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.auth-card h1 { margin-top: 0; }

.auth-lede {
  margin: 6px 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: white;
  color: #1f2330;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  border: 1px solid var(--border);
  transition: transform 90ms ease, box-shadow 120ms ease;
}
.auth-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,0.35); }
.auth-btn:active { transform: translateY(0); }

.auth-hint {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 12px;
}
