/* ==========================================================================
   THEME - the design system every page shares.

   1. Fonts            self-hosted, no requests to other sites
   2. Tokens           colours, type, radius, shadow (light + dark)
   3. Base             reset and typography
   4. Components       logo, buttons, form fields, alerts, pills, cards,
                       theme switch, modal, toast, spinner, skeleton

   Brand colours come from private/brand.php (as --brand-* variables).
   Everything else is derived here. To restyle the product, change tokens,
   not components.
   ========================================================================== */

/* 1. Fonts ---------------------------------------------------------------- */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("fonts/bricolage-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("fonts/bricolage-latin-ext.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+1E00-1E9F, U+20A0-20AB, U+20AD-20C0, U+2113;
}
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Onest has no rupee sign; borrow it from the display face. */
@font-face {
  font-family: "Onest";
  src: url("fonts/bricolage-latin-ext.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+20B9;
}

/* 2. Tokens --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --font-display: "Bricolage Grotesque", "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* brand */
  --primary: var(--brand-primary, #2747F5);          /* solid fills: buttons, active states */
  --primary-contrast: #FFFFFF;                        /* text on --primary */
  --link: var(--brand-primary, #2747F5);              /* coloured text and icons */
  --accent: var(--brand-accent, #FFAE1F);             /* a real person is here */
  --accent-contrast: #2B1B00;                         /* text on --accent */
  --accent-text: #7C5A1F;                             /* yellow-family text on light tints */

  /* surfaces and text */
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --surface-2: #F1F4FA;
  --surface-3: #E7ECF6;
  --ink: var(--brand-ink, #0F1730);
  --text: #1B2440;
  --muted: #5B6680;
  --faint: #646E86;
  --line: #E2E7F1;
  --line-strong: #CBD3E2;

  /* status */
  --success: #0A7551;
  --warning: #8F5B00;
  --danger: #C62C38;
  --info: var(--link);

  --shadow-1: 0 1px 2px rgba(15, 23, 48, .06);
  --shadow-2: 0 10px 28px -12px rgba(15, 23, 48, .22), 0 2px 6px rgba(15, 23, 48, .05);
  --shadow-3: 0 30px 70px -28px rgba(15, 23, 48, .38), 0 6px 18px rgba(15, 23, 48, .06);

  --radius-s: 8px;       /* controls */
  --radius-m: 14px;      /* cards */
  --radius-l: 22px;      /* large panels */
  --radius-pill: 999px;

  --control-h: 42px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[data-theme="dark"] {
  color-scheme: dark;

  --primary: #3D5BFF;
  --primary-contrast: #FFFFFF;
  --link: var(--brand-primary-dark, #8EA2FF);
  --accent: #FFBE45;
  --accent-contrast: #2B1B00;
  --accent-text: #F9D799;

  --bg: #0A1022;
  --surface: #111A33;
  --surface-2: #17223F;
  --surface-3: #1F2C4E;
  --ink: #F2F5FF;
  --text: #D9E0F2;
  --muted: #98A4C0;
  --faint: #808CAA;
  --line: #232F50;
  --line-strong: #33416A;

  --success: #4FD1A1;
  --warning: #F3BC55;
  --danger: #FF8088;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 12px 30px -12px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-3: 0 30px 70px -24px rgba(0, 0, 0, .85), 0 6px 18px rgba(0, 0, 0, .35);
}

/* Derived colours: tints of the tokens above on the current surface. */
:root, [data-theme="dark"] {
  --primary-hover: color-mix(in srgb, var(--primary) 86%, #000);
  --primary-soft: color-mix(in srgb, var(--link) 11%, var(--surface));
  --primary-line: color-mix(in srgb, var(--link) 30%, var(--surface));
  --accent-soft: color-mix(in srgb, var(--accent) 20%, var(--surface));
  --success-soft: color-mix(in srgb, var(--success) 13%, var(--surface));
  --warning-soft: color-mix(in srgb, var(--warning) 14%, var(--surface));
  --danger-soft: color-mix(in srgb, var(--danger) 11%, var(--surface));
  --danger-line: color-mix(in srgb, var(--danger) 32%, var(--surface));
  --info-soft: var(--primary-soft);
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--link) 32%, transparent);
  --overlay: color-mix(in srgb, #050914 62%, transparent);
}

/* 3. Base ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -.02em;
  margin: 0 0 .5em;
  font-weight: 700;
  text-wrap: balance;
}
p { margin: 0 0 1em; }
a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd { font-family: var(--font-mono); font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
::selection { background: color-mix(in srgb, var(--link) 26%, transparent); }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }

.icon { flex: none; display: inline-block; vertical-align: -.18em; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* 4. Components ----------------------------------------------------------- */

/* Logo: mark + two-weight wordmark */
.logo {
  display: inline-flex; align-items: center; gap: 9px;
  color: var(--ink); text-decoration: none;
  --logo-primary: var(--link);
  --logo-accent: var(--accent);
}
.logo-word {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 500; letter-spacing: -.03em; line-height: 1;
}
.logo-word b { font-weight: 800; }
.logo-tag {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill);
  padding: 2px 8px; margin-left: 2px; line-height: 1.4;
}

/* Buttons */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 18px;
  border: 1px solid var(--btn-line); border-radius: var(--radius-s);
  background: var(--btn-bg); color: var(--btn-fg);
  font-family: var(--font-body); font-size: 14.5px; font-weight: 600; line-height: 1.2;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .08s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { --btn-bg: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--link); }
.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--primary-contrast); --btn-line: transparent; }
.btn-primary:hover { --btn-bg: var(--primary-hover); }
.btn-secondary { --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-line: var(--line-strong); }
.btn-ghost { --btn-bg: transparent; --btn-line: transparent; --btn-fg: var(--text); }
.btn-ghost:hover { --btn-bg: var(--surface-2); }
.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-line: var(--danger-line); }
.btn-danger:hover { --btn-bg: color-mix(in srgb, var(--danger) 18%, var(--surface)); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--accent-contrast); --btn-line: transparent; }
.btn-accent:hover { --btn-bg: color-mix(in srgb, var(--accent) 88%, #000); }

.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 7px; }
.btn-lg { min-height: 50px; padding: 0 24px; font-size: 16px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }

/* A button that is working: label stays, a spinner joins it. */
.btn.is-loading { pointer-events: none; opacity: .85; }
.btn.is-loading::before {
  content: ""; width: 15px; height: 15px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Form fields */
.field { margin-bottom: 18px; }
.field > label, .label {
  display: block; margin-bottom: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--ink);
}
.label-note { font-weight: 400; color: var(--muted); }
.input, .form-input, .form-textarea, select.form-input {
  display: block; width: 100%;
  min-height: var(--control-h); padding: 9px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink);
  font-family: var(--font-body); font-size: 15px; line-height: 1.4;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.input::placeholder, .form-input::placeholder, .form-textarea::placeholder { color: var(--faint); opacity: 1; }
.input:hover, .form-input:hover, .form-textarea:hover { border-color: var(--faint); }
.input:focus, .form-input:focus, .form-textarea:focus, select.form-input:focus {
  outline: none; border-color: var(--link); box-shadow: var(--focus-ring);
}
.input[readonly], .form-input[readonly], .input:disabled, .form-input:disabled {
  background: var(--surface-2); color: var(--muted); cursor: default;
}
textarea.input, .form-textarea { min-height: 96px; resize: vertical; }
select.input, select.form-input {
  appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237C879F' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input.is-invalid, .form-input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus, .form-input.is-invalid:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 26%, transparent); }
.field-hint, .form-help { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.field-error {
  display: flex; align-items: flex-start; gap: 6px;
  margin-top: 6px; font-size: 13px; font-weight: 500; color: var(--danger);
}
.field-error:empty { display: none; }

/* Field with a button inside (show / hide password) */
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; }
.input-action {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 36px; height: 34px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer;
}
.input-action:hover { color: var(--ink); background: var(--surface-2); }

/* Alerts */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 14px; margin-bottom: 16px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--text);
  font-size: 14px; line-height: 1.5;
}
.alert .icon { margin-top: 2px; }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, var(--surface)); color: var(--success); }
.alert-warn, .alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, var(--surface)); color: var(--warning); }
.alert-error, .alert-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: var(--primary-line); color: var(--link); }
.alert a { color: inherit; font-weight: 600; }

/* Pills: small status labels with a dot */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--muted);
  font-size: 12.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill-green { background: var(--success-soft); color: var(--success); }
.pill-amber { background: var(--warning-soft); color: var(--warning); }
.pill-red { background: var(--danger-soft); color: var(--danger); }
.pill-blue { background: var(--primary-soft); color: var(--link); }
.pill-gray { background: var(--surface-2); color: var(--muted); }
.pill-live { background: var(--accent-soft); color: var(--accent-text); }
.pill-plain::before { display: none; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 22px;
}

/* Theme switch */
.theme-toggle {
  width: 38px; height: 38px; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--ink); background: var(--surface-2); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--link); }
.theme-toggle .icon { grid-area: 1 / 1; transition: transform .35s var(--ease), opacity .2s; }
.theme-icon-moon { opacity: 0; transform: rotate(-60deg) scale(.6); }
[data-theme="dark"] .theme-icon-moon { opacity: 1; transform: none; }
[data-theme="dark"] .theme-icon-sun { opacity: 0; transform: rotate(60deg) scale(.6); }

/* Modal: confirmations and short forms */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 20px;
  background: var(--overlay);
  animation: fade-in .15s ease-out;
}
.modal {
  width: min(440px, 100%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-m);
  box-shadow: var(--shadow-3);
  padding: 24px;
  animation: modal-in .2s var(--ease);
}
.modal h2 { font-size: 19px; margin: 0 0 8px; }
.modal p { margin: 0; color: var(--muted); font-size: 14.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* Toasts: short confirmations after an action */
.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 210;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
  padding: 12px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in .25s var(--ease);
}
.toast.is-error { background: var(--danger); color: #fff; }
[data-theme="dark"] .toast.is-error { color: #2A0508; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* Loading: spinner and skeleton lines */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--line-strong); border-top-color: var(--link); border-radius: 50%;
  animation: spin .7s linear infinite;
}
.skeleton {
  display: block; height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 45%, var(--surface-2) 65%);
  background-size: 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Text helpers */
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-small { font-size: 13px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
