/* CrisisLink — accessible, trauma-informed styling.
   Calm palette, high contrast, large touch targets, no jarring motion. */

:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-2: #eef3f6;
  --ink: #1c2b33;
  --ink-soft: #4a5d68;
  --muted: #6b7c86;
  --line: #d7e0e6;
  --brand: #1f6f78;          /* teal — calm, trustworthy */
  --brand-dark: #155059;
  --brand-soft: #e3f1f2;
  --accent: #c2571a;         /* warm, for primary actions */
  --accent-dark: #9c440f;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --ok: #2e7d52;
  --ok-soft: #e6f4ec;
  --warn: #8a6100;
  --warn-soft: #fcf3da;
  --focus: #1769aa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(28, 43, 51, 0.08);
  --shadow-lg: 0 8px 30px rgba(28, 43, 51, 0.16);
  --maxw: 1080px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3 { line-height: 1.2; color: var(--ink); margin: 0 0 .5em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
a { color: var(--brand-dark); }
.muted { color: var(--muted); }
small, .small { font-size: .86rem; }

/* ---------- accessibility helpers ---------- */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 1000;
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
.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;
}

@media (prefers-reduced-motion: no-preference) {
  .fade-in { animation: fade .25s ease both; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* ---------- crisis bar ---------- */
.crisis-bar { background: #2b1413; color: #fff; font-size: .95rem; }
.crisis-bar__inner {
  max-width: var(--maxw); margin: 0 auto; padding: .5rem 1rem;
  display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center;
}
.crisis-bar a { color: #ffd9b3; text-decoration: none; }
.crisis-bar a:hover { text-decoration: underline; }
.crisis-bar__label { font-weight: 500; }
.crisis-bar__links { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.crisis-bar .linkbtn { color: #ffd9b3; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
.quick-exit {
  margin-left: auto; background: #fff; color: #2b1413; border: 0; font-weight: 700;
  padding: .4rem .8rem; border-radius: var(--radius-sm); cursor: pointer; font-size: .9rem;
}
.quick-exit:hover { background: #ffe; }

/* ---------- header / nav ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.site-header__inner, .site-footer__inner {
  max-width: var(--maxw); margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.3rem; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.brand__mark { height: 28px; width: auto; display: block; }
.main-nav { margin-left: auto; display: flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
.main-nav a, .main-nav .navbtn {
  color: var(--ink-soft); text-decoration: none; padding: .5rem .75rem; border-radius: var(--radius-sm);
  font-weight: 600; font-size: .95rem; background: none; border: 0; cursor: pointer; font-family: inherit;
}
.main-nav a:hover, .main-nav .navbtn:hover { background: var(--surface-2); }
.main-nav a.active { background: var(--brand-soft); color: var(--brand-dark); }
.nav-chip { font-size: .8rem; background: var(--surface-2); border-radius: 999px; padding: .25rem .6rem; color: var(--ink-soft); }

/* ---------- layout ---------- */
main { flex: 1; }
.app { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.site-footer { background: var(--surface); border-top: 1px solid var(--line); margin-top: auto; }
.site-footer__inner { display: block; font-size: .9rem; color: var(--ink-soft); }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.center { text-align: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card--pad-lg { padding: 1.75rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.card--link { cursor: pointer; transition: box-shadow .15s, transform .15s; text-align: left; width: 100%; font: inherit; color: inherit; }
.card--link:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.tile { display: block; }
.hero { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%); color: #fff; border-radius: var(--radius); padding: 2rem; }
.hero h1 { color: #fff; }
.hero p { color: #e7f3f4; max-width: 60ch; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  padding: .7rem 1.2rem; border-radius: var(--radius-sm); border: 2px solid transparent;
  background: var(--surface-2); color: var(--ink); min-height: 44px; line-height: 1.1;
}
.btn:hover { filter: brightness(.97); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); filter: none; }
.btn--brand { background: var(--brand); color: #fff; }
.btn--brand:hover { background: var(--brand-dark); filter: none; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: .4rem .7rem; min-height: 36px; font-size: .9rem; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }

/* ---------- forms ---------- */
label { font-weight: 600; display: block; margin-bottom: .35rem; }
.field { margin-bottom: 1.1rem; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .9rem; margin: .15rem 0 .4rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
select, textarea {
  width: 100%; padding: .65rem .75rem; font: inherit; color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline-offset: 1px; }

/* choice options (radio/checkbox as cards) */
.options { display: grid; gap: .6rem; }
.option {
  display: flex; gap: .75rem; align-items: flex-start; padding: .85rem 1rem;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; cursor: pointer;
}
.option:hover { border-color: var(--brand); background: var(--brand-soft); }
.option input { margin-top: .25rem; width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--brand); }
.option--checked { border-color: var(--brand); background: var(--brand-soft); }
.option__text { font-weight: 600; }
.option__desc { font-weight: 400; color: var(--muted); font-size: .9rem; }

.why {
  font-size: .85rem; color: var(--brand-dark); background: var(--brand-soft);
  border-radius: var(--radius-sm); padding: .5rem .75rem; margin-top: .5rem;
}
.skip-note { color: var(--muted); font-size: .85rem; }

/* ---------- badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px; }
.badge--verified { background: var(--ok-soft); color: var(--ok); }
.badge--partner { background: #e8eefc; color: #2547a8; }
.badge--self { background: var(--surface-2); color: var(--ink-soft); }
.badge--pending { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.pill { display: inline-block; font-size: .8rem; background: var(--surface-2); color: var(--ink-soft); padding: .2rem .6rem; border-radius: 999px; margin: 0 .25rem .25rem 0; }
.pill--cat { background: var(--brand-soft); color: var(--brand-dark); }

.match-score { font-weight: 800; color: var(--brand-dark); }
.cap { font-weight: 700; }
.cap--open { color: var(--ok); }
.cap--full { color: var(--danger); }
.cap--limited { color: var(--warn); }

/* ---------- progress / steps ---------- */
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-bottom: 1rem; }
.progress__bar { height: 100%; background: var(--brand); transition: width .2s; }
.steps { display: flex; gap: .5rem; flex-wrap: wrap; list-style: none; padding: 0; margin: 0 0 1rem; font-size: .85rem; }
.steps li { color: var(--muted); }
.steps li.active { color: var(--brand-dark); font-weight: 700; }
.steps li.done { color: var(--ok); }

/* ---------- alerts ---------- */
.alert { border-radius: var(--radius-sm); padding: 1rem 1.1rem; border: 1px solid; margin-bottom: 1rem; }
.alert--danger { background: var(--danger-soft); border-color: #f3b3ae; }
.alert--ok { background: var(--ok-soft); border-color: #bfe3cd; }
.alert--warn { background: var(--warn-soft); border-color: #ecd99a; }
.alert--info { background: var(--brand-soft); border-color: #b9dde0; }
.alert h3 { margin-top: 0; }
.alert--crisis { border-width: 2px; }
.alert--crisis .btn-row { margin-top: .5rem; }

/* ---------- tables / lists ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list > li { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: .25rem 1rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.stat { text-align: center; }
.stat__num { font-size: 2rem; font-weight: 800; color: var(--brand-dark); display: block; }
.stat__label { color: var(--muted); font-size: .9rem; }

/* ---------- modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 30, 35, .55); display: flex;
  align-items: center; justify-content: center; padding: 1rem; z-index: 200;
}
.modal {
  background: var(--surface); border-radius: var(--radius); max-width: 520px; width: 100%;
  padding: 1.5rem; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto;
}
.modal h2 { margin-top: 0; }
#toast-root { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.toast--ok { background: var(--ok); }
.toast--danger { background: var(--danger); }

.divider { height: 1px; background: var(--line); border: 0; margin: 1.5rem 0; }
.tag-danger { color: var(--danger); font-weight: 700; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: .5rem; }
  .quick-exit { margin-left: 0; }
}

/* ============================================================
   ORG PORTAL — tabbed dashboard components
   ============================================================ */
.eyebrow { font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; font-weight: 700; color: var(--muted); }

/* tab strip (adapts D1's sidebar to the existing top-bar shell) */
.org-tabs { display: flex; gap: .15rem; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; -webkit-overflow-scrolling: touch; }
.org-tab {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: .45rem; padding: .65rem .85rem;
  border: 0; background: none; cursor: pointer; font: inherit; font-weight: 600; font-size: .95rem;
  color: var(--ink-soft); border-bottom: 2.5px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.org-tab:hover { color: var(--ink); }
.org-tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 700; }
.tab-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .7rem; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }

/* availability status toggle (Open / Limited / Full) */
.statusseg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.statusbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .45rem;
  min-height: 92px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; font: inherit; font-weight: 800; color: var(--ink-soft); transition: transform .12s, box-shadow .15s, border-color .15s;
}
.statusbtn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.statusbtn__icon { width: 30px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.statusbtn--green .statusbtn__icon { background: var(--ok-soft); color: var(--ok); }
.statusbtn--amber .statusbtn__icon { background: var(--warn-soft); color: var(--warn); }
.statusbtn--red   .statusbtn__icon { background: var(--danger-soft); color: var(--danger); }
.statusbtn--green.is-on { background: var(--ok); border-color: var(--ok); color: #fff; }
.statusbtn--amber.is-on { background: #b07a12; border-color: #b07a12; color: #fff; }
.statusbtn--red.is-on   { background: var(--danger); border-color: var(--danger); color: #fff; }
.statusbtn.is-on .statusbtn__icon { background: rgba(255,255,255,.22); color: #fff; }

/* toggle switch */
.switch { position: relative; width: 46px; height: 28px; flex: 0 0 auto; border: 0; border-radius: 999px; background: var(--line); cursor: pointer; padding: 0; transition: background .15s; }
.switch.is-on { background: var(--brand); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.is-on::after { transform: translateX(18px); }

/* −/+ stepper */
.stepper { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper button { width: 40px; height: 40px; border: 0; background: var(--surface); cursor: pointer; font: inherit; font-size: 1.3rem; font-weight: 700; color: var(--brand-dark); line-height: 1; }
.stepper button:hover { background: var(--surface-2); }
.stepper button:disabled { opacity: .4; cursor: not-allowed; }
.stepper__val { min-width: 44px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }

/* settings row */
.setrow { display: flex; align-items: flex-start; gap: .85rem; padding: .35rem 0; }
.setrow__main { flex: 1; min-width: 0; }
.setrow__title { font-weight: 700; }
.setrow__sub { font-size: .88rem; color: var(--muted); margin-top: .1rem; }

/* live "how clients see you" preview */
.client-preview { border: 1.5px dashed var(--brand); border-radius: var(--radius); background: var(--brand-soft); padding: .9rem 1rem; }

/* stat tiles (new flares / referrals) */
.stat-tile { flex: 1; min-width: 0; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 1rem; cursor: pointer; box-shadow: var(--shadow); font: inherit; transition: box-shadow .15s, transform .12s; }
.stat-tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.stat-tile__label { font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.stat-tile__num { font-size: 2rem; font-weight: 800; line-height: 1; margin-top: .35rem; }
.stat-tile--terra .stat-tile__num { color: var(--accent); }
.stat-tile--teal  .stat-tile__num { color: var(--brand-dark); }

/* cohort capacity rows */
.cohort { display: flex; align-items: center; gap: .6rem; }
.cohort + .cohort { margin-top: .55rem; }
.cohort__label { width: 84px; font-weight: 700; font-size: .9rem; color: var(--ink-soft); }
.cohort__bar { flex: 1; height: 9px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.cohort__fill { height: 100%; border-radius: 999px; }
.cohort__num { width: 46px; text-align: right; font-weight: 700; font-size: .9rem; font-variant-numeric: tabular-nums; }

/* segmented control (walk-in) */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.segbtn { min-height: 52px; border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font: inherit; font-weight: 700; font-size: .9rem; color: var(--ink-soft); display: flex; align-items: center; justify-content: center; gap: .4rem; }
.segbtn--green.is-on { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.segbtn--amber.is-on { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.segbtn--red.is-on   { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

/* status pills + dot */
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--danger { background: var(--danger-soft); color: var(--danger); }
.statusdot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
