/* Shared light/dark theme tokens for every Carpe page. */
:root {
  color-scheme: dark;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1a1a !important;
  --panel: #212121 !important;
  --cell: #272727 !important;
  --panel2: #272727 !important;
  --bg-secondary: #272727 !important;
  --bg-panel: #212121 !important;
  --bg-cell: #272727 !important;
  --text: #ececec !important;
  --dim: #9a9a9a !important;
  --text-dim: #9a9a9a !important;
  --border: #383838 !important;
  --accent: #c3dfff !important;
  --accent-dim: rgba(195, 223, 255, 0.18) !important;
  --on-accent: #1a1a1a !important;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff !important;
  --panel: #ffffff !important;
  --cell: #f3f6fa !important;
  --panel2: #f3f6fa !important;
  --bg-panel: #ffffff !important;
  --bg-cell: #f3f6fa !important;
  --text: #182230 !important;
  --dim: #647184 !important;
  --text-dim: #647184 !important;
  --border: #d9e2ec !important;
  --accent: #326fa9 !important;
  --accent-dim: rgba(77, 143, 207, 0.14) !important;
  --on-accent: #ffffff !important;
  --bubble-user: #e7f2ff !important;
  --danger: #c94f5b !important;
  --red: #c94f5b !important;
}

html[data-theme="light"],
html[data-theme="light"] body,
html[data-theme="light"] main,
html[data-theme="light"] .content {
  background-color: #ffffff !important;
  color: var(--text);
}

/* Some pages use a translucent dark header instead of a theme token. */
html[data-theme="light"] header,
html[data-theme="light"] .header,
html[data-theme="light"] .topbar {
  background-color: rgba(255, 255, 255, 0.96) !important;
  color: var(--text) !important;
}

html[data-theme="light"] .sidebar,
html[data-theme="light"] .card,
html[data-theme="light"] .modal,
html[data-theme="light"] .modal-card,
html[data-theme="light"] dialog {
  background-color: var(--panel) !important;
  color: var(--text) !important;
}

html[data-theme="light"] .progress,
html[data-theme="light"] .track {
  background-color: #e7edf4 !important;
}

html[data-theme="light"] input,
html[data-theme="light"] textarea,
html[data-theme="light"] select,
html[data-theme="light"] button {
  color-scheme: light;
}

.theme-choice {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-choice select {
  max-width: 260px;
}

.theme-current {
  margin-top: 10px !important;
}

/* Light-mode coverage for legacy components that still use dark literals. */
html[data-theme="light"] {
  --bg-secondary: #f3f6fa !important;
  --surface: #ffffff !important;
  --surface-2: #f3f6fa !important;
  --input-bg: #ffffff !important;
}

html[data-theme="light"] .modal-content,
html[data-theme="light"] .dialog,
html[data-theme="light"] .dialog-card,
html[data-theme="light"] .popup,
html[data-theme="light"] .popover,
html[data-theme="light"] .dropdown,
html[data-theme="light"] .menu,
html[data-theme="light"] .sheet,
html[data-theme="light"] .chat-notice,
html[data-theme="light"] .chat-options,
html[data-theme="light"] .chat-convert,
html[data-theme="light"] .chat-bell,
html[data-theme="light"] .chat-run {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="light"] input,
html[data-theme="light"] textarea,
html[data-theme="light"] select,
html[data-theme="light"] .chat-convert input {
  background-color: var(--input-bg) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="light"] dialog button,
html[data-theme="light"] .modal button,
html[data-theme="light"] .modal-card button,
html[data-theme="light"] .modal-content button,
html[data-theme="light"] .dialog button,
html[data-theme="light"] .dialog-card button,
html[data-theme="light"] .popup button,
html[data-theme="light"] .popover button,
html[data-theme="light"] .chat-notice button,
html[data-theme="light"] .chat-options button,
html[data-theme="light"] .chat-convert button,
html[data-theme="light"] .chat-run button,
html[data-theme="light"] .conversation-tools button,
html[data-theme="light"] .conversation-tools select {
  background-color: var(--cell) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

html[data-theme="light"] dialog button.primary,
html[data-theme="light"] dialog button[type="submit"],
html[data-theme="light"] .modal button.primary,
html[data-theme="light"] .modal button[type="submit"],
html[data-theme="light"] .modal-card button.primary,
html[data-theme="light"] .modal-card button[type="submit"],
html[data-theme="light"] .modal-content button.primary,
html[data-theme="light"] .modal-content button[type="submit"],
html[data-theme="light"] .chat-options button.primary,
html[data-theme="light"] .chat-convert button.primary,
html[data-theme="light"] button.modal-submit,
html[data-theme="light"] button.primary,
html[data-theme="light"] button#add-submit,
html[data-theme="light"] button.manual-submit,
html[data-theme="light"] button.plan-add,
html[data-theme="light"] button.save,
html[data-theme="light"] .chat-convert button[type="submit"] {
  background-color: var(--accent) !important;
  color: var(--on-accent) !important;
  border-color: var(--accent) !important;
}

html[data-theme="light"] .chat-notice a,
html[data-theme="light"] .chat-options a {
  color: #326fa9 !important;
}

html[data-theme="light"] .chat-approval pre {
  background: #eef2f6 !important;
}

html[data-theme="light"] dialog::backdrop,
html[data-theme="light"] .chat-options::backdrop,
html[data-theme="light"] .chat-convert::backdrop {
  background: rgba(24, 34, 48, 0.28) !important;
}

/* All sidebar pages share the same activity light, including non-chat pages. */
#project-list {
  --project-activity-color: #c3dfff;
  --project-activity-min-opacity: 0.45;
  --project-activity-halo: rgba(195, 223, 255, 0.16);
}
/* Keep the sky-blue hue visible on white, even at the pulse's dimmest point. */
html[data-theme="light"] #project-list {
  --project-activity-color: #1674bc;
  --project-activity-min-opacity: 0.85;
  --project-activity-halo: rgba(22, 116, 188, 0.22);
}
#project-list .project-row.has-active-chat::before {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--project-activity-color);
  animation: carpe-project-active-pulse 1.6s ease-in-out infinite;
}
@keyframes carpe-project-active-pulse {
  0%, 100% { opacity: var(--project-activity-min-opacity); box-shadow: 0 0 0 0 transparent; }
  50% { opacity: 1; box-shadow: 0 0 0 4px var(--project-activity-halo); }
}
@media (prefers-reduced-motion: reduce) {
  #project-list .project-row.has-active-chat::before {
    animation: none;
    opacity: 1;
    box-shadow: none;
  }
}


/* Upgrade is a top-level destination, outside the collapsible project list. */
.sidebar > #upgrade-nav {
  position: relative;
  flex-shrink: 0;
  padding-right: 28px;
  --project-activity-color: #c3dfff;
  --project-activity-min-opacity: 0.45;
  --project-activity-halo: rgba(195, 223, 255, 0.16);
}
html[data-theme="light"] .sidebar > #upgrade-nav {
  --project-activity-color: #1674bc;
  --project-activity-min-opacity: 0.85;
  --project-activity-halo: rgba(22, 116, 188, 0.22);
}
#upgrade-nav.has-active-chat::after {
  content: '';
  position: absolute;
  right: 11px;
  top: calc(50% - 3.5px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--project-activity-color);
  animation: carpe-project-active-pulse 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #upgrade-nav.has-active-chat::after { animation: none; opacity: 1; }
}

/* Conversation memory uses the same quiet, rounded action style as Carpe controls. */
.memory-chat-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
}
.memory-chat-btn:hover:not(:disabled),
.memory-chat-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.memory-chat-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.memory-chat-btn:disabled { opacity: .45; cursor: wait; }
.memory-chat-btn::before {
  content: '✦';
  flex-shrink: 0;
  font-size: 14px;
  line-height: 1;
}
@media (max-width: 600px) {
  .memory-chat-btn {
    width: 36px;
    padding: 8px;
    overflow: hidden;
    color: transparent;
    gap: 0;
  }
  .memory-chat-btn::before { color: var(--text-dim); }
  .memory-chat-btn.active::before { color: var(--accent); }
}
