/* =====================================================
   Rewards Design System — Foundations
   Maps to Flask/Tailwind/Flowbite stack already in base.html
   - Primary scale = Tailwind 'primary' (green) already wired
   - Adds: surface scale, status colors, dark/light parity, RTL
   ===================================================== */

:root {
  color-scheme: light;

  /* primary — Last Z hazmat lime */
  --p-50:#F7FEE7; --p-100:#ECFCCB; --p-200:#D9F99D; --p-300:#BEF264;
  --p-400:#A3E635; --p-500:#84CC16; --p-600:#65A30D; --p-700:#4D7C0F;
  --p-800:#3F6212; --p-900:#365314; --p-950:#1A2E05;

  /* neutral surface scale — light theme */
  --sf-canvas:#F7F8FA;          /* page bg */
  --sf-surface:#FFFFFF;          /* cards */
  --sf-surface-2:#F1F3F6;        /* inset / table head */
  --sf-border:#E4E7EC;
  --sf-border-strong:#CDD2DA;
  --sf-text:#0F172A;             /* slate-900 */
  --sf-text-2:#475569;           /* slate-600 */
  --sf-text-3:#94A3B8;           /* slate-400 */
  --sf-text-on-primary:#FFFFFF;

  /* status */
  --st-success:#16A34A; --st-success-bg:#DCFCE7; --st-success-border:#86EFAC;
  --st-danger:#DC2626;  --st-danger-bg:#FEE2E2;  --st-danger-border:#FCA5A5;
  --st-warn:#D97706;    --st-warn-bg:#FEF3C7;    --st-warn-border:#FCD34D;
  --st-info:#2563EB;    --st-info-bg:#DBEAFE;    --st-info-border:#93C5FD;
  --st-pending:#7C3AED; --st-pending-bg:#EDE9FE; --st-pending-border:#C4B5FD;

  /* type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* scale */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(15,23,42,0.06);
  --sh-md: 0 1px 3px rgba(15,23,42,0.08), 0 1px 2px rgba(15,23,42,0.04);
  --sh-lg: 0 10px 30px -10px rgba(15,23,42,0.18), 0 2px 6px rgba(15,23,42,0.06);
  --sh-focus: 0 0 0 3px rgba(34,197,94,0.30);
}

.dark {
  --sf-canvas:#0B1220;
  --sf-surface:#111827;
  --sf-surface-2:#1F2937;
  --sf-border:#1F2937;
  --sf-border-strong:#374151;
  --sf-text:#F1F5F9;
  --sf-text-2:#CBD5E1;
  --sf-text-3:#94A3B8;

  --st-success-bg:rgba(22,163,74,0.15);  --st-success-border:rgba(22,163,74,0.4);
  --st-danger-bg:rgba(220,38,38,0.15);   --st-danger-border:rgba(220,38,38,0.4);
  --st-warn-bg:rgba(217,119,6,0.15);     --st-warn-border:rgba(217,119,6,0.4);
  --st-info-bg:rgba(37,99,235,0.15);     --st-info-border:rgba(37,99,235,0.4);
  --st-pending-bg:rgba(124,58,237,0.15); --st-pending-border:rgba(124,58,237,0.4);

  /* Foreground colours: the default :root values (#DC2626 etc.) read
     OK at AA but are visually muted against the deep dark canvas.
     Lift each status colour by ~2 shades so the pill / button text
     stays vivid in dark mode without losing semantic meaning. */
  --st-success:#4ADE80;
  --st-danger:#F87171;
  --st-warn:#FBBF24;
  --st-info:#60A5FA;
}

/* Dark mode override — gunmetal / concrete vibe */
.dark {
  color-scheme: dark;
  --sf-canvas:#0A0E0A;
  --sf-surface:#121712;
  --sf-surface-2:#1B221B;
  --sf-border:#1F2A1F;
  --sf-border-strong:#374237;
}
:root { --sh-focus: 0 0 0 3px rgba(132,204,22,0.30); }

/* Native <dialog>'s UA stylesheet resets `color: CanvasText` and
   `background-color: Canvas`, which Chromium paints as black-on-white
   when `color-scheme` isn't declared on the host doc — making every
   modal that doesn't set its own `color` unreadable in dark mode
   (titles, table cells, <pre> blocks).  Reset both to design tokens
   so any text inside a dialog inherits the active theme by default.
   Per-dialog inline overrides (background: transparent on the
   dashboard's card-wrapped dialogs) continue to win via specificity. */
dialog {
  color: var(--sf-text);
  background: var(--sf-surface);
}

/* ─── Base reset for the doc itself ─── */
.ds-page {
  font-family: var(--font-sans);
  background: var(--sf-canvas);
  color: var(--sf-text);
  -webkit-font-smoothing: antialiased;
  /* Sticky-footer scaffolding: page is a flex column at least as tall
     as the viewport. The site footer sits at the end of the column;
     `margin-block-start: auto` on `.lz-site-footer` (set in lastz.css)
     pushes it to the bottom when content is shorter than the viewport.
     Without this, the footer floats up against short pages (e.g.
     /admin/cache, /admin/page-alerts) and leaves a blank gap below. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* RTL helpers — most spacing flips naturally via logical properties */
[dir="rtl"] .ds-flip { transform: scaleX(-1); }

/* ─── Type ─── */
.t-display { font-size: 40px; line-height: 1.1; font-weight: 700; letter-spacing: -0.025em; }
.t-h1      { font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.t-h2      { font-size: 22px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; }
.t-h3      { font-size: 17px; line-height: 1.35; font-weight: 600; }
.t-body    { font-size: 14px; line-height: 1.55; }
.t-sm      { font-size: 13px; line-height: 1.5; color: var(--sf-text-2); }
.t-xs      { font-size: 11.5px; line-height: 1.4; color: var(--sf-text-3); letter-spacing: 0.02em; }
.t-eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--sf-text-3); }
.t-mono    { font-family: var(--font-mono); }
.t-num     { font-variant-numeric: tabular-nums; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--r-md);
  font: 500 14px/1 var(--font-sans);
  border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
  /* `min-height: 44px` (set in lastz.css mobile rule for WCAG 2.5.5)
     was being treated as a content-area floor instead of a border-box
     floor, so padding+border stacked on top — `.btn-lg` rendered at
     ~69-70px tall on mobile instead of the intended ~44px. */
  box-sizing: border-box;
  /* `.btn` is used on both <button> and <a> elements; <a> brings the
     default text-decoration: underline which reads as a link, not a
     button, and stacks oddly with the pill shape on hero CTAs. */
  text-decoration: none;
}
.btn:focus-visible { outline: none; box-shadow: var(--sh-focus); }
.btn:active { transform: translateY(0.5px); }
.btn-primary   { background: var(--p-600); color: #fff; }
.btn-primary:hover { background: var(--p-700); }
.btn-secondary { background: var(--sf-surface); color: var(--sf-text); border-color: var(--sf-border-strong); }
.btn-secondary:hover { background: var(--sf-surface-2); }
.btn-ghost     { background: transparent; color: var(--sf-text-2); }
.btn-ghost:hover { background: var(--sf-surface-2); color: var(--sf-text); }
.btn-danger    { background: var(--st-danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-sm  { padding: 6px 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-lg  { padding: 12px 22px; font-size: 15px; }

/* ─── Inputs ─── */
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--sf-text-2); margin-bottom: 6px; }
.field-input, .field-select, .field-textarea,
input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input:not([type]),
textarea,
select {
  box-sizing: border-box;
  padding: 8px 12px; border-radius: var(--r-md);
  background: var(--sf-surface); border: 1px solid var(--sf-border-strong);
  color: var(--sf-text); font: 400 14px/1.4 var(--font-sans);
  transition: border-color .15s, box-shadow .15s;
}
.field-input, .field-select, .field-textarea { width: 100%; }
.field-input:focus, .field-select:focus, .field-textarea:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input:not([type]):focus,
textarea:focus,
select:focus {
  outline: none; border-color: var(--p-500); box-shadow: var(--sh-focus);
}
input::placeholder, textarea::placeholder { color: var(--sf-text-3); opacity: 0.85; }
input:hover:not(:focus), textarea:hover:not(:focus), select:hover:not(:focus) {
  border-color: var(--sf-text-3);
}
.field-help { font-size: 12px; color: var(--sf-text-3); margin-top: 6px; }
.field-error { font-size: 12px; color: var(--st-danger); margin-top: 6px; }

/* ─── Cards ─── */
.card {
  background: var(--sf-surface);
  border: 1px solid var(--sf-border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}
.card-pad { padding: 20px; }
.card-pad-lg { padding: 28px; }
.card-elev { box-shadow: var(--sh-md); }

/* ─── Status pills ─── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 7px; border-radius: var(--r-pill);
  font: 600 11px/1.4 var(--font-sans);
  letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid transparent;
}
.pill::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}
.pill-success { background: var(--st-success-bg); color: var(--st-success); border-color: var(--st-success-border); }
.pill-danger  { background: var(--st-danger-bg);  color: var(--st-danger);  border-color: var(--st-danger-border); }
.pill-warn    { background: var(--st-warn-bg);    color: var(--st-warn);    border-color: var(--st-warn-border); }
.pill-info    { background: var(--st-info-bg);    color: var(--st-info);    border-color: var(--st-info-border); }
.pill-pending { background: var(--st-pending-bg); color: var(--st-pending); border-color: var(--st-pending-border); }
.pill-muted   { background: var(--sf-surface-2);  color: var(--sf-text-2);  border-color: var(--sf-border-strong); }
.pill-muted::before { background: var(--sf-text-3); }

/* ─── Table ─── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl thead th {
  text-align: start; padding: 11px 14px;
  background: var(--sf-surface-2);
  font-weight: 600; font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--sf-text-2);
  border-bottom: 1px solid var(--sf-border);
}
.tbl tbody td { padding: 12px 14px; border-bottom: 1px solid var(--sf-border); color: var(--sf-text); }
.tbl tbody tr:hover td { background: var(--sf-surface-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }

/* ─── Empty state ─── */
.empty {
  padding: 48px 24px; text-align: center;
  border: 1px dashed var(--sf-border-strong);
  border-radius: var(--r-lg);
  background: var(--sf-surface);
}
.empty-icon {
  width: 48px; height: 48px; margin: 0 auto 12px;
  border-radius: 12px;
  background: var(--sf-surface-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--sf-text-3); font-size: 22px;
}

/* ─── Nav (header) ─── */
.nav {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 24px;
  background: var(--sf-surface);
  border-bottom: 1px solid var(--sf-border);
}
.nav a { color: var(--sf-text-2); font-size: 14px; font-weight: 500; text-decoration: none; padding: 6px 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--sf-text); }
.nav a.active { color: var(--p-600); border-bottom-color: var(--p-600); }

/* ─── Toast / Alert ─── */
.alert {
  display: flex; gap: 12px; padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid;
  font-size: 13.5px;
}
.alert-success { background: var(--st-success-bg); border-color: var(--st-success-border); color: var(--st-success); }
.alert-danger  { background: var(--st-danger-bg);  border-color: var(--st-danger-border);  color: var(--st-danger); }
.alert-warn    { background: var(--st-warn-bg);    border-color: var(--st-warn-border);    color: var(--st-warn); }
.alert-info    { background: var(--st-info-bg);    border-color: var(--st-info-border);    color: var(--st-info); }

/* ─── Swatches (for the doc) ─── */
.swatch-grid { display: grid; grid-template-columns: repeat(11, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1.4; border-radius: 8px; display: flex; flex-direction: column; justify-content: flex-end; padding: 6px 8px; font: 600 10px/1 var(--font-mono); }

/* ─── Demo grid scaffolding ─── */
.ds-section { padding: 40px 48px; border-bottom: 1px solid var(--sf-border); }
.ds-section h2.ds-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
.ds-section p.ds-sub { color: var(--sf-text-2); font-size: 14px; margin: 0 0 28px; max-width: 60ch; }
.ds-grid { display: grid; gap: 20px; }
.ds-row  { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.ds-stack { display: flex; flex-direction: column; gap: 14px; }
.ds-label { font-size: 11px; font-weight: 600; color: var(--sf-text-3); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px; }

/* Topbar of the foundations doc */
.ds-topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--sf-surface) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--sf-border);
  display: flex; align-items: center; gap: 16px; padding: 12px 28px;
}
.ds-topbar .seg { display: inline-flex; background: var(--sf-surface-2); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.ds-topbar .seg button {
  border: 0; background: transparent; color: var(--sf-text-2);
  padding: 6px 12px; border-radius: var(--r-pill);
  font: 600 12px/1 var(--font-sans); cursor: pointer;
}
.ds-topbar .seg button.on { background: var(--sf-surface); color: var(--sf-text); box-shadow: var(--sh-sm); }
