/*
 * OrgTrax v2 — custom styles.
 * Design tokens and theme variables.
 * No inline styles in templates — all styling here or in Bootstrap classes.
 *
 * Layer order:
 *   1. :root tokens — brand-specific CSS custom properties, light mode defaults
 *   2. [data-bs-theme="dark"] overrides — dark mode surface/text shifts
 *   3. Component tweaks — small adjustments layered on top of Bootstrap utilities
 */

/* ============================================================
   1. DESIGN TOKENS — light mode defaults
   ============================================================ */
:root {
  /* Brand palette */
  --orgtrax-brand-primary:   #05234F;   /* VA-1: navy brand anchor (was #0d6efd) */
  --orgtrax-brand-accent:    #6610f2;   /* Indigo accent for secondary actions */
  --orgtrax-brand-navy:      #05234F;   /* Deep navy — icon tile, sampled from the mark */
  --orgtrax-brand-success:   #198754;
  --orgtrax-brand-warning:   #ffc107;
  --orgtrax-brand-danger:    #dc3545;
  --orgtrax-brand-info:      #0dcaf0;

  /* VA-1 brand ramp — navy steps (light) + derived bright blues (dark controls) */
  --orgtrax-navy-700: #0d3a75;   /* hover/lighter step */
  --orgtrax-navy-800: #0a3061;   /* active/pressed step */
  --orgtrax-blue-500: #2f6fd0;   /* dark-mode control base */
  --orgtrax-blue-400: #4d8be8;   /* dark-mode hover */
  --orgtrax-blue-300: #7fb0f5;   /* dark-mode links */

  /* VA-1 Bootstrap primary + link + focus-ring overrides (light) */
  --bs-primary: #05234F;
  --bs-primary-rgb: 5, 35, 79;
  --bs-link-color: #0a4fa8;
  --bs-link-color-rgb: 10, 79, 168;
  --bs-link-hover-color: #05234F;
  --bs-link-hover-color-rgb: 5, 35, 79;
  --bs-focus-ring-color: rgba(5, 35, 79, 0.25);

  /* Surface tokens — light mode */
  --orgtrax-surface-page:    var(--bs-body-bg);
  --orgtrax-surface-card:    var(--bs-body-bg);
  --orgtrax-surface-subtle:  var(--bs-secondary-bg);

  /* Text tokens — light mode */
  --orgtrax-text-primary:    var(--bs-body-color);
  --orgtrax-text-secondary:  var(--bs-secondary-color);
  --orgtrax-text-muted:      var(--bs-tertiary-color);

  /* Border tokens */
  --orgtrax-border-color:    var(--bs-border-color);
  --orgtrax-border-radius:   var(--bs-border-radius);

  /* VA-3 module accents — one hue per module, used for the icon tint AND the
     dashboard card's stat, so each card reads as one signal. Light values are
     copied from landing.css's .icon-* rules (which keep their own hardcoded
     copies; landing.css loads after this file, so landing is unaffected). */
  --orgtrax-mod-at:      #0d6efd;
  --orgtrax-mod-at-bg:   rgba(13, 110, 253, 0.12);
  --orgtrax-mod-bt:      #198754;
  --orgtrax-mod-bt-bg:   rgba(25, 135, 84, 0.12);
  --orgtrax-mod-hp:      #6610f2;
  --orgtrax-mod-hp-bg:   rgba(102, 16, 242, 0.12);
  /* Fiduciary has no landing card; it takes the brand navy — the anchor hue
     suits the module that exists to keep an account accountable. */
  --orgtrax-mod-fid:     var(--orgtrax-brand-navy);
  --orgtrax-mod-fid-bg:  rgba(5, 35, 79, 0.10);

  /* Typography */
  --orgtrax-font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Spacing rhythm */
  --orgtrax-spacer-xs: 0.25rem;
  --orgtrax-spacer-sm: 0.5rem;
  --orgtrax-spacer-md: 1rem;
  --orgtrax-spacer-lg: 1.5rem;
  --orgtrax-spacer-xl: 3rem;
}

/* ============================================================
   2. DARK MODE OVERRIDES
   Bootstrap 5.3 flips --bs-* vars when data-bs-theme="dark".
   We shadow our tokens here so component code never needs to
   branch on theme — just use the token.
   ============================================================ */
[data-bs-theme="dark"] {
  /* Surface tokens — dark mode */
  --orgtrax-surface-page:   var(--bs-body-bg);
  --orgtrax-surface-card:   var(--bs-body-bg);
  --orgtrax-surface-subtle: var(--bs-secondary-bg);

  /* Text tokens — dark mode */
  --orgtrax-text-primary:   var(--bs-body-color);
  --orgtrax-text-secondary: var(--bs-secondary-color);
  --orgtrax-text-muted:     var(--bs-tertiary-color);

  /* Border tokens — dark mode */
  --orgtrax-border-color: var(--bs-border-color);

  /* VA-3: the light accents are too dense to read on a dark surface — lift each
     to its Bootstrap dark-emphasis counterpart, and open the tints up a step.
     Navy would vanish entirely, so fiduciary borrows the VA-1 blue ramp. */
  --orgtrax-mod-at:      #6ea8fe;
  --orgtrax-mod-at-bg:   rgba(110, 168, 254, 0.16);
  --orgtrax-mod-bt:      #75b798;
  --orgtrax-mod-bt-bg:   rgba(117, 183, 152, 0.16);
  --orgtrax-mod-hp:      #a98eda;
  --orgtrax-mod-hp-bg:   rgba(169, 142, 218, 0.16);
  --orgtrax-mod-fid:     var(--orgtrax-blue-300);
  --orgtrax-mod-fid-bg:  rgba(127, 176, 245, 0.16);

  /* VA-1: navy is too dark for dark-mode controls — brighten to the blue ramp */
  --bs-primary: #4d8be8;
  --bs-primary-rgb: 77, 139, 232;
  --bs-link-color: #7fb0f5;
  --bs-link-color-rgb: 127, 176, 245;
  --bs-link-hover-color: #a7c9f8;
  --bs-link-hover-color-rgb: 167, 201, 248;
  --bs-focus-ring-color: rgba(77, 139, 232, 0.3);
}

/* ============================================================
   3. LAYOUT HELPERS
   ============================================================ */

/* Sticky footer: body fills viewport; main grows to push footer down */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

/* ============================================================
   4. COMPONENT TWEAKS
   ============================================================ */

/* Navbar brand — use brand primary on hover */
.navbar-brand:hover {
  color: var(--orgtrax-brand-primary);
}

/* Card surfaces use color-scheme-aware background */
.card {
  background-color: var(--orgtrax-surface-card);
  border-color: var(--orgtrax-border-color);
}

/* Monospace utility for access codes, hashes, IDs */
.text-mono {
  font-family: var(--orgtrax-font-mono);
  font-size: 0.875em;
}

/* ============================================================
   ALPINE x-cloak
   Prevents fiduciary cluster (and any other x-cloak element) from flashing
   before Alpine initialises on a non-fiduciary ledger edit form.
   ============================================================ */
[x-cloak] {
  display: none !important;
}

/* ============================================================
   THEME TOGGLE — icon swap
   The toggle button renders both icons; CSS shows/hides per theme.
   No inline style="display:..." needed (strict CSP).
   ============================================================ */
.theme-icon-dark {
  display: none;
}

[data-bs-theme="dark"] .theme-icon-light {
  display: none;
}

[data-bs-theme="dark"] .theme-icon-dark {
  display: inline;
}

/* ============================================================
   HTMX indicator styles
   htmx normally injects these as an inline <style> at runtime, which strict
   CSP (style-src 'self', no 'unsafe-inline') blocks. We disable that injection
   via <meta name="htmx-config" content='{"includeIndicatorStyles": false}'>
   in base.html and ship the equivalent rules here instead.
   ============================================================ */
.htmx-indicator {
  opacity: 0;
  transition: opacity 200ms ease-in;
}
.htmx-request .htmx-indicator {
  opacity: 1;
}
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* ============================================================
   VA-1 — BRAND RETHEME (component rules)
   Navy #05234F anchors light mode; dark mode brightens controls to
   the #4d8be8 blue ramp. Token declarations live in the :root and
   [data-bs-theme="dark"] blocks above; these are the component-level
   rules Bootstrap 5.3 hardcodes (not var-driven).
   ============================================================ */
.btn-primary {
  --bs-btn-bg: #05234F;
  --bs-btn-border-color: #05234F;
  --bs-btn-hover-bg: #0d3a75;
  --bs-btn-hover-border-color: #0d3a75;
  --bs-btn-active-bg: #0a3061;
  --bs-btn-active-border-color: #0a3061;
  --bs-btn-disabled-bg: #05234F;
  --bs-btn-disabled-border-color: #05234F;
  --bs-btn-focus-shadow-rgb: 5, 35, 79;
}
.btn-outline-primary {
  --bs-btn-color: #05234F;
  --bs-btn-border-color: #05234F;
  --bs-btn-hover-bg: #05234F;
  --bs-btn-hover-border-color: #05234F;
  --bs-btn-active-bg: #05234F;
  --bs-btn-active-border-color: #05234F;
  --bs-btn-focus-shadow-rgb: 5, 35, 79;
}

/* Bootstrap 5.3 hardcodes these control colors (not var-driven) —
   explicit overrides required: */
.form-control:focus, .form-select:focus {
  border-color: #7fa4d4;
  box-shadow: 0 0 0 0.25rem rgba(5, 35, 79, 0.25);
}
.form-check-input:checked {
  background-color: #05234F;
  border-color: #05234F;
}
.form-check-input:focus {
  border-color: #7fa4d4;
  box-shadow: 0 0 0 0.25rem rgba(5, 35, 79, 0.25);
}

/* ---- Dark mode: brighten controls, keep brand family ---- */
[data-bs-theme="dark"] .btn-primary {
  --bs-btn-bg: #2f6fd0;
  --bs-btn-border-color: #2f6fd0;
  --bs-btn-hover-bg: #4d8be8;
  --bs-btn-hover-border-color: #4d8be8;
  --bs-btn-active-bg: #275fb4;
  --bs-btn-active-border-color: #275fb4;
  --bs-btn-disabled-bg: #2f6fd0;
  --bs-btn-disabled-border-color: #2f6fd0;
  --bs-btn-focus-shadow-rgb: 77, 139, 232;
}
[data-bs-theme="dark"] .btn-outline-primary {
  --bs-btn-color: #7fb0f5;
  --bs-btn-border-color: #4d8be8;
  --bs-btn-hover-bg: #2f6fd0;
  --bs-btn-hover-border-color: #2f6fd0;
  --bs-btn-active-bg: #2f6fd0;
  --bs-btn-active-border-color: #2f6fd0;
  --bs-btn-focus-shadow-rgb: 77, 139, 232;
}
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  border-color: #4d8be8;
  box-shadow: 0 0 0 0.25rem rgba(77, 139, 232, 0.3);
}
[data-bs-theme="dark"] .form-check-input:checked {
  background-color: #2f6fd0;
  border-color: #2f6fd0;
}

/* ============================================================
   VA-2 — EMPTY STATE PATTERN
   Markup lives in templates/includes/empty_state.html. The glyph is
   inline SVG (currentColor does not inherit through <img>).
   ============================================================ */
.empty-state {
  max-width: 26rem;
  margin: 0 auto;
  padding: 3.5rem 1rem;
  text-align: center;
}
.empty-state-icon {
  width: 3.25rem;
  height: auto;
  color: var(--bs-secondary-color);
  opacity: 0.6;
}
.empty-state h2 { margin-top: 1rem; }
.empty-state p { color: var(--bs-secondary-color); }

/* ============================================================
   VA-3 — DASHBOARD MODULE CARDS
   Markup: templates/core/dashboard.html; glyphs are the shared includes
   in templates/includes/icons/ (inline SVG — currentColor does not
   inherit through <img>).

   Each card carries ONE class, .mod-<key>, which sets the accent pair.
   The icon and the stat both consume it, so a module's glyph and its
   number are the same hue and the card reads as a single signal. Adding
   a module = one .mod-* rule + its two tokens, nothing else.

   .module-icon's geometry is copied from landing.css (which keeps its own
   copy — it is not loaded app-wide).
   ============================================================ */
.module-icon {
  width: 3rem;
  height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
}
.module-icon svg {
  width: 1.5rem;
  height: 1.5rem;
}

.module-tile.mod-at  { --module-accent: var(--orgtrax-mod-at);  --module-accent-bg: var(--orgtrax-mod-at-bg); }
.module-tile.mod-bt  { --module-accent: var(--orgtrax-mod-bt);  --module-accent-bg: var(--orgtrax-mod-bt-bg); }
.module-tile.mod-hp  { --module-accent: var(--orgtrax-mod-hp);  --module-accent-bg: var(--orgtrax-mod-hp-bg); }
.module-tile.mod-fid { --module-accent: var(--orgtrax-mod-fid); --module-accent-bg: var(--orgtrax-mod-fid-bg); }

.module-tile .module-icon {
  background: var(--module-accent-bg);
  color: var(--module-accent);
  margin-bottom: var(--orgtrax-spacer-sm);
}

.module-tile-title {
  color: var(--orgtrax-text-secondary);
  font-weight: 600;
  margin-bottom: var(--orgtrax-spacer-sm);
}

/* The number is the card's payload: it gets the size, the accent, and
   tabular figures so the four cards' stats line up as a column. */
.module-stat {
  font-size: 1.875rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--module-accent);
  margin-bottom: 0.125rem;
}
/* The one place colour leaves module identity — so red on this page always
   means "look here", never "this is HomePay". */
.module-stat.stat-negative { color: var(--bs-danger); }
.module-stat.stat-muted    { color: var(--orgtrax-text-muted); }

.module-stat-label {
  color: var(--orgtrax-text-muted);
  font-size: 0.8125rem;
  margin-bottom: var(--orgtrax-spacer-md);
}

.module-tile-desc {
  font-size: 0.875rem;
  margin-bottom: var(--orgtrax-spacer-md);
}
