/* ===========================================================================
   Finperiti — application design system
   Petrol/teal brand, Manrope type. Replaces Bootstrap entirely.
   Tokens mirror docs/brand.html so the app and the brand book stay in sync.
   =========================================================================== */

/* Theme: light / dark / system via the CSS color-scheme keyword + light-dark().
   - :root defaults to "light dark" → follows the OS (System).
   - [data-theme="light|dark"] (set by the toggle, persisted in localStorage) forces one scheme.
   Every theme-dependent token is a light-dark(<light>, <dark>) pair, so there's a single source of truth
   and no duplicated @media override block. */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

:root {
  --font-sans: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;

  /* Brand palette (docs/brand.html) — constant across themes. */
  --petrol: #0e4f5e;
  --teal: #0e9f90;
  --teal-deep: #0b7e72;
  --steel: #5b6b7c;
  --mist: #eaf0f1;
  --bright: #5de6d2;

  /* Surface / ink tokens — light value first, dark second. */
  --ink:          light-dark(#08191c, #e6efef);
  --bg:           light-dark(#f6f7f9, #0c1416);
  --surface:      light-dark(#ffffff, #121d20);
  --surface-2:    light-dark(#eef2f3, #16252a);
  --ink-soft:     light-dark(#475061, #aec2c2);
  --ink-faint:    light-dark(#636d7e, #8fa3a3);
  --border:       light-dark(#e0e6e8, #213035);
  --border-strong:light-dark(#cdd6d9, #324349);
  --heading:      light-dark(#0e4f5e, #cfe7e6);

  --accent: var(--petrol);
  --accent-ink: light-dark(#0a6f64, #3fd0be);
  --accent-soft: light-dark(#eaf0f1, #16252a);
  --green: light-dark(#1c7a5b, #46c996);
  --orange: light-dark(#a34a07, #f0a94e);
  --amber: #f59e0b;
  --red: light-dark(#c0352a, #ff8a7d);

  --shadow-sm: 0 1px 2px rgba(8, 25, 28, .06), 0 1px 3px rgba(8, 25, 28, .08);
  --shadow-md: 0 4px 12px rgba(8, 25, 28, .08), 0 2px 6px rgba(8, 25, 28, .05);
  --radius: 12px;
  --radius-sm: 8px;

  /* Readable text on an --accent (petrol) fill. */
  --on-accent: #ffffff;
  /* Modal/overlay scrim — a brand-dark veil, kept dark in both themes. */
  --scrim: light-dark(rgb(8 25 28 / .45), rgb(0 0 0 / .6));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; letter-spacing: -.015em; }
h1 { font-size: 2rem; margin: 0 0 .5rem; font-weight: 800; }
/* Blazor's FocusOnNavigate focuses the route <h1> on every navigation (good for screen readers), but the
   <h1> isn't interactive, so the browser's focus ring just looks like a stray highlight. Suppress it while
   keeping the element focusable/announced. */
h1:focus, h1:focus-visible { outline: none; }
h2 { font-size: 1.4rem; margin: 0 0 .75rem; font-weight: 700; }
h3 { font-size: 1.12rem; margin: 1.5rem 0 .6rem; font-weight: 700; }
p { margin: 0 0 1rem; }
.lead { font-size: 1.12rem; color: var(--ink-soft); max-width: 70ch; margin: 0 0 1.75rem; }

a { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration: none; }

code, .mono { font-family: var(--font-mono); font-size: .86em; }

/* ---------- Cards ---------- */
.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin: 1.5rem 0; }

.card {
  display: block;
  padding: 1.4rem 1.5rem;
  margin: 0 0 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
}
.cards .card { margin: 0; transition: transform .12s, box-shadow .12s, border-color .12s; }
a.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); text-decoration: none; }
.card h2, .card h3 { margin-top: 0; }
.card p:last-child { margin-bottom: 0; }

/* ---------- Forms ---------- */
.field { margin: 0 0 1rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .3rem; }
.field small { display: block; margin-top: .35rem; font-size: .8rem; color: var(--ink-soft); }

/* Text-like form controls. Checkboxes/radios are excluded so they keep their native box. */
input:not([type=checkbox]):not([type=radio]), select, textarea {
  font: inherit;
  width: 100%;
  max-width: 32rem;
  padding: .55rem .7rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--teal-deep);
  box-shadow: 0 0 0 3px rgba(14, 159, 144, .18);
}

/* Checkboxes & radios: native size, brand accent, and a clickable label row. */
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent-ink); cursor: pointer; }
.check {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: .5rem;
  margin: 0 0 1rem;
  font-size: .95rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.check input { margin: 0; }

/* ---------- Buttons ---------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: .55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--petrol);
  color: #fff;
  transition: background .12s, box-shadow .12s;
}
button:hover, .btn:hover { background: var(--teal-deep); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(14, 159, 144, .35); }
/* :not(...) excludes .button-primary/-secondary/-danger — those own their full colour story (see components.css) and a same-or-higher-specificity generic rule here would otherwise clobber it, especially on hover. */
button[type="button"]:not(.button-primary):not(.button-secondary):not(.button-danger) { background: var(--surface-2); color: var(--ink); border-color: var(--border-strong); }
button[type="button"]:not(.button-primary):not(.button-secondary):not(.button-danger):hover { background: var(--border); } /* was var(--mist), a constant (non-theme-aware) tint that broke dark-mode text contrast */

/* ---------- Tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 1rem 0;
}
th, td { text-align: left; padding: .8rem .95rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-soft); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* Required-field marker: a red asterisk after the label, instead of the word "required". */
label.required::after { content: " *"; color: var(--red); font-weight: 700; }

/* ---------- Validation ---------- */
.valid.modified:not([type=checkbox]) { border-color: var(--green); }
.invalid { border-color: var(--red); }
.validation-message { color: var(--red); font-size: .85rem; }

/* ---------- Country coverage (signup) ----------
   The flag and map visuals live in the Finperiti.Geography component library; these are just the
   page-level layout (legend + flag wrapping) and the brand theming of the library's CSS variables. */
.coverage-legend { display: flex; flex-wrap: wrap; gap: 1.25rem; font-size: .85rem; color: var(--ink-soft); margin: .25rem 0 1rem; }
.coverage-legend .dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
.coverage-legend .dot-ok { background: var(--green); }
.coverage-legend .dot-no { background: var(--ink-faint); }

.flag-grid { display: flex; flex-wrap: wrap; gap: .35rem; margin: .25rem 0 1.25rem; }

/* Data-boundary selection table (signup): checkbox + per-boundary coverage in one grid. */
.boundary-table td:nth-child(4), .boundary-table th:nth-child(4),
.boundary-table td:nth-child(5), .boundary-table th:nth-child(5) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.boundary-table td { vertical-align: middle; }
.boundary-table tbody tr.is-selected { background: color-mix(in srgb, var(--green) 8%, var(--surface)); }
.boundary-table tbody tr.is-selected:hover { background: color-mix(in srgb, var(--green) 12%, var(--surface)); }
.boundary-table input[type=checkbox] { width: 1.05rem; height: 1.05rem; }

/* Theme the reusable map to the brand palette. */
.coverage-map-host {
  --fpg-map-bg: var(--surface-2);
  --fpg-map-border: var(--border);
  --fpg-map-land: var(--border-strong);
  --fpg-map-highlight: var(--teal);
  --fpg-map-hover: var(--petrol);
  --fpg-map-credit: var(--ink-faint);
}

/* ---------- Blazor error UI ---------- */
.blazor-error-boundary {
  background: var(--red);
  padding: 1rem 1.25rem;
  color: #fff;
  border-radius: var(--radius-sm);
}
.blazor-error-boundary::after { content: "An error has occurred."; }

/* Blazor moves focus to the page heading after each navigation (FocusOnNavigate) so screen readers announce
   the new page; that focus is programmatic (tabindex=-1), so it must not draw a highlight box for everyone. */
h1[tabindex="-1"]:focus, h1:focus:not(:focus-visible) { outline: none; } /* focus-on-navigate */
