/* ============================================================================
 * modules/dark_mode/dark.css — Dark mode: auto / light / dark switch (v146, switch v149, module dark_mode)
 * ============================================================================
 * Loaded on every page (through head_extra) while the module is on. Every rule needs <html class="dm-dark">,
 * which the small script in <head> (module.php) sets: the person's own choice (☀️ light / 🌙 dark), or
 * "auto" = follow the phone/computer. Without the class nothing here applies — the old light site.
 * How it works: the stylesheets keep their light colours as fallbacks —
 *   background: var(--surface, #fff)   color: var(--tx, #1B2420)   border: 1px solid var(--bd, #E1E7E3)
 * — and these variables exist only here. Each page's own variables (--ink, --card, --line …) get dark values too.
 * `html.dm-dark:root` (not `:root`) wins over the :root blocks pages print in <style>; `… body` too,
 * because the product page sets its colours on body.pm.
 * ============================================================================ */

html.dm-dark:root, html.dm-dark:root body {
  color-scheme: dark;
  /* new hooks used by the fallbacks */
  --surface: #161d19;  --surface-2: #1d2621;  --tx: #e6ece8;  --tx2: #a3b0a8;  --bd: #2e3833;
  --brand-tx: #5fd394; --ink-bg: #334039;

  /* shop (app.css), sign-in (auth.css), seller dashboard, admin, chat, live */
  --bg: #0e1310;  --card: #161d19;  --ink: #e6ece8;  --muted: #a3b0a8;
  --line: #2e3833; --line-lt: #26302b; --line-2: #26302b;
  --brand-lt: #163322; --brand-soft: #163322; --gm-lt: #163322; --gm-ink: #e6ece8; --gm-line: #2e3833;
  --warn-soft: #33260f; --bad-bg: #3a1714; --ok-bg: #12301f;
  --bad: #f97066; --warn: #fdb022; --ok: #47cd89;
  --amber: #fdb022; --amber-lt: #33260f; --blue: #84adff; --blue-lt: #17233f; --red: #f97066; --red-lt: #3a1714;
  --hp-ok-lt: #163322; --hp-red-lt: #3a1714; --hp-red: #f97066; --hp-amb-lt: #33260f; --hp-amb-ln: #5c4517; --hp-amb: #fdb022;
  --sh: 0 1px 2px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.3);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}
html.dm-dark body { background: var(--bg); color: var(--ink); }

/* links and green text keep enough contrast on dark (:where = no extra weight, so component colours still win) */
:where(html.dm-dark) a { color: var(--brand-tx); }
:where(html.dm-dark) a:hover { color: var(--tx); }

/* form fields without their own colours */
:where(html.dm-dark) :where(input:not([type=checkbox], [type=radio], [type=range], [type=color], [type=submit], [type=button]), select, textarea) {
  background-color: var(--surface); color: var(--tx); border-color: var(--bd);
}
:where(html.dm-dark) input::placeholder, :where(html.dm-dark) textarea::placeholder { color: #7d8a83; }
:where(html.dm-dark) table th, :where(html.dm-dark) table td { border-color: var(--bd); }
:where(html.dm-dark) hr { border-color: var(--bd); }

/* photos and logos: no change, but soften pure-white product shots a little at night */
:where(html.dm-dark) .pc-img img, :where(html.dm-dark) .gt-img { filter: brightness(.94); }

/* the search box sits on the green header */
:where(html.dm-dark) .gm-search { background: var(--surface); }
:where(html.dm-dark) .gm-suggest { box-shadow: 0 10px 28px rgba(0,0,0,.6); }

/* bottom sheet / dialogs dim the page more */
:where(html.dm-dark) .gm-sheet-bg, :where(html.dm-dark) .gm-modal-bg { background: rgba(0,0,0,.6); }

/* skeleton shimmer used a white highlight */
:where(html.dm-dark) .gm-anim .pc-img { background: linear-gradient(100deg, var(--brand-lt) 40%, #1f3a29 50%, var(--brand-lt) 60%) 0 0 / 300% 100%; }

/* payment logos keep their white plate (logos are made for white), so their text stays dark */
:where(html.dm-dark) .gm-pay { color: #1B2420; }
/* red "Log out" in the menu */
html.dm-dark:root .gmd-foot a.bad { color: #f97066; }   /* menu styles come later in the page, so a little more weight */

/* sign-up button before "I agree" is ticked */
html.dm-dark:root .au-btn.is-off { background: #333d38 !important; color: #8d9a93 !important; }

/* code / tags with fixed pastel backgrounds stay pastel but get dark text */
:where(html.dm-dark) .gm-tag.warn, :where(html.dm-dark) .pc-zone { color: #7A4B00; }

/* seller pages: new-attribute button, empty product photo squares, wholesale "✘ Not yet" */
html.dm-dark:root .pa-lib.new { background: #163322; }
html.dm-dark:root .pl-th { background-color: #1d2621; color: #7d8a83; }
html.dm-dark:root span.no { color: #f97066; }

/* seller dashboard top bar was see-through white */
html.dm-dark:root .sd-top { background: rgba(22,29,25,.92); }

/* ---- the switch itself (menu, My account, dashboard, admin) ---------------------------------- */
.dm-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 12px; background: var(--surface-2, #F1F4F2); border: 1px solid var(--bd, #E1E7E3); }
.dm-seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--tx2, #5A665F); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px; -webkit-tap-highlight-color: transparent; }
.dm-seg button:hover { color: var(--tx, #1B2420); }
.dm-seg button:focus-visible { outline: 2px solid #12A150; outline-offset: 1px; }
.dm-seg button[aria-pressed="true"] { background: var(--surface, #fff); color: var(--brand-tx, #0B7A3B); box-shadow: 0 1px 2px rgba(16,40,28,.10), 0 1px 6px rgba(16,40,28,.08); }
.dm-row { display: flex; flex-direction: column; gap: 8px; }
.dm-row small { color: var(--tx2, #6B7670); font-size: 12px; line-height: 1.4; }
.dm-row-menu { padding: 4px 16px 12px; border-bottom: 1px solid var(--bd, #E8ECEA); }
.dm-row-menu .dm-h { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--tx2, #7C8781); padding: 10px 0 0; }
.dm-row-me { padding: 14px 4px; border-bottom: 1px solid var(--line, #E1E7E3); }
.dm-row-me b { font-size: 15px; }
/* admin menu (dark green side panel) */
#adminMenu .dm-row-menu { padding: 6px 6px 2px; border-bottom: 0; }
#adminMenu .dm-h, #adminMenu .dm-row small { color: #8FB5A0; }
#adminMenu .dm-seg { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.12); }
#adminMenu .dm-seg button { color: #B8CFC2; min-height: 36px; font-size: 13px; }
#adminMenu .dm-seg button[aria-pressed="true"] { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; }
.dm-ic { position: relative; flex: none; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; padding: 0; }
.dm-ic:hover { background: rgba(127,127,127,.14); }
.dm-ic .dm-moon { display: inline; } .dm-ic .dm-sun { display: none; }
html.dm-dark .dm-ic .dm-moon { display: none; } html.dm-dark .dm-ic .dm-sun { display: inline; }
.dm-toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9999; background: #1B2420; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.3); pointer-events: none; opacity: 0; transition: opacity .2s; }
.dm-toast.on { opacity: 1; }
html.dm-dark .dm-toast { background: #e6ece8; color: #0e1310; }
html.dm-anim, html.dm-anim * { transition: background-color .25s ease, color .25s ease, border-color .25s ease !important; }
@media (prefers-reduced-motion: reduce) { html.dm-anim, html.dm-anim * { transition: none !important; } }
