/* Components: buttons, forms, cards, stats, tables, badges, alerts, dialogs, toasts */

/* Buttons */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--navy-900); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-size: var(--fs-sm); font-weight: 600; line-height: 1;
  padding: .7rem 1rem; min-height: 42px; border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg); border: 1px solid var(--btn-bd);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { background: var(--gray-50); color: var(--navy-900); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: var(--accent); box-shadow: 0 1px 2px rgba(37,99,235,.3); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-navy { --btn-bg: var(--navy-900); --btn-fg: #fff; --btn-bd: var(--navy-900); }
.btn-navy:hover { background: var(--navy-800); color: #fff; }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn-danger { --btn-fg: var(--red-700); --btn-bd: #f1c4bf; }
.btn-danger:hover { background: var(--red-50); color: var(--red-700); }
.btn-lg { padding: .9rem 1.35rem; font-size: var(--fs-base); min-height: 50px; border-radius: var(--radius); }
.btn-sm { padding: .45rem .7rem; min-height: 34px; font-size: var(--fs-xs); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* Forms */
.field { display: grid; gap: .35rem; align-content: start; }
.field label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--gray-700); }
.field .hint { font-size: var(--fs-xs); color: var(--text-subtle); }
.field .error { font-size: var(--fs-xs); color: var(--red-700); font-weight: 600; }
.input, .select, .textarea {
  font: inherit; font-size: var(--fs-base); color: var(--text); width: 100%;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: .6rem .75rem; min-height: 44px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { min-height: 84px; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--gray-500); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--red-700); }
.input-affix { position: relative; display: flex; }
.input-affix .affix { position: absolute; top: 0; bottom: 0; display: grid; place-items: center; color: var(--text-subtle); font-size: var(--fs-sm); pointer-events: none; }
.input-affix .affix.pre { left: .75rem; }
.input-affix .affix.post { right: .75rem; }
.input-affix .input.has-pre { padding-left: 1.7rem; }
.input-affix .input.has-post { padding-right: 2.6rem; }
.form-grid { display: grid; gap: var(--sp-4); }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); } .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); } .span-all { grid-column: 1 / -1; } }
.check { display: flex; gap: .6rem; align-items: flex-start; font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 650; color: var(--navy-900); padding: 0; margin-bottom: var(--sp-3); }

/* Segmented control */
.segmented { display: inline-flex; background: var(--gray-100); padding: 4px; border-radius: var(--radius); gap: 4px; flex-wrap: wrap; }
.segmented button, .segmented label {
  font: inherit; font-size: var(--fs-sm); font-weight: 600; color: var(--gray-700);
  border: 0; background: transparent; padding: .5rem .9rem; border-radius: 7px; cursor: pointer; min-height: 38px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.segmented [aria-pressed="true"], .segmented input:checked + span { background: var(--surface); color: var(--navy-900); box-shadow: var(--shadow-sm); }
.segmented label { padding: 0; }
.segmented label span { display: block; padding: .5rem .9rem; border-radius: 7px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-body { padding: var(--sp-5); }
@media (max-width: 480px) { .card-body { padding: var(--sp-4); } }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-header h2, .card-header h3 { margin: 0; font-size: var(--fs-md); }
.card-title { font-size: var(--fs-md); margin: 0; }

/* Stat tiles */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4) var(--sp-5); box-shadow: var(--shadow-sm); display: grid; gap: .3rem; min-width: 0; }
.stat-label { font-size: var(--fs-xs); font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: .4rem; }
.stat-value { font-size: var(--fs-xl); font-weight: 750; color: var(--navy-900); font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.stat-sub { font-size: var(--fs-sm); color: var(--text-muted); }
.stat.feature { background: linear-gradient(140deg, var(--navy-900), var(--navy-700)); border-color: var(--navy-900); }
.stat.feature .stat-label, .stat.feature .stat-sub { color: #b8c8e0; }
.stat.feature .stat-value { color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { font-size: var(--fs-sm); }
.table th { text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 650; padding: .65rem .9rem; border-bottom: 1px solid var(--border); background: var(--gray-25); white-space: nowrap; }
.table td { padding: .75rem .9rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.table tbody tr:hover { background: var(--gray-25); }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: var(--fs-xs); font-weight: 650; padding: .2rem .55rem; border-radius: var(--radius-pill); background: var(--gray-100); color: var(--gray-700); white-space: nowrap; }
.badge-blue { background: var(--blue-50); color: var(--blue-700); }
.badge-green { background: var(--green-50); color: var(--green-700); }
.badge-amber { background: var(--amber-50); color: var(--amber-700); }
.badge-red { background: var(--red-50); color: var(--red-700); }
.badge-navy { background: var(--navy-900); color: #fff; }

/* Alerts / callouts */
.callout { border: 1px solid var(--border); border-left: 4px solid var(--accent); background: var(--surface); border-radius: var(--radius); padding: var(--sp-4) var(--sp-5); font-size: var(--fs-sm); }
.callout > :last-child { margin-bottom: 0; }
.callout strong:first-child { color: var(--navy-900); }
.callout-info { background: var(--blue-50); border-color: var(--blue-100); border-left-color: var(--accent); }
.callout-warn { background: var(--amber-50); border-color: #f3dfb5; border-left-color: #c27c0e; }
.callout-danger { background: var(--red-50); border-color: #f1c4bf; border-left-color: var(--red-700); }
.callout-success { background: var(--green-50); border-color: #bfe5cd; border-left-color: var(--green-700); }

/* Progress meter */
.meter { height: 10px; background: var(--gray-100); border-radius: var(--radius-pill); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 400ms var(--ease); }
.meter.warn > span { background: #d98a0b; }
.meter.over > span { background: var(--red-700); }

/* Empty state */
.empty { text-align: center; padding: var(--sp-7) var(--sp-5); color: var(--text-muted); }
.empty-icon { width: 56px; height: 56px; margin: 0 auto var(--sp-4); border-radius: 14px; background: var(--blue-50); color: var(--accent); display: grid; place-items: center; }
.empty-icon svg { width: 26px; height: 26px; }
.empty h3 { margin-bottom: var(--sp-2); }

/* Dialog */
dialog.modal { border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px); color: var(--text); }
dialog.modal::backdrop { background: rgba(7, 20, 38, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h2 { font-size: var(--fs-md); margin: 0; }
.modal-body { padding: var(--sp-5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--gray-25); position: sticky; bottom: 0; flex-wrap: wrap; }
@media (prefers-reduced-motion: no-preference) {
  dialog.modal[open] { animation: modal-in 180ms var(--ease); }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

/* Toasts */
.toasts { position: fixed; bottom: var(--sp-4); right: var(--sp-4); left: var(--sp-4); display: grid; gap: var(--sp-2); z-index: 200; pointer-events: none; justify-items: end; }
.toast { pointer-events: auto; background: var(--navy-900); color: #fff; padding: .75rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: var(--fs-sm); max-width: 420px; }
.toast.error { background: var(--red-700); }
@media (prefers-reduced-motion: no-preference) { .toast { animation: modal-in 200ms var(--ease); } }

/* Page hero + content */
.page-hero { background: linear-gradient(180deg, var(--navy-900), var(--navy-800)); color: #dbe6f5; padding: var(--sp-7) 0 var(--sp-7); }
.page-hero h1 { color: #fff; font-size: var(--fs-3xl); max-width: 22ch; }
.page-hero p.lead { font-size: var(--fs-md); max-width: 62ch; color: #c3d3ea; }
.eyebrow { display: inline-block; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #93b4f5; margin-bottom: var(--sp-3); }
.section { padding: var(--sp-7) 0; }
.section-tight { padding: var(--sp-5) 0; }
.prose { max-width: 72ch; }
.prose h2 { margin-top: var(--sp-6); font-size: var(--fs-lg); }
.prose h3 { margin-top: var(--sp-5); }
.prose ul, .prose ol { padding-left: 1.25rem; margin: 0 0 var(--sp-4); }
.prose li + li { margin-top: .35rem; }
.prose table { margin: var(--sp-4) 0 var(--sp-5); font-size: var(--fs-sm); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.prose th, .prose td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--gray-100); vertical-align: top; }
.prose th { background: var(--gray-25); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.reviewed { display: inline-flex; gap: .4rem; align-items: center; font-size: var(--fs-xs); color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); padding: .25rem .6rem; border-radius: var(--radius-pill); }
.page-hero .reviewed { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.14); color: #c3d3ea; }
.breadcrumb { font-size: var(--fs-sm); margin-bottom: var(--sp-4); }
.breadcrumb a { color: #9fb3d1; text-decoration: none; }
.breadcrumb a:hover { color: #fff; }
.breadcrumb span { color: #6f86a8; margin: 0 .35rem; }

/* Feature tiles */
.feature-card { display: block; text-decoration: none; color: inherit; padding: var(--sp-5); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.feature-card:hover { border-color: var(--blue-500); box-shadow: var(--shadow); color: inherit; }
@media (prefers-reduced-motion: no-preference) { .feature-card:hover { transform: translateY(-2px); } }
.feature-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--blue-50); color: var(--accent); display: grid; place-items: center; margin-bottom: var(--sp-4); }
.feature-icon svg { width: 22px; height: 22px; }
.feature-card h3 { margin-bottom: var(--sp-2); }
.feature-card p { color: var(--text-muted); font-size: var(--fs-sm); margin: 0; }
.link-arrow { font-weight: 600; font-size: var(--fs-sm); color: var(--accent); display: inline-flex; gap: .3rem; align-items: center; margin-top: var(--sp-3); }

/* Reserved ad slot: stays hidden unless extras.js activates it (ads enabled + unit ID + page opted in) */
.ad-slot { display: none; }
.ad-slot.is-live { display: block; min-height: 120px; margin: var(--sp-6) 0; padding-top: var(--sp-2); border-top: 1px solid var(--border); }
.ad-slot.is-live::before { content: "Advertisement"; display: block; font-size: var(--fs-xs); color: var(--text-subtle); text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--sp-2); }

/* Recommendations */
.rec-list { list-style: none; padding: 0; margin: var(--sp-4) 0 0; display: grid; gap: var(--sp-3); }
@media (min-width: 720px) { .rec-list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.rec-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--sp-4); display: grid; gap: .5rem; align-content: start; }
.rec-card p { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.rec-card .btn { justify-self: start; }
.rec-head { display: flex; justify-content: space-between; gap: var(--sp-3); align-items: flex-start; }

/* Print */
@media print {
  .site-header, .site-footer, .nav-toggle, .btn, .toasts { display: none !important; }
  body { background: #fff; }
  .card, .stat { box-shadow: none; }
}
