/* ============================================================
   app-base.css — Tokens, reset, element base
   Load first. Declares cascade @layer order for the design system.
   ============================================================ */

@layer reset, base, layout, components, utilities;


/* ============================================================
   Tokens — outside layers so every layer can reference them
   ============================================================ */

:root {
  /* Spacing (4 px base unit) */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;

  /* Type scale */
  --text-xs:   0.6875rem;   /*  11 px */
  --text-sm:   0.8125rem;   /*  13 px */
  --text-base: 1rem;        /*  16 px */
  --text-lg:   1.125rem;   /*  18 px */
  --text-xl:   1.25rem;    /*  20 px */
  --text-2xl:  1.5rem;     /*  24 px */
  --text-3xl:  1.875rem;   /*  30 px */

  /* Neutral palette (warm undertone) */
  --n-50:  #f9f8f6;
  --n-100: #f0ede8;
  --n-150: #e5e1da;
  --n-200: #d5d0c8;
  --n-300: #bab3a9;
  --n-400: #9e9689;
  --n-500: #7d746a;
  --n-600: #5d5750;
  --n-700: #3b3830;
  --n-800: #201e18;
  --n-900: #0d0c0a;

  /* Surfaces */
  --bg:        white;
  --bg-subtle: hsl(44 15% 93%);
  --surface:   hsl(44 35% 99%);

  /* Borders */
  --border:        #7d746a;   /* ~8:1 on bg */
  --border-subtle: #a8a299;   /* ~5:1 on bg */

  /* Text */
  --text:        #1c1b18;
  --text-muted:  #3b3830;   /* ~14:1 on bg */
  --text-faint:  #5d5750;   /* ~10:1 on bg */

  /* Interactive */
  --link:         #1a4e8a;
  --link-visited: #5b2d8a;

  /* Status colors */
  --success:    #14532d;
  --success-bg: #f0fdf4;
  --success-bd: #bbf7d0;

  --error:    #991b1b;
  --error-bg: #fef2f2;
  --error-bd: #fecaca;

  --warning:    #7c2d12;
  --warning-bg: #fff7ed;
  --warning-bd: #fed7aa;

  /* Typography */
  --font:      system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  /* Extended font tokens — can be overridden by scoped stylesheets */
  --fg-mono:   ui-monospace, SFMono-Regular, Menlo, monospace;
  --fg-paper:  #ffffff;
  --fg-accent: #3d6fb2;

  /* Shape */
  --radius: 3px;

  /* Layout */
  --max-w:    72rem;
  --page-px:  clamp(var(--sp-4), 4vw, var(--sp-8));
  --header-h: 2.75rem;
}


/* ============================================================
   Reset
   ============================================================ */

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }

  @media (prefers-reduced-motion: no-preference) {
    html { interpolate-size: allow-keywords; }
  }

  body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }

  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
  }

  input, button, textarea, select { font: inherit; }

  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  p   { text-wrap: pretty; }
  h1, h2, h3, h4, h5, h6 { text-wrap: balance; }

  #root, #__next { isolation: isolate; }
}


/* ============================================================
   Base — element selectors only, no classes
   ============================================================ */

@layer base {
  html {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--text-base);
  }

  a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
  }

  a:visited { color: var(--link-visited); }
  a:hover   { text-decoration-thickness: 2px; }

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

  h1 { font-size: var(--text-2xl);  line-height: 1.2;  font-weight: 700; }
  h2 { font-size: var(--text-xl);   line-height: 1.25; font-weight: 600; }
  h3 { font-size: var(--text-lg);   line-height: 1.3;  font-weight: 600; }
  h4 { font-size: var(--text-base); line-height: 1.4;  font-weight: 600; }
  h5 { font-size: var(--text-sm);   line-height: 1.4;  font-weight: 600; }
  h6 {
    font-size: var(--text-xs);
    line-height: 1.4;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  code, kbd, samp {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--n-100);
    padding: 0.1em 0.35em;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
  }

  pre {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    background: var(--n-100);
    padding: var(--sp-4);
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    overflow-x: auto;
  }

  pre code { background: none; border: none; padding: 0; font-size: inherit; }

  hr {
    border: none;
    border-top: 1px solid var(--border);
  }

  small { font-size: var(--text-sm); color: var(--text-muted); }
}


/* ============================================================
   Wizard drawer — shared across Programs, Proposals, and any
   future aspect that mounts a form wizard via Turbo Frame.
   ============================================================ */

/* ── Drawer shell ────────────────────────────────────────── */
.wiz-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background 0.38s ease;
  z-index: 200;
  pointer-events: none;
}
.wiz-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(50vw, 680px);
  height: 100dvh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.38s ease;
  z-index: 201;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.wiz-drawer.open .wiz-backdrop {
  background: rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}
.wiz-drawer.open .wiz-panel {
  transform: translateX(0);
  box-shadow: -12px 0 56px rgba(0, 0, 0, 0.15);
}
@media (max-width: 768px) {
  .wiz-panel { width: 100%; }
}

.wiz-panel-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  gap: 12px;
}
.wiz-label {
  font-family: var(--fg-mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}
.wiz-title {
  font-family: var(--fg-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: block;
}
.wiz-close {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  border-radius: 2px;
  transition: color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.wiz-close:hover { color: var(--text); border-color: var(--text); }

.wiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 40px;
}

/* ── Dark panel theme — redefine tokens, everything cascades ─ */
.wiz-panel[data-theme="dark"] {
  --bg:            #131210;
  --bg-subtle:     rgba(255, 255, 255, 0.07);
  --surface:       rgba(255, 255, 255, 0.05);
  --text:          #f5f4f0;
  --text-muted:    rgba(245, 244, 240, 0.52);
  --text-faint:    rgba(245, 244, 240, 0.3);
  --border:        rgba(255, 255, 255, 0.16);
  --border-subtle: rgba(255, 255, 255, 0.09);
  --fg-paper:      rgba(255, 255, 255, 0.06);
}

/* ── Wizard step form ────────────────────────────────────── */
#p2-wizard > p {
  font-family: var(--fg-mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
  text-align: center;
  margin-top: 18px;
}

nav[aria-label="Quote steps"] {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.p2-progress-step {
  flex: 1;
  padding: 10px 12px;
  text-align: center;
  position: relative;
}
.p2-progress-step.active { background: var(--bg-subtle); }
.p2-progress-step.done   { background: var(--bg-subtle); opacity: 0.6; }
@scope (.p2-progress-step) {
  span:first-child {
    font-family: var(--fg-mono);
    font-size: 9px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    display: block;
    margin-bottom: 2px;
    opacity: 0.5;
  }
  span:last-child {
    font-family: var(--fg-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
  }
}
.p2-progress-step.active span:last-child { color: var(--text); }
@media (max-width: 560px) {
  .p2-progress-step:not(.active) span:last-child { display: none; }
  .p2-progress-step:not(.active) { padding: 10px 6px; }
}

.p2-wiz-card {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 32px;
  max-width: 520px;
}
@scope (.p2-wiz-card) {
  > span {
    font-family: var(--fg-mono);
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-muted);
    display: block;
    margin-bottom: 8px;
  }
  h3 {
    font-family: var(--fg-mono);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 4px;
  }
  > p {
    font-family: var(--fg-mono);
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 22px;
  }
  > button {
    display: block;
    width: 100%;
    text-align: left;
    font-family: var(--fg-mono);
    font-size: 13px;
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--fg-paper);
    padding: 10px 14px;
    cursor: pointer;
    margin-bottom: 6px;
    border-radius: 2px;
    transition: border-color 0.1s ease, background 0.1s ease;
  }
  > button:last-of-type { margin-bottom: 0; }
  > button:hover { border-color: var(--text); background: var(--bg-subtle); }
  > button.sel   { border-color: var(--text); background: var(--bg-subtle); font-weight: 600; }
  footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border-subtle);
  }
  footer button {
    font-family: var(--fg-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 10px 20px;
    background: var(--text);
    color: var(--bg);
    border: none;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
  }
  footer button:hover { background: var(--fg-accent); }
}

/* ── FAQ accordion — used by content_blocks/_faq and programs/show ── */
.p2-faq {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
}
@scope (.p2-faq) {
  > li { border-bottom: 1px solid var(--border-subtle); }
  details { display: grid; grid-template-columns: minmax(0, 1fr); }
  details summary {
    font-family: var(--fg-mono);
    font-size: 14px;
    color: var(--text);
    padding: 14px 0;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    list-style: none;
    user-select: none;
  }
  details summary > span:first-child { flex: 1; min-width: 0; }
  details summary::-webkit-details-marker { display: none; }
  summary [data-icon] { font-size: 18px; color: var(--text-muted); flex-shrink: 0; }
  summary [data-icon="minus"] { display: none; }
  details[open] summary [data-icon="plus"]  { display: none; }
  details[open] summary [data-icon="minus"] { display: inline; }
  details p {
    font-family: var(--fg-mono);
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.75;
    padding-bottom: 16px;
  }
}
