/* =====================================================================
   LoadMap dark mode — used when the phone or computer is set to dark mode.
   Same LoadMap colours: dark green backgrounds, light text, and the gold stays gold.
   (Having our own dark mode also stops Samsung Internet recolouring the site.)
   ===================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f1ebdd; --ink-2: #d3ccb9; --muted: #a6a290;
    --paper: #11160f; --card: #1a2217; --line: #313d2c;
    --wheat: #d9a441; --wheat-deep: #e2b558; --wheat-soft: #3a3220;
    --ok: #7cbc72; --ok-soft: #1d321c; --warn: #f0914f; --warn-soft: #3c2a1b; --full: #e8806a; --full-soft: #3d221c;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 8px 22px rgba(0,0,0,.35);
    --deep: #0c110a; --panel: #222c1e; --panel-2: #283324; --cream: #efe8d6; --dark-text: #1c2419;
  }
  html, body { background: var(--paper); color: var(--ink); }

  /* Things that are dark in the light design stay dark */
  .site-header, .l-hero, .l-section.dark { background-color: var(--deep); }
  .l-hero { background: radial-gradient(1200px 500px at 85% 0%, rgba(217,164,65,.16), transparent 60%), repeating-linear-gradient(100deg, rgba(255,255,255,.02) 0 2px, transparent 2px 22px), var(--deep); }
  .tile.accent, .feat .ico, .who, .suggest .tag.farm, .l-live .go, .overview .go, .farm-card .go { background: var(--deep); border-color: var(--line); color: #fff; }
  .l-live > .go:hover, .l-live-link:hover .go { background: #18200f; }

  /* Main buttons and selected options: light cream on dark, so they still stand out */
  .btn.primary, .seg button[aria-pressed=true], .chip[aria-pressed=true], .tabs button[aria-pressed=true], .tabs button.on,
  .toast, .l-cta-band .btn.wheat { background: var(--cream); border-color: var(--cream); color: var(--dark-text); }
  .btn.primary:hover { background: #fff; border-color: #fff; }
  .toast.error { background: var(--full); border-color: var(--full); color: #fff; }

  /* Gold stays gold, with dark writing on it */
  .site-nav a.cta, .site-nav a.cta[aria-current=page], .btn.wheat, .l-strip, .who.farmer, .ga-steps2 li::before { background: var(--wheat); color: var(--dark-text); }
  .site-nav a.cta:hover, .btn.wheat:hover { background: #e6b350; color: var(--dark-text); }
  .l-strip-grid div { border-color: rgba(28,36,25,.2); }
  .l-cta-band { background: var(--wheat); color: var(--dark-text); }
  .l-cta-band h2, .l-cta-band .l-h2 { color: var(--dark-text); }
  .l-cta-inner p { color: #3a4335; }
  .l-cta-band .btn.ghost-light { color: var(--dark-text); border-color: rgba(28,36,25,.4); }

  /* Cards, panels and boxes */
  .btn { background: var(--panel); border-color: var(--line); color: var(--ink); }
  .btn:hover { background: var(--panel-2); border-color: #4a5843; }
  .btn.ghost { background: transparent; }
  .btn.danger { background: #b23b2b; border-color: #b23b2b; color: #fff; }
  .btn.still-btn { background: var(--deep); border-color: #3c4a36; color: #fff; }
  .btn.still-btn.done { background: #2f8f4e; border-color: #2f8f4e; }
  input, textarea, select, .field input, .field textarea, .field select, .mach-input { background: var(--panel); border-color: #3c4a36; color: var(--ink); }
  input::placeholder, textarea::placeholder { color: #7d806f; }
  .tile, .bin-box, .ci, .notes, .mini-bin, .loc2-block, .eta, .coords, .suggest li:hover, .suggest li.on { background: var(--panel); }
  .overview:hover { background: var(--panel); }
  .l-section.alt { background: #151c12; }
  .tabs, .pm, .seg { background: #2a3426; }
  .pill { background: #2a3426; color: var(--ink-2); }
  .pill.finished { background: #2a3426; color: #b5b2a5; }
  .fill-track, .fill .fill-track { background: #2a3426; }
  .steps li::before { background: var(--wheat-soft); color: var(--wheat); }
  .suggest .tag.delivery { background: #1f2a36; color: #a9c2e0; }
  .suggest { background: var(--card); border-color: var(--line); }
  .why-list li { color: #d8d1bd; }
  .site-footer, footer.site-footer { border-color: var(--line); }
  .demo-banner { background: #3a3220; color: #f1e3bd; border-color: #5a4a26; }
  .demo-banner code { background: #1a2217; }
  .demo-login, .app-preview-note, .checkmail .cm-icon, #site1Head .fullest-tag { background: var(--wheat-soft); border-color: #5a4a26; color: var(--ink); }
  .demo-login code { background: var(--card); color: var(--ink); }
  .ga-card, .ga-sheet-box, .get-app { background: var(--card); }
  .ga-done { background: var(--ok-soft); color: #a6dc9b; }
  .ga-steps2 .ico { color: #7fb0ff; }
  .ga-alt a, .get-app .go { color: var(--wheat); }
  .ga-qr .qr { background: #fff; }   /* QR codes need a white background to scan */
  .update-bar { background: var(--deep); }
  .app-bar { background: var(--deep); border: 1px solid var(--line); }

  /* Farm page and dashboard details */
  .site-head { border-color: var(--wheat); }
  .site-head .site-no { color: var(--ink); }
  .site-head .site-name { color: var(--wheat); }
  .keep-box { background: var(--panel); border-color: #3c4a36; }
  .keep-box:has(input:checked) { background: var(--wheat-soft); border-color: var(--wheat); }
  .keep-note { background: var(--wheat-soft); border-color: #6b5628; color: #f1d58f; }
  .danger-card { border-color: #5a2a22; }
  .danger-card h2 { color: #ef8b77; }
  .contact-strip .qc-uhf, .qc-uhf { background: var(--wheat-soft); color: var(--wheat); }
  .mach.off .mach-btns { opacity: .4; }

  /* Storage bar: dark empty space, brighter red for headers so it shows up */
  .tank { --header: #c2412f; }
  .tank-seg { background: #0f150d; }
  .sw.header { border-color: #c2412f; }

  /* Harvest speed dial */
  .gauge .track { stroke: #2c3728; }
  .gauge .tick.minor { stroke: #5b6452; }
  .gauge .hub { fill: var(--ink); }
  .gauge .hub-in { fill: var(--card); }

  /* Maps: pop-ups and buttons */
  .leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--card); color: var(--ink); box-shadow: 0 6px 22px rgba(0,0,0,.5); }
  .leaflet-popup-content-wrapper a { color: var(--wheat); }
  .leaflet-bar a, .leaflet-bar a:hover { background: var(--card); color: var(--ink); border-color: var(--line); }
  .leaflet-control-layers { background: var(--card); color: var(--ink); }
  .leaflet-control-layers-toggle { filter: invert(.9); }
  .leaflet-control-attribution { background: rgba(17,22,15,.75) !important; color: #b9b5a4; }
  .leaflet-control-attribution a { color: #d9c48f; }
  #liveMap, #map { background: #1d2419; }
}

@media (prefers-color-scheme: dark) {
  .cargo-grain { background: var(--wheat-soft) !important; color: var(--wheat) !important; border-color: #5a4a26 !important; }
  .tabs { background: #10160e; }
  .tabs button { color: #a9b3a0; }
  .tabs button[aria-selected=true] { background: var(--cream); color: var(--dark-text); box-shadow: none; }
}

@media (prefers-color-scheme: dark) {
  .input, input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=search], select, textarea, .mach-input, .adjust input {
    background: var(--panel); border-color: #3c4a36; color: var(--ink);
  }
  .seg button[aria-pressed=true], #statusSeg2 button[aria-pressed=true] { background: var(--cream); color: var(--dark-text); }
  .keep-box { background: var(--panel); }
}
