/* Reusable components (PLAN §4.2). */

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  padding: var(--s6);
  min-width: 0; max-width: 100%;
}
.card.tight { padding: var(--s4); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; min-width: 0; }
.card-head > * { min-width: 0; }
.card-head h3 { font-size: var(--fs-14); overflow-wrap: anywhere; }
.card-head .card-sub { color: var(--muted); font-size: var(--fs-12); overflow-wrap: anywhere; }

/* --- Stat tile --- */
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: var(--s5); display: flex; flex-direction: column; gap: var(--s2);
  min-width: 0; max-width: 100%;
}
.tile .tile-label { color: var(--ink-2); font-size: var(--fs-13); overflow-wrap: anywhere; }
.tile .tile-value { font-size: var(--fs-28); font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.tile .tile-value .unit { font-size: var(--fs-16); color: var(--muted); font-weight: 500; margin-left: 2px; }
.tile .tile-foot { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-12); flex-wrap: wrap; min-width: 0; }
.tile .tile-foot > * { min-width: 0; overflow-wrap: anywhere; }
.delta { font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up-good, .delta.down-good { color: var(--ok); }
.delta.up-bad, .delta.down-bad { color: var(--critical); }
.delta.flat { color: var(--muted); }
.tile .spark { margin-top: var(--s1); }

/* --- Insight card --- */
.insight {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r); box-shadow: var(--shadow-1);
  padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3);
  position: relative; transition: box-shadow .12s ease, transform .12s ease;
  min-height: 168px; text-align: left; width: 100%; min-width: 0; max-width: 100%;
}
a.insight:hover { box-shadow: var(--shadow-2); text-decoration: none; transform: translateY(-1px); }
.insight .ins-top { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.insight .ins-top .ins-tag { min-width: 0; }
.insight .ins-sev-word { font-size: var(--fs-12); font-weight: 700; flex: none; }
.insight .ins-sev-word.ins-sev-1 { color: var(--ink-2); }
.insight .ins-sev-word.ins-sev-2 { color: var(--serious); }
.insight .ins-sev-word.ins-sev-3 { color: var(--critical); }
.insight .sev-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.insight .sev-1 { background: var(--muted); }
.insight .sev-2 { background: var(--serious); }
.insight .sev-3 { background: var(--critical); }
.insight .ins-tag { font-size: var(--fs-12); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.insight .ins-headline { font-size: var(--fs-14); font-weight: 600; line-height: 1.35; color: var(--ink); overflow-wrap: break-word; }
.grid-5 .insight .ins-headline { min-height: 57px; }
.insight .ins-figure { font-size: var(--fs-34); font-weight: 700; letter-spacing: -0.02em; line-height: 1; color: var(--ink); overflow-wrap: anywhere; }
.insight .ins-figure .of { font-size: var(--fs-14); color: var(--muted); font-weight: 500; }
.insight .ins-action { color: var(--ink-2); font-size: var(--fs-13); line-height: 1.4; overflow-wrap: break-word; }
.insight .ins-link { margin-top: auto; color: var(--brand); font-weight: 600; font-size: var(--fs-13); display: inline-flex; align-items: center; gap: 4px; overflow-wrap: anywhere; }

/* --- Badges & chips --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-12); font-weight: 600; padding: 2px 8px;
  border-radius: var(--r-pill); border: 1px solid transparent;
  white-space: normal; text-align: left; max-width: 100%; min-width: 0;
}
.badge .b-ico { font-size: 10px; }
.badge.conf-High { background: var(--ok-bg); color: #0a7a0a; border-color: #bfe3bf; }
.badge.conf-Moderate { background: var(--warn-bg); color: #8a6208; border-color: #e7d29a; }
.badge.conf-Exploratory { background: var(--surface-2); color: var(--ink-2); border-color: var(--hairline); }
.badge.status-good { background: var(--ok-bg); color: #0a7a0a; }
.badge.status-serious { background: var(--serious-bg); color: var(--serious); }
.badge.status-critical { background: var(--critical-bg); color: var(--critical); }
.badge.cursor { cursor: help; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-12); font-weight: 600; padding: 1px 7px;
  border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--hairline);
}
.chip.type-LES { color: #1a539f; background: #eaf2fd; border-color: #cde2fb; }
.chip.type-DES { color: #4a3aa7; background: #efecfa; border-color: #d8d0f0; }
.chip.type-NES { color: #8a6208; background: var(--warn-bg); border-color: #e7d29a; }
.chip.off { color: var(--muted); }

/* --- Meter --- */
.meter { display: flex; flex-direction: column; gap: 6px; }
.meter .meter-track {
  height: 8px; border-radius: var(--r-pill); background: var(--seq-100);
  position: relative; overflow: hidden;
}
.meter .meter-fill { height: 100%; border-radius: var(--r-pill); background: var(--seq-500); }
.meter .meter-target {
  position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink);
}
.meter .meter-legend { display: flex; justify-content: space-between; font-size: var(--fs-12); color: var(--muted); }

/* --- Data table --- */
.table-wrap { border: 1px solid var(--hairline); border-radius: var(--r); overflow-x: auto; overflow-y: hidden; max-width: 100%; -webkit-overflow-scrolling: touch; background: var(--surface); }
.table-toolbar { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--hairline); flex-wrap: wrap; }
.table-toolbar .grow { flex: 1; }
table.dt { width: 100%; min-width: max-content; border-collapse: collapse; font-size: var(--fs-13); }
table.dt thead th {
  position: sticky; top: 0; background: var(--surface-2);
  text-align: left; font-weight: 600; color: var(--ink-2);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--hairline);
  white-space: nowrap; cursor: default; font-size: var(--fs-12);
}
table.dt thead th.sortable { cursor: pointer; user-select: none; }
table.dt thead th.sortable:hover { color: var(--ink); }
table.dt thead th .arrow { color: var(--brand); margin-left: 3px; }
table.dt td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--hairline); color: var(--ink); }
table.dt tbody tr:last-child td { border-bottom: none; }
table.dt tbody tr:hover td { background: var(--surface-2); }
table.dt td.num, table.dt th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--hairline); color: var(--muted); font-size: var(--fs-12); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s4); min-width: 0; }
.table-foot > * { min-width: 0; overflow-wrap: anywhere; }
.check-cell { display: inline-flex; width: 20px; height: 20px; border-radius: 5px; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.check-cell.done { background: var(--ok-bg); color: #0a7a0a; }
.check-cell.miss { background: var(--critical-bg); color: var(--critical); }

/* --- Buttons / toggles / selects --- */
.btn {
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink-2);
  padding: 5px 11px; border-radius: var(--r-sm); font-weight: 600; font-size: var(--fs-13);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--ring-strong); color: var(--ink); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.06); }

.segmented { display: inline-flex; border: 1px solid var(--hairline); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.segmented button {
  border: none; background: transparent; padding: 5px 12px; font-weight: 600;
  font-size: var(--fs-13); color: var(--ink-2); border-right: 1px solid var(--hairline);
  transition: background .12s ease, color .12s ease;
}
.segmented button:last-child { border-right: none; }
.segmented button:hover:not(.on) { background: var(--surface-2); color: var(--ink); }
.segmented button.on { background: var(--brand-tint); color: var(--brand); }

select.sel, input.inp {
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink);
  padding: 5px 10px; border-radius: var(--r-sm); font-size: var(--fs-13); font-family: inherit;
  min-width: 0; max-width: 100%;
}
label.chk { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-13); color: var(--ink-2); }

/* --- Persona dropdown --- */
.persona { position: relative; min-width: 0; }
.persona .persona-btn {
  display: flex; align-items: center; gap: var(--s2);
  border: 1px solid var(--hairline); background: var(--surface); color: var(--ink);
  padding: 6px 12px; border-radius: var(--r-sm); font-weight: 600; font-size: var(--fs-13);
  min-width: 0; max-width: 100%;
}
.persona .persona-btn .p-kind { color: var(--muted); font-weight: 500; flex: none; }
.persona .persona-btn #persona-name { min-width: 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.persona .menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: min(320px, calc(100vw - 24px)); max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r);
  box-shadow: var(--shadow-pop); padding: var(--s2); z-index: 60;
  opacity: 0; pointer-events: none; transform: translateY(-4px);
  transition: opacity .12s ease, transform .12s ease;
}
.persona.open .menu { opacity: 1; pointer-events: auto; transform: none; }
.persona .menu button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; text-align: left; background: transparent; border: none;
  padding: var(--s3); border-radius: var(--r-sm); color: var(--ink);
}
.persona .menu button:hover { background: var(--surface-2); }
.persona .menu button.on { background: var(--brand-tint); }
.persona .menu button .m-kind { font-size: var(--fs-12); color: var(--muted); }
.persona .menu button .m-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.synth-pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--synth-bg); color: var(--synth); border: 1px solid var(--synth-ring);
  border-radius: var(--r-pill); padding: 3px 10px; font-size: var(--fs-12); font-weight: 700;
  letter-spacing: 0.02em;
}

/* --- Caveat strip / callouts --- */
.caveat {
  margin-top: var(--s7); background: var(--surface-2);
  border: 1px solid var(--hairline); border-radius: var(--r);
  padding: var(--s5); color: var(--ink-2); font-size: var(--fs-13); line-height: 1.5;
}
.caveat h4 { font-size: var(--fs-13); margin-bottom: var(--s2); color: var(--ink); display: flex; align-items: center; gap: 6px; }
.caveat ul.dotted li { position: relative; padding-left: 16px; margin-top: 4px; }
.caveat ul.dotted li::before { content: "•"; position: absolute; left: 4px; color: var(--muted); }

.callout {
  border: 1px solid var(--hairline); border-left: 3px solid var(--brand);
  background: var(--brand-tint); border-radius: var(--r-sm);
  padding: var(--s3) var(--s4); font-size: var(--fs-13); color: var(--ink-2);
}
.callout.gov { border-left-color: var(--muted); background: var(--surface-2); }
.callout.boundary { border-left-color: var(--serious); background: var(--serious-bg); }

/* --- Legend --- */
.legend { display: flex; flex-wrap: wrap; gap: var(--s3); font-size: var(--fs-12); color: var(--ink-2); }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend .lg .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend .lg .ln { width: 14px; height: 2px; border-radius: 2px; flex: none; }

/* --- Drawer --- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(11,11,11,.28); z-index: 70; display: none; }
.drawer-scrim.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw;
  background: var(--surface); border-left: 1px solid var(--hairline);
  box-shadow: var(--shadow-pop); z-index: 71; transform: translateX(100%);
  transition: transform .18s ease; overflow-y: auto; padding: var(--s6);
}
.drawer.open { transform: translateX(0); }
.drawer .drawer-close { position: absolute; top: var(--s4); right: var(--s4); border: none; background: transparent; font-size: 20px; color: var(--muted); }
.drawer > h3:first-of-type { padding-right: 32px; overflow-wrap: anywhere; }

/* --- Misc --- */
.kv { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px var(--s4); font-size: var(--fs-13); }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.pill-count { background: var(--surface-2); border: 1px solid var(--hairline); border-radius: var(--r-pill); padding: 1px 8px; font-size: var(--fs-12); font-weight: 600; color: var(--ink-2); }
.divider { height: 1px; background: var(--hairline); margin: var(--s5) 0; }
.empty-state { padding: var(--s7); text-align: center; color: var(--muted); }

/* --- Responsive: figure step-downs & persona --- */
@media (max-width: 640px) {
  .persona .persona-btn #persona-name { max-width: 130px; }
  .persona .menu {
    position: fixed; top: calc(var(--ribbon-h) + var(--header-h) + 6px);
    right: 8px; left: auto; width: min(320px, calc(100vw - 16px)); min-width: 0;
  }
  .tile .tile-value { font-size: 24px; }
  .insight .ins-figure { font-size: 28px; }
}
