/* ---------- Panels ---------- */
.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.012), transparent 40%), var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  min-width: 0;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-2); margin-bottom: var(--s-2); }
.panel-head h2, .panel-head h3 { font-size: var(--fs-md); display: flex; align-items: center; gap: 10px; }
.panel-head h2 svg, .panel-head h3 svg { width: 18px; height: 18px; color: var(--teal); flex: none; }
.panel-head .sub { font-size: var(--fs-sm); color: var(--text-3); margin-top: 4px; }
.panel-foot { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--s-1); flex-wrap: wrap; font-size: var(--fs-sm); color: var(--text-3); }
.panel.tight { padding: var(--s-2); }
.panel.flush { padding: 0; overflow: hidden; }
.panel.accent { border-color: var(--teal-line); }

.eyebrow { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface-raised); --btn-fg: var(--text); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 var(--s-2);
  background: var(--btn-bg); color: var(--btn-fg); border: 1px solid var(--btn-bd);
  border-radius: var(--r-md); font: inherit; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:hover { background: var(--surface-hover); color: var(--btn-fg); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--teal); --btn-fg: var(--text-on-accent); --btn-bd: var(--teal); }
.btn-primary:hover { background: #6fdccb; }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-raised); color: var(--text); }
.btn-danger { --btn-fg: var(--red); --btn-bd: var(--red-line); --btn-bg: transparent; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-lg { min-height: 48px; padding: 0 var(--s-3); font-size: var(--fs-base); }
.btn-icon { width: 40px; padding: 0; }
.btn-block { width: 100%; }
.btn .spinner { width: 14px; height: 14px; }

.link-btn { background: none; border: 0; padding: 0; color: var(--teal); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.field .error { font-size: var(--fs-xs); color: var(--red); display: flex; gap: 6px; align-items: flex-start; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-2); }

.input, select.input, textarea.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  background: var(--surface-sunken); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font: inherit; font-size: var(--fs-sm);
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
textarea.input { min-height: 88px; resize: vertical; line-height: 1.5; }
.input::placeholder { color: #6f7a8e; }
.input:hover { border-color: #3a5079; }
.input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--ring); }
.input[aria-invalid='true'] { border-color: var(--red); }
select.input { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23929db0' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input-unit { display: flex; align-items: stretch; }
.input-unit .input { border-top-right-radius: 0; border-bottom-right-radius: 0; font-variant-numeric: tabular-nums; }
.input-unit .unit { display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0; background: var(--surface-raised); color: var(--text-2); font-size: var(--fs-sm); white-space: nowrap; }

.check { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: var(--fs-sm); }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--teal); flex: none; }

/* Segmented control (radio group) */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--r-md); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 34px; padding: 0 12px; border-radius: var(--r-sm); font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease); font-variant-numeric: tabular-nums; }
.segmented input:hover + span { color: var(--text); background: var(--surface-raised); }
.segmented input:checked + span { background: var(--surface-hover); color: var(--text); box-shadow: inset 0 0 0 1px var(--teal-line); }
.segmented input:focus-visible + span { outline: 2px solid var(--border-focus); outline-offset: 1px; }
.segmented.fill { display: flex; }
.segmented.fill label { flex: 1; }
.segmented.fill span { width: 100%; }

/* Option cards (radio cards) */
.option-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--s-1); }
.option-card { position: relative; display: block; cursor: pointer; }
.option-card input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.option-card .oc-body { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 14px var(--s-2); border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface-sunken); transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease); }
.option-card .oc-title { font-weight: 600; font-size: var(--fs-sm); display: flex; align-items: center; gap: 8px; }
.option-card .oc-desc { font-size: var(--fs-xs); color: var(--text-3); }
.option-card input:hover + .oc-body { border-color: #3a5079; }
.option-card input:checked + .oc-body { border-color: var(--teal); background: var(--teal-soft); }
.option-card input:focus-visible + .oc-body { box-shadow: var(--ring); }

/* Toggle switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-sm); color: var(--text-2); user-select: none; }
.switch input { appearance: none; width: 36px; height: 20px; border-radius: 999px; background: var(--surface-hover); border: 1px solid var(--border-strong); position: relative; cursor: pointer; margin: 0; transition: background var(--dur-1) var(--ease); flex: none; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-2); transition: transform var(--dur-1) var(--ease), background var(--dur-1) var(--ease); }
.switch input:checked { background: var(--teal-soft); border-color: var(--teal); }
.switch input:checked::after { transform: translateX(16px); background: var(--teal); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; background: var(--grey-soft); color: var(--text-2); border: 1px solid transparent; }
.badge svg { width: 13px; height: 13px; flex: none; }
.badge.teal { background: var(--teal-soft); color: var(--teal); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.attention { background: var(--amber-soft); color: var(--amber); }
.badge.urgent { background: var(--red-soft); color: var(--red); }
.badge.unknown { background: var(--grey-soft); color: var(--grey); }
.badge.outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.badge.historical { background: rgba(201, 195, 182, 0.1); color: #d8d2c4; border-color: rgba(201, 195, 182, 0.25); }

.chip-grid { display: flex; flex-wrap: wrap; gap: var(--s-1); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface-sunken); color: var(--text-2); font: inherit; font-size: var(--fs-sm); cursor: pointer; transition: all var(--dur-1) var(--ease); }
.chip:hover { color: var(--text); border-color: #3a5079; }
.chip[aria-pressed='true'] { background: var(--teal-soft); border-color: var(--teal); color: var(--text); }
.chip svg { width: 14px; height: 14px; }

.provenance { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-3); }
.provenance svg { width: 13px; height: 13px; }

/* ---------- Metric tiles ---------- */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s-2); }
.metric {
  display: flex; flex-direction: column; gap: 6px; padding: var(--s-2); min-height: 132px;
  background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--r-md);
}
.metric-head { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); font-weight: 500; }
.metric-head svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.metric-value { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; display: flex; align-items: baseline; gap: 6px; }
.metric-value .unit { font-size: var(--fs-sm); color: var(--text-3); font-weight: 500; letter-spacing: 0; }
.metric-empty { font-size: var(--fs-sm); color: var(--grey); display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.metric-empty svg { width: 14px; height: 14px; }
.metric-meta { margin-top: auto; display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: var(--fs-xs); color: var(--text-3); }
.metric.is-empty { border-style: dashed; background: transparent; }

/* ---------- Empty states ---------- */
.empty { display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1); padding: var(--s-3); border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: rgba(13, 22, 40, 0.5); }
.empty.center { align-items: center; text-align: center; padding: var(--s-5) var(--s-3); }
.empty .empty-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-raised); color: var(--teal); border: 1px solid var(--border-strong); }
.empty .empty-icon svg { width: 20px; height: 20px; }
.empty h3 { font-size: var(--fs-base); margin-top: 4px; }
.empty p { color: var(--text-2); font-size: var(--fs-sm); max-width: 56ch; }
.empty .btn { margin-top: var(--s-1); }

/* ---------- Callouts ---------- */
.callout { display: flex; gap: 12px; padding: 14px var(--s-2); border-radius: var(--r-md); border: 1px solid var(--border-strong); background: var(--surface-sunken); font-size: var(--fs-sm); color: var(--text-2); }
.callout > svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--info); }
.callout strong { color: var(--text); }
.callout.attention { border-color: var(--amber-line); background: var(--amber-soft); }
.callout.attention > svg { color: var(--amber); }
.callout.urgent { border-color: var(--red-line); background: var(--red-soft); }
.callout.urgent > svg { color: var(--red); }
.callout.teal { border-color: var(--teal-line); background: var(--teal-soft); }
.callout.teal > svg { color: var(--teal); }
.callout .callout-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

/* ---------- Lists ---------- */
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.list > li { padding: 12px 0; border-top: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.list > li:first-child { border-top: 0; padding-top: 0; }
.list > li:last-child { padding-bottom: 0; }
.list .li-main { flex: 1; min-width: 0; }
.list .li-title { font-weight: 600; font-size: var(--fs-sm); }
.list .li-meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.list .li-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-raised); color: var(--text-2); }
.list .li-icon svg { width: 16px; height: 16px; }
.list .li-icon.attention { background: var(--amber-soft); color: var(--amber); }
.list .li-icon.urgent { background: var(--red-soft); color: var(--red); }
.list .li-icon.info { background: var(--info-soft); color: var(--info); }
.list .li-icon.teal { background: var(--teal-soft); color: var(--teal); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--s-3); overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 10px 14px; color: var(--text-2); font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected='true'] { color: var(--text); border-bottom-color: var(--teal); }
.tabs .count { font-size: 11px; padding: 0 7px; border-radius: 999px; background: var(--surface-raised); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th { text-align: left; font-weight: 600; color: var(--text-2); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; padding: 10px 12px; background: var(--surface-sunken); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; }
table.data caption { text-align: left; padding: 10px 12px; color: var(--text-3); font-size: var(--fs-xs); caption-side: bottom; }

dl.kv { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: 8px var(--s-2); margin: 0; font-size: var(--fs-sm); }
dl.kv dt { color: var(--text-3); }
dl.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }

/* ---------- Stepper ---------- */
.stepper { display: flex; gap: var(--s-1); list-style: none; padding: 0; margin: 0 0 var(--s-3); counter-reset: step; }
.stepper li { flex: 1; min-width: 0; }
.stepper button { width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; background: none; border: 0; padding: 0; color: var(--text-3); font: inherit; font-size: var(--fs-xs); cursor: pointer; text-align: left; }
.stepper button::before { content: ''; display: block; width: 100%; height: 3px; border-radius: 3px; background: var(--border-strong); transition: background var(--dur-2) var(--ease); }
.stepper .step-num { font-variant-numeric: tabular-nums; }
.stepper .step-name { font-weight: 600; font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.stepper li.done button::before { background: var(--teal-strong); }
.stepper li.current button::before { background: var(--teal); }
.stepper li.current .step-name { color: var(--text); }
.stepper button:disabled { cursor: default; }

/* ---------- Toast ---------- */
.toast-region { position: fixed; right: var(--s-3); bottom: var(--s-3); z-index: 80; display: flex; flex-direction: column; gap: var(--s-1); max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 14px var(--s-2); border-radius: var(--r-md); background: var(--surface-raised); border: 1px solid var(--border-strong); box-shadow: var(--shadow-2); font-size: var(--fs-sm); animation: toast-in var(--dur-2) var(--ease); }
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast.success svg { color: var(--teal); }
.toast.error { border-color: var(--red-line); }
.toast.error svg { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Dialog ---------- */
dialog.modal { padding: 0; border: 1px solid var(--border-strong); border-radius: var(--r-lg); background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); box-shadow: var(--shadow-2); }
dialog.modal::backdrop { background: rgba(3, 7, 15, 0.7); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); }
.modal-body { padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); }
.modal-foot { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s-1); flex-wrap: wrap; }

/* ---------- Status pill (connection) ---------- */
.status-pill { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--text-2); padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--grey); flex: none; }
.status-dot.ok { background: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.status-dot.warn { background: var(--amber); }
.status-dot.bad { background: var(--red); }

/* ---------- Loading ---------- */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--teal); animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { border-radius: var(--r-md); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-raised) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.loading-block { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: var(--fs-sm); padding: var(--s-3); }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 340px; }
.chart-box.sm { height: 240px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px var(--s-2); font-size: var(--fs-xs); color: var(--text-2); margin-bottom: var(--s-1); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 8px; }
.chart-legend .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.chart-legend .swatch.line { height: 2px; border-radius: 1px; }
.chart-legend .swatch.dash { height: 0; border-top: 2px dashed var(--series-baseline); background: none !important; }
.chart-legend .swatch.hollow { background: transparent !important; border: 2px solid var(--grey); border-radius: 50%; width: 10px; height: 10px; }
.chart-legend .swatch.tri { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--text-2); border-radius: 0; background: none !important; }
.chart-legend .swatch.dot { border-radius: 50%; width: 10px; height: 10px; background: var(--text-2); }
.chart-caption { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--s-1); }

/* ---------- Timeline ---------- */
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 1px; background: var(--border-strong); }
.timeline li { position: relative; padding: 0 0 var(--s-2) 28px; font-size: var(--fs-sm); }
.timeline li::before { content: ''; position: absolute; left: 3px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--teal); }
.timeline .tl-time { font-size: var(--fs-xs); color: var(--text-3); }

/* ---------- Details / disclosure ---------- */
details.disclosure { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-sunken); }
details.disclosure > summary { cursor: pointer; padding: 12px var(--s-2); font-size: var(--fs-sm); font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3); transform: rotate(-45deg); transition: transform var(--dur-1) var(--ease); margin-right: 4px; }
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .disclosure-body { padding: 0 var(--s-2) var(--s-2); font-size: var(--fs-sm); color: var(--text-2); }

.divider-label { display: flex; align-items: center; gap: 12px; font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: 0.1em; }
.divider-label::before, .divider-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
