/* ---------- Card ---------- */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card__head {
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-border);
  display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap;
}
.card__head h2, .card__head h3 { margin: 0; }
.card__head .spacer { flex: 1; }
.card__body { padding: var(--s-5); }
.card__body--flush { padding: 0; }
.card__foot {
  padding: var(--s-3) var(--s-5); border-top: 1px solid var(--c-border);
  background: var(--c-surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg);
  font-size: var(--fs-sm); color: var(--c-text-2);
}
.card--accent { border-left: 3px solid var(--c-brand); }

/* ---------- Stat ---------- */
.stat { display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-5); }
.stat__label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em; font-weight: 640; color: var(--c-text-3); }
.stat__value { font-size: var(--fs-2xl); font-weight: 660; letter-spacing: -.03em; line-height: 1.1; }
.stat__value--sm { font-size: var(--fs-xl); }
.stat__sub { font-size: var(--fs-sm); color: var(--c-text-2); }
.stat--positive .stat__value { color: var(--c-positive); }
.stat--negative .stat__value { color: var(--c-negative); }
.stat--brand .stat__value { color: var(--c-brand); }

/* ---------- Badges & pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px;
  border-radius: 99px; font-size: var(--fs-xs); font-weight: 640; letter-spacing: .01em;
  background: var(--c-surface-3); color: var(--c-text-2); white-space: nowrap;
}
.badge--positive { background: var(--c-positive-soft); color: var(--c-positive); }
.badge--negative { background: var(--c-negative-soft); color: var(--c-negative); }
.badge--warning  { background: var(--c-warning-soft); color: var(--c-warning); }
.badge--info     { background: var(--c-info-soft); color: var(--c-info); }
.badge--brand    { background: var(--c-brand-soft); color: var(--c-brand-ink); }
.badge--opportunity { background: var(--c-opportunity-soft); color: var(--c-opportunity); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 7px 14px; border-radius: var(--r-sm); border: 1px solid var(--c-border-strong);
  background: var(--c-surface); color: var(--c-text); font-size: var(--fs-sm); font-weight: 580;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--c-surface-3); text-decoration: none; }
.btn--primary { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.btn--primary:hover { background: var(--c-brand-2); border-color: var(--c-brand-2); }
.btn--danger { background: var(--c-negative); border-color: var(--c-negative); color: #fff; }
.btn--danger:hover { filter: brightness(1.08); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--c-text-2); }
.btn--ghost:hover { background: var(--c-surface-3); }
.btn--sm { padding: 4px 10px; font-size: var(--fs-xs); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th, .tbl td { padding: 9px var(--s-4); text-align: left; border-bottom: 1px solid var(--c-border); }
.tbl thead th {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .05em;
  font-weight: 640; color: var(--c-text-3); background: var(--c-surface-2);
  position: sticky; top: 0; z-index: 1;
}
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover { background: var(--c-surface-2); }
.tbl tr.is-total td { font-weight: 660; background: var(--c-surface-3); border-top: 2px solid var(--c-border-strong); }
.tbl tr.is-emphasis td { font-weight: 640; background: var(--c-brand-soft); }
.tbl tr.is-subtle td { color: var(--c-text-2); }
.tbl caption { text-align: left; padding: var(--s-3) var(--s-4); color: var(--c-text-2); font-size: var(--fs-sm); }

/* ---------- Alerts ---------- */
.alert {
  display: flex; gap: var(--s-3); padding: var(--s-4);
  border-radius: var(--r-md); border: 1px solid var(--c-border); background: var(--c-surface-2);
}
.alert__icon { flex: none; width: 20px; height: 20px; display: grid; place-items: center; font-size: 13px; font-weight: 700; border-radius: 50%; margin-top: 1px; }
.alert__body { min-width: 0; flex: 1; }
.alert__title { font-weight: 620; margin-bottom: 2px; }
.alert__detail { font-size: var(--fs-sm); color: var(--c-text-2); }
.alert__action { font-size: var(--fs-sm); margin-top: var(--s-2); color: var(--c-text); font-weight: 560; }
.alert--critical { border-color: color-mix(in srgb, var(--c-negative) 35%, transparent); background: var(--c-negative-soft); }
.alert--critical .alert__icon { background: var(--c-negative); color: #fff; }
.alert--warning { border-color: color-mix(in srgb, var(--c-warning) 35%, transparent); background: var(--c-warning-soft); }
.alert--warning .alert__icon { background: var(--c-warning); color: #fff; }
.alert--opportunity { border-color: color-mix(in srgb, var(--c-opportunity) 30%, transparent); background: var(--c-opportunity-soft); }
.alert--opportunity .alert__icon { background: var(--c-opportunity); color: #fff; }
.alert--info { border-color: color-mix(in srgb, var(--c-info) 30%, transparent); background: var(--c-info-soft); }
.alert--info .alert__icon { background: var(--c-info); color: #fff; }

/* ---------- Banner ---------- */
.banner {
  display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-5);
  font-size: var(--fs-sm); border-bottom: 1px solid var(--c-border);
  background: var(--c-warning-soft); color: var(--c-warning);
}
.banner strong { color: inherit; }
.banner .btn { margin-left: auto; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--s-4); }
.field label { font-size: var(--fs-sm); font-weight: 580; color: var(--c-text-2); }
.field .hint { font-size: var(--fs-xs); color: var(--c-text-3); }
.input, select.input, textarea.input {
  padding: 7px 10px; border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
  background: var(--c-surface); font-size: var(--fs-sm); width: 100%;
}
.input:focus { border-color: var(--c-brand); }
.input--money { font-variant-numeric: tabular-nums; text-align: right; }
.input-group { display: flex; align-items: stretch; }
.input-group__prefix {
  display: grid; place-items: center; padding: 0 9px; border: 1px solid var(--c-border-strong);
  border-right: none; border-radius: var(--r-sm) 0 0 var(--r-sm); background: var(--c-surface-3);
  color: var(--c-text-3); font-size: var(--fs-sm);
}
.input-group .input { border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--s-4); }
input[type="range"] { width: 100%; accent-color: var(--c-brand); }
.toggle { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-sm); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; background: var(--c-surface-3); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.segmented button {
  border: none; background: transparent; padding: 5px 12px; border-radius: 5px;
  font-size: var(--fs-sm); font-weight: 560; color: var(--c-text-2);
}
.segmented button[aria-pressed="true"] { background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-sm); }

/* ---------- Charts ---------- */
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--c-border); stroke-width: 1; }
.chart .axis-label { fill: var(--c-text-3); font-size: 10px; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { opacity: .10; }
.chart .bar { rx: 2; }
.chart .zero-line { stroke: var(--c-border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-legend { display: flex; gap: var(--s-4); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--c-text-2); margin-top: var(--s-3); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* ---------- Meters ---------- */
.meter { height: 6px; background: var(--c-surface-3); border-radius: 99px; overflow: hidden; }
.meter__fill { height: 100%; background: var(--c-brand); border-radius: 99px; }
.meter__fill--positive { background: var(--c-positive); }
.meter__fill--warning { background: var(--c-warning); }
.meter__fill--negative { background: var(--c-negative); }

.bar-split { display: flex; height: 26px; border-radius: var(--r-sm); overflow: hidden; font-size: var(--fs-xs); }
.bar-split > div { display: grid; place-items: center; color: #fff; font-weight: 620; min-width: 0; overflow: hidden; }

/* ---------- Score ring ---------- */
.score { display: flex; align-items: center; gap: var(--s-5); }
.score__ring { position: relative; width: 96px; height: 96px; flex: none; }
.score__num {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: var(--fs-xl); font-weight: 680; letter-spacing: -.03em;
}

/* ---------- Priority card ---------- */
.priority { border: 1px solid var(--c-border); border-radius: var(--r-md); overflow: hidden; background: var(--c-surface); }
.priority__head { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-4) var(--s-5); }
.priority__rank {
  width: 24px; height: 24px; border-radius: 7px; background: var(--c-brand); color: #fff;
  display: grid; place-items: center; font-size: var(--fs-sm); font-weight: 700; flex: none;
}
.priority__title { font-weight: 640; }
.priority__body { padding: 0 var(--s-5) var(--s-4); }
.priority__meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3);
  padding: var(--s-4) var(--s-5); background: var(--c-surface-2); border-top: 1px solid var(--c-border);
  font-size: var(--fs-sm);
}
.priority__meta dt { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-3); font-weight: 640; }
.priority__meta dd { margin: 2px 0 0; color: var(--c-text-2); }

/* ---------- Provenance ---------- */
.prov { font-size: var(--fs-xs); color: var(--c-text-3); }
.prov__dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; }
.prov__dot--high { background: var(--c-positive); }
.prov__dot--medium { background: var(--c-warning); }
.prov__dot--low { background: var(--c-negative); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.55); z-index: 100;
  display: grid; place-items: center; padding: var(--s-4);
}
.modal {
  background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  max-width: 680px; width: 100%; max-height: 86vh; display: flex; flex-direction: column;
}
.modal__head { padding: var(--s-5); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: var(--s-3); }
.modal__body { padding: var(--s-5); overflow-y: auto; }
.modal__foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--c-border); display: flex; gap: var(--s-3); justify-content: flex-end; }
.modal pre {
  background: var(--c-surface-3); padding: var(--s-4); border-radius: var(--r-sm);
  font-size: var(--fs-xs); overflow: auto; max-height: 320px; margin: 0;
}

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--s-12) var(--s-5); color: var(--c-text-2); }
.empty h3 { margin-bottom: var(--s-2); color: var(--c-text); }

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--c-border); margin: var(--s-5) 0; }
.kv { display: flex; justify-content: space-between; gap: var(--s-4); padding: 5px 0; font-size: var(--fs-sm); border-bottom: 1px solid var(--c-border); }
.kv:last-child { border-bottom: none; }
.kv__k { color: var(--c-text-2); }
.kv__v { font-weight: 600; font-variant-numeric: tabular-nums; }
.note {
  font-size: var(--fs-sm); color: var(--c-text-2); background: var(--c-surface-2);
  border-left: 2px solid var(--c-border-strong); padding: var(--s-3) var(--s-4); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.note--brand { border-left-color: var(--c-brand); background: var(--c-brand-soft); color: var(--c-brand-ink); }
details.disclosure { border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); }
details.disclosure summary { cursor: pointer; font-weight: 580; font-size: var(--fs-sm); }
details.disclosure[open] summary { margin-bottom: var(--s-3); }
