/* ---------------------------------------------------------------------------
   Tokens

   Two independent palettes on purpose:

   --sl-*    the brand. Teal, used for anything the visitor can act on.
   --chart-* the data palette. Blue/orange/red, validated for colour-vision
             deficiency against the surfaces charts actually paint on. It is
             deliberately NOT the brand colour: recolouring data to match a
             logo trades away an accessibility guarantee for tidiness.
--------------------------------------------------------------------------- */

:root {
  /* Onest is a variable face (400-800 in one file per subset); IBM Plex Mono
     carries the numbers, where tabular figures keep table columns aligned. */
  --bs-body-font-family: Onest, system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-font-monospace: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --bs-body-letter-spacing: -0.005em;

  --sl-brand: #1d6f6a;
  --sl-brand-hover: #185c58;
  --sl-brand-active: #14504c;
  --sl-brand-soft: #e8f2f1;
  --sl-brand-rgb: 29, 111, 106;
  --sl-on-brand: #ffffff;
  --sl-quiet: #4a5754;

  --chart-series-1: #2a78d6;
  --chart-series-2: #eb6834;
  --chart-critical: #d03b3b;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --chart-surface: #ffffff;
  --chart-ink: #0b0b0b;

  --sl-navbar-bg: #ffffff;
}

[data-bs-theme="dark"] {
  /* Lighter teal: the light-mode brand drops to 1.4:1 on a dark ground. */
  --sl-brand: #2a9189;
  --sl-brand-hover: #34a39b;
  --sl-brand-active: #45b5ac;
  --sl-brand-soft: #16302e;
  --sl-brand-rgb: 42, 145, 137;
  --sl-on-brand: #06100f;
  --sl-link: #45b5ac;
  --sl-quiet: #a9b6b3;

  --chart-series-1: #3987e5;
  --chart-series-2: #d95926;
  --chart-critical: #d03b3b;
  --chart-grid: #2a3432;
  --chart-axis: #3d4947;
  --chart-muted: #8b9996;
  --chart-surface: #161d1c;
  --chart-ink: #e8edec;

  --bs-body-bg: #0e1413;
  --bs-body-bg-rgb: 14, 20, 19;
  --bs-body-color: #e8edec;
  --bs-body-color-rgb: 232, 237, 236;
  --bs-emphasis-color: #ffffff;
  --bs-secondary-color: rgba(232, 237, 236, 0.72);
  --bs-secondary-bg: #1b2322;
  --bs-tertiary-bg: #161d1c;
  --bs-tertiary-color: rgba(232, 237, 236, 0.5);
  --bs-border-color: #2a3432;
  --bs-border-color-translucent: rgba(255, 255, 255, 0.12);
  --bs-heading-color: #ffffff;

  --sl-navbar-bg: #121917;
}

/* --- Bootstrap's blue -> the brand ---------------------------------------- */

:root,
[data-bs-theme="dark"] {
  --bs-primary: var(--sl-brand);
  --bs-primary-rgb: var(--sl-brand-rgb);
  --bs-primary-text-emphasis: var(--sl-brand-active);
  --bs-primary-bg-subtle: var(--sl-brand-soft);
  --bs-primary-border-subtle: var(--sl-brand);
  --bs-link-color: var(--sl-link, var(--sl-brand));
  --bs-link-color-rgb: var(--sl-brand-rgb);
  --bs-link-hover-color: var(--sl-brand-hover);
  --bs-link-hover-color-rgb: var(--sl-brand-rgb);
  --bs-focus-ring-color: rgba(var(--sl-brand-rgb), 0.3);
}

.btn-primary {
  --bs-btn-color: var(--sl-on-brand);
  --bs-btn-bg: var(--sl-brand);
  --bs-btn-border-color: var(--sl-brand);
  --bs-btn-hover-color: var(--sl-on-brand);
  --bs-btn-hover-bg: var(--sl-brand-hover);
  --bs-btn-hover-border-color: var(--sl-brand-hover);
  --bs-btn-active-color: var(--sl-on-brand);
  --bs-btn-active-bg: var(--sl-brand-active);
  --bs-btn-active-border-color: var(--sl-brand-active);
  --bs-btn-disabled-color: var(--sl-on-brand);
  --bs-btn-disabled-bg: var(--sl-brand);
  --bs-btn-disabled-border-color: var(--sl-brand);
  --bs-btn-focus-shadow-rgb: var(--sl-brand-rgb);
}

.btn-outline-primary {
  --bs-btn-color: var(--sl-link, var(--sl-brand));
  --bs-btn-border-color: var(--sl-brand);
  --bs-btn-hover-color: var(--sl-on-brand);
  --bs-btn-hover-bg: var(--sl-brand);
  --bs-btn-hover-border-color: var(--sl-brand);
  --bs-btn-active-color: var(--sl-on-brand);
  --bs-btn-active-bg: var(--sl-brand);
  --bs-btn-active-border-color: var(--sl-brand);
  --bs-btn-disabled-color: var(--sl-brand);
  --bs-btn-disabled-border-color: var(--sl-brand);
  --bs-btn-focus-shadow-rgb: var(--sl-brand-rgb);
}

.btn-link {
  --bs-btn-color: var(--sl-link, var(--sl-brand));
  --bs-btn-hover-color: var(--sl-brand-hover);
}

/* Bootstrap's secondary grey reads at 3.8:1 on this dark ground — fine for a
   plain border, short of the 4.5:1 these buttons' labels need. */
.btn-outline-secondary {
  --bs-btn-color: var(--sl-quiet);
  --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-color: var(--bs-emphasis-color);
  --bs-btn-hover-bg: var(--bs-tertiary-bg);
  --bs-btn-hover-border-color: var(--bs-border-color);
  --bs-btn-active-color: var(--bs-emphasis-color);
  --bs-btn-active-bg: var(--bs-secondary-bg);
  --bs-btn-active-border-color: var(--bs-border-color);
}

.nav-pills {
  --bs-nav-pills-link-active-bg: var(--sl-brand);
  --bs-nav-pills-link-active-color: var(--sl-on-brand);
}

.nav-link {
  --bs-nav-link-color: var(--bs-body-color);
  --bs-nav-link-hover-color: var(--sl-link, var(--sl-brand-hover));
}

.form-control:focus,
.form-select:focus {
  border-color: var(--sl-brand);
  box-shadow: 0 0 0 0.25rem rgba(var(--sl-brand-rgb), 0.25);
}

.form-check-input:checked {
  background-color: var(--sl-brand);
  border-color: var(--sl-brand);
}

.form-check-input:focus {
  border-color: var(--sl-brand);
  box-shadow: 0 0 0 0.25rem rgba(var(--sl-brand-rgb), 0.25);
}

.text-bg-primary {
  background-color: var(--sl-brand) !important;
  color: var(--sl-on-brand) !important;
}

/* --- Typography ------------------------------------------------------------ */

body {
  letter-spacing: var(--bs-body-letter-spacing);
}

h1, h2, h3, .display-1, .display-2, .display-3, .display-4, .display-5, .display-6 {
  letter-spacing: -0.03em;
}

/* Figures line up in a column only when they are all the same width. */
.font-monospace,
.table td,
.table th {
  font-variant-numeric: tabular-nums;
}


/* --- Site chrome ---------------------------------------------------------- */

.navbar.bg-body {
  background-color: var(--sl-navbar-bg) !important;
}

.brand-mark {
  color: var(--sl-brand);
  font-weight: 700;
}

.navbar-brand {
  letter-spacing: -0.01em;
}

.hero {
  background: linear-gradient(180deg, var(--sl-brand-soft) 0%, transparent 100%);
}

.hero__title {
  font-size: clamp(2.25rem, 1.2rem + 3.2vw, 3.75rem);
  font-weight: 800;
  line-height: 1.04;
  text-wrap: balance;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--bs-font-monospace);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sl-link, var(--sl-brand));
}

.eyebrow__rule {
  width: 1.375rem;
  height: 1px;
  background: currentColor;
}

.hero__dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--bs-border-color);
}

.hero__demo-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sl-brand);
}

/* The embedded widget is already a card; drop its inner one so the hero does
   not show a card inside a card. */
.hero__demo .card {
  border: 0;
  box-shadow: none;
  background: transparent;
}

.hero__demo .card-body {
  padding: 0;
}

.hero__demo > .card-body {
  padding: 1rem 1.25rem 1.25rem;
}

.answer-card {
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.answer-card:hover {
  border-color: var(--sl-brand);
  transform: translateY(-2px);
}

.answer-card__icon {
  width: 24px;
  height: 24px;
  color: var(--sl-link, var(--sl-brand));
}

.answer-card__tool {
  color: var(--sl-link, var(--sl-brand));
}

.panel-brand {
  background: var(--sl-brand);
  color: var(--sl-on-brand);
  border-radius: var(--bs-border-radius-xl);
}

.panel-brand .btn-light {
  --bs-btn-color: var(--sl-brand);
}

.panel-brand__chip {
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.15);
}

.lesson-row {
  padding: 0.8rem 0.9rem;
  color: inherit;
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  transition: border-color 0.15s ease;
}

.lesson-row:hover {
  border-color: var(--sl-brand);
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  .answer-card,
  .lesson-row {
    transition: none;
  }
  .answer-card:hover {
    transform: none;
  }
}

[data-bs-theme="dark"] .card {
  --bs-card-bg: #161d1c;
  --bs-card-cap-bg: #1b2322;
}

.theme-switcher__icon--auto,
.theme-switcher__icon--light,
.theme-switcher__icon--dark {
  display: none;
}

[data-sl-theme="auto"] .theme-switcher__icon--auto,
[data-sl-theme="light"] .theme-switcher__icon--light,
[data-sl-theme="dark"] .theme-switcher__icon--dark {
  display: inline-block;
}

/* --- Error pages ---------------------------------------------------------- */

.error-code {
  font-size: clamp(3rem, 2rem + 5vw, 5rem);
  font-weight: 500;
  line-height: 1;
  color: var(--sl-brand);
  opacity: 0.35;
  margin-bottom: 0.5rem;
}


/* --- Loading state --------------------------------------------------------- */

/* Hold the previous answer at reduced opacity while the next one computes:
   swapping in a skeleton would make the page jump and lose the reader's place. */
.htmx-request .calc-results {
  opacity: 0.4;
  transition: opacity 0.12s ease-in;
}

@media (prefers-reduced-motion: reduce) {
  .htmx-request .calc-results {
    transition: none;
  }
}


/* --- Components ----------------------------------------------------------- */

.chart-box {
  position: relative;
  height: 280px;
}

/* allauth renders its own markup; this gives its pages the card the rest of
   the site's forms sit in. */
.statlab-auth {
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius-lg);
  padding: 1.75rem;
  box-shadow: 0 .125rem .25rem rgba(0, 0, 0, .075);
}

.statlab-auth ul {
  padding-left: 1.1rem;
  margin-bottom: .5rem;
}

.lesson-prose {
  max-width: 62ch;
  line-height: 1.7;
}

.lesson-prose h2 { font-size: 1.25rem; margin-top: 2rem; }
.lesson-prose h3 { font-size: 1.05rem; margin-top: 1.5rem; }
.lesson-prose p, .lesson-prose ul, .lesson-prose ol { margin-bottom: 1rem; }

.lesson-prose blockquote {
  border-left: 3px solid var(--sl-brand);
  padding-left: 1rem;
  color: var(--bs-secondary-color);
}

/* ---- Mening savatim ---- */

.basket-pick {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  cursor: pointer;
}

.basket-pick:has(input:checked) {
  border-color: var(--sl-brand);
  background: var(--sl-brand-soft);
}

.basket-pick:has(input:focus-visible) {
  outline: 3px solid var(--bs-focus-ring-color);
  outline-offset: 1px;
}

/* The one figure the page exists to show. */
.basket-figure {
  font-family: var(--bs-font-monospace);
  font-variant-numeric: tabular-nums;
  font-size: 2.5rem;
  font-weight: 500;
  line-height: 1;
}

.basket-figure--up { color: var(--chart-series-2); }
.basket-figure--down { color: var(--sl-brand); }

.basket-contrib {
  display: grid;
  grid-template-columns: minmax(5rem, 7rem) minmax(0, 1fr) 4.2rem;
  gap: .6rem;
  align-items: center;
  font-size: .9rem;
}

.basket-contrib__track {
  height: .55rem;
  border-radius: 999px;
  background: var(--bs-tertiary-bg);
  overflow: hidden;
}

.basket-contrib__bar {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--chart-series-2);
}

.basket-contrib__bar--down { background: var(--sl-brand); }

.basket-contrib__value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: .82rem;
  color: var(--bs-secondary-color);
}

/* Lesson HTML is hand-written in the admin, so bare tags have to look right
   on their own — an author should not have to remember Bootstrap classes. */
.lesson-prose table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
}

.lesson-prose th,
.lesson-prose td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--bs-border-color);
  text-align: left;
  vertical-align: top;
}

.lesson-prose thead th {
  border-bottom: 2px solid var(--bs-border-color);
  font-weight: 600;
}

.lesson-prose tbody tr:last-child td { border-bottom: none; }

/* Sample data the reader is meant to copy into the calculator below. */
.lesson-prose pre {
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  font-size: 0.925rem;
}

.lesson-prose :not(pre) > code {
  background: var(--bs-tertiary-bg);
  border-radius: 0.25rem;
  padding: 0.1rem 0.35rem;
  font-size: 0.9em;
  color: var(--bs-body-color);
}

.lesson-widget {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius-lg);
  background: var(--bs-tertiary-bg);
  padding: 1.25rem;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  color: var(--chart-muted);
}

.chart-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.chart-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.chart-legend__swatch--series-1 { background: var(--chart-series-1); }
.chart-legend__swatch--series-2 { background: var(--chart-series-2); }
.chart-legend__swatch--shade-series { background: color-mix(in srgb, var(--chart-series-1) 25%, var(--chart-surface)); }
.chart-legend__swatch--shade-critical { background: color-mix(in srgb, var(--chart-critical) 22%, var(--chart-surface)); }

.chart-legend__swatch--rule,
.chart-legend__swatch--rule-critical {
  width: 2px;
  height: 14px;
  border-radius: 0;
  background: var(--chart-ink);
}

.chart-legend__swatch--rule-critical { background: var(--chart-critical); }

.table-scroll {
  max-height: 320px;
  overflow-y: auto;
}

details > summary {
  cursor: pointer;
}
