/* Day/Night mode — follows system preference by default, with manual override */

/* Light theme values (default) */
:root {
  color-scheme: light dark;

  /* Surface colors */
  --bg-body: #eee;
  --bg-surface: #fff;
  --bg-surface-alt: #fdfdfd;
  --bg-surface-dim: #ececec;
  --bg-overlay-modal: #eee;

  /* Text colors */
  --text-primary: #111;
  --text-secondary: #444;
  --text-muted: #999;

  /* Border colors */
  --border-color: #333;
  --border-light: #ccc;

  /* Interactive colors */
  --link-color: #668bd4;
  --bg-selected: #cbe2ff;
  --bg-selected-transparent: #cbe2ff88;

  /* Table colors */
  --bg-table-header: #fff;
  --bg-not-editable: #eee;

  /* Semantic colors (kept similar in both modes) */
  --color-true-green: rgba(10, 200, 10, 0.3);
  --color-false-red: rgba(200, 10, 10, 0.3);
  --color-true-highlight: #fce8b2;

  /* Input colors */
  --bg-input: #fff;
  --text-input: #111;
  --border-input: #999;
}

/* Dark theme values — applied by system preference (auto) or manual override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg-body: #1a1a1a;
    --bg-surface: #2a2a2a;
    --bg-surface-alt: #252525;
    --bg-surface-dim: #333;
    --bg-overlay-modal: #333;
    --text-primary: #e0e0e0;
    --text-secondary: #bbb;
    --text-muted: #888;
    --border-color: #555;
    --border-light: #444;
    --link-color: #7eaaef;
    --bg-selected: #2a4060;
    --bg-selected-transparent: #2a406088;
    --bg-table-header: #2a2a2a;
    --bg-not-editable: #333;
    --color-true-green: rgba(30, 180, 30, 0.35);
    --color-false-red: rgba(200, 50, 50, 0.35);
    --color-true-highlight: #5a4a20;
    --bg-input: #333;
    --text-input: #e0e0e0;
    --border-input: #666;
  }
  :root:not([data-theme="light"]) img {
    opacity: 0.9;
  }
}

/* Forced dark mode (manual override) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-body: #1a1a1a;
  --bg-surface: #2a2a2a;
  --bg-surface-alt: #252525;
  --bg-surface-dim: #333;
  --bg-overlay-modal: #333;
  --text-primary: #e0e0e0;
  --text-secondary: #bbb;
  --text-muted: #888;
  --border-color: #555;
  --border-light: #444;
  --link-color: #7eaaef;
  --bg-selected: #2a4060;
  --bg-selected-transparent: #2a406088;
  --bg-table-header: #2a2a2a;
  --bg-not-editable: #333;
  --color-true-green: rgba(30, 180, 30, 0.35);
  --color-false-red: rgba(200, 50, 50, 0.35);
  --color-true-highlight: #5a4a20;
  --bg-input: #333;
  --text-input: #e0e0e0;
  --border-input: #666;
}
:root[data-theme="dark"] img {
  opacity: 0.9;
}

/* Base element defaults using theme variables */
body {
  background-color: var(--bg-body);
  color: var(--text-primary);
}

a {
  color: var(--link-color);
}

input, select, textarea {
  background-color: var(--bg-input);
  color: var(--text-input);
  border: 1px solid var(--border-input);
}

hr {
  border-color: var(--border-light);
}

/* ---- Theme toggle widget ---- */
.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 9999;
}

.theme-toggle-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  font-size: 64px;
  line-height: 0.6;
  color: var(--text-muted);
  opacity: 0.5;
  transition: opacity 0.15s;
}

.theme-toggle-btn:hover {
  opacity: 1;
}

.theme-toggle-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  min-width: 120px;
  overflow: hidden;
}

.theme-toggle-menu.open {
  display: block;
}

.theme-toggle-option {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.theme-toggle-option:hover {
  background: var(--bg-surface-dim);
}

.theme-toggle-option.active {
  font-weight: bold;
}
