/*
 * HAVS Calculator shared components.
 * Built from docs/design/02-ui-components.png and 03-layouts-and-structure.png.
 * All values come from tokens.css.
 */

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
img, svg { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.container { max-width: calc(var(--container) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.eyebrow { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--link); }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ---------- Logo ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.logo img { width: auto; height: 42px; }
.logo-text { font-family: var(--font-brand); line-height: 1; }
.logo-text strong { display: block; font-size: 1.32rem; font-weight: 800; letter-spacing: 0.01em; color: var(--text); }
.logo-text span { display: block; font-size: 0.98rem; font-weight: 500; color: var(--wordmark-sub); margin-top: 1px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 0.98rem;
  min-height: 46px; padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  text-decoration: none; cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn-lg { min-height: 54px; padding: 14px 26px; font-size: 1.05rem; }
.btn-sm { min-height: 38px; padding: 6px 14px; font-size: 0.9rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--link); }
.btn-secondary:hover { background: var(--accent-soft); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--field); }
.btn-destructive { background: var(--status-limit-bg); color: var(--status-limit-text); border-color: var(--status-limit-border); }
.btn-destructive:hover { background: var(--status-limit); color: #fff; border-color: var(--status-limit); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--field); color: var(--muted); border-color: var(--border); cursor: not-allowed; transform: none; }
.text-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--link); font-weight: 600; text-decoration: underline; text-underline-offset: 4px;
  background: none; border: 0; padding: 0; font: inherit; font-weight: 600; cursor: pointer;
}
.text-link svg { width: 16px; height: 16px; transition: transform 0.15s; }
.text-link:hover svg { transform: translateX(3px); }
.icon-btn {
  width: 42px; height: 42px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--link); }
.icon-btn svg { width: 20px; height: 20px; }

/* Theme toggle icons */
.theme-toggle .sun { display: none; }
.is-dark .theme-toggle .sun { display: block; }
.is-dark .theme-toggle .moon { display: none; }

/* ---------- Top navigation ---------- */
.topnav {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topnav .container { display: flex; align-items: center; gap: 16px; height: var(--nav-height); }
.topnav .logo { margin-right: auto; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a {
  position: relative;
  white-space: nowrap;
  padding: 8px 12px;
  color: var(--text); text-decoration: none;
  font-size: 0.95rem; font-weight: 500;
  border-radius: var(--radius-sm);
}
.nav-links a:hover { color: var(--link); }
.nav-links a[aria-current="page"] { color: var(--link); font-weight: 600; }
.app-nav .nav-links a[aria-current="page"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -19px;
  height: 2px; border-radius: 2px; background: var(--link);
}
.menu-btn { display: none; }

/* Mobile menu panel */
.mobile-menu {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11, 20, 34, 0.45);
  display: none;
}
.mobile-menu.open { display: block; }
.mobile-menu .panel-inner {
  position: absolute; top: 8px; right: 8px; left: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 16px;
}
.mobile-menu .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mobile-menu nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
  border-bottom: 1px solid var(--border);
}
.mobile-menu nav a svg { width: 20px; height: 20px; color: var(--muted); }
.mobile-menu nav a[aria-current="page"] { color: var(--link); }
.mobile-menu .btn { margin-top: 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}
.card-title { font-size: 1.15rem; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.icon-tile {
  width: 52px; height: 52px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent-soft); color: var(--link);
}
.icon-tile svg { width: 26px; height: 26px; }
.icon-tile.round { border-radius: 50%; width: 64px; height: 64px; }
.icon-tile.safe { background: var(--status-safe-bg); color: var(--status-safe); }
.icon-tile.action { background: var(--status-action-bg); color: var(--status-action); }
.icon-tile.limit { background: var(--status-limit-bg); color: var(--status-limit); }

/* ---------- Form fields ---------- */
.field { display: block; min-width: 0; }
.field-label { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; font-weight: 600; margin-bottom: 8px; white-space: nowrap; }
.field-label .hint { font-weight: 400; color: var(--muted); }
.info-icon { width: 16px; height: 16px; color: var(--muted); cursor: help; }
.input, .select {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  font: inherit; font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.input:focus, .select:focus, .input-group:focus-within { border-color: var(--link); box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 18%, transparent); }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235a6b82' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px;
  cursor: pointer;
}
.input-group {
  display: flex; align-items: stretch;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.input-group input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; outline: none; background: transparent;
  padding: 0 14px;
  font: inherit; font-size: 1.05rem; font-weight: 500; color: var(--text);
  -moz-appearance: textfield; appearance: textfield;
}
.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-group .addon {
  display: grid; place-items: center;
  padding: 0 12px;
  background: var(--field); color: var(--muted);
  font-size: 0.9rem;
}
.input-group .addon svg { width: 18px; height: 18px; }
.input-group.leading .addon { background: transparent; padding-right: 0; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 6px;
  border-radius: var(--radius-pill);
  font-size: 0.85rem; font-weight: 600;
  white-space: nowrap;
  background: var(--status-draft-bg); color: var(--muted);
}
.badge svg { width: 18px; height: 18px; flex-shrink: 0; }
.badge.safe { background: var(--status-safe-bg); color: var(--status-safe-text); }
.badge.safe svg { color: var(--status-safe); }
.badge.action { background: var(--status-action-bg); color: var(--status-action-text); }
.badge.action svg { color: var(--status-action); }
.badge.limit { background: var(--status-limit-bg); color: var(--status-limit-text); }
.badge.limit svg { color: var(--status-limit); }
.badge.saved { background: var(--accent-soft); color: var(--link); }
.badge.sm { font-size: 0.78rem; padding: 3px 10px 3px 5px; }
.badge.sm svg { width: 15px; height: 15px; }

/* ---------- Alerts ---------- */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--field);
}
.alert > svg { width: 24px; height: 24px; flex-shrink: 0; color: var(--muted); }
.alert strong { display: block; font-weight: 700; }
.alert p { font-size: 0.9rem; color: var(--muted); margin-top: 2px; }
.alert.safe { background: var(--status-safe-bg); border-color: var(--status-safe-border); }
.alert.safe > svg { color: var(--status-safe); }
.alert.safe strong { color: var(--status-safe-text); }
.alert.action { background: var(--status-action-bg); border-color: var(--status-action-border); }
.alert.action > svg { color: var(--status-action); }
.alert.action strong { color: var(--status-action-text); }
.alert.limit { background: var(--status-limit-bg); border-color: var(--status-limit-border); }
.alert.limit > svg { color: var(--status-limit); }
.alert.limit strong { color: var(--status-limit-text); }
.alert.info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--link) 30%, transparent); }
.alert.info > svg { color: var(--link); }

/* ---------- Exposure result component ---------- */
.result { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; }
.donut { position: relative; width: 190px; height: 190px; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .track { stroke: var(--track); }
.donut .arc { stroke: var(--status-safe); transition: stroke-dashoffset 0.6s cubic-bezier(.2,.8,.2,1), stroke 0.3s; }
.donut-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-label strong { font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.donut-label .unit { font-size: 1rem; font-weight: 600; margin-top: 2px; }
.donut-label .cap { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.14em; color: var(--muted); margin-top: 6px; }
[data-level="action"] .donut .arc { stroke: var(--status-action); }
[data-level="limit"] .donut .arc { stroke: var(--status-limit); }
.result-copy h3 { font-size: 1.25rem; margin: 12px 0 6px; }
.result-copy p { color: var(--muted); font-size: 0.93rem; }
.stat-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin-top: 16px;
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  padding: 14px 4px;
}
.stat-row div { padding: 0 14px; border-left: 1px solid var(--border); }
.stat-row div:first-child { border-left: 0; }
.stat-row strong { display: block; font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-row strong small { font-size: 0.8rem; font-weight: 600; }
.stat-row > div > span { font-size: 0.82rem; color: var(--muted); }

/* EAV/ELV scale bar */
.scale { margin-top: 22px; }
.scale-bar { position: relative; height: 10px; border-radius: 5px; background: var(--track); }
.scale-bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 5px; background: var(--status-safe); transition: width 0.5s, background 0.3s; }
[data-level="action"] .scale-bar .fill { background: linear-gradient(to right, var(--status-safe) 0 40%, var(--status-action) 60%); }
[data-level="limit"] .scale-bar .fill { background: linear-gradient(to right, var(--status-safe) 0 30%, var(--status-action) 45% 70%, var(--status-limit) 85%); }
.scale-bar .tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--muted); opacity: 0.5; }
.scale-labels { position: relative; height: 34px; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.scale-labels span { position: absolute; top: 6px; transform: translateX(-50%); text-align: center; line-height: 1.2; white-space: nowrap; }
.scale-labels span:first-child { transform: none; }
.scale-labels span:last-child { transform: translateX(-100%); text-align: right; }
.scale-labels .elv { color: var(--status-limit-text); }

/* ---------- Tabs & pills ---------- */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font: inherit; font-size: 0.9rem; font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.pill:hover { border-color: var(--link); }
.pill[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
  text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--muted);
  padding: 10px 12px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th:first-child { border-top-left-radius: var(--radius-sm); }
.table th:last-child { border-top-right-radius: var(--radius-sm); }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.tool-cell { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.tool-cell .thumb { width: 38px; height: 38px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--accent-soft); color: var(--link); flex-shrink: 0; }
.tool-cell .thumb svg { width: 24px; height: 24px; }
.tool-cell strong { display: block; font-weight: 600; }
.tool-cell small { color: var(--muted); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 56px 0 28px; background: var(--bg); }
.footer-grid { display: grid; grid-template-columns: 1.6fr repeat(2, 1fr); gap: var(--space-card-gap); }
.footer-grid p { color: var(--muted); font-size: 0.92rem; margin-top: 14px; max-width: 26rem; }
.footer-grid h4 { margin: 0 0 12px; font-size: 0.92rem; }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li { margin: 8px 0; }
.footer-grid li a { color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.footer-grid li a:hover { color: var(--link); }
.footer-bottom { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }

/* ---------- Sections ---------- */
.section { padding: var(--space-section) 0; scroll-margin-top: var(--nav-height); }
.section.soft { background: var(--bg-soft); }
.section-head { text-align: center; max-width: 44rem; margin: 0 auto var(--space-block); }
.section-head h2 { font-size: var(--fs-h2); font-weight: 800; letter-spacing: -0.01em; margin-top: 8px; }
.section-head p { color: var(--muted); margin-top: 10px; font-size: 1.05rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  .nav-links, .topnav .nav-cta { display: none; }
  .menu-btn { display: grid; }
}
@media (max-width: 767px) {
  .logo img { height: 36px; }
  .logo-text strong { font-size: 1.15rem; }
  .logo-text span { font-size: 0.85rem; }
  .card { padding: 20px; }
  .result { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .result-copy .badge { margin: 0 auto; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .footer-grid > :first-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
