/* ============================================================
 * Agentic Chat — Styles
 * ============================================================ */

/* --- Dark theme (default) --- */
:root,
[data-theme="dark"] {
  --bg-primary: #111;
  --bg-secondary: #1a1a1a;
  --bg-blackbox: #0d0d0d;
  --bg-console: #222;
  --text-primary: #eee;
  --text-muted: #aaa;
  --text-dim: #666;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --danger: #ef4444;
  --success: #4ade80;
  --border: #444;
  --border-box: #333;
  --disabled-bg: #555;
  --disabled-text: #999;
  --shadow: #000;
  --modal-bg: rgba(0, 0, 0, 0.53);
  --msg-user-bg: #1e3a5f;
  --msg-assistant-bg: #1a2e1a;
  --snippet-tag-bg: rgba(56, 189, 248, 0.15);
  --snippet-tag-border: rgba(56, 189, 248, 0.25);
  --template-hover-bg: rgba(56, 189, 248, 0.12);
  --template-active-bg: rgba(56, 189, 248, 0.22);
  --apikey-modal-bg: #fff;
  --apikey-modal-text: #000;
  --kbd-shadow: rgba(0, 0, 0, 0.3);
}

/* --- Light theme --- */
[data-theme="light"] {
  --bg-primary: #f5f5f5;
  --bg-secondary: #ffffff;
  --bg-blackbox: #eaeaea;
  --bg-console: #f0f0f0;
  --text-primary: #1a1a1a;
  --text-muted: #555;
  --text-dim: #888;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --danger: #dc2626;
  --success: #16a34a;
  --border: #ccc;
  --border-box: #ddd;
  --disabled-bg: #d4d4d4;
  --disabled-text: #888;
  --shadow: rgba(0, 0, 0, 0.1);
  --modal-bg: rgba(0, 0, 0, 0.35);
  --msg-user-bg: #dbeafe;
  --msg-assistant-bg: #dcfce7;
  --snippet-tag-bg: rgba(2, 132, 199, 0.1);
  --snippet-tag-border: rgba(2, 132, 199, 0.25);
  --template-hover-bg: rgba(2, 132, 199, 0.08);
  --template-active-bg: rgba(2, 132, 199, 0.16);
  --apikey-modal-bg: #ffffff;
  --apikey-modal-text: #1a1a1a;
  --kbd-shadow: rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
  padding: 1rem 0;
  margin: 0;
}

/* ---- Toolbar ---- */
.toolbar {
  max-width: 700px;
  margin: 0 auto 1rem;
  display: flex;
  gap: 0.5rem;
}

.toolbar input {
  flex: 1;
  padding: 0.5rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.95rem;
}

/* ---- Buttons ---- */
button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 5px;
  background: var(--accent);
  color: #000;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s;
}

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

button:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-text);
  cursor: not-allowed;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-secondary {
  background: var(--disabled-bg);
  color: var(--text-primary);
}

/* ---- Blackbox (chat area) ---- */
#char-count {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 0.5rem;
  color: var(--text-dim);
  font-size: 0.75rem;
  text-align: right;
}

#last-prompt {
  max-width: 700px;
  margin: 0 auto 1rem;
  padding: 0.5rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

#blackbox {
  max-width: 700px;
  margin: 0 auto 2rem;
  background: var(--bg-blackbox);
  border: 2px solid var(--border-box);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 0 10px var(--shadow);
  position: relative;
}

#chat-output {
  margin-bottom: 1rem;
  white-space: pre-wrap;
}

#console-output {
  background: var(--bg-console);
  padding: 0.75rem;
  border-radius: 6px;
  font-family: monospace;
  min-height: 2.5rem;
}

#token-usage {
  color: #888;
  font-size: 0.8rem;
  margin-top: 0.5rem;
  text-align: right;
}

pre {
  background: var(--bg-secondary);
  padding: 0.75rem;
  border-radius: 6px;
  overflow: auto;
}

/* ---- API Key Modal ---- */
#apikey-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#apikey-modal-content {
  background: var(--apikey-modal-bg);
  color: var(--apikey-modal-text);
  padding: 2rem;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  text-align: center;
}

#user-api-key {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.5rem;
}

/* ---- Accessibility ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Conversation History Panel ---- */
#history-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: right 0.25s ease;
}

#history-panel.open {
  right: 0;
}

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
  flex-shrink: 0;
}

#history-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-sm:hover {
  background: var(--border);
}

#history-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

.history-msg {
  margin-bottom: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.history-msg.user {
  background: var(--msg-user-bg);
  border-left: 3px solid var(--accent);
}

.history-msg.assistant {
  background: var(--msg-assistant-bg);
  border-left: 3px solid var(--success);
}

.history-msg .msg-role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.history-msg pre {
  margin: 0.3rem 0 0;
  padding: 0.5rem;
  font-size: 0.82rem;
  background: var(--bg-blackbox);
  border-radius: 4px;
  overflow-x: auto;
}

.history-msg .msg-text {
  white-space: pre-wrap;
}

.history-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
}

/* Overlay behind history panel on mobile */
#history-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
  display: none;
}

#history-overlay.visible {
  display: block;
}

/* ---- Prompt Templates Panel ---- */
#templates-panel {
  position: fixed;
  top: 0;
  left: -420px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 2px solid var(--border-box);
  box-shadow: 4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: left 0.25s ease;
}

#templates-panel.open {
  left: 0;
}

#templates-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
  flex-shrink: 0;
}

#templates-actions {
  display: flex;
  gap: 0.35rem;
}

#templates-search-wrap {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-box);
  flex-shrink: 0;
}

#templates-search {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

#templates-search:focus {
  border-color: var(--accent);
}

#templates-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.template-category {
  margin-bottom: 0.75rem;
}

.template-category-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border-box);
  margin-bottom: 0.4rem;
}

.template-card {
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 0.25rem;
}

.template-card:hover,
.template-card:focus {
  background: var(--template-hover-bg);
  outline: none;
}

.template-card:active {
  background: var(--template-active-bg);
}

.template-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.15rem;
  color: var(--text-primary);
}

.template-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.templates-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
}

#templates-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
  display: none;
}

#templates-overlay.visible {
  display: block;
}

/* ---- Code Action Buttons ---- */
#code-actions {
  display: flex;
  gap: 0.35rem;
  margin: 0.35rem 0 0.5rem;
  flex-wrap: wrap;
}

#code-actions .btn-sm {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
}

/* ---- Snippets Panel ---- */
#snippets-panel {
  position: fixed;
  top: 0;
  right: -460px;
  width: 440px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: right 0.25s ease;
}

#snippets-panel.open {
  right: 0;
}

#snippets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
  flex-shrink: 0;
}

#snippets-actions {
  display: flex;
  gap: 0.35rem;
}

#snippets-search-wrap {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-box);
  flex-shrink: 0;
}

#snippets-search {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
}

#snippets-search:focus {
  border-color: var(--accent);
}

#snippets-count {
  padding: 0.25rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

#snippets-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.snippet-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-box);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.snippet-card:hover {
  border-color: var(--accent);
}

.snippet-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.snippet-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: default;
}

.snippet-time {
  font-size: 0.7rem;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.snippet-tags {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.snippet-tag {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: var(--snippet-tag-bg);
  color: var(--accent);
  border: 1px solid var(--snippet-tag-border);
}

.snippet-code-preview {
  font-size: 0.76rem;
  padding: 0.4rem;
  margin: 0.25rem 0;
  background: var(--bg-blackbox);
  border-radius: 4px;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.3;
  max-height: 4.5rem;
  overflow-y: hidden;
}

.snippet-card-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.3rem;
  flex-wrap: wrap;
}

.snippet-card-actions .btn-sm {
  font-size: 0.72rem;
  padding: 0.15rem 0.4rem;
}

.snippet-rename-input {
  width: 100%;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
  border: 1px solid var(--accent);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  outline: none;
}

.btn-danger-sm {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger-sm:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* ---- Message Search ---- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
}

.search-bar input {
  flex: 1;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.search-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 50px;
  text-align: center;
}

.search-nav {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.search-nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.search-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

mark.search-highlight {
  background: rgba(250, 204, 21, 0.35);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

mark.search-highlight.search-current {
  background: rgba(250, 204, 21, 0.75);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Theme Toggle ---- */
#theme-btn {
  font-size: 1rem;
  min-width: 2.2rem;
  padding: 0.5rem 0.6rem;
  transition: background 0.15s, transform 0.2s;
}

#theme-btn:hover {
  transform: scale(1.08);
}

/* Smooth color transitions when switching themes */
body,
#blackbox,
#console-output,
.toolbar input,
pre,
.history-msg,
.snippet-card,
.template-card,
#shortcuts-modal-content,
#snippet-save-content,
#apikey-modal-content,
button,
.btn-sm,
kbd {
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.snippets-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 1rem;
  font-style: italic;
  white-space: pre-line;
  line-height: 1.6;
}

#snippets-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
  display: none;
}

#snippets-overlay.visible {
  display: block;
}

/* ---- Save Snippet Dialog ---- */
#snippet-save-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#snippet-save-content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 440px;
  border: 1px solid var(--border-box);
}

#snippet-save-content label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
  color: var(--text-muted);
}

.label-hint {
  font-weight: 400;
  color: var(--text-dim);
}

#snippet-save-content input[type="text"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

#snippet-save-content input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}

#snippet-code-preview {
  font-family: monospace;
  font-size: 0.76rem;
  padding: 0.5rem;
  margin: 0.75rem 0;
  background: var(--bg-blackbox);
  border-radius: 4px;
  border: 1px solid var(--border-box);
  white-space: pre;
  overflow-x: auto;
  max-height: 6rem;
  overflow-y: auto;
  line-height: 1.3;
}

#snippet-modal-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

#snippet-modal-buttons button {
  padding: 0.4rem 1rem;
  font-size: 0.88rem;
}

/* ---- Keyboard Shortcuts Modal ---- */
#shortcuts-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

#shortcuts-modal.visible {
  display: flex;
}

#shortcuts-modal-content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0;
  border-radius: 10px;
  width: 90%;
  max-width: 420px;
  border: 1px solid var(--border-box);
  box-shadow: 0 8px 32px var(--shadow);
  overflow: hidden;
}

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

#shortcuts-list {
  padding: 0.75rem 1rem 1rem;
  max-height: 60vh;
  overflow-y: auto;
}

.shortcut-group {
  margin-bottom: 0.85rem;
}

.shortcut-group:last-child {
  margin-bottom: 0;
}

.shortcut-group-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border-box);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.85rem;
}

.shortcut-row span {
  color: var(--text-muted);
  font-size: 0.82rem;
}

kbd {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 1px 2px var(--kbd-shadow);
  min-width: 1.4rem;
  text-align: center;
  line-height: 1.4;
}

/* ---- Voice Input Button ---- */
#voice-btn {
  position: relative;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

#voice-btn.voice-recording {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
  animation: voice-pulse 1.5s ease-in-out infinite;
}

#voice-btn:disabled {
  opacity: 0.4;
}

@keyframes voice-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* ---- Sessions Panel ---- */
#sessions-panel {
  position: fixed;
  top: 0;
  right: -460px;
  width: 440px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: right 0.25s ease;
}

#sessions-panel.open {
  right: 0;
}

#sessions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
  flex-shrink: 0;
}

#sessions-actions {
  display: flex;
  gap: 0.35rem;
}

#sessions-toolbar {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-box);
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

.sessions-autosave-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: auto;
  user-select: none;
}

.sessions-autosave-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--accent);
}

#sessions-count {
  padding: 0.25rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

#sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.sessions-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 1rem;
  font-size: 0.88rem;
  white-space: pre-line;
  line-height: 1.6;
}

.session-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-box);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  transition: border-color 0.15s;
}

.session-card:hover {
  border-color: var(--accent);
}

.session-card.session-active {
  border-left: 3px solid var(--accent);
}

.session-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.session-name {
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.session-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.12);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.session-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

.session-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.session-card-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.session-rename-input {
  width: 100%;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  outline: none;
}

#sessions-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 49;
  display: none;
}

#sessions-overlay.visible {
  display: block;
}

/* ---- Session Save Dialog ---- */
#session-save-modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#session-save-content {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 1.5rem;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  border: 1px solid var(--border-box);
}

#session-save-content label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
  color: var(--text-muted);
}

#session-save-content input[type="text"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
}

#session-save-content input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}

#session-modal-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

#session-modal-buttons button {
  padding: 0.4rem 1rem;
  font-size: 0.88rem;
}

/* ---------- Bookmarks Panel ---------- */
.bookmarks-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 55;
}

.bookmarks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  flex-shrink: 0;
}

.bookmarks-header h3 {
  margin: 0;
  font-size: 1rem;
}

.bookmarks-header button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
}

.bookmarks-header button:hover {
  color: var(--text-primary);
}

.bookmarks-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem;
}

.bookmarks-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem 1rem;
  font-style: italic;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border-box);
}

.bookmark-item:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.05));
}

.bookmark-role {
  flex-shrink: 0;
  font-size: 1rem;
}

.bookmark-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.bookmark-time {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.bookmark-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

.bookmark-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.bookmark-indicator {
  cursor: pointer;
  font-size: 0.8rem;
  margin-left: 0.5rem;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.bookmark-indicator:hover {
  opacity: 1;
}

/* ---------- Slash Commands ---------- */
.slash-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-secondary, #1e1e2e);
    border: 1px solid var(--border-color, #444);
    border-radius: 8px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
    z-index: 100;
    margin-bottom: 4px;
}
.slash-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background 0.15s;
}
.slash-item:hover,
.slash-item-selected {
    background: var(--bg-hover, #2a2a3e);
}
.slash-item-icon { font-size: 1.2em; width: 24px; text-align: center; }
.slash-item-name { font-weight: 600; color: var(--text-primary, #e0e0e0); }
.slash-item-desc { color: var(--text-secondary, #aaa); font-size: 0.85em; margin-left: auto; }

/* Message Reactions */
.reaction-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; align-items: center; }
.reaction-badge { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; border-radius: 12px; font-size: 0.85em; cursor: pointer; border: 1px solid var(--border-color, #444); background: var(--msg-bg, rgba(255,255,255,0.05)); transition: background 0.15s, border-color 0.15s; }
.reaction-badge:hover { background: var(--hover-bg, rgba(255,255,255,0.1)); }
.reaction-badge.active { border-color: var(--accent-color, #3b82f6); background: rgba(59, 130, 246, 0.15); }
.reaction-add-btn { width: 24px; height: 24px; border-radius: 50%; border: 1px dashed var(--border-color, #444); background: transparent; color: var(--text-secondary, #888); cursor: pointer; font-size: 0.85em; display: flex; align-items: center; justify-content: center; transition: background 0.15s, color 0.15s; }
.reaction-add-btn:hover { background: var(--hover-bg, rgba(255,255,255,0.1)); color: var(--text-color, #eee); }
.emoji-picker { position: absolute; bottom: 100%; left: 0; display: flex; gap: 4px; padding: 6px 8px; background: var(--panel-bg, #1e1e2e); border: 1px solid var(--border-color, #444); border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 100; }
.emoji-option { background: none; border: none; font-size: 1.2em; cursor: pointer; padding: 4px; border-radius: 4px; transition: background 0.15s; }
.emoji-option:hover { background: var(--hover-bg, rgba(255,255,255,0.1)); }

/* Chat Statistics Dashboard */
.stats-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 999; }
.stats-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: var(--bg-secondary, #1e1e2e); color: var(--text-primary, #cdd6f4); border-radius: 12px; padding: 0; width: 480px; max-width: 90vw; max-height: 80vh; overflow-y: auto; z-index: 1000; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.stats-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-color, #313244); }
.stats-header h3 { margin: 0; font-size: 1.1em; }
.stats-close { background: none; border: none; color: var(--text-secondary, #a6adc8); font-size: 1.5em; cursor: pointer; padding: 0 4px; line-height: 1; }
.stats-close:hover { color: var(--text-primary, #cdd6f4); }
.stats-body { padding: 16px 20px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.stats-card { background: var(--bg-primary, #181825); border-radius: 8px; padding: 14px; text-align: center; border: 1px solid var(--border-color, #313244); }
.stats-card-value { font-size: 1.8em; font-weight: 700; color: var(--accent-color, #89b4fa); }
.stats-card-label { font-size: 0.8em; color: var(--text-secondary, #a6adc8); margin-top: 4px; }
.stats-section { margin-bottom: 16px; }
.stats-section h4 { margin: 0 0 10px 0; font-size: 0.95em; }
.stats-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border-color, #313244); font-size: 0.9em; }
.stats-longest { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 0.85em; }
.stats-longest-role { font-weight: 600; }
.stats-longest-len { color: var(--text-secondary, #a6adc8); }
.stats-longest-preview { font-size: 0.8em; color: var(--text-secondary, #a6adc8); font-style: italic; word-break: break-word; }
.stats-words { margin-top: 8px; }
.stats-word-row { display: flex; align-items: center; margin-bottom: 4px; gap: 8px; }
.stats-word-label { font-size: 0.85em; min-width: 80px; text-align: right; }
.stats-word-bar { background: var(--accent-color, #89b4fa); border-radius: 4px; padding: 2px 8px; font-size: 0.75em; color: var(--bg-primary, #181825); font-weight: 600; text-align: right; min-width: 24px; }
.stats-empty { color: var(--text-secondary, #a6adc8); font-style: italic; font-size: 0.85em; }

/* --- Persona / System Prompt Presets Panel --- */
#persona-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 49;
}
#persona-overlay.open { display: block; }

#persona-panel {
  position: fixed;
  top: 0;
  right: -460px;
  width: 440px;
  max-width: 92vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: right 0.25s ease;
}
#persona-panel.open { right: 0; }

#persona-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
  flex-shrink: 0;
}

#persona-actions { display: flex; gap: 0.35rem; }

#persona-active {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-box);
}

#persona-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
}

.persona-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-box);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.persona-card:hover { border-color: var(--accent); }
.persona-card.active { border-color: var(--accent); background: rgba(137,180,250,0.08); }

.persona-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}
.persona-card-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.3;
}

#persona-custom-section {
  padding: 0.75rem;
  border-top: 1px solid var(--border-box);
  flex-shrink: 0;
}
#persona-custom-section label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}
#persona-custom-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
  margin-bottom: 0.5rem;
}
#persona-custom-input:focus { border-color: var(--accent); }
#persona-custom-apply {
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

/* ---------- Model Selector ---------- */
#model-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1099;
}
#model-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg, #1e1e1e);
  border: 1px solid var(--border, #444);
  border-radius: 12px;
  padding: 1.25rem;
  z-index: 1100;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
#model-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 600;
  font-size: 1.05rem;
}
#model-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.model-option {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  text-align: left;
  border: 1px solid var(--border, #444);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.model-option:hover {
  background: rgba(255,255,255,0.08);
}
.model-active {
  background: rgba(99,102,241,0.2);
  border-color: #6366f1;
  font-weight: 600;
}
#model-btn #model-label {
  font-size: 0.85rem;
}

/* --- File Drop Zone --- */
.file-drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(56, 189, 248, 0.08);
  border: 3px dashed var(--accent);
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.file-drop-overlay.visible {
  display: flex;
}

.file-drop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.file-drop-icon {
  font-size: 2.5rem;
}

.file-drop-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
}

.file-drop-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---- Zen / Focus Mode ---- */
body.zen-mode h2 {
  display: none;
}

body.zen-mode .toolbar:first-of-type {
  display: none;
}

body.zen-mode .toolbar button:not(#send-btn):not(#cancel-btn):not(#zen-btn) {
  display: none;
}

body.zen-mode .toolbar {
  max-width: 900px;
}

body.zen-mode #blackbox {
  max-width: 900px;
  margin: 0 auto;
}

body.zen-mode #char-count,
body.zen-mode #last-prompt {
  display: none;
}

body.zen-mode #token-usage {
  display: none;
}

#zen-btn {
  position: relative;
}

#zen-btn.active {
  background: var(--accent);
  color: #000;
}

body.zen-mode .zen-indicator {
  display: block;
}

.zen-indicator {
  display: none;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.zen-indicator kbd {
  font-family: inherit;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1em 0.4em;
  font-size: 0.7rem;
}

/* ---- Scratchpad Panel ---- */
#scratchpad-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 59;
}
#scratchpad-overlay.open { display: block; }

#scratchpad-panel {
  position: fixed;
  top: 0;
  right: -500px;
  width: 480px;
  max-width: 95vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border-box);
  box-shadow: -4px 0 20px var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: right 0.25s ease;
}
#scratchpad-panel.open { right: 0; }

#scratchpad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-box);
  font-weight: 600;
}

#scratchpad-header .scratchpad-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#scratchpad-status {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 400;
}

#scratchpad-toolbar {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-box);
  flex-wrap: wrap;
}

#scratchpad-textarea {
  flex: 1;
  width: 100%;
  padding: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  line-height: 1.6;
}
#scratchpad-textarea::placeholder {
  color: var(--muted);
}

#scratchpad-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border-box);
  font-size: 0.75rem;
  color: var(--muted);
}

#scratchpad-wordcount {
  font-variant-numeric: tabular-nums;
}

/* ---------- Quick Reply Suggestions ---------- */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-box);
  animation: quickRepliesFadeIn 0.3s ease;
}

@keyframes quickRepliesFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.quick-reply-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid var(--border-box);
  border-radius: 20px;
  background: var(--bg-card, rgba(255, 255, 255, 0.05));
  color: var(--fg);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.quick-reply-chip:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.12));
  border-color: var(--accent, #60a5fa);
  transform: translateY(-1px);
}

.quick-reply-chip:active {
  transform: scale(0.97);
}

/* Light theme adjustments */
html.light .quick-reply-chip {
  background: rgba(0, 0, 0, 0.04);
}

html.light .quick-reply-chip:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* --- Response Time Badge --- */
.response-time-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  margin: 4px 0 0 0;
  font-size: 0.78rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #aaa;
  opacity: 0;
  transition: opacity 0.3s ease;
  user-select: none;
}
.response-time-badge.rt-visible {
  opacity: 1;
}
.rt-icon {
  font-size: 0.85rem;
}
.rt-fast {
  color: #4ade80;
}
.rt-medium {
  color: #facc15;
}
.rt-slow {
  color: #f87171;
}

/* Timing in history panel msg-role */
.msg-timing {
  font-size: 0.72rem;
  opacity: 0.7;
  margin-left: 6px;
}
.msg-timing .rt-fast { color: #4ade80; }
.msg-timing .rt-medium { color: #facc15; }
.msg-timing .rt-slow { color: #f87171; }

/* Light theme overrides */
html.light .response-time-badge {
  background: rgba(0, 0, 0, 0.05);
  color: #666;
}
html.light .rt-fast { color: #16a34a; }
html.light .rt-medium { color: #ca8a04; }
html.light .rt-slow { color: #dc2626; }

/* ---------- Conversation Fork ---------- */

.fork-btn {
  display: inline-block;
  padding: 2px 8px;
  margin-top: 6px;
  font-size: 0.75rem;
  background: transparent;
  color: #888;
  border: 1px solid rgba(136, 136, 136, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  opacity: 0;
}

.history-msg:hover .fork-btn {
  opacity: 1;
}

.fork-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.4);
}

.fork-btn:active {
  transform: scale(0.95);
}

/* Fork notification toast */
.fork-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e1b4b;
  color: #e0e7ff;
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.85rem;
  z-index: 10000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 420px;
}

.fork-notification.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.fork-notification-icon {
  font-size: 1.1rem;
}

/* Light theme */
html.light .fork-btn {
  color: #666;
  border-color: rgba(102, 102, 102, 0.3);
}

html.light .fork-btn:hover {
  background: rgba(99, 102, 241, 0.1);
  color: #4f46e5;
  border-color: rgba(99, 102, 241, 0.3);
}

html.light .fork-notification {
  background: #eef2ff;
  color: #312e81;
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* ---------- Cross-Tab Sync Banner ---------- */
.cross-tab-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}
.cross-tab-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.cross-tab-banner .btn-sm {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  cursor: pointer;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
}
.cross-tab-banner .btn-sm:hover {
  background: rgba(255,255,255,0.35);
}

/* ---------- Offline Banner ---------- */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fff;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  animation: slideDown 0.3s ease-out;
}
.offline-banner .btn-sm {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  cursor: pointer;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
}
.offline-banner .btn-sm:hover {
  background: rgba(255,255,255,0.35);
}

/* ---------- Global Session Search ---------- */
#global-search-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1099;
}
#global-search-overlay.visible { display: block; }

#global-search-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(680px, 92vw);
  max-height: 80vh;
  background: var(--bg-secondary, #1e1e2e);
  border: 1px solid var(--border, #444);
  border-radius: 12px;
  z-index: 1100;
  display: none;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}
#global-search-panel[style*="display: flex"],
#global-search-panel.open { display: flex; }

#global-search-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border, #444);
  font-weight: 600; font-size: 1rem;
}

#global-search-input-wrap {
  padding: 12px 18px 8px;
}
#global-search-input {
  width: 100%; box-sizing: border-box;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border, #555);
  background: var(--bg-primary, #11111b);
  color: var(--text, #cdd6f4);
  font-size: 0.95rem;
}
#global-search-input:focus {
  outline: none;
  border-color: var(--accent, #89b4fa);
  box-shadow: 0 0 0 2px rgba(137,180,250,0.2);
}
#global-search-filters {
  display: flex; gap: 14px; margin-top: 8px;
  font-size: 0.82rem; color: var(--text-muted, #a6adc8);
}
#global-search-filters label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

#global-search-status {
  padding: 4px 18px 2px;
  font-size: 0.82rem;
  color: var(--text-muted, #a6adc8);
  min-height: 22px;
}

#global-search-results {
  overflow-y: auto; flex: 1;
  padding: 0 18px 14px;
  max-height: 55vh;
}

.gs-result-group {
  margin-bottom: 14px;
}
.gs-result-session {
  font-weight: 600; font-size: 0.88rem;
  color: var(--accent, #89b4fa);
  margin-bottom: 6px;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.gs-result-session:hover { text-decoration: underline; }
.gs-result-session .gs-msg-count {
  font-weight: 400; font-size: 0.78rem;
  color: var(--text-muted, #a6adc8);
}

.gs-result-item {
  padding: 8px 12px; margin-bottom: 4px;
  border-radius: 6px;
  background: var(--bg-primary, #11111b);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1.5;
  transition: border-color 0.15s;
}
.gs-result-item:hover { border-color: var(--accent, #89b4fa); }
.gs-result-item .gs-role {
  font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.gs-result-item .gs-role.user { color: #a6e3a1; }
.gs-result-item .gs-role.assistant { color: #89b4fa; }
.gs-result-item mark {
  background: rgba(249, 226, 175, 0.35);
  color: inherit; border-radius: 2px;
  padding: 0 1px;
}
.gs-no-results {
  text-align: center; padding: 30px;
  color: var(--text-muted, #a6adc8);
  font-size: 0.9rem;
}

/* ── Cost Dashboard ─────────────────────────────────────────── */
.cost-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 5000; animation: fade-in .15s ease;
}
.cost-panel {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, 92vw); max-height: 85vh;
  overflow-y: auto;
  background: var(--bg-surface, #1e1e2e);
  border: 1px solid var(--border, #45475a);
  border-radius: 12px; padding: 20px;
  z-index: 5001; box-shadow: 0 8px 32px rgba(0,0,0,.4);
  animation: slide-up .2s ease;
}
.cost-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.cost-header h3 { margin: 0; font-size: 1.1rem; }
.cost-header div { display: flex; gap: 4px; }
.cost-summary {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; margin-bottom: 16px;
}
.cost-stat {
  text-align: center; padding: 10px 4px;
  background: var(--bg-code, #181825);
  border-radius: 8px;
}
.cost-stat-value { font-size: 1.15rem; font-weight: 700; color: var(--accent, #89b4fa); }
.cost-stat-label { font-size: .7rem; color: var(--text-muted, #a6adc8); margin-top: 2px; }
.cost-section { margin-bottom: 16px; }
.cost-section h4 { margin: 0 0 8px; font-size: .9rem; }

/* Daily chart */
.cost-chart {
  display: flex; align-items: flex-end; gap: 3px;
  height: 90px; padding: 4px 0;
  border-bottom: 1px solid var(--border, #45475a);
}
.cost-bar-col {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; height: 100%;
  justify-content: flex-end;
}
.cost-bar {
  width: 100%; min-width: 6px; border-radius: 3px 3px 0 0;
  background: var(--accent, #89b4fa); transition: height .3s ease;
}
.cost-bar-label {
  font-size: .55rem; color: var(--text-muted, #a6adc8);
  margin-top: 3px; white-space: nowrap;
}

/* Model table */
.cost-table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
}
.cost-table th {
  text-align: left; padding: 4px 6px; font-weight: 600;
  border-bottom: 1px solid var(--border, #45475a);
  color: var(--text-muted, #a6adc8); font-size: .7rem;
}
.cost-table td { padding: 4px 6px; }
.cost-table tr:hover { background: var(--bg-code, #181825); }
.cost-model-name { font-family: 'SF Mono', 'Fira Code', monospace; font-size: .75rem; }
.cost-amount { font-weight: 600; color: var(--accent, #89b4fa); }
.cost-empty { text-align: center; padding: 20px; color: var(--text-muted, #a6adc8); }

/* Budget bar */
.cost-budget-bar {
  position: relative; height: 22px; border-radius: 6px;
  background: var(--bg-code, #181825);
  margin-bottom: 14px; overflow: hidden;
}
.cost-budget-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, #a6e3a1, #f9e2af 60%, #f38ba8 100%);
  transition: width .3s ease;
}
.cost-budget-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600;
  color: var(--text, #cdd6f4); text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.cost-budget-warning {
  color: #f38ba8; font-weight: 600; font-size: .8rem;
  animation: pulse 1.5s ease infinite;
}
@keyframes pulse { 50% { opacity: .6; } }

/* ---------- Prompt Library ---------- */
#prompt-library-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1099;
}

#prompt-library-panel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(620px, 92vw);
  max-height: 80vh;
  background: var(--bg-secondary, #1e1e2e);
  border: 1px solid var(--border, #444);
  border-radius: 12px;
  z-index: 1100;
  display: none;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  overflow: hidden;
}
#prompt-library-panel[style*="display: flex"],
#prompt-library-panel:not([style*="display: none"]):not([style=""]) { display: flex; }

#prompt-library-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--border, #444);
  font-weight: 600; font-size: 1rem;
}
#prompt-library-actions { display: flex; gap: 6px; }

#prompt-library-search-wrap { padding: 12px 18px 4px; }
#prompt-library-search {
  width: 100%; box-sizing: border-box;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--border, #555);
  background: var(--bg-primary, #11111b);
  color: var(--text, #cdd6f4);
  font-size: 0.95rem;
}
#prompt-library-search:focus {
  outline: none;
  border-color: var(--accent, #89b4fa);
  box-shadow: 0 0 0 2px rgba(137,180,250,0.2);
}

#prompt-library-filters {
  display: flex; gap: 10px; padding: 4px 18px 8px;
}
#prompt-library-filters select {
  flex: 1; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border, #555);
  background: var(--bg-primary, #11111b);
  color: var(--text, #cdd6f4);
  font-size: 0.85rem;
}

#prompt-library-count {
  padding: 2px 18px 6px;
  font-size: 0.8rem;
  color: var(--text-muted, #a6adc8);
}

#prompt-library-list {
  overflow-y: auto; flex: 1;
  padding: 0 18px 14px;
  max-height: 50vh;
}

.prompt-library-item {
  padding: 12px 14px; margin-bottom: 8px;
  border-radius: 8px;
  background: var(--bg-primary, #11111b);
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.prompt-library-item:hover { border-color: var(--accent, #89b4fa); }

.prompt-library-item-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.prompt-library-item-name {
  font-weight: 600; font-size: 0.92rem;
  color: var(--text, #cdd6f4);
}
.prompt-library-item-folder {
  font-size: 0.75rem;
  color: var(--text-muted, #a6adc8);
  background: var(--bg-secondary, #1e1e2e);
  padding: 2px 8px; border-radius: 10px;
}
.prompt-library-item-preview {
  font-size: 0.82rem;
  color: var(--text-muted, #a6adc8);
  line-height: 1.4;
  margin-bottom: 6px;
}
.prompt-library-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted, #a6adc8);
  margin-bottom: 6px;
}
.prompt-library-item-actions {
  display: flex; gap: 6px;
}

.prompt-library-empty {
  text-align: center; padding: 30px;
  color: var(--text-muted, #a6adc8);
  font-size: 0.9rem;
}

/* Save/Edit Modal */
#prompt-library-save-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1200;
  display: none;
  align-items: center; justify-content: center;
}
#prompt-library-save-modal[style*="display: flex"],
#prompt-library-save-modal:not([style*="display: none"]):not([style=""]) {
  display: flex;
}
#prompt-library-save-content {
  background: var(--bg-secondary, #1e1e2e);
  border: 1px solid var(--border, #444);
  border-radius: 12px;
  padding: 24px;
  width: min(460px, 90vw);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
#prompt-library-save-content label {
  display: block; font-size: 0.82rem; font-weight: 600;
  margin: 10px 0 4px; color: var(--text-muted, #a6adc8);
}
#prompt-library-save-content input,
#prompt-library-save-content textarea {
  width: 100%; box-sizing: border-box;
  padding: 8px 12px; border-radius: 6px;
  border: 1px solid var(--border, #555);
  background: var(--bg-primary, #11111b);
  color: var(--text, #cdd6f4);
  font-size: 0.9rem;
  font-family: inherit;
}
#prompt-library-save-content textarea { resize: vertical; min-height: 80px; }
#prompt-library-modal-buttons {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 16px;
}

/* ---------- Message Editor ---------- */

.msg-edit-btn {
  display: inline-block;
  padding: 2px 8px;
  margin-top: 6px;
  margin-right: 4px;
  font-size: 0.75rem;
  background: transparent;
  color: #888;
  border: 1px solid rgba(136, 136, 136, 0.3);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  opacity: 0;
}

.history-msg:hover .msg-edit-btn {
  opacity: 1;
}

.msg-edit-btn:hover {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
  border-color: rgba(234, 179, 8, 0.4);
}

.msg-edit-btn:active {
  transform: scale(0.95);
}

/* Edit notification toast */
.msg-edit-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #422006;
  color: #fbbf24;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 10001;
  pointer-events: none;
}

.msg-edit-notification.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.msg-edit-notification-icon {
  font-size: 1.1rem;
}


/* ═══ Message Scheduler ═══ */
.scheduler-panel {
  position: fixed;
  top: 0; right: -400px;
  width: 380px; height: 100vh;
  background: var(--bg-primary, #fff);
  border-left: 1px solid var(--border, #e0e0e0);
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  font-family: inherit;
}
.scheduler-panel-visible { right: 0; }
.scheduler-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border, #e0e0e0);
}
.scheduler-header h3 { margin: 0; font-size: 1.1rem; }
.scheduler-close {
  background: none; border: none;
  font-size: 1.5rem; cursor: pointer;
  color: var(--text-secondary, #666);
}
.scheduler-body {
  flex: 1; overflow-y: auto;
  padding: 1rem 1.25rem;
}
.scheduler-form { margin-bottom: 1.25rem; }
.scheduler-textarea {
  width: 100%; padding: 0.6rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px; font-family: inherit;
  font-size: 0.9rem; resize: vertical;
  box-sizing: border-box;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #333);
}
.scheduler-time-row {
  display: flex; align-items: center;
  gap: 0.5rem; margin-top: 0.5rem;
  flex-wrap: wrap;
}
.scheduler-time-row label {
  font-size: 0.8rem; font-weight: 600;
  color: var(--text-secondary, #555);
  white-space: nowrap;
}
.scheduler-datetime {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px; font-size: 0.85rem;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #333);
}
.scheduler-quick-btns { display: flex; gap: 0.3rem; }
.scheduler-quick {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 12px; background: var(--bg-secondary, #f5f5f5);
  font-size: 0.75rem; cursor: pointer;
  transition: all 0.15s;
  color: var(--text-primary, #333);
}
.scheduler-quick:hover {
  border-color: #007aff; color: #007aff;
  background: rgba(0,122,255,0.05);
}
.scheduler-label-input {
  width: 100%; padding: 0.4rem 0.6rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px; font-size: 0.85rem;
  margin-top: 0.5rem; box-sizing: border-box;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #333);
}
.scheduler-submit {
  margin-top: 0.75rem; width: 100%;
  padding: 0.6rem; background: #007aff;
  color: #fff; border: none; border-radius: 8px;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer; transition: background 0.2s;
}
.scheduler-submit:hover { background: #0062cc; }
.scheduler-list { margin-bottom: 0.75rem; }
.scheduler-item {
  display: flex; flex-direction: column;
  gap: 0.25rem; padding: 0.75rem;
  border: 1px solid var(--border, #eee);
  border-radius: 8px; margin-bottom: 0.5rem;
  position: relative;
  background: var(--bg-primary, #fff);
}
.scheduler-item:hover { border-color: #007aff; }
.scheduler-item-time {
  display: flex; align-items: center;
  gap: 0.5rem; font-size: 0.8rem;
}
.scheduler-item-when {
  font-weight: 600;
  color: var(--text-primary, #333);
}
.scheduler-item-relative {
  color: #007aff; font-size: 0.75rem;
}
.scheduler-item-label {
  font-size: 0.75rem; color: var(--text-secondary, #888);
  font-style: italic;
}
.scheduler-item-text {
  font-size: 0.85rem;
  color: var(--text-secondary, #555);
  line-height: 1.3;
}
.scheduler-cancel-btn, .scheduler-remove-btn {
  position: absolute; top: 0.5rem; right: 0.5rem;
  background: none; border: none; cursor: pointer;
  font-size: 0.9rem; opacity: 0.4;
  color: var(--text-secondary, #666);
  transition: opacity 0.15s;
}
.scheduler-cancel-btn:hover, .scheduler-remove-btn:hover { opacity: 1; }
.scheduler-item-history { opacity: 0.7; }
.scheduler-status-sent { color: #34c759; font-size: 0.75rem; font-weight: 600; }
.scheduler-status-cancelled { color: #ff3b30; font-size: 0.75rem; font-weight: 600; }
.scheduler-empty {
  text-align: center; padding: 1.5rem;
  color: var(--text-secondary, #999);
  font-size: 0.85rem;
}
.scheduler-history-toggle {
  display: flex; gap: 0.5rem;
  justify-content: center;
  margin-top: 0.5rem;
}
.scheduler-history-btn, .scheduler-clear-btn {
  background: none; border: none;
  color: var(--text-secondary, #888);
  font-size: 0.8rem; cursor: pointer;
  text-decoration: underline;
}
.scheduler-history-btn:hover, .scheduler-clear-btn:hover { color: #007aff; }
.scheduler-toggle-btn {
  position: relative; background: none;
  border: none; font-size: 1.3rem; cursor: pointer;
  padding: 0.4rem; border-radius: 6px;
  color: var(--text-primary, #333);
  transition: background 0.15s;
}
.scheduler-toggle-btn:hover { background: var(--bg-secondary, #f0f0f0); }
.scheduler-badge {
  position: absolute; top: -2px; right: -4px;
  background: #ff3b30; color: #fff;
  font-size: 0.6rem; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; display: flex;
  align-items: center; justify-content: center;
  line-height: 1;
}
.scheduler-toast {
  position: fixed; bottom: 2rem;
  left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--bg-tertiary, #333);
  color: var(--text-inverse, #fff);
  padding: 0.6rem 1.5rem;
  border-radius: 8px; font-size: 0.9rem;
  z-index: 9500; opacity: 0;
  transition: all 0.3s ease;
}
.scheduler-toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 500px) {
  .scheduler-panel { width: 100%; right: -100%; }
  .scheduler-time-row { flex-direction: column; align-items: stretch; }
}

/* ---------- Smart Retry ---------- */
.smart-retry-indicator {
  margin: 12px 0;
  padding: 12px 16px;
  border-radius: 8px;
  background: #1a1a2e;
  border: 1px solid #e94560;
  animation: retryPulse 2s ease-in-out infinite;
}
.retry-header {
  font-size: 14px;
  color: #e94560;
  margin-bottom: 6px;
}
.retry-icon {
  display: inline-block;
  animation: retrySpin 1s linear infinite;
}
.retry-reason {
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
  word-break: break-word;
}
.retry-countdown {
  font-size: 13px;
  color: #ccc;
  margin-bottom: 8px;
}
#retry-seconds {
  font-weight: bold;
  color: #e94560;
}
.retry-cancel-btn {
  background: transparent;
  border: 1px solid #e94560;
  color: #e94560;
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}
.retry-cancel-btn:hover {
  background: #e94560;
  color: #fff;
}
@keyframes retrySpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes retryPulse {
  0%, 100% { border-color: #e94560; }
  50%      { border-color: #e9456080; }
}

/* ---------- Usage Heatmap ---------- */
#heatmap-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1099;
}
#heatmap-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary, #1e1e2e);
  border: 1px solid var(--border, #333);
  border-radius: 12px;
  padding: 20px 24px;
  z-index: 1100;
  width: min(680px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
#heatmap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 1.1rem;
  font-weight: 600;
}
#heatmap-actions {
  display: flex;
  gap: 6px;
}
#heatmap-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border, #333);
}
.heatmap-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}
.heatmap-stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary, #e0e0e0);
}
.heatmap-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary, #888);
  margin-top: 2px;
}
#heatmap-grid {
  overflow-x: auto;
}
.heatmap-row {
  display: flex;
  gap: 2px;
  align-items: center;
}
.heatmap-header-row {
  margin-bottom: 2px;
}
.heatmap-label {
  width: 32px;
  min-width: 32px;
  font-size: 0.7rem;
  color: var(--text-secondary, #888);
  text-align: right;
  padding-right: 6px;
}
.heatmap-hour-label {
  width: 22px;
  min-width: 22px;
  font-size: 0.6rem;
  color: var(--text-secondary, #888);
  text-align: center;
}
.heatmap-cell {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 3px;
  cursor: default;
  transition: transform 0.1s;
}
.heatmap-cell:hover {
  transform: scale(1.3);
  z-index: 1;
}
.heatmap-level-0 { background: var(--heatmap-0, #161b22); }
.heatmap-level-1 { background: var(--heatmap-1, #0e4429); }
.heatmap-level-2 { background: var(--heatmap-2, #006d32); }
.heatmap-level-3 { background: var(--heatmap-3, #26a641); }
.heatmap-level-4 { background: var(--heatmap-4, #39d353); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 12px;
  justify-content: flex-end;
}
.heatmap-legend-label {
  font-size: 0.7rem;
  color: var(--text-secondary, #888);
  margin: 0 4px;
}
.heatmap-legend-cell {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 2px;
}

/* Light theme overrides */
body.light-theme .heatmap-level-0 { background: #ebedf0; }
body.light-theme .heatmap-level-1 { background: #9be9a8; }
body.light-theme .heatmap-level-2 { background: #40c463; }
body.light-theme .heatmap-level-3 { background: #30a14e; }
body.light-theme .heatmap-level-4 { background: #216e39; }
body.light-theme #heatmap-panel {
  background: #fff;
  border-color: #ddd;
}


/* --- Context Window Meter --- */
.context-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 12px;
  font-size: 0.75rem;
  color: #9ca3af;
  transition: opacity 0.3s ease;
}
.context-meter--hidden { opacity: 0; pointer-events: none; }
.context-meter__bar {
  flex: 1;
  height: 6px;
  background: #1f2937;
  border-radius: 3px;
  overflow: hidden;
  max-width: 200px;
}
.context-meter__fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background-color 0.3s ease;
  width: 0;
}
.context-meter__fill--green  { background-color: #22c55e; }
.context-meter__fill--yellow { background-color: #eab308; }
.context-meter__fill--red    { background-color: #ef4444; }
.context-meter__label {
  white-space: nowrap;
  min-width: 100px;
  font-variant-numeric: tabular-nums;
}

/* Light theme overrides */
[data-theme="light"] .context-meter__bar { background: #e5e7eb; }
[data-theme="light"] .context-meter { color: #6b7280; }
