/* Moneymate shared design tokens.
   Source of truth: brand guide "Renkler & Font" (Renk-Font.pdf).

   Palette (exact swatch values from the guide):
     #EEE48C  238, 228, 140    0, 4, 41, 7      light gold
     #9C8A3C  156, 138, 60     0, 12, 62, 39    gold
     #000033  0, 0, 51         100, 100, 0, 80  navy
     #000000  0, 0, 0          0, 0, 0, 100     black
   Logo gradient: #9C8A3C -> #F4EA92 -> #CFC26E -> #9C8A3C

   Type: Montserrat (Light 300 / Regular 400 / Medium 500 / SemiBold 600),
   self-hosted under assets/fonts so a card-entry page loads no third-party
   font host. Both files are the same variable font, subset per unicode-range. */

@font-face {
  font-family: "Montserrat";
  font-style: normal;
  /* Variable file; the declared range is limited to the four brand weights so a
     stray font-weight: 700 clamps to SemiBold instead of going off-brand. */
  font-weight: 300 600;
  font-display: swap;
  src: url("fonts/Montserrat-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Montserrat";
  font-style: normal;
  font-weight: 300 600;
  font-display: swap;
  src: url("fonts/Montserrat-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;

  /* ---- Brand constants (never theme-dependent) ---- */
  --brand-gold: #9C8A3C;
  --brand-gold-light: #EEE48C;
  --brand-navy: #000033;
  --brand-black: #000000;

  /* Logo gradient stops */
  --gold-deep: #7d6d2c;
  --gold: #9C8A3C;
  --gold-mid: #CFC26E;
  --gold-light: #F4EA92;

  --font-sans: "Montserrat", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;

  /* ---- Light theme: white surfaces, navy-derived neutrals ---- */
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #f8f8f8;
  --text: #000000;
  --text-muted: #545454;
  --border: #e0e0e0;
  --border-strong: #c4c4c4;
  --accent: #9C8A3C;
  --accent-hover: #7d6d2c;
  --accent-soft: #faf6e2;
  --danger: #b4321f;
  --danger-soft: #fdf2ef;
  --success: #2f6b46;
  --success-soft: #edf5f0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px -12px rgba(0, 0, 0, .24);
  --gold-gradient: linear-gradient(100deg, var(--gold) 0%, var(--gold-light) 36%, var(--gold-mid) 67%, var(--gold) 100%);
  /* Text that sits on the gold gradient (buttons, active pills). */
  --on-gold: #000000;
}

/* The brand ships four weights (300/400/500/600). Browser defaults for h1-h6,
   b, strong and th are `bold` (700), which has no brand cut — clamp them to
   SemiBold so headings render on-brand instead of being synthesised. */
h1,
h2,
h3,
h4,
h5,
h6,
b,
strong,
th {
  font-weight: 600;
}

/* System is the original Moneymate warm palette. It still follows the OS for
   light/dark, but remains visually distinct from the explicit black Dark theme. */
:root:not([data-theme]),
:root[data-theme="system"] {
  --bg: #f7f5ee;
  --surface: #ffffff;
  --surface-2: #faf8f1;
  --text: #1c1a12;
  --text-muted: #6f6a58;
  --border: #e7e1cf;
  --border-strong: #d3caab;
  --accent: #8a7830;
  --accent-hover: #6f6025;
  --accent-soft: #f6f1dd;
  --danger: #b4321f;
  --danger-soft: #fdf2ef;
  --success: #5f7d2c;
  --success-soft: #f2f6e8;
  --shadow: 0 1px 2px rgba(60, 50, 20, .05), 0 8px 24px -12px rgba(60, 50, 20, .22);
  --on-gold: #241f10;
}

/* Explicit dark choice. Keep this selector outside the media query so it wins
   even when the operating system is light. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0d0d0d;
  --surface-2: #161616;
  --text: #f5f5f5;
  --text-muted: #a8a8a8;
  --border: #262626;
  --border-strong: #3d3d3d;
  --accent: #EEE48C;
  --accent-hover: #F4EA92;
  --accent-soft: #1a1710;
  --danger: #f0937f;
  --danger-soft: #2c1210;
  --success: #7fc9a0;
  --success-soft: #0d1f16;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -12px rgba(0, 0, 0, .7);
}

/* High Contrast is intentionally black/white/gold rather than another visual
   theme. Pure text/boundary values, no shadows, and a strong focus outline
   preserve structure without relying on subtle tonal differences. */
:root[data-theme="high-contrast"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #000000;
  --surface-2: #000000;
  --text: #ffffff;
  --text-muted: #ffffff;
  --border: #ffffff;
  --border-strong: #ffffff;
  --accent: #EEE48C;
  --accent-hover: #F4EA92;
  --accent-soft: #000000;
  --danger: #ffb4a8;
  --danger-soft: #000000;
  --success: #b6ffcf;
  --success-soft: #000000;
  --shadow: none;
}

:root[data-theme="high-contrast"] :focus-visible {
  outline: 3px solid #EEE48C !important;
  outline-offset: 3px;
}

:root[data-theme="high-contrast"] body::before {
  display: none;
}

/* With no JavaScript the missing attribute still follows the OS. The runtime
   writes `system` before CSS is parsed when JavaScript is available. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #0f0e09;
    --surface: #191710;
    --surface-2: #211e15;
    --text: #f5f1e2;
    --text-muted: #a79f86;
    --border: #2e2a1d;
    --border-strong: #45402c;
    --accent: #d9c96f;
    --accent-hover: #ecdc8a;
    --accent-soft: #2a2517;
    --danger: #f0937f;
    --danger-soft: #2c1712;
    --success: #a8c46a;
    --success-soft: #1e2213;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -12px rgba(0, 0, 0, .7);
    --on-gold: #241f10;
  }
}

/* Shared top-bar theme icon. The language control remains page-owned because
   its links preserve different request context on checkout versus receipt. */
.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: .5rem;
  margin-inline-start: auto;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  background: var(--surface-2);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, transform .1s;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.theme-toggle:active {
  transform: scale(.96);
}

.theme-toggle:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

.theme-icon {
  display: none;
}

:root:not([data-theme]) .theme-icon-system,
:root[data-theme="system"] .theme-icon-system,
:root[data-theme="light"] .theme-icon-light,
:root[data-theme="dark"] .theme-icon-dark,
:root[data-theme="high-contrast"] .theme-icon-high-contrast {
  display: inline;
}

@media (max-width: 560px) {
  .topbar-actions {
    width: 100%;
  }
}

@media print {
  .theme-toggle {
    display: none !important;
  }
}
