/* ==========================================================================
   KP Stellar Astro — shared components
   Depends on static/theme.css (must be linked first). Every value here comes
   from a theme.css token; there is no raw hex in this file except third-party
   brand marks, which are commented /* raw: reason */.
   ========================================================================== */

/* ---- reset / base ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; }
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}
.wrap { max-width: 840px; width: 100%; margin: 0 auto; padding-inline: var(--s-5); }
.wrap.wide { max-width: 1180px; }

/* ---- buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: var(--ctl-h, 36px);
  padding-inline: var(--s-5);
  border-radius: var(--r-md);
  font-weight: 700; font-size: var(--fs-sm);
  cursor: pointer; text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--card); color: var(--primary); border-color: var(--line-strong); }
.btn-ghost:hover { border-color: var(--primary); background: var(--primary-soft); }
.btn-subtle { background: var(--primary-soft); color: var(--primary); }
.btn-subtle:hover { background: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { height: 28px; padding-inline: var(--s-3); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { height: 44px; padding-inline: var(--s-6); font-size: var(--fs-md); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; color: var(--on-primary);
  animation: kp-spin .7s linear infinite;
}
.btn-ghost.is-loading::after, .btn-subtle.is-loading::after { color: var(--primary); }
@keyframes kp-spin { to { transform: rotate(360deg); } }

/* ---- card / panel ------------------------------------------------------ */
.card, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }

/* ---- header / nav ------------------------------------------------------- */
header.site-header, header.kp-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--card) 90%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav { display: flex; align-items: center; gap: var(--s-4); max-width: 1180px; margin: 0 auto; padding: var(--s-4) var(--s-5); }
.nav .brand { display: flex; align-items: center; gap: var(--s-3); text-decoration: none; }
.nav .brand img { width: 34px; height: 34px; }
.nav .brand b { font-size: 1.05rem; color: var(--heading); letter-spacing: -.01em; }
.nav .spacer { flex: 1; }
.nav .navlinks { display: flex; gap: var(--s-6); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); margin-right: var(--s-2); }
.nav .navlinks a { text-decoration: none; }
.nav .navlinks a:hover, .nav .navlinks a.active { color: var(--primary); }
@media (max-width: 760px) { .nav .navlinks { display: none; } }

/* ---- footer -------------------------------------------------------------- */
footer.site-footer { border-top: 1px solid var(--line); color: var(--text-muted); font-size: var(--fs-sm); padding: var(--s-6) var(--s-5); }
footer.site-footer a { color: var(--text-muted); text-decoration: none; }
footer.site-footer a:hover { color: var(--primary); }

/* ---- form controls ------------------------------------------------------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  height: var(--ctl-h, 36px); padding-inline: var(--s-3);
}
textarea { height: auto; padding-block: var(--s-2); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus-ring); outline: none; }
input.is-error, select.is-error, textarea.is-error { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-xs); margin-top: var(--s-1); }
label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }

input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--line-strong); border-radius: var(--r-pill);
  transition: background var(--dur) var(--ease);
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- pill / chip / verdict ------------------------------------------------ */
.pill, .chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 2px var(--s-3); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em;
  background: var(--primary-soft); color: var(--on-soft-primary);
}
.pill.favour, .chip.favour, .verdict-favour { background: var(--favour-soft); color: var(--favour); }
.pill.against, .chip.against, .verdict-against { background: var(--against-soft); color: var(--against); }
.pill.neutral, .chip.neutral, .verdict-neutral { background: var(--neutral-soft); color: var(--neutral); }

/* ---- badges --------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; padding: 1px var(--s-2); border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 700; background: var(--gold); color: var(--gold-ink); }
.badge-admin { background: var(--primary); color: #fff; }

/* ---- tables --------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table th { text-align: left; font-size: var(--fs-xs); letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); padding: var(--s-2) var(--s-3); }
table td { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line); }

/* ---- tabs (kptabs) --------------------------------------------------------- */
.kptabs, .tabs { display: flex; gap: var(--s-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.kptabs button, .tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: var(--s-3) var(--s-4); font-weight: 600; color: var(--text-muted); cursor: pointer;
}
.kptabs button.active, .tabs button.active, .kptabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- modal / bottom sheet ------------------------------------------------- */
.modal-bg { position: fixed; inset: 0; background: var(--overlay); z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal {
  background: var(--card); border-radius: var(--r-xl); box-shadow: var(--shadow-3);
  max-width: 520px; width: calc(100% - var(--s-6)); max-height: 86vh; overflow: auto; padding: var(--s-6);
}
@media (max-width: 640px) {
  .modal-bg { align-items: flex-end; }
  .modal { width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92vh; }
}

/* ---- toast / banner --------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: var(--s-6); transform: translateX(-50%);
  background: var(--text); color: var(--card); padding: var(--s-3) var(--s-5);
  border-radius: var(--r-md); box-shadow: var(--shadow-2); font-size: var(--fs-sm); z-index: 300;
}
.banner { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-radius: var(--r-md); font-size: var(--fs-sm); background: var(--info-soft); color: var(--info); border: 1px solid var(--line); }
.banner.warning { background: var(--warning-soft); color: var(--warning); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }

/* ---- skeleton loader --------------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; border-radius: var(--r-sm);
  animation: kp-skeleton 1.4s ease infinite;
}
@keyframes kp-skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---- empty state --------------------------------------------------------------- */
.empty-state { text-align: center; padding: var(--s-8) var(--s-5); color: var(--text-muted); }
.empty-state h3 { color: var(--heading); margin: var(--s-3) 0 var(--s-1); }

/* ---- mobile bottom bar ----------------------------------------------------------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: none; justify-content: space-around; align-items: center;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: var(--shadow-2);
  padding: var(--s-2) 0 max(var(--s-2), env(safe-area-inset-bottom));
}
@media (max-width: 760px) { .bottom-bar { display: flex; } }
.bottom-bar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: var(--fs-xs); color: var(--text-muted); text-decoration: none; }
.bottom-bar a.active { color: var(--primary); }

/* ---- shared guide/article template (about/features/learn/etc.) ------------------- */
.crumbs { font-family: var(--font-mono); font-size: .74rem; color: var(--text-faint); }
.crumbs a { color: var(--text-muted); text-decoration: none; }
.crumbs a:hover { color: var(--primary); }
article.guide, .feature-card, .pan-card, .hub-card { box-shadow: none; }
article.guide { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 36px 40px 40px; margin: 20px 0 40px; }
@media (max-width: 640px) { article.guide { padding: 24px 20px 28px; } }
.guide .eyebrow { display: block; background: none; padding: 0; border-radius: 0; color: var(--text-faint);
  font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; margin-bottom: 14px; }
.guide h1, .hero h1, .card h1 { font-family: var(--font-serif); font-weight: 600; color: var(--text); letter-spacing: -.005em; text-wrap: balance; margin: 0 0 10px; font-size: var(--fs-2xl); line-height: var(--lh-tight); }
.guide h2 { font-family: var(--font-serif); font-weight: 600; color: var(--text); padding-top: 18px; border-top: 1px solid var(--line); margin: 34px 0 12px; font-size: var(--fs-xl); }
.guide h3, .card h2, .card h3, .pan-card h3, .gl-term h3 { color: var(--text); }
.card h2, .pan-card h3, .gl-term h3 { font-family: var(--font-serif); font-weight: 600; }
.guide p, .guide li { color: var(--text); font-size: .98rem; }
.guide ul, .guide ol { margin: 0 0 16px; padding-left: 22px; }
.guide li { margin-bottom: 6px; }
.guide .dek { color: var(--text-muted); margin: 0 0 28px; font-size: 1.05rem; }
.guide strong { color: var(--text); }
.guide p a, .guide li a { color: var(--primary); }
.callout { background: var(--sheet); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--r-md); color: var(--text); padding: 16px 18px; margin: 20px 0; font-size: .92rem; }
.callout b { color: var(--text); }
.callout.warn { border-left-color: var(--accent); }
.callout.danger { border-left-color: var(--danger); }
.related a, .related-links a { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.related a:hover, .related-links a:hover { background: var(--sheet); border-color: var(--line-strong); }
.hub-card { background: var(--card); border: 1px solid var(--line); border-bottom: 3px solid var(--line-strong); border-radius: var(--r-md); }
.hub-card:hover { border-color: var(--line-strong); }
.hub-card h3 { color: var(--text); font-weight: 600; }
.faq-item summary { font-family: var(--font-serif); font-weight: 600; font-size: 1rem; color: var(--text); }
.faq-item summary::after { font-family: var(--font-mono); color: var(--text-faint); }
.faq-item[open] summary::after { content: "\2212"; color: var(--accent); }
.docnav-title { color: var(--text-faint); letter-spacing: .09em; }
.docnav-link { color: var(--text-muted); }
.docnav-link.current { background: var(--sheet); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.card { background: var(--card); border-color: var(--line); }
/* legal pages: readable long-form measure, serif headings, ruled sections */
body.legal { font-size: 16px; }
body.legal .wrap { max-width: 760px; }
body.legal header { background: var(--bg); border-bottom: 1px solid var(--line); }
body.legal h1 { font-family: var(--font-serif); font-weight: 600; font-size: 2.2rem; line-height: 1.15; color: var(--text); text-wrap: balance; }
body.legal h2 { font-family: var(--font-serif); font-weight: 600; font-size: 1.3rem; color: var(--text); }
body.legal .updated { font-family: var(--font-mono); font-size: .76rem; color: var(--text-faint); }
body.legal .card { background: none; border: none; border-radius: 0; padding: 22px 0 0; margin: 22px 0 0; border-top: 1px solid var(--line); }
body.legal .card:first-of-type { border-top: none; margin-top: 8px; padding-top: 0; }
body.legal p, body.legal li { max-width: 68ch; line-height: 1.7; color: var(--text); }
body.legal .notice, body.legal .grievance { background: var(--sheet); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: var(--r-md); padding: 14px 16px; }
body.legal table { border-collapse: collapse; }
body.legal th { background: transparent; color: var(--text-faint); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; border-bottom: 1px solid var(--line-strong); }
body.legal td { border-bottom: 1px solid var(--line); }

/* ---- admin stat tiles (Apple-style redesign) ------------------------------------- */
.stat-tile {
  background: color-mix(in srgb, var(--card) 72%, var(--bg));
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s-4);
}
.stat-tile .stat-value { font-size: var(--fs-2xl); font-weight: 700; color: var(--heading); font-variant-numeric: tabular-nums; }
.stat-tile .stat-label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
