/* ==========================================================================
   Pearto public reference design system
   --------------------------------------------------------------------------
   Derived from the 8 supplied reference images (64 panels). It is loaded ONLY
   by templates/base.html, which the staff control center does not extend
   (templates/staff/base.html is standalone with its own <head>), so nothing in
   this file can reach /staff/ or /django-admin/.

   It ADDS to the token system in app.css rather than overriding it. No existing
   token is redefined, so any surface that does not opt into a .ref-* class is
   unchanged. Where the reference differs most from what Pearto already had:
     - a warm paper canvas instead of a cool grey one
     - larger card radii and almost no shadow (borders do the work)
     - tinted pastel panels for results rather than white-on-white
     - a photographic-feeling hero band (built from CSS, not licensed imagery)
   ========================================================================== */

:root {
  /* Warm paper rather than the cool --ink-50. The reference reads like paper. */
  --ref-canvas: #faf8f3;
  --ref-canvas-deep: #f3f0e7;
  --ref-surface: #ffffff;
  --ref-line: #e7e3d8;
  --ref-line-strong: #d8d2c2;

  /* Tinted panels. Low saturation so text at AA contrast sits on them. */
  --ref-tint-green: #eaf3e6;
  --ref-tint-green-line: #cfe3c6;
  --ref-tint-blue: #e9eef8;
  --ref-tint-blue-line: #cfdaf0;
  --ref-tint-amber: #fdf4e4;
  --ref-tint-amber-line: #f0e0bd;
  --ref-tint-red: #fbebe8;
  --ref-tint-red-line: #f0cfc9;

  --ref-ink: #17271f;
  --ref-ink-2: #46584f;
  --ref-ink-3: #6d7d74;

  /* Borrowed from the reference's softer elevation: borders, not shadows. */
  --ref-shadow: 0 1px 2px rgba(23, 39, 31, 0.04);
  --ref-shadow-lift: 0 4px 14px rgba(23, 39, 31, 0.06);

  --ref-radius: 18px;
  --ref-radius-lg: 24px;
  --ref-radius-sm: 12px;
}

/* ---------- Canvas -------------------------------------------------------
 * Applied to body rather than to an opt-in class. That is safe because this
 * file is loaded only by templates/base.html; templates/staff/base.html is a
 * standalone document with its own <head> and never loads it, so staff keeps
 * its own chrome untouched.
 */
body {
  background: var(--ref-canvas);
  color: var(--ref-ink);
}

/* ---------- Hero band ----------------------------------------------------
 * The reference uses mountain photography on every landing page. Licensed
 * imagery is out of scope for a CSS change, so this builds a comparable calm
 * band from layered gradients. It reads as a horizon without pretending to be
 * a photograph, and it costs no bytes and causes no layout shift.
 */
.ref-hero {
  position: relative;
  padding: var(--space-8) 0 var(--space-6);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(250, 248, 243, 0.94)),
    radial-gradient(120% 80% at 78% 12%, var(--brand-100) 0%, transparent 58%),
    radial-gradient(90% 70% at 12% 96%, #dfeaf3 0%, transparent 62%),
    linear-gradient(180deg, #eef4ee 0%, var(--ref-canvas) 100%);
  border-bottom: 1px solid var(--ref-line);
  overflow: hidden;
}

/* A soft ridge line, drawn rather than photographed. */
.ref-hero::after {
  content: "";
  position: absolute;
  inset: auto 0 -1px 0;
  height: 58px;
  background: var(--ref-canvas);
  clip-path: polygon(0 62%, 14% 40%, 27% 58%, 41% 22%, 55% 52%, 68% 30%, 82% 55%, 100% 34%, 100% 100%, 0 100%);
  opacity: 0.9;
  pointer-events: none;
}

.ref-hero > .container {
  position: relative;
  z-index: 1;
}

.ref-hero h1 {
  margin: var(--space-2) 0 var(--space-2);
  font-size: clamp(1.75rem, 3.6vw, 2.5rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.ref-hero-lede {
  max-width: 62ch;
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--ref-ink-2);
}

.ref-eyebrow {
  display: inline-block;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand-700);
}

/* ---------- Page toolbar (Analyze / Compare / Save / Share) --------------- */
.ref-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-4);
}

.ref-toolbar-end {
  margin-inline-start: auto;
}

.ref-toolbar .ref-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 14px;
  border: 1px solid var(--ref-line-strong);
  border-radius: var(--radius-pill);
  background: var(--ref-surface);
  color: var(--ref-ink-2);
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  transition: border-color var(--duration) var(--ease), color var(--duration) var(--ease);
}

.ref-toolbar .ref-icon-btn:hover {
  border-color: var(--brand-500);
  color: var(--brand-700);
}

.ref-toolbar .ref-icon-btn:focus-visible {
  outline: 3px solid var(--brand-300);
  outline-offset: 2px;
}

/* ---------- Cards -------------------------------------------------------- */
.ref-card {
  padding: var(--space-5);
  background: var(--ref-surface);
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius);
  box-shadow: var(--ref-shadow);
}

.ref-card-lg {
  border-radius: var(--ref-radius-lg);
}

.ref-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.ref-card-head h2,
.ref-card-head h3 {
  margin: 0;
  font-size: 1.02rem;
}

.ref-card-note {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ref-ink-3);
}

/* ---------- Metric ------------------------------------------------------ */
.ref-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ref-metric {
  padding: var(--space-4);
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-surface);
}

.ref-metric-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ref-ink-3);
}

.ref-metric-value {
  display: block;
  margin-top: 2px;
  font-size: clamp(1.3rem, 2.6vw, 1.75rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ref-ink);
  overflow-wrap: anywhere;
}

.ref-metric-delta {
  display: inline-block;
  margin-top: var(--space-1);
  font-size: 0.8rem;
  font-weight: 600;
}

.ref-metric[data-tone="positive"] .ref-metric-delta { color: var(--positive-600); }
.ref-metric[data-tone="caution"] .ref-metric-delta { color: var(--caution-700); }
.ref-metric[data-tone="critical"] .ref-metric-delta { color: var(--critical-700); }

/* ---------- Tinted summary panels --------------------------------------- */
.ref-panel {
  padding: var(--space-4);
  border: 1px solid var(--ref-tint-green-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-tint-green);
}

.ref-panel[data-tone="blue"] { background: var(--ref-tint-blue); border-color: var(--ref-tint-blue-line); }
.ref-panel[data-tone="amber"] { background: var(--ref-tint-amber); border-color: var(--ref-tint-amber-line); }
.ref-panel[data-tone="critical"] { background: var(--ref-tint-red); border-color: var(--ref-tint-red-line); }

.ref-panel-title {
  margin: 0 0 var(--space-1);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ref-ink-2);
}

.ref-panel-value {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ref-ink);
  overflow-wrap: anywhere;
}

.ref-panel-note {
  margin: var(--space-1) 0 0;
  font-size: 0.82rem;
  color: var(--ref-ink-2);
}

/* ---------- Recommendation banner --------------------------------------- */
.ref-recommend {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--ref-tint-green-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-tint-green);
}

.ref-recommend-mark {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
}

.ref-recommend-body { min-width: 0; }

.ref-recommend-headline {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ref-ink);
}

.ref-recommend-note {
  margin: var(--space-1) 0 0;
  font-size: 0.86rem;
  color: var(--ref-ink-2);
}

/* ---------- Gauge (score ring) ------------------------------------------ */
.ref-gauge {
  --ref-gauge: 0;
  --ref-gauge-size: 116px;
  display: grid;
  place-items: center;
  width: var(--ref-gauge-size);
  height: var(--ref-gauge-size);
  border-radius: 50%;
  background:
    conic-gradient(var(--brand-500) calc(var(--ref-gauge) * 1%), var(--ref-line) 0);
  position: relative;
  flex: none;
}

.ref-gauge::before {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  background: var(--ref-surface);
}

.ref-gauge-value {
  position: relative;
  z-index: 1;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ref-ink);
}

.ref-gauge-label {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ref-ink-3);
  text-align: center;
}

/* ---------- Step badge -------------------------------------------------- */
.ref-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-3);
  counter-reset: ref-step;
}

.ref-step {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  counter-increment: ref-step;
}

.ref-step::before {
  content: counter(ref-step);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
}

.ref-step-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 650;
}

.ref-step-note {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--ref-ink-2);
}

/* ---------- Section tabs ------------------------------------------------ */
.ref-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 var(--space-4);
  padding: 3px;
  background: var(--ref-canvas-deep);
  border-radius: var(--radius-pill);
  overflow-x: auto;
  scrollbar-width: none;
}

.ref-tabs::-webkit-scrollbar { display: none; }

.ref-tabs a,
.ref-tabs button {
  flex: 1 0 auto;
  padding: 8px var(--space-4);
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ref-ink-3);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}

.ref-tabs [aria-selected="true"],
.ref-tabs .is-active {
  background: var(--ref-surface);
  color: var(--ref-ink);
  box-shadow: var(--ref-shadow);
}

.ref-tabs a:focus-visible,
.ref-tabs button:focus-visible {
  outline: 3px solid var(--brand-300);
  outline-offset: 2px;
}

/* ---------- Versus (A vs B) -------------------------------------------- */
.ref-versus {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: center;
}

.ref-versus-side {
  padding: var(--space-4);
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-surface);
  min-width: 0;
}

.ref-versus-side[data-winner="true"] {
  border-color: var(--brand-500);
  background: var(--ref-tint-green);
}

.ref-versus-vs {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ref-ink);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ref-versus-name {
  margin: 0 0 var(--space-1);
  font-size: 0.95rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .ref-versus {
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
  }
  .ref-versus-vs { justify-self: center; }
}

/* ---------- Table -------------------------------------------------------
 * Wrapped so a wide comparison can scroll inside its own panel rather than
 * pushing the page sideways.
 */
.ref-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-surface);
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.ref-table caption {
  padding: var(--space-3);
  text-align: left;
  font-weight: 650;
  color: var(--ref-ink);
}

.ref-table th,
.ref-table td {
  padding: 10px var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--ref-line);
  white-space: nowrap;
}

.ref-table tbody tr:last-child th,
.ref-table tbody tr:last-child td { border-bottom: 0; }

.ref-table thead th {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ref-ink-3);
  background: var(--ref-canvas-deep);
}

.ref-table td[data-align="right"],
.ref-table th[data-align="right"] { text-align: right; }

/* ---------- Chart (CSS only) ------------------------------------------- */
.ref-chart {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 128px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ref-chart li {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}

.ref-chart-bar {
  display: block;
  width: 100%;
  min-height: 3px;
  border-radius: 6px 6px 2px 2px;
  background: var(--brand-500);
}

.ref-chart li[data-series="b"] .ref-chart-bar { background: var(--info-700); }

.ref-chart-key {
  font-size: 0.7rem;
  color: var(--ref-ink-3);
  text-align: center;
  overflow-wrap: anywhere;
}

.ref-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--ref-ink-2);
}

.ref-legend li { display: flex; gap: 6px; align-items: center; }

.ref-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--brand-500);
  flex: none;
}

.ref-legend li[data-series="b"] .ref-legend-swatch { background: var(--info-700); }

/* ---------- Assumptions ------------------------------------------------- */
.ref-assumptions {
  padding: var(--space-4);
  background: var(--ref-canvas-deep);
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius-sm);
}

.ref-assumptions dl {
  margin: 0;
  display: grid;
  gap: var(--space-2);
}

.ref-assumptions dt {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--ref-ink-3);
}

.ref-assumptions dd {
  margin: 0 0 var(--space-1);
  font-size: 0.88rem;
  color: var(--ref-ink);
  overflow-wrap: anywhere;
}

/* ---------- Notice / alert --------------------------------------------- */
.ref-notice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2) var(--space-3);
  align-items: start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--ref-line);
  border-left: 3px solid var(--info-700);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-surface);
}

.ref-notice[data-tone="positive"] { border-left-color: var(--positive-600); }
.ref-notice[data-tone="caution"] { border-left-color: var(--caution-700); }
.ref-notice[data-tone="critical"] { border-left-color: var(--critical-700); }

.ref-notice-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.ref-notice-body {
  grid-column: 2;
  margin: 0;
  font-size: 0.85rem;
  color: var(--ref-ink-2);
}

/* ---------- Upload / file card ----------------------------------------- */
.ref-upload {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-5);
  border: 2px dashed var(--ref-line-strong);
  border-radius: var(--ref-radius);
  background: var(--ref-surface);
  text-align: center;
  min-width: 0;
}

.ref-upload-file {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3);
  border: 1px solid var(--ref-line);
  border-radius: var(--ref-radius-sm);
  background: var(--ref-canvas);
  text-align: left;
  min-width: 0;
}

.ref-upload-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ref-upload-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ref-ink-3);
}

/* ---------- Switch list ------------------------------------------------- */
.ref-switches {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-3);
}

.ref-switch {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.ref-switch input {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 2px;
  accent-color: var(--brand-600);
  flex: none;
}

.ref-switch-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 550;
}

.ref-switch-note {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--ref-ink-3);
}

/* ---------- Trust strip ------------------------------------------------- */
.ref-trust {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-6);
  align-items: center;
  justify-content: center;
  padding: var(--space-4) 0;
  border-top: 1px solid var(--ref-line);
  font-size: 0.84rem;
  color: var(--ref-ink-2);
}

.ref-trust-item {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.ref-trust-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ref-tint-green);
  color: var(--brand-700);
  font-size: 0.72rem;
  font-weight: 700;
  flex: none;
}

/* ---------- Utility ---------------------------------------------------- */
.ref-stack {
  display: grid;
  gap: var(--space-4);
}

.ref-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.ref-split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

@media (max-width: 900px) {
  .ref-split { grid-template-columns: minmax(0, 1fr); }
}

/* Every grid item must be allowed to shrink, or a single wide child pushes the
   page sideways. This one rule prevents the whole class of overflow defect. */
.ref-card,
.ref-metric,
.ref-panel,
.ref-versus-side,
.ref-upload-file,
.ref-assumptions { min-width: 0; }

@media (prefers-reduced-motion: reduce) {
  .ref-toolbar .ref-icon-btn { transition: none; }
}

@media print {
  .ref-toolbar,
  .ref-tabs { display: none; }
}
