/* dark-mode.css | global dark-mode overrides (token-based) */

/* 1) Global tokens hook (only needed if you toggle via data-theme) */
:root[data-theme="dark"] {
  /* (keeps your existing palette) */
  --color-text: #eaeaea;
  --color-muted: #c4c4c4;
  --color-bg: #2b2e2b;
  --color-bg-soft: #242524;
  --color-bg-subtle: #1f201f;
  --color-border-subtle: #3a3a3a;
}

/* 2) Universal form + button normalization (low specificity) */
:root[data-theme="dark"] :where(
  input, select, textarea, button,
  input[type="button"], input[type="submit"], input[type="reset"]
) {
  color: var(--color-text);
  background: var(--color-bg);
  border-color: var(--color-border-subtle);
}

:root[data-theme="dark"] :where(input::placeholder, textarea::placeholder) {
  color: var(--color-muted);
}

/* Better focus ring */
:root[data-theme="dark"] :where(input, select, textarea, button):focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Radios/checkboxes pick brand color */
:root[data-theme="dark"] :where(input[type="radio"], input[type="checkbox"]) {
  accent-color: var(--color-accent);
}

/* WebKit autofill fix (prevents white fill) */
:root[data-theme="dark"] input:-webkit-autofill,
:root[data-theme="dark"] input:-webkit-autofill:hover,
:root[data-theme="dark"] input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--color-text);
  -webkit-box-shadow: 0 0 0 1000px var(--color-bg) inset;
}

/* 3) Generic “card/panel” surfaces */
:root[data-theme="dark"] :where(.result-card, .pv-panel, .pv-item, .pv-tag,
                                #chatBox, #docLink, .modal.modal--profile,
                                .collections-card, .md-card) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

/* 4) Buttons you use everywhere (anchors too) */
:root[data-theme="dark"] :where(button, .btn, .hub-btn, .credit-button, .pv-btn, a.btn) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-accent);
}
:root[data-theme="dark"] :where(button, .btn, .hub-btn, .credit-button, .pv-btn, a.btn):hover {
  background: var(--color-bg-subtle);
}

/* 5) Composer input + action row buttons (chat) */
:root[data-theme="dark"] :where(.composer__input) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

/* 6) Calendar component (replace hard-coded whites) */
:root[data-theme="dark"] :where(.cal-section,
                                .cal-side,
                                .cal-day-cell,
                                .cal-note-editor textarea,
                                .cal-nav,
                                .cal-btn,
                                .cal-icon-btn) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
:root[data-theme="dark"] :where(.cal-day-cell.selected) {
  background: color-mix(in oklab, var(--color-accent), transparent 88%);
}

/* 7) Focus Goals (FG) module — normalize #fff → tokens */
:root[data-theme="dark"] :where(.fg-card,
                                .fg-input,
                                .fg-select,
                                .fg-btn,
                                .fg-icon-btn,
                                .fg-item,
                                .fg-progress) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
:root[data-theme="dark"] .fg-chip { background: var(--color-bg-subtle); }
:root[data-theme="dark"] .fg-empty { background: var(--color-bg); border-style: dashed; }

/* 8) Project Viewer + Tag Search specifics */
:root[data-theme="dark"] :where(.tagsearch__input,
                                .pv input[type="url"],
                                .pv input[type="date"],
                                .pv textarea) {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

/* 9) Misc. states */
:root[data-theme="dark"] .text-muted { color: var(--color-muted); }
/* --------------------------------------------
   Dark Mode — Small Viewports (phones & tablets)
   Append to dark-mode.css
--------------------------------------------- */

/* Hint UAs we’re in dark UI; helps iOS form widgets */
:root[data-theme="dark"] {
  color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}

/* ====== Tablet and down ====== */
@media (max-width: 768px) {

  /* Global rhythm & readability */
  :root[data-theme="dark"] :where(body) {
    line-height: 1.5;
  }

  /* Cards / panels tighten padding; keep contrast */
  :root[data-theme="dark"] :where(.result-card, .pv-panel, .pv-item, .fg-card,
                                  .collections-card, .md-card, .modal, #chatBox) {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
    padding: clamp(12px, 2vw, 16px);
    box-shadow: none; /* reduce bloom on OLED */
  }

  /* Buttons: bigger targets, stack by default */
  :root[data-theme="dark"] :where(button, .btn, .hub-btn, .credit-button, .pv-btn,
                                  input[type="submit"], input[type="button"], a.btn) {
    background: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-accent);
    display: block;
    width: 100%;
    min-height: 44px;                 /* ✅ a11y touch target */
    padding: 12px 14px;
    font-size: 1rem;
  }
  /* compact button rows -> wrap nicely */
  :root[data-theme="dark"] :where(.btn-row, .actions, .pv-actions, .composer__actions) {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Inputs: no white flashes; avoid iOS zoom by using >=16px */
  :root[data-theme="dark"] :where(input, select, textarea) {
    background: var(--color-bg-soft);
    color: var(--color-text);
    border: 1px solid var(--color-border-subtle);
    width: 100%;
    min-height: 44px;
    font-size: 16px;                  /* ✅ prevents iOS zoom-on-focus */
    padding: 10px 12px;
    background-clip: padding-box;
  }
  :root[data-theme="dark"] :where(input::placeholder, textarea::placeholder) {
    color: var(--color-muted);
  }

  /* Form groups breathe a bit */
  :root[data-theme="dark"] :where(.form-row, .field, .form-group) {
    gap: 8px;
    margin-block: 8px;
  }

  /* Grids collapse to one column (safe, low specificity) */
  :root[data-theme="dark"] :where(.grid, .hub-grid, .pv-grid, .fg-grid, .card-grid) {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Modals fit viewport with safe insets */
  :root[data-theme="dark"] :where(.modal, .modal.modal--profile) {
    width: 100vw;
    max-width: none;
    margin: 0;
    border-radius: 0;
    inset: auto 0 0 0;
  }

  /* Chat composer: input grows, actions wrap */
  :root[data-theme="dark"] :where(.composer) { gap: 8px; }
  :root[data-theme="dark"] :where(.composer__input) {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
    min-height: 44px;
  }

  /* Calendar: sidebar collapses; cells tighten */
  :root[data-theme="dark"] :where(.cal-side) { display: none; }
  :root[data-theme="dark"] :where(.cal-nav) {
    position: sticky; top: 0;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border-strong);
    padding: 8px 12px;
    z-index: 2;
  }
  :root[data-theme="dark"] :where(.cal-grid, .cal-days, .cal-week) {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
  }
  :root[data-theme="dark"] :where(.cal-day-cell) {
    min-height: 58px;
    padding: 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border-subtle);
  }
  :root[data-theme="dark"] :where(.cal-day-cell.selected) {
    background: color-mix(in oklab, var(--color-accent), transparent 85%);
    border-color: var(--color-accent);
  }
  :root[data-theme="dark"] :where(.cal-note-editor textarea) {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
    min-height: 100px;
  }

  /* Focus Goals: single column + legible chips */
  :root[data-theme="dark"] :where(.fg-grid) { grid-template-columns: 1fr !important; }
  :root[data-theme="dark"] :where(.fg-chip) {
    background: var(--color-bg-subtle);
    border: 1px solid var(--color-border-subtle);
    padding: 6px 10px;
  }

  /* Project Viewer / Tag Search */
  :root[data-theme="dark"] :where(.tagsearch__input,
                                  .pv input[type="url"],
                                  .pv input[type="date"],
                                  .pv textarea) {
    background: var(--color-bg);
    border-color: var(--color-border-strong);
    width: 100%;
  }
}

/* ====== Small phones ====== */
@media (max-width: 480px) {

  /* Tighter typography scale */
  :root[data-theme="dark"] :where(h1){ font-size: 1.4rem; }
  :root[data-theme="dark"] :where(h2){ font-size: 1.2rem; }
  :root[data-theme="dark"] :where(h3){ font-size: 1.05rem; }

  /* Buttons slightly chunkier for thumbs */
  :root[data-theme="dark"] :where(button, .btn, .hub-btn, .pv-btn, a.btn) {
    padding: 12px 16px;
    letter-spacing: 0.01em;
  }

  /* Calendar day labels can wrap or shrink */
  :root[data-theme="dark"] :where(.cal-day-label){ font-size: .85rem; }
  :root[data-theme="dark"] :where(.cal-day-cell){ min-height: 52px; }

  /* Composer actions stack */
  :root[data-theme="dark"] :where(.composer__actions){ flex-direction: column; }
}

/* ====== Motion-sensitive users (bonus) ====== */
@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] :where(*){
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
/* Herb Profile — Tabs (container + anchors) */
:root[data-theme="dark"] .apoth-tabs {
  background: var(--color-bg);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border-subtle);
  /* optional layout polish */
  display: flex;
  gap: 8px;
  padding: 8px 12px;
}

:root[data-theme="dark"] .apoth-tab {
  /* make <a> look like a button/pill in dark */
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  border-radius: 6px;
  padding: 8px 12px;
}

:root[data-theme="dark"] .apoth-tab:hover,
:root[data-theme="dark"] .apoth-tab:focus-visible {
  background: var(--color-bg-subtle);
  border-color: var(--color-accent);
  outline: none; /* you already add a focus outline elsewhere */
}

:root[data-theme="dark"] .apoth-tab[aria-current="page"],
:root[data-theme="dark"] .apoth-tab.is-active {
  background: color-mix(in oklab, var(--color-accent), transparent 88%);
  border-color: var(--color-accent);
  color: var(--color-text);
}
/* ===== Recipe Card (dark) ===== */
:root[data-theme="dark"] .rc-wrap {
  background: var(--color-bg-soft);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  border-radius: 10px;          /* match your light style */
  box-shadow: none;             /* optional: keep flat in dark */
}

:root[data-theme="dark"] .rc-title {
  color: var(--color-text);
}

/* Each bordered block inside the card */
:root[data-theme="dark"] .rc-wrap .apoth-section {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
}

/* Hints/labels inside sections */
:root[data-theme="dark"] .rc-wrap .apoth-hint,
:root[data-theme="dark"] .rc-wrap .rc-hint,
:root[data-theme="dark"] .rc-wrap label {
  color: var(--color-muted);
}

/* Make radio/checkbox accents visible in dark */
:root[data-theme="dark"] .rc-wrap input[type="radio"],
:root[data-theme="dark"] .rc-wrap input[type="checkbox"] {
  accent-color: var(--color-text);
}

/* Buttons row at the bottom (you already theme .hub-btn; this just ensures the row base matches) */
:root[data-theme="dark"] .rc-wrap .rc-row {
  background: transparent;
}

/* If you have a white “panel” around the form itself */
:root[data-theme="dark"] .rc-wrap form {
  background: transparent; } /* let .apoth-sec*
}
/* ===== Recipe Card (dark) ===== */
:root[data-theme="dark"] .rc-wrap {
  background: var(--color-bg-soft);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
  border-radius: 10px;          /* match your light style */
  box-shadow: none;             /* optional: keep flat in dark */
}

:root[data-theme="dark"] .rc-title {
  color: var(--color-text);
}

/* Each bordered block inside the card */
:root[data-theme="dark"] .rc-wrap .apoth-section {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
}

/* Hints/labels inside sections */
:root[data-theme="dark"] .rc-wrap .apoth-hint,
:root[data-theme="dark"] .rc-wrap .rc-hint,
:root[data-theme="dark"] .rc-wrap label {
  color: var(--color-muted);
}

/* Make radio/checkbox accents visible in dark */
:root[data-theme="dark"] .rc-wrap input[type="radio"],
:root[data-theme="dark"] .rc-wrap input[type="checkbox"] {
  accent-color: var(--color-text);
}

/* Buttons row at the bottom (you already theme .hub-btn; this just ensures the row base matches) */
:root[data-theme="dark"] .rc-wrap .rc-row {
  background: transparent;
}

/* If you have a white “panel” around the form itself */
:root[data-theme="dark"] .rc-wrap form {
  background: transparent; } /* let .apoth-sec*
/* Reuseable surfaces in dark mode */
:root[data-theme="dark"] .rc-wrap,
:root[data-theme="dark"] .apoth-section,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .panel {
  background: var(--color-bg);            /* or var(--color-bg-soft) for the outermost */
  color: var(--color-text);
  border: 1px solid var(--color-border-subtle);
}
/* === Global gold borders in dark mode === */
:root {
  /* adjust to your exact gold */
  --color-gold: #c9a45c;
}

/* 1) Default 1px gold border for common components */
:root[data-theme="dark"] :where(
  .rc-wrap,
  .apoth-section,
  .apoth-tabs,
  .apoth-tab,
  .card,
  .panel,
  .apoth-preview,
  .doc-open-link,
  .doc-frame,
  .chip,
  .pill,
  .badge,
  input,
  textarea,
  select,
  button,
  progress,
  fieldset,
  hr
) {
  border-color: var(--color-gold);
  border-width: 1px;
  border-style: solid;
}

/* 2) Inputs/buttons focus state should also show gold */
:root[data-theme="dark"] :is(
  input,
  textarea,
  select,
  button,
  .apoth-tab,
  .credit-button
):focus-visible {
  border-color: var(--color-gold);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-gold), transparent 75%);
}

/* 3) Horizontal rules */
:root[data-theme="dark"] hr {
  border-top-color: var(--color-gold);
}

/* 4) Radios/checkboxes accent */
:root[data-theme="dark"] input[type="radio"],
:root[data-theme="dark"] input[type="checkbox"] {
  accent-color: var(--color-gold);
}

/* 5) Range slider thumb ring (optional) */
:root[data-theme="dark"] input[type="range"]::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--color-gold);
}
:root[data-theme="dark"] input[type="range"]::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--color-gold);
}

/* 6) Progress bars (border treatment) */
:root[data-theme="dark"] progress {
  border-color: var(--color-gold);
}
/* Calendar buttons — fix white "ghost" buttons in dark */
:root[data-theme="dark"] body .cal-btn.ghost { background: transparent; }
:root[data-theme="dark"] .cal-btn {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-gold);
  border-radius: 8px;
}

:root[data-theme="dark"] .cal-btn.ghost {
  background: transparent;                 /* stop the white fill */
  color: var(--color-text);
  border: 1px solid var(--color-gold);
}

:root[data-theme="dark"] .cal-btn:hover,
:root[data-theme="dark"] .cal-btn:focus-visible {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-gold), transparent 75%);
  outline: none;
}

:root[data-theme="dark"] .cal-btn:disabled,
:root[data-theme="dark"] .cal-btn.ghost:disabled {
  opacity: .65;
  cursor: not-allowed;
}

/* (optional) mini-calendar "today" & "selected" pills so they don't go white */
:root[data-theme="dark"] .cal-day-cell.today {
  background: color-mix(in oklab, var(--color-gold), transparent 85%);
  color: var(--color-text);
  border-color: var(--color-gold);
}
:root[data-theme="dark"] .cal-day-cell.selected {
  background: color-mix(in oklab, var(--color-gold), transparent 75%);
  color: var(--color-text);
  border-color: var(--color-gold);
}
/* utility for stubborn cases */
.border-gold { border-color: var(--color-gold) !important; border-width:1px !important; border-style:solid !important; }
