/* =============================================================================
   PHYSICIAN FREEDOM SYSTEM — COMPONENT & LAYOUT LAYER
   Built entirely on design-tokens.css. No hard-coded brand values here.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text-body);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--text-strong); font-family: var(--font-display); line-height: var(--lh-tight); margin: 0; font-weight: var(--fw-bold); letter-spacing: -0.02em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding-inline: var(--space-5); }
.container--narrow { max-width: var(--container-narrow); }

.muted { color: var(--text-muted); }
.center { text-align: center; }
.eyebrow {
  text-transform: uppercase; letter-spacing: .14em; font-size: var(--fs-xs);
  font-weight: var(--fw-bold); color: var(--brand); margin-bottom: var(--space-2);
}

/* ---- App header ------------------------------------------------------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: rgba(255,255,255,.82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.site-header__inner { height: 100%; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.brand:hover { text-decoration: none; }
.brand__logo { width: 40px; height: 40px; flex: none; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.brand__name { font-weight: var(--fw-bold); color: var(--text-strong); font-size: var(--fs-md); letter-spacing: -.02em; line-height: 1.1; }
.brand__sub { font-size: var(--fs-xs); color: var(--text-muted); letter-spacing: .04em; }
.header-nav { display: flex; align-items: center; gap: var(--space-5); }
.header-nav a { color: var(--text-body); font-size: var(--fs-sm); font-weight: var(--fw-medium); }

/* ---- Buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: var(--font-sans); font-weight: var(--fw-semi); font-size: var(--fs-sm);
  padding: 0.7rem 1.25rem; border-radius: var(--radius-pill); border: 1px solid transparent;
  cursor: pointer; transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
  white-space: nowrap; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--grad-brand); color: var(--text-onbrand); box-shadow: var(--shadow-sm); }
.btn--primary:hover { box-shadow: var(--shadow-md); text-decoration: none; }
.btn--ghost { background: var(--bg-surface); color: var(--text-strong); border-color: var(--border-strong); }
.btn--ghost:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn--lg { padding: 0.95rem 1.7rem; font-size: var(--fs-base); }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---- Cards ------------------------------------------------------------ */
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card--pad { padding: var(--space-6); }

/* ---- Hero ------------------------------------------------------------- */
.hero { position: relative; overflow: hidden; background: var(--grad-ink); color: #e9f1f7; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 80% at 85% -10%, rgba(20,184,138,.35), transparent 60%),
    radial-gradient(40% 60% at 10% 110%, rgba(201,162,75,.18), transparent 60%);
  pointer-events: none;
}
.hero__inner { position: relative; z-index: 1; padding-block: var(--space-12) var(--space-10); }
.hero h1 { color: #fff; font-size: var(--fs-3xl); max-width: 16ch; }
.hero p { color: rgba(233,241,247,.82); font-size: var(--fs-md); margin-top: var(--space-4); max-width: 56ch; }
.hero__cta { margin-top: var(--space-6); display: flex; gap: var(--space-3); flex-wrap: wrap; }
.hero__chips { margin-top: var(--space-7); display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  color: #cfe3ee; padding: .4rem .8rem; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: var(--fw-medium);
}

/* ---- Section ---------------------------------------------------------- */
.section { padding-block: var(--space-10); }
.section__head { max-width: 60ch; margin-bottom: var(--space-7); }
.section__head h2 { font-size: var(--fs-2xl); }
.section__head p { color: var(--text-muted); margin-top: var(--space-3); font-size: var(--fs-md); }

/* ---- Calculator grid -------------------------------------------------- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: var(--space-5); }
.tool-card {
  position: relative; display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-6); background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); cursor: pointer; overflow: hidden;
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tool-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--grad-brand); opacity: 0; transition: opacity var(--dur) var(--ease);
}
.tool-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.tool-card:hover::before { opacity: 1; }
.tool-card__icon {
  width: 48px; height: 48px; border-radius: var(--radius-md); display: grid; place-items: center;
  background: var(--emerald-100); color: var(--emerald-600); font-size: 22px; flex: none;
}
.tool-card__title { font-size: var(--fs-md); font-weight: var(--fw-bold); color: var(--text-strong); }
.tool-card__desc { font-size: var(--fs-sm); color: var(--text-muted); line-height: var(--lh-snug); flex: 1; }
.tool-card__cta { font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--brand); display: inline-flex; align-items: center; gap: 6px; }
.badge {
  align-self: flex-start; font-size: var(--fs-xs); font-weight: var(--fw-bold); letter-spacing: .05em;
  text-transform: uppercase; padding: .2rem .55rem; border-radius: var(--radius-pill);
  background: var(--gold-300); color: #7a5a12;
}

/* ---- Platform CTA (landing) ------------------------------------------- */
.platform-cta { position: relative; overflow: hidden; background: var(--grad-ink); border-radius: var(--radius-xl); padding: var(--space-10) var(--space-8); box-shadow: var(--shadow-lg); }
.platform-cta::after { content: ""; position: absolute; inset: 0; background: radial-gradient(50% 80% at 90% 10%, rgba(20,184,138,.4), transparent 60%), radial-gradient(40% 70% at 0% 100%, rgba(201,162,75,.22), transparent 60%); pointer-events: none; }
.platform-cta__text { position: relative; z-index: 1; max-width: 60ch; }
.platform-cta h2 { color: #fff; font-size: var(--fs-2xl); }
.platform-cta p { color: rgba(233,241,247,.85); font-size: var(--fs-md); margin-top: var(--space-3); }
.platform-cta__chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-5); }
.platform-cta__chips .chip { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); color: #cfe3ee; }
.platform-cta__actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); flex-wrap: wrap; }

/* ---- Calculator view -------------------------------------------------- */
.calc-layout { display: grid; grid-template-columns: 1fr; gap: var(--space-6); align-items: start; }
@media (min-width: 920px) { .calc-layout { grid-template-columns: 1.1fr .9fr; } }

.calc-head { display: flex; align-items: flex-start; gap: var(--space-4); margin-bottom: var(--space-6); }
.calc-head__icon { width: 56px; height: 56px; border-radius: var(--radius-md); background: var(--emerald-100); color: var(--emerald-600); display: grid; place-items: center; font-size: 26px; flex: none; }
.calc-head h1 { font-size: var(--fs-xl); }
.calc-head p { color: var(--text-muted); margin-top: var(--space-2); }

.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); margin-bottom: var(--space-5); cursor: pointer; }
.back-link:hover { color: var(--brand); text-decoration: none; }

/* ---- Forms ------------------------------------------------------------ */
.field { margin-bottom: var(--space-5); }
.field__label { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); }
.field__label label { font-weight: var(--fw-semi); color: var(--text-strong); font-size: var(--fs-sm); }
.field__help { color: var(--text-muted); font-size: var(--fs-xs); margin-top: var(--space-1); line-height: var(--lh-snug); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap__affix { position: absolute; color: var(--text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); pointer-events: none; }
.input-wrap__affix--prefix { left: 0.9rem; }
.input-wrap__affix--suffix { right: 0.9rem; }
.input {
  width: 100%; font-family: var(--font-sans); font-size: var(--fs-base); color: var(--text-strong);
  background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring-brand); }
.input.has-prefix { padding-left: 1.9rem; }
.input.has-suffix { padding-right: 2.6rem; }
.input--invalid { border-color: var(--bad); }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .9rem center; padding-right: 2.4rem; }
.field__error { color: var(--bad); font-size: var(--fs-xs); margin-top: var(--space-1); display: none; }
.field--error .field__error { display: block; }

.form-actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); }

/* ---- Result panel ----------------------------------------------------- */
.result-panel { position: sticky; top: calc(var(--header-h) + var(--space-5)); }
.result-empty { text-align: center; padding: var(--space-8) var(--space-5); color: var(--text-muted); }
.result-empty__icon { font-size: 34px; opacity: .5; margin-bottom: var(--space-3); }

.result-card { overflow: hidden; }
.result-card__head { background: var(--grad-ink); color: #fff; padding: var(--space-6); position: relative; overflow: hidden; }
.result-card__head::after { content:""; position:absolute; inset:0; background: radial-gradient(70% 120% at 90% -20%, rgba(20,184,138,.4), transparent 55%); }
.result-headline { position: relative; z-index: 1; font-size: var(--fs-lg); color: #fff; }
.result-sub { position: relative; z-index: 1; color: rgba(233,241,247,.8); font-size: var(--fs-sm); margin-top: var(--space-2); }

/* Score gauge */
.gauge { position: relative; z-index: 1; display: flex; align-items: center; gap: var(--space-5); margin-top: var(--space-5); }
.gauge__ring { --p: 0; width: 104px; height: 104px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--emerald-400) calc(var(--p) * 1%), rgba(255,255,255,.14) 0);
  display: grid; place-items: center; transition: background var(--dur-slow) var(--ease); }
.gauge__ring::before { content:""; position:absolute; width:80px; height:80px; border-radius:50%; background: var(--ink-900); }
.gauge__num { position: relative; z-index:1; font-size: var(--fs-xl); font-weight: var(--fw-bold); color: #fff; line-height: 1; }
.gauge__den { position: relative; z-index:1; font-size: var(--fs-xs); color: rgba(255,255,255,.6); }
.gauge__label { font-size: var(--fs-sm); color: rgba(233,241,247,.85); }
.gauge__tier { display:inline-block; margin-top: var(--space-2); font-weight: var(--fw-bold); color: var(--gold-300); }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.metric { background: var(--bg-surface); padding: var(--space-4) var(--space-5); }
.metric__label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); text-transform: uppercase; letter-spacing: .04em; }
.metric__value { font-size: var(--fs-lg); font-weight: var(--fw-bold); color: var(--text-strong); margin-top: var(--space-1); font-variant-numeric: tabular-nums; }
.metric--emphasis .metric__value { color: var(--brand); }

.interp { padding: var(--space-5) var(--space-6); display: grid; gap: var(--space-3); }
.note { display: flex; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--bg-surface); }
.note__dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.note__title { font-weight: var(--fw-bold); color: var(--text-strong); font-size: var(--fs-sm); }
.note__text { font-size: var(--fs-sm); color: var(--text-body); margin-top: 2px; }
.note--good { background: var(--good-bg); border-color: #bfe9d7; } .note--good .note__dot { background: var(--good); }
.note--warn { background: var(--warn-bg); border-color: #f3dcae; } .note--warn .note__dot { background: var(--warn); }
.note--bad  { background: var(--bad-bg);  border-color: #f3c6bb; } .note--bad  .note__dot { background: var(--bad); }
.note--info { background: var(--info-bg); border-color: #c7ddf3; } .note--info .note__dot { background: var(--info); }

.actions-list { padding: 0 var(--space-6) var(--space-5); }
.actions-list h4 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: var(--space-3); }
.actions-list ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.actions-list li { position: relative; padding-left: 1.6rem; font-size: var(--fs-sm); color: var(--text-body); }
.actions-list li::before { content: "→"; position: absolute; left: 0; color: var(--brand); font-weight: var(--fw-bold); }

/* ---- Live badge ------------------------------------------------------- */
.live-badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: var(--fw-semi); color: var(--brand); align-self: center; }

/* ---- Conversational (one-question) mode ------------------------------- */
.conv { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-7); margin-top: var(--space-3); }
.conv__progress { height: 6px; background: var(--bg-sunken); border-radius: var(--radius-pill); overflow: hidden; margin-bottom: var(--space-5); }
.conv__bar { height: 100%; background: var(--grad-brand); border-radius: var(--radius-pill); transition: width var(--dur) var(--ease-out); }
.conv__step { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); font-weight: var(--fw-bold); margin-bottom: var(--space-3); }
.conv__q { font-size: var(--fs-xl); margin-bottom: var(--space-2); }
.conv__help { color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: var(--space-5); }
.conv__field { margin: var(--space-5) 0 var(--space-6); }
.conv__field .input { font-size: var(--fs-lg); padding: 0.9rem 1rem; }
.conv__field .input.has-prefix { padding-left: 2.2rem; }
.conv__field .input-wrap__affix { font-size: var(--fs-md); }
.conv__nav { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.conv__done { display: flex; justify-content: flex-end; margin-bottom: var(--space-3); }

/* ---- Lead capture ----------------------------------------------------- */
.lead { border-top: 1px solid var(--border); padding: var(--space-5) var(--space-6); background: var(--bg-sunken); }
.lead h4 { font-size: var(--fs-md); margin-bottom: var(--space-1); }
.lead p { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--space-3); }
.lead__row { display: flex; gap: var(--space-2); }
.lead__row .input { flex: 1; }
.lead__ok { color: var(--good); font-size: var(--fs-sm); font-weight: var(--fw-semi); }

/* ---- Footer ----------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--border); padding-block: var(--space-7); margin-top: var(--space-10); color: var(--text-muted); font-size: var(--fs-sm); }
.site-footer__inner { display: flex; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; align-items: center; }
.disclaimer { font-size: var(--fs-xs); color: var(--text-muted); max-width: 70ch; margin-top: var(--space-3); line-height: var(--lh-snug); }

/* ---- Utility / states ------------------------------------------------- */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.fade-in { animation: fadeIn var(--dur-slow) var(--ease-out); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.skeleton { background: linear-gradient(90deg, var(--slate-100), var(--slate-200), var(--slate-100)); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: var(--radius-md); }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink-900); color: #fff; padding: .8rem 1.2rem; border-radius: var(--radius-pill); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); z-index: 100; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 600px) {
  .hero h1 { font-size: var(--fs-2xl); }
  .header-nav a:not(.btn) { display: none; }
  .metrics { grid-template-columns: 1fr; }
}
