:root {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-raised: #1e222d;
  --text: #eceef3;
  --text-dim: #8b8fa3;
  --accent: #7c9aff;
  --accent-strong: #5b7cf5;
  --bubble-user: #2c3a63;
  --bubble-assistant: #1b1e29;
  --border: #272b38;
  --danger: #ff6b6b;
  --success: #5ecf87;
  --system-color: #e0a458;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f2f3f7;
    --bg-elevated: #ffffff;
    --bg-raised: #ffffff;
    --text: #14161c;
    --text-dim: #6b6f80;
    --accent: #3a5fd9;
    --accent-strong: #2f4fc0;
    --bubble-user: #dfe6ff;
    --bubble-assistant: #ffffff;
    --border: #e1e3ea;
    --success: #1f8a4d;
    --system-color: #a86a1a;
    --shadow: 0 8px 24px rgba(20, 22, 30, 0.08);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-raised: #1e222d;
  --text: #eceef3;
  --text-dim: #8b8fa3;
  --accent: #7c9aff;
  --bubble-user: #2c3a63;
  --bubble-assistant: #1b1e29;
  --border: #272b38;
  --success: #5ecf87;
  --system-color: #e0a458;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f2f3f7;
  --bg-elevated: #ffffff;
  --bg-raised: #ffffff;
  --text: #14161c;
  --text-dim: #6b6f80;
  --accent: #3a5fd9;
  --bubble-user: #dfe6ff;
  --bubble-assistant: #ffffff;
  --border: #e1e3ea;
  --success: #1f8a4d;
  --system-color: #a86a1a;
  --shadow: 0 8px 24px rgba(20, 22, 30, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Thin themed scrollbars (Chromium/WebView2 - the desktop tray popup and
   any Chrome/Edge tab both use these; mobile browsers just ignore them and
   fall back to their own transient overlay scrollbar). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-app-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.topbar-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.topbar-heading h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Was 52vw - with 2 more icon buttons added to .topbar-actions since this
     was tuned, that left too little guaranteed room and forced the action
     row to wrap (the settings gear ending up stranded on its own line). */
  max-width: 34vw;
}

.topbar-subtitle {
  background: none;
  border: 0;
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 0;
  margin-top: 1px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  row-gap: 6px;
  flex-shrink: 0;
  /* flex-wrap stays as a last-resort safety net for truly narrow widths, but
     the max-width cap that was here forced a wrap even when there was
     actually enough room, stranding the settings gear on its own line - the
     h1's own max-width (above) is what should be doing the space-making now. */
  flex-wrap: wrap;
}

.usage-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}
.usage-badge.hidden { display: none; }

.usage-badge-ring circle {
  fill: none;
  stroke-width: 3;
}
.usage-badge.ok .usage-badge-ring circle { stroke: #4ade80; }
.usage-badge.warn .usage-badge-ring circle { stroke: #fbbf24; }
.usage-badge.limited .usage-badge-ring circle { stroke: var(--danger); }

/* #voiceModeBadge has no ring (plain text badge) - color the text itself. */
#voiceModeBadge.ok { color: #4ade80; }
#voiceModeBadge.warn { color: #fbbf24; }

/* #sessionSizeBadge is also a plain text badge, no ring. */
#sessionSizeBadge.warn { color: #fbbf24; }
#sessionSizeBadge.limited { color: var(--danger); }

/* Context gauge: a 2-row dot grid instead of the quota badge's ring, on
   purpose - the two badges sit right next to each other in the topbar and
   were too easy to mistake for the same thing at a glance when both used a
   ring. Dots fill left-to-right, row by row, like a docker-compose-style
   progress indicator. */
.context-gauge-dots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 2px;
  width: 10px;
  height: 22px;
}
.cg-dot {
  width: 4px;
  height: 3px;
  border-radius: 1px;
  background: var(--border);
}
.context-gauge.ok .cg-dot.lit { background: #4ade80; }
.context-gauge.warn .cg-dot.lit { background: #fbbf24; }
.context-gauge.limited .cg-dot.lit { background: var(--danger); }

.icon-btn {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  /* 44px matches the Apple HIG / Material touch-target minimum - the icon
     glyph itself stays visually compact via font-size, centered in the
     larger box via flex, so this doesn't blow up the visible icon size. */
  width: 44px;
  height: 44px;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease;
}

.icon-btn:active { transform: scale(0.92); }
.icon-btn.small { width: 40px; height: 40px; font-size: 14px; }

/* Needs to show a short model name, not a single glyph - overrides the
   fixed square sizing above with a compact pill instead. */
.model-cycle-btn {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* Same opacity-dim convention as .composer button:disabled below - not a
   hue-only cue, so it still reads as "off" without relying on color vision. */
.icon-btn.muted { opacity: 0.45; }
#micBtn.hidden { display: none; }

/* Live dictation feedback - a filled red pulse rather than just a color
   swap, so "still listening" reads at a glance without staring at the icon. */
#micBtn.recording {
  background: #e5484d;
  color: #fff;
  border-color: #e5484d;
  animation: mic-pulse 1.4s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); }
}

/* ---- Views ---- */
.view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view.hidden { display: none; }
.view { position: relative; }

.scroll-bottom-btn {
  /* Anchored to .composer-area (its containing block - position:sticky
     still establishes one for absolute descendants) rather than a fixed
     pixel offset from the viewport: the composer's real height varies
     (attach previews, thinking bar, safe-area-inset-bottom on notched
     phones), and a hardcoded number drifts out of sync with it - this
     stays glued to the composer's actual top edge on every device. */
  position: absolute;
  right: 16px;
  bottom: 100%;
  margin-bottom: 10px;
  background: var(--accent-strong);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 17px;
  box-shadow: var(--shadow);
  z-index: 6;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.scroll-bottom-btn:active { transform: scale(0.9); }
.scroll-bottom-btn.hidden { display: none; }

/* ---- Notification watch toast (Tasker-fed SMS/WhatsApp/mail alerts) ----
   Only the fallback/expanded-text path (see showNotifyToast in app.js) -
   the primary path is a real OS notification, a separate popup that can't
   cover the conversation. Small and corner-anchored on purpose: a first
   version spanned the full width at the top of the screen and, on the
   narrow tray popup window, hid most of the visible chat. */
.notify-toast {
  position: fixed;
  right: 12px;
  bottom: 84px;
  z-index: 20;
  width: 260px;
  max-width: calc(100vw - 24px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.notify-toast.hidden { display: none; }

.notify-toast-label {
  font-size: 12.5px;
  font-weight: 600;
}

.notify-toast-body {
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-height: 30vh;
  overflow-y: auto;
}
.notify-toast-body.hidden { display: none; }

.notify-toast-actions {
  display: flex;
  gap: 6px;
}

.notify-toast-actions button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm, 8px);
  padding: 7px 10px;
  font-size: 13px;
}
.notify-toast-actions button:active { transform: scale(0.96); }
.notify-toast-actions .notify-toast-dismiss { flex: 0 0 auto; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 6px;
}

.section-header h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 0;
  font-weight: 600;
}

.section-header-actions { display: flex; gap: 6px; }

/* ---- Conversation feed ---- */
.feed {
  flex: 1;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feed-status {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
}
.feed-status.hidden { display: none; }

.msg {
  max-width: 86%;
  border-radius: var(--radius-md);
  padding: 10px 13px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Shown the instant a message is submitted, before the transcript file has
   actually picked it up (see renderOptimisticUserMessage in app.js) - most
   noticeable for a message sent mid-turn, which can sit unprocessed for a
   while. Faded until the confirmed version replaces it. */
.msg.pending {
  opacity: 0.55;
}

.msg .role {
  display: block;
  font-size: 10.5px;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.msg.streaming .stream-text::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  animation: blink 1s step-start infinite;
  color: var(--accent);
}

@keyframes blink { 50% { opacity: 0; } }

.msg a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 50%, transparent);
  word-break: break-all;
}

.msg code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: rgba(127, 127, 127, 0.16);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}

.msg .md-pre {
  display: block;
  overflow-x: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 6px 0;
}

.msg .md-pre code {
  background: none;
  padding: 0;
  font-size: 12.5px;
  white-space: pre;
}

.msg .md-h {
  display: inline-block;
  font-weight: 700;
  font-size: 1.05em;
}

.chip {
  align-self: flex-start;
  max-width: 86%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chip.error { border-color: var(--danger); color: var(--danger); }

.chip.system {
  font-family: inherit;
  font-style: italic;
  border-style: solid;
  opacity: 0.7;
}

.tool-chip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-style: solid;
  border-left-width: 3px;
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--bg-elevated));
}

.tool-chip.success {
  border-left-color: var(--success);
  background: color-mix(in srgb, var(--success) 7%, var(--bg-elevated));
}

.tool-chip.error {
  border-left-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 7%, var(--bg-elevated));
  /* .chip.error (above) also tints the whole chip's text red - here the
     title alone carries the color instead, so reset that back to the
     normal ink color for the result text underneath. */
  color: var(--text-dim);
}

.tool-chip.system {
  border-left-color: var(--system-color);
  background: color-mix(in srgb, var(--system-color) 7%, var(--bg-elevated));
  font-style: normal;
  opacity: 1;
}

.tool-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.tool-chip.success .tool-title { color: var(--success); }
.tool-chip.error .tool-title { color: var(--danger); }
.tool-chip.system .tool-title { color: var(--system-color); }

.tool-cmd {
  display: block;
  color: var(--text);
}

.tool-cmd::before {
  content: '→ ';
  color: var(--text-dim);
}

.tool-cmd.no-arrow::before {
  content: none;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.ask-user-card {
  align-self: flex-start;
  max-width: 92%;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise 0.18s ease;
}

.ask-user-header {
  font-size: 10.5px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.ask-user-question {
  font-size: 14.5px;
  line-height: 1.45;
}

.ask-user-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ask-user-option {
  font-size: 13.5px;
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: inherit;
  cursor: pointer;
}

.ask-user-option:disabled { opacity: 0.5; cursor: default; }
.ask-user-option.selected { border-color: var(--accent); color: var(--accent); }

.ask-user-back {
  background: transparent;
  border-style: dashed;
  color: var(--text-dim);
}

.ask-user-breadcrumb {
  font-size: 11px;
  color: var(--text-dim);
  margin: -4px 0 0;
}
.ask-user-breadcrumb.hidden { display: none; }

.ask-user-confirm {
  align-self: flex-start;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
}

.ask-user-answer {
  font-size: 12.5px;
  color: var(--text-dim);
  font-style: italic;
}

.ask-user-card.answered { border-color: var(--border); }

.ask-user-freetext {
  display: flex;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 2px;
}

.ask-user-freetext input {
  flex: 1;
  min-width: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
}

.ask-user-freetext button {
  background: var(--accent-strong);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  width: 32px;
  flex-shrink: 0;
  font-size: 13px;
}

.ask-user-card.answered .ask-user-freetext { display: none; }

/* ---- Composer ---- */
/* Sticky on the wrapper (not .composer itself) so thinkingBar right above
   the input row is pinned to the same spot, always visible regardless of
   feed scroll position or content - it used to live as a normal child of
   the scrolling feed, which pushed it out of view the moment anything else
   got appended after it mid-turn (a tool call, streamed text...). */
.composer-area {
  position: sticky;
  bottom: 0;
  background: var(--bg-elevated);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.thinking-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-style: italic;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.thinking-bar.hidden { display: none; }

.thinking-bar::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 13px;
  font-size: 14.5px;
  font-family: inherit;
}

.composer textarea:focus { outline: none; border-color: var(--accent); }

#composerSend {
  background: var(--accent-strong);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 16px;
  flex-shrink: 0;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

#composerSend:active { transform: scale(0.9); }
#composerSend.hidden { display: none; }
.composer button:disabled { opacity: 0.45; }

#composerStop {
  background: var(--danger);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 15px;
  flex-shrink: 0;
  transition: transform 0.1s ease;
}
#composerStop:active { transform: scale(0.9); }
#composerStop.hidden { display: none; }

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
  background: var(--bg-elevated);
}
.attach-preview.hidden { display: none; }

.attach-preview .attach-thumb-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
}

.attach-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
}

.attach-preview .attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--bg-elevated);
  font-size: 11px;
  line-height: 1;
}

.attach-preview .attach-file-chip {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px;
}

.attach-preview .attach-file-icon { font-size: 20px; }

.attach-preview .attach-file-name {
  font-size: 9px;
  color: var(--text-dim);
  text-align: center;
  max-width: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border: 3px dashed var(--accent);
  border-radius: var(--radius-md);
  margin: 6px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  pointer-events: none;
}
.drop-overlay.hidden { display: none; }

.msg-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin-top: 2px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  max-width: 100%;
}
.msg-file-chip .attach-file-icon { font-size: 16px; }
.msg-file-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-image {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
  margin-top: 2px;
}

/* ---- Sandbox gallery ---- */
.sandbox-grid {
  padding: 4px 14px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
}

.tool-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  text-align: left;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 92px;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}

.tool-card:active { transform: scale(0.96); }

.tool-card .tool-icon {
  font-size: 20px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 9px;
}

.tool-card .tool-date { font-size: 11px; color: var(--text-dim); font-weight: 400; }

/* ---- Tool viewer overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.overlay.hidden { display: none; }

.overlay-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
}

#overlayFrame {
  flex: 1;
  border: 0;
  width: 100%;
}

/* ---- Tab bar ---- */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
}

.tab {
  flex: 1;
  background: none;
  border: 0;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 0 7px;
  font-size: 11px;
  font-weight: 500;
}

.tab-icon { font-size: 19px; }
.tab.active { color: var(--accent); }

/* ---- Bottom sheets ---- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
}
.sheet.hidden { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  position: relative;
  width: 100%;
  max-height: 75vh;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px auto 12px;
}

.sheet-panel h2 {
  font-size: 15px;
  margin: 0 0 12px;
}

.sheet-close {
  position: absolute;
  top: 10px;
  right: 14px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  min-height: 44px;
  box-sizing: border-box;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
}

.session-row.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-raised));
}

.session-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-row-date {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 2px;
  min-height: 44px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.settings-row:last-of-type { border-bottom: 0; }

.settings-row.action {
  width: 100%;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
  font-weight: 600;
  text-align: left;
}

.settings-row.hidden { display: none; }

.settings-row input[type="checkbox"] {
  width: 40px;
  height: 24px;
  accent-color: var(--accent-strong);
}

.settings-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  line-height: 1.4;
}
.settings-hint.hidden { display: none; }

.settings-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 22px 0 4px;
}

.settings-row-column {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.settings-text,
.settings-number {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
}

.settings-number { width: 90px; text-align: right; }
.settings-number.small { width: 70px; }

.settings-token-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.settings-token-row input {
  flex: 1;
  min-width: 0;
}

#tokenDisplay {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  font-family: monospace;
}

.settings-hotkey-btn {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  min-width: 140px;
}

.settings-hotkey-btn.recording {
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Notify-watch rules ---- */
.notify-rules-list { display: flex; flex-direction: column; }

.notify-rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.notify-rule-row-label { flex: 1; min-width: 0; }

.notify-rule-form {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 2px;
}

.notify-rule-form select { flex: 0 0 auto; }
.notify-rule-form input { flex: 1; min-width: 0; }

/* ---- Maison (HA/BambuBuddy) ---- */
.home-content { padding: 4px 16px 16px; }

.home-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.home-card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.home-card-empty { font-size: 13px; color: var(--text-dim); }

.home-printer-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.home-printer-row:last-child { border-bottom: 0; }
.home-printer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.home-printer-state { color: var(--text-dim); font-size: 12.5px; }
.home-printer-controls { display: flex; gap: 8px; margin-top: 8px; }
.home-printer-btn {
  flex: 1;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
}
.home-printer-btn:active { transform: scale(0.96); }
.home-printer-btn:disabled { opacity: 0.5; }

/* ---- Aperçu (glance dashboard, added 2026-08-15) ---- */
.glance-content { padding: 4px 16px 16px; }
.glance-presence-badge {
  display: inline-block;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.glance-presence-badge.glance-presence-home { border-color: var(--success); color: var(--success); }
.glance-printer-state.glance-state-error { color: var(--danger); font-weight: 600; }
.glance-printer-state.glance-state-active { color: var(--success); font-weight: 600; }
.glance-lowstock-row { padding: 3px 0; }

.filament-archived-toggle { padding: 8px 16px; border: 0; }
.filament-list { padding: 4px 16px 16px; }
.filament-empty { font-size: 13px; color: var(--text-dim); padding: 8px 0; }

.filament-row {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.filament-row.low-stock { border-color: #c0392b; }
.filament-row-header { display: flex; align-items: center; gap: 10px; }
.filament-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.filament-row-title { flex: 1; font-size: 14px; font-weight: 600; }
.filament-row-pct { font-size: 13px; color: var(--text-dim); }
.filament-row-pct.low { color: #e74c3c; font-weight: 600; }
.filament-row-detail { font-size: 12.5px; color: var(--text-dim); margin: 6px 0; }
.filament-row-controls { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.filament-threshold-input { width: 56px; }
.filament-row-controls .home-printer-btn { flex: none; padding: 6px 10px; }

.suivi-list { padding: 4px 16px 16px; }
.suivi-badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex-shrink: 0;
}
.suivi-badge-d { color: #2980b9; border-color: #2980b9; }
.suivi-badge-f { color: #27ae60; border-color: #27ae60; }
.suivi-badge-retard { color: #e74c3c; border-color: #e74c3c; }
.suivi-badge-attente { color: #e67e22; border-color: #e67e22; }
.suivi-statut-select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  padding: 6px 8px;
  font-size: 13px;
}

.suivi-filters { padding: 8px 16px 0; }
.suivi-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 14px;
  margin-bottom: 8px;
}
.suivi-filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.suivi-chip {
  background: var(--bg-raised);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.suivi-chip.active { background: var(--accent, #4a7dfc); color: #fff; border-color: transparent; }
.suivi-group-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 14px 4px 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Tri de notifications (#27) - réutilise .filament-row pour les cartes */
.notify-section { padding: 4px 16px 0; }
.notify-section h3 { font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 10px 4px 6px; text-transform: uppercase; letter-spacing: 0.02em; }
.notify-list { display: flex; flex-direction: column; gap: 8px; }
.notify-row-dim { opacity: 0.6; }
.notify-correct-label { font-size: 12px; color: var(--text-dim); }
.notify-correct-select { padding: 4px 6px; font-size: 12.5px; }
.notify-spam-details { margin: 14px 16px 16px; font-size: 13px; }
.notify-spam-details summary { cursor: pointer; color: var(--text-dim); padding: 6px 0; }
.notify-spam-details .notify-list { padding-top: 8px; }

.suivi-new-panel { max-height: 92vh; overflow-y: auto; }
.suivi-form-subheader { margin-top: 14px; padding: 0 0 4px; }
.suivi-form-subheader h3 { font-size: 14px; margin: 0; }
.suivi-form-details { margin: 12px 0; font-size: 13px; }
.suivi-form-details summary { cursor: pointer; color: var(--text-dim); padding: 6px 0; }
.suivi-line-row {
  display: grid;
  grid-template-columns: 1fr 1fr 70px 70px 50px 28px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.suivi-line-row input { min-width: 0; }
#suiviLaserLines .suivi-line-row { grid-template-columns: 1fr 70px 50px 28px; }
.suivi-line-remove { flex: none; }
.suivi-preview-box {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 14px;
}
.settings-row.action.primary { background: var(--accent, #4a7dfc); color: #fff; border-color: transparent; }

.ha-control-panel { max-height: 88vh; }
.ha-control-search {
  margin: 4px 0 10px;
  width: 100%;
  box-sizing: border-box;
}
.ha-control-list { overflow-y: auto; max-height: 65vh; padding-bottom: 8px; }
.ha-control-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  overflow: hidden;
}
.ha-control-group summary {
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-raised);
}
.ha-control-group summary::-webkit-details-marker { display: none; }
.ha-control-group summary .ha-group-count { color: var(--text-dim); font-weight: 400; font-size: 12px; }
.ha-control-group-body { padding: 4px 12px 8px; }
.ha-entity-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.ha-entity-row:last-child { border-bottom: 0; }
.ha-entity-name { flex: 1; min-width: 120px; font-size: 13px; }
.ha-entity-state { font-size: 12px; color: var(--text-dim); }
.ha-entity-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.ha-entity-controls .home-printer-btn { flex: none; padding: 5px 9px; font-size: 12px; }
.ha-entity-controls input[type="number"] { width: 56px; }
.ha-toggle-btn.on { background: var(--accent, #4a9eff); color: #fff; border-color: transparent; }
.ha-readonly-row { padding: 5px 0; font-size: 12.5px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
.ha-readonly-row:last-child { border-bottom: 0; }
.ha-readonly-row b { color: var(--text); font-weight: 500; }

/* ---- TV ---- */
.tv-section { padding: 0 4px 16px; }
.tv-section.hidden { display: none; }

.tv-list { padding: 4px 12px; }

.tv-pin-form {
  display: flex;
  gap: 10px;
  padding: 0 16px 14px;
}

.tv-pin-form input {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 22px;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 10px;
}

.tv-pin-form button {
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent-strong);
  color: #fff;
  font-weight: 600;
  padding: 0 18px;
}

.remote-row {
  display: flex;
  gap: 10px;
  padding: 6px 16px;
  justify-content: center;
}

.remote-row.power-row { padding-top: 10px; }

.remote-btn {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.remote-btn:active { transform: scale(0.92); }

.remote-btn.wide {
  border-radius: var(--radius-md);
  width: auto;
  flex: 1;
  height: 48px;
  font-size: 14px;
  font-weight: 600;
}

.remote-btn.primary {
  background: var(--accent-strong);
  color: #fff;
  font-weight: 700;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 60px);
  gap: 8px;
  justify-content: center;
  padding: 10px 16px;
}
