/* ==========================================================================
   Themes: Emerald (default), Dark and Light.
   js/theme.js puts data-theme on <html> and remembers the choice.
   Each page's own stylesheet holds the Emerald colors; this file only adds the
   shared helpers and swaps the colors for Dark and Light. It covers both naming
   sets: index.css (--bg-primary, --text-primary...) and search.css / login.html
   (--bg, --text...).
   ========================================================================== */
:root {
  --tint: 255, 255, 255;               /* faint overlays on cards and inputs */
  --shade: 12, 20, 15;                 /* see-through dark panels */
  --glow: 60, 110, 72;                 /* soft glow behind the page */
  --inset: rgba(0, 0, 0, 0.15);        /* sunken boxes */
  --text-strong: #fff;
  --topbar: rgba(8, 17, 12, 0.9);
  --gold-grad: linear-gradient(145deg, #e6c882, #cda85e);
  color-scheme: dark;
}

/* ---------- Dark: neutral charcoal, same gold accents ---------- */
:root[data-theme="dark"] {
  --shade: 17, 18, 22;
  --glow: 70, 78, 96;
  --topbar: rgba(13, 14, 17, 0.92);

  --bg-primary: #0d0e11;
  --bg-secondary: #15171b;
  --card-bg: linear-gradient(160deg, rgba(31, 33, 38, 0.78), rgba(18, 19, 23, 0.86));
  --card-bg-solid: rgba(24, 26, 30, 0.82);
  --card-bg-hover: linear-gradient(160deg, rgba(39, 41, 47, 0.84), rgba(22, 23, 28, 0.9));
  --text-primary: #f2f2f0;
  --text-secondary: #9ca0a8;
  --text-muted: #70757e;

  --bg: #0d0e11;
  --panel: rgba(24, 26, 31, 0.88);
  --panel-solid: #16181c;
  --card: linear-gradient(160deg, rgba(31, 33, 38, 0.8), rgba(18, 19, 23, 0.88));
  --text: #f2f2f0;
  --muted: #9ca0a8;
  --muted-2: #70757e;
}

/* ---------- Light: warm off-white, darker gold so text stays readable ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --tint: 24, 32, 27;
  --shade: 255, 255, 255;
  --glow: 214, 196, 150;
  --inset: rgba(24, 32, 27, 0.04);
  --text-strong: #000;
  --topbar: rgba(255, 255, 255, 0.94);

  --bg-primary: #f5f3ee;
  --bg-secondary: #ffffff;
  --card-bg: linear-gradient(160deg, #ffffff, #fbfaf6);
  --card-bg-solid: #ffffff;
  --card-bg-hover: linear-gradient(160deg, #ffffff, #f6f2e8);
  --border-color: rgba(120, 95, 40, 0.2);
  --border-glow: rgba(150, 115, 40, 0.38);
  --gold: #a8812f;
  --gold-light: #8a6620;
  --gold-deep: #7a5a1a;
  --emerald: #2f7d4f;
  --emerald-light: #2f7d4f;
  --accent-cyan: #8f6a1f;
  --accent-blue: #3f6f8a;
  --accent-teal: #2f7d4f;
  --accent-amber: #a06c0c;
  --accent-red: #b84444;
  --text-primary: #1c211d;
  --text-secondary: #566058;
  --text-muted: #7a847c;

  --bg: #f5f3ee;
  --panel: #ffffff;
  --panel-solid: #ffffff;
  --card: #ffffff;
  --card-shadow: rgba(60, 50, 20, 0.12);
  --gold-lt: #8a6620;
  --text: #1c211d;
  --muted: #566058;
  --muted-2: #7a847c;
  --green: #2f7d4f;
  --green-lt: #2f7d4f;
  --amber: #a06c0c;
  --red: #b84444;
  --ok: #2f7d4f;
  --line: rgba(120, 95, 40, 0.22);
  --line-soft: rgba(24, 32, 27, 0.1);
}

/* Light: the logo's white and pale-gold letters would vanish on a light page. */
:root[data-theme="light"] .brand-logo :is(path,text)[fill="#f3f1e9"] { fill: #1c211d; }
:root[data-theme="light"] .brand-logo :is(path,text)[fill="#e6c882"] { fill: #a8812f; }
:root[data-theme="light"] .brand-logo { filter: none !important; }
/* Light: heavy black shadows look dirty on white, so soften them. */
:root[data-theme="light"] .card,
:root[data-theme="light"] .panel,
:root[data-theme="light"] .band { box-shadow: 0 1px 3px rgba(60, 50, 20, 0.08); }

/* ---------- The switcher itself ---------- */
.theme-switch {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px;
  border: 1px solid rgba(205, 168, 94, 0.28); border-radius: 999px;
  background: rgba(var(--tint), 0.04);
  font-family: inherit;
}
.theme-switch button {
  font: inherit; font-size: 12px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none; border-radius: 999px; padding: 4px 9px; cursor: pointer;
  color: var(--muted, var(--text-secondary));
}
.theme-switch button:hover { color: var(--text, var(--text-primary)); }
.theme-switch button[aria-pressed="true"] {
  background: rgba(205, 168, 94, 0.18); color: var(--gold-lt, var(--gold-light));
}
.theme-switch .dot { width: 9px; height: 9px; border-radius: 50%; border: 1px solid rgba(128, 128, 128, 0.5); }
.theme-switch .dot.light { background: #f5f3ee; }
.theme-switch .dot.dark { background: #15171b; }
.theme-switch .dot.emerald { background: #2f6b45; }

/* Top bar: the three buttons sit in a small "Theme" drop-down */
.theme-menu { position: relative; }
.theme-menu > summary { list-style: none; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.theme-menu > summary::-webkit-details-marker { display: none; }
.theme-menu > summary::after { content: "\25BE"; font-size: 11px; }
.theme-menu[open] > summary { color: var(--gold-lt, var(--gold-light)); }
.theme-menu .theme-switch {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 50; flex-direction: column; align-items: stretch;
  border-radius: 12px; padding: 4px; background: var(--panel-solid, var(--bg-secondary, #16181c));
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.theme-menu .theme-switch button { border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* Where the switcher sits on each page */
.sidebar .theme-slot { margin-top: auto; padding-top: 1rem; display: flex; justify-content: center; }
.login-theme { position: fixed; top: 16px; right: 16px; }
/* Phones: the header has no room, so the switcher gets its own row under it. */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .top [data-theme-switcher]:not([data-theme-switcher="menu"]) { order: 10; margin-left: auto; }
}
@media print { .theme-switch { display: none !important; } }
