/* ==========================================================================
   RT Dua — Theme layer (light / dark)
   Loaded LAST so it can override both style.css and dashboard.css.
   The active theme is set by <html data-theme="light|dark">.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Dark palette — overrides the :root tokens
   -------------------------------------------------------------------------- */
html[data-theme='dark'] {
  /* Brand — green lifted for dark surfaces; gold used for accents */
  --primary: #2e9e63;
  --primary-600: #35b371;
  --primary-700: #4bc986;
  --primary-soft: #16301f;
  --primary-softer: #12291a;

  --gold: #e0bc4a;
  --gold-600: #eac869;
  --gold-700: #f2d98f;
  --gold-soft: #332a10;
  --gold-softer: #29220e;

  --primary-rgb: 46, 158, 99;
  --gold-rgb: 224, 188, 74;

  /* Semantic — brighter hues, dark translucent backgrounds */
  --success: #5fd07a;
  --success-soft: #16301f;
  --error: #ff7a78;
  --error-soft: #3a1d1d;
  --warning: #ffb74d;
  --warning-soft: #3a2c12;
  --info: #64b5f6;
  --info-soft: #142a3d;
  --purple: #b18aff;
  --purple-soft: #2a2140;
  --teal: #4dd0b8;
  --teal-soft: #10302b;

  /* Neutrals — inverted ramp */
  --text: #e8eaed;
  --text-2: #a8aeb8;
  --text-3: #7d838d;
  --border: #2c313a;
  --border-2: #242830;
  --bg: #12151a;
  --surface: #1a1e25;
  --surface-2: #20242c;

  /* Stat-card tints */
  --stat-success-bg: #152a1a;
  --stat-success-border: #2c5234;
  --stat-success-text: #86e39b;
  --stat-error-bg: #2e1a1a;
  --stat-error-border: #5a3030;
  --stat-error-text: #ff9a97;

  /* Elevation — deeper shadows read better on dark */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .25);
  --shadow: 0 4px 12px rgba(0, 0, 0, .35);
  --shadow-md: 0 10px 26px rgba(0, 0, 0, .42);
  --shadow-lg: 0 22px 48px rgba(0, 0, 0, .55);

  color-scheme: dark;
}

html[data-theme='light'] {
  color-scheme: light;
}

/* Baseline: when no data-theme is set yet, follow the OS. theme.js always
   writes an explicit value, so this is only a safety net. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
  }
}

/* --------------------------------------------------------------------------
   2. Component fixes — colours that were hard-coded and would break on dark
   -------------------------------------------------------------------------- */

/* Scrollbars */
html[data-theme='dark'] ::-webkit-scrollbar-thumb { background: #3a4049; }
html[data-theme='dark'] ::-webkit-scrollbar-thumb:hover { background: #4a515c; }
html[data-theme='dark'] ::-webkit-scrollbar-track { background: #16191f; }

/* Buttons */
html[data-theme='dark'] .btn-soft:hover { background: #4a3a15; }
html[data-theme='dark'] .btn-danger:hover { background: #4a2222; }

/* Progress / bar track */
html[data-theme='dark'] .bar { background: #2b3039; }

/* Skeleton shimmer */
html[data-theme='dark'] .skeleton {
  background: linear-gradient(90deg, #232830 25%, #2b313a 50%, #232830 75%);
}

/* Landing surfaces that were literally #fff */
html[data-theme='dark'] body.landing { background: var(--bg); }
html[data-theme='dark'] .pub-nav { background: rgba(18, 21, 26, .88); border-bottom-color: var(--border); }
html[data-theme='dark'] .feat,
html[data-theme='dark'] .svc,
html[data-theme='dark'] .news,
html[data-theme='dark'] .pengurus,
html[data-theme='dark'] .hero-frame,
html[data-theme='dark'] .hero-stats { background: var(--surface); border-color: var(--border); }

/* Pengurus cards — the card surface is themed above, but the name (h4) and
   phone line inherited a light text colour that vanished on the card. Pin
   them explicitly so the whole card reads correctly in both themes. */
html[data-theme='dark'] .pengurus h4 { color: var(--text); }
html[data-theme='dark'] .pengurus .jabatan { color: #6fd39a; }
html[data-theme='dark'] .pengurus .telp { color: var(--text-3); }
html[data-theme='dark'] .pengurus:hover { border-color: #2f3540; }

/* Service-card additions: the 24/7 + Baru pills and the deep-link arrow use
   the light brand tints, which fall below readable contrast on a dark card.
   Lift the text and deepen the pill backgrounds. */
html[data-theme='dark'] .svc-badge { background: rgba(75, 201, 134, .17); color: #7fe0a8; }
html[data-theme='dark'] .svc-link { color: #7fe0a8; }
html[data-theme='dark'] .svc-link:hover { color: #a5edc4; }
html[data-theme='dark'] .t-teal { background: rgba(22, 160, 133, .19); color: #5fd6bd; }
html[data-theme='dark'] .t-gold { background: rgba(201, 162, 39, .19); color: #e8c765; }

/* Dashboard shell surfaces that were hard-coded #fff */
html[data-theme='dark'] .sidebar { background: var(--surface); }
html[data-theme='dark'] .topbar { background: var(--surface); border-bottom-color: var(--border); }
html[data-theme='dark'] .table-wrap,
html[data-theme='dark'] table.data { background: var(--surface); }
html[data-theme='dark'] table.data th { background: var(--surface-2); }
html[data-theme='dark'] table.data tbody tr:hover { background: var(--surface-2); }
html[data-theme='dark'] .tl-item::before { background: var(--surface); }

/* Badge text colours were hard-coded dark hues — lift them for dark surfaces */
html[data-theme='dark'] .badge-success { color: #86e39b; }
html[data-theme='dark'] .badge-error   { color: #ff9a97; }
html[data-theme='dark'] .badge-warning { color: #ffca7a; }
html[data-theme='dark'] .badge-info    { color: #7cc4ff; }
html[data-theme='dark'] .badge-purple  { color: #c4a6ff; }
html[data-theme='dark'] .badge-neutral { background: #272c34; color: var(--text-2); }
html[data-theme='dark'] .badge-primary { color: var(--primary-700); }

/* Landing floating stat cards */
html[data-theme='dark'] .float-card { background: var(--surface); border-color: var(--border); }

/* The hero village illustration is intentionally a bright "daytime photo"
   panel — keep it light in both themes, and match the frame background to the
   illustration's ground so no dark seam shows through. */
html[data-theme='dark'] .hero-frame { background: #f7f9f7; border-color: #3a4049; }

/* NOTE: .hero-pill, .hero .badge and similar white-on-amber chips sit INSIDE
   the orange hero and are intentionally translucent white — they stay as-is. */

html[data-theme='dark'] .hero { background: linear-gradient(180deg, #1a1e25 0%, #12151a 100%); }
html[data-theme='dark'] .section-alt { background: var(--surface-2); }

/* Kept dark on purpose (contact card + footer) but soften the edge */
html[data-theme='dark'] .contact-card { background: linear-gradient(130deg, #232833, #171b22); }
html[data-theme='dark'] .foot { background: #0d1015; }

/* Modal + toast already dark-friendly; just normalise the backdrop */
html[data-theme='dark'] .modal-backdrop { background: rgba(0, 0, 0, .62); }

/* Chart internals that used light greys */
html[data-theme='dark'] .chart-track { background: #2b3039; }
html[data-theme='dark'] .hbar-row .hbar-track { background: #2b3039; }
html[data-theme='dark'] .timeline::before { background: var(--border); }

/* Donut / chart centre text stays readable */
html[data-theme='dark'] .donut-center strong { color: var(--text); }
html[data-theme='dark'] .donut-center span { color: var(--text-2); }

/* Sidebar brand mark text */
html[data-theme='dark'] .brand-mark { color: #12151a; }

/* --------------------------------------------------------------------------
   3a. Brand logo image (replaces the old icon mark)
   -------------------------------------------------------------------------- */
.brand-logo {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 11px;
  object-fit: cover;
  display: block;
  box-shadow: 0 3px 10px rgba(13, 94, 53, .28);
}
html[data-theme='dark'] .brand-logo {
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
  outline: 1px solid rgba(255, 255, 255, .08);
  outline-offset: -1px;
}
.side-brand .brand-logo { width: 40px; height: 40px; }
.foot-brand .brand-logo { width: 40px; height: 40px; }

/* --------------------------------------------------------------------------
   3. Theme toggle button — shared by the public nav and the dashboard topbar
   -------------------------------------------------------------------------- */
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex: none;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease;
}
.theme-toggle:hover {
  background: var(--primary-soft);
  color: var(--primary-700);
  border-color: var(--primary);
}
.theme-toggle:active { transform: scale(.94); }
.theme-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.theme-toggle svg { width: 19px; height: 19px; display: block; }

/* Icon swap: show sun in dark mode, moon in light mode */
.theme-toggle .ico-sun { display: none; }
html[data-theme='dark'] .theme-toggle .ico-sun { display: block; }
html[data-theme='dark'] .theme-toggle .ico-moon { display: none; }

/* Smooth the transition when the user flips the theme (not on first paint) */
html.theme-anim,
html.theme-anim body,
html.theme-anim body * {
  transition: background-color .22s ease, color .18s ease, border-color .22s ease !important;
}

/* ==========================================================================
   Auth pages — dark overrides
   The brand panel is already dark in both themes; only the form panel and the
   pending/confirmation state need adjusting.
   ========================================================================== */
html[data-theme='dark'] .auth-panel { background: var(--surface); }
html[data-theme='dark'] .auth-head h2 { color: var(--text); }

html[data-theme='dark'] .auth-head .auth-eyebrow {
  background: #16301f;
  color: #7cd7a1;
}

html[data-theme='dark'] .pw-toggle:hover { background: #272c34; }

html[data-theme='dark'] .auth-steps,
html[data-theme='dark'] .auth-demo,
html[data-theme='dark'] .auth-hint {
  background: var(--surface-2);
  border-color: var(--border);
}

html[data-theme='dark'] .auth-step-n {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-3);
}

html[data-theme='dark'] .auth-demo-row code {
  background: #1a1e24;
  border-color: var(--border);
  color: var(--text-2);
}

html[data-theme='dark'] .auth-done-ico {
  background: #332a10;
  border-color: #4a3c17;
  color: #e0bc4a;
}
html[data-theme='dark'] .auth-done-ico.is-ok {
  background: #16301f;
  border-color: #22452f;
  color: #7cd7a1;
}

html[data-theme='dark'] .auth-link,
html[data-theme='dark'] .auth-alt a,
html[data-theme='dark'] .auth-alt button,
html[data-theme='dark'] .auth-demo-fill { color: #7cd7a1; }

/* --------------------------------------------------------------------------
   CCTV + Marketplace — dark overrides
   The camera tiles stay dark in both themes (that's how a monitor wall reads),
   but the surrounding panels, pills and cards follow the theme.
   -------------------------------------------------------------------------- */
html[data-theme='dark'] .cctv-pill.ok   { background: #16301f; color: #7cd7a1; }
html[data-theme='dark'] .cctv-pill.warn { background: #332a10; color: #e0bc4a; }
html[data-theme='dark'] .cctv-pill.off  { background: #3a1c1c; color: #f09494; }

html[data-theme='dark'] .ev-dot.hi  { box-shadow: 0 0 0 3px #3a1c1c; }
html[data-theme='dark'] .ev-dot.mid { box-shadow: 0 0 0 3px #332a10; }
html[data-theme='dark'] .ev-dot.lo  { box-shadow: 0 0 0 3px #262b33; background: #6b7683; }

html[data-theme='dark'] .rec-thumb { background: #16301f; color: #7cd7a1; }

html[data-theme='dark'] .ev-inline {
  background: var(--surface-2);
  border-color: var(--border);
}

html[data-theme='dark'] .cam-tile { border-color: #262b33; }
html[data-theme='dark'] .cam-tile:hover,
html[data-theme='dark'] .cam-tile:focus-visible { border-color: #4f9e74; }

html[data-theme='dark'] .cam-foot { background: #161b21; border-top-color: rgba(255,255,255,.06); }

/* Marketplace */
html[data-theme='dark'] .mk-thumb { background: linear-gradient(160deg, #1b2028, #222831); }
html[data-theme='dark'] .mk-price { color: #7cd7a1; }
html[data-theme='dark'] .mk-seller { border-top-color: var(--border); }
