/* ==========================================================================
   Components
   ========================================================================== */

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
    color var(--dur-1) var(--ease), opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn-primary {
  background: var(--inv-bg);
  color: var(--inv-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--inv-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--line-2);
  color: var(--fg-1);
  box-shadow: var(--highlight);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-3);
}

.btn-ghost {
  color: var(--fg-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--fg-1);
}

.btn-outline {
  border-color: var(--line-3);
  color: var(--fg-1);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--fg-1);
}

/* Destructive stays monochrome: a hard outline and a strong label. */
.btn-danger {
  border-color: var(--line-4);
  color: var(--fg-1);
  background: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: var(--fg-1);
  color: var(--canvas);
  border-color: var(--fg-1);
}

.btn:disabled {
  opacity: 0.45;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: var(--r-sm);
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

.btn-xs {
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
  border-radius: var(--r-sm);
  gap: 5px;
}

.btn-xs svg {
  width: 13px;
  height: 13px;
}

.btn-lg {
  height: 38px;
  padding: 0 16px;
  font-size: 14px;
}

.btn-block {
  width: 100%;
}

.btn .kbd {
  margin-left: 2px;
}

.btn-primary .kbd {
  background: transparent;
  border-color: color-mix(in srgb, var(--inv-fg) 25%, transparent);
  color: color-mix(in srgb, var(--inv-fg) 65%, transparent);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--r-md);
  color: var(--fg-3);
  position: relative;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--fg-1);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-btn.sm {
  width: 26px;
  height: 26px;
}

.icon-btn .badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-1);
  box-shadow: 0 0 0 2px var(--canvas);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 1px solid var(--line-2);
  border-bottom-width: 1.5px;
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
  background: var(--surface-2);
  line-height: 1;
}

.spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid var(--line-3);
  border-top-color: var(--fg-1);
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

.spinner.sm {
  width: 11px;
  height: 11px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Form controls ------------------------------------------------------- */

.input,
.select,
.textarea {
  width: 100%;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--fg-1);
  font-size: 13.5px;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
  outline: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--fg-4);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--line-3);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--line-4);
  box-shadow: 0 0 0 3px var(--glow);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 11px;
  line-height: 1.5;
  resize: vertical;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-3) 50%),
    linear-gradient(135deg, var(--fg-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.input.sm,
.select.sm {
  height: 30px;
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > label,
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-2);
}

.field-hint {
  font-size: 11.5px;
  color: var(--fg-3);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field svg {
  position: absolute;
  left: 10px;
  color: var(--fg-3);
  pointer-events: none;
}

.search-field .input {
  padding-left: 32px;
}

.checkbox {
  appearance: none;
  width: 15px;
  height: 15px;
  border: 1px solid var(--line-4);
  border-radius: var(--r-xs);
  display: inline-grid;
  place-items: center;
  margin: 0;
  cursor: pointer;
  background: transparent;
}

.checkbox:checked {
  background: var(--fg-1);
  border-color: var(--fg-1);
}

.checkbox:checked::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 1.5px solid var(--canvas);
  border-bottom: 1.5px solid var(--canvas);
  transform: rotate(-45deg) translate(1px, -1px);
}

/* --- Status & tags ------------------------------------------------------- */

/* Status shape language (no hue):
   s-crit  solid marker    — act on this (unauthorized, failing, high)
   s-warn  half marker     — undecided (unverified, needs review)
   s-ok    ring marker     — fine (authorized, active, done)
   s-mute  dash marker     — inert (ignored, closed, paused)          */
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px 0 7px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--fg-2);
  white-space: nowrap;
  line-height: 1;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  box-sizing: border-box;
}

.status.s-crit {
  color: var(--fg-1);
  border-color: var(--line-4);
}

.status.s-crit::before {
  background: var(--fg-1);
}

.status.s-warn::before {
  border: 1.25px solid var(--fg-2);
  background: linear-gradient(90deg, var(--fg-2) 50%, transparent 50%);
}

.status.s-ok::before {
  border: 1.25px solid var(--fg-3);
}

.status.s-mute {
  color: var(--fg-3);
}

.status.s-mute::before {
  width: 7px;
  height: 1.5px;
  border-radius: 0;
  background: var(--fg-3);
}

.status.s-live::before {
  background: var(--fg-1);
  animation: pulse 2s var(--ease) infinite;
}

.status.plain {
  border: 0;
  padding: 0;
  height: auto;
}

.status.solid.s-crit {
  background: var(--fg-1);
  color: var(--canvas);
}

.status.solid.s-crit::before {
  background: var(--canvas);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tag.outline {
  background: transparent;
  border: 1px solid var(--line-2);
}

.tag.inv {
  background: var(--inv-bg);
  color: var(--inv-fg);
}

.tag svg {
  width: 11px;
  height: 11px;
}

.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-1);
  flex-shrink: 0;
}

.dot.half {
  border: 1.25px solid var(--fg-2);
  background: linear-gradient(90deg, var(--fg-2) 50%, transparent 50%);
  width: 7px;
  height: 7px;
}

.dot.ring {
  border: 1.25px solid var(--fg-3);
  background: transparent;
  width: 7px;
  height: 7px;
}

.dot.dim {
  background: var(--fg-4);
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-1);
  flex-shrink: 0;
  animation: pulse 2s var(--ease) infinite;
}

.pulse.idle {
  background: var(--fg-3);
  animation: none;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--fg-1) 45%, transparent);
  }
  70% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--fg-1) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* Severity: three-step signal bars */
.sev {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.sev i {
  width: 3px;
  border-radius: 1px;
  background: var(--line-3);
}

.sev i:nth-child(1) { height: 5px; }
.sev i:nth-child(2) { height: 8.5px; }
.sev i:nth-child(3) { height: 12px; }

.sev[data-level="1"] i:nth-child(-n + 1),
.sev[data-level="2"] i:nth-child(-n + 2),
.sev[data-level="3"] i:nth-child(-n + 3) {
  background: var(--fg-1);
}

.sev[data-level="1"] i:nth-child(1) {
  background: var(--fg-3);
}

.sev-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-3);
}

.sev-wrap {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.sev-wrap.high .sev-label {
  color: var(--fg-1);
}

/* Meter */
.meter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}

.meter-track {
  position: relative;
  width: 56px;
  height: 3px;
  border-radius: 2px;
  background: var(--line-2);
  overflow: hidden;
}

.meter-track i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  background: var(--fg-1);
}

.meter.mid .meter-track i {
  background: var(--fg-2);
}

.meter.low .meter-track i {
  background: var(--fg-3);
}

.meter-label {
  font-family: var(--font-sans);
  color: var(--fg-3);
  font-size: 11.5px;
}

.progress {
  height: 4px;
  border-radius: 2px;
  background: var(--line-2);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  background: var(--fg-1);
  border-radius: 2px;
}

/* --- Panels -------------------------------------------------------------- */

.panel {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-lg);
  box-shadow: var(--highlight);
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 16px;
}

.panel-head.bordered {
  border-bottom: 1px solid var(--line-1);
}

.panel-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--fg-1);
  white-space: nowrap;
}

.panel-sub {
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 2px;
}

.panel-head-text {
  min-width: 0;
  flex: 1 1 auto;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .panel-head {
    flex-wrap: wrap;
  }
  .panel-head-actions {
    flex-shrink: 1;
    flex-wrap: wrap;
    max-width: 100%;
  }
}

.panel-body {
  padding: 4px 16px 16px;
}

.panel-body.flush {
  padding: 0;
}

.panel-body.pad {
  padding: 16px;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-top: 1px solid var(--line-1);
  font-size: 12px;
  color: var(--fg-3);
}

.panel-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--fg-2);
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease);
}

.panel-link:hover {
  color: var(--fg-1);
}

.panel-link svg {
  width: 13px;
  height: 13px;
  transition: transform var(--dur-1) var(--ease);
}

.panel-link:hover svg {
  transform: translateX(2px);
}

/* Section heading outside of panels */
.section-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin: 8px 0 12px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-sub {
  font-size: 12.5px;
  color: var(--fg-3);
  margin-top: 2px;
}

/* Signature "instrument" panel: dot grid + corner ticks */
.panel.instrument {
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, var(--grid-dot) 1px, transparent 1.2px) 0 0 / 16px 16px,
    var(--surface-1);
}

.ticks::before,
.ticks::after,
.ticks > .tick-b::before,
.ticks > .tick-b::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-color: var(--fg-3);
  border-style: solid;
  pointer-events: none;
  z-index: 1;
}

.ticks::before {
  top: 7px;
  left: 7px;
  border-width: 1px 0 0 1px;
}

.ticks::after {
  top: 7px;
  right: 7px;
  border-width: 1px 1px 0 0;
}

.ticks > .tick-b::before {
  bottom: 7px;
  left: 7px;
  border-width: 0 0 1px 1px;
}

.ticks > .tick-b::after {
  bottom: 7px;
  right: 7px;
  border-width: 0 1px 1px 0;
}

/* --- KPI ----------------------------------------------------------------- */

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(var(--kpi-cols, 4), minmax(0, 1fr));
  background: var(--surface-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-lg);
  box-shadow: var(--highlight);
  overflow: hidden;
}

.kpi-strip > .kpi + .kpi {
  border-left: 1px solid var(--line-1);
}

.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  min-width: 0;
  text-align: left;
}

.kpi.clickable {
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}

.kpi.clickable:hover {
  background: var(--surface-2);
}

.kpi-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  white-space: nowrap;
}

.kpi-value {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--fg-1);
  white-space: nowrap;
}

.kpi-value small {
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--fg-3);
  font-weight: 400;
  margin-left: 2px;
}

.kpi.dim .kpi-value {
  color: var(--fg-2);
}

.kpi-foot {
  font-size: 12px;
  color: var(--fg-3);
  min-height: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-foot b {
  color: var(--fg-2);
  font-weight: 500;
}

.kpi-spark {
  height: 30px;
  margin-top: 2px;
}

.kpi.hot::after {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 2px;
  background: var(--fg-1);
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-2);
}

@media (max-width: 1180px) {
  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-strip > .kpi:nth-child(odd) {
    border-left: 0;
  }

  .kpi-strip > .kpi:nth-child(n + 3) {
    border-top: 1px solid var(--line-1);
  }
}

/* --- Tables -------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 34px;
  padding: 0 12px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  background: var(--surface-1);
  border-bottom: 1px solid var(--line-1);
  white-space: nowrap;
}

.table td {
  height: 48px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-1);
  vertical-align: middle;
  color: var(--fg-2);
}

.table tr:last-child td {
  border-bottom: 0;
}

.table th:first-child,
.table td:first-child {
  padding-left: 16px;
}

.table th:last-child,
.table td:last-child {
  padding-right: 16px;
}

.table td.primary,
.table td .primary {
  color: var(--fg-1);
  font-weight: 500;
}

.table td.num,
.table th.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

.table td.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.table tbody tr {
  transition: background var(--dur-1) var(--ease);
}

.table tbody tr.clickable {
  cursor: pointer;
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table tbody tr.selected {
  background: var(--surface-3);
}

.table .cell-sub {
  display: block;
  font-size: 11.5px;
  color: var(--fg-3);
  margin-top: 2px;
  font-weight: 400;
}

.table td.actions {
  text-align: right;
  white-space: nowrap;
}

.table td.actions .row {
  justify-content: flex-end;
}

.table.compact td {
  height: 38px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.cell-entity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cell-entity .grow {
  min-width: 0;
}

/* --- Segmented / filters ------------------------------------------------ */

.seg {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--surface-1);
}

.seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--fg-3);
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.seg button:hover {
  color: var(--fg-1);
}

.seg button.active {
  background: var(--surface-4);
  color: var(--fg-1);
  font-weight: 500;
}

.seg .seg-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
}

.seg button.active .seg-count {
  color: var(--fg-2);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar .spacer {
  flex: 1 1 auto;
}

.chip-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-full);
  font-size: 12.5px;
  color: var(--fg-2);
  white-space: nowrap;
  transition: all var(--dur-1) var(--ease);
}

.chip-filter:hover {
  border-color: var(--line-3);
  color: var(--fg-1);
}

.chip-filter.active {
  background: var(--inv-bg);
  border-color: var(--inv-bg);
  color: var(--inv-fg);
}

.chip-filter .seg-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  opacity: 0.7;
}

/* --- Lists --------------------------------------------------------------- */

.list {
  display: flex;
  flex-direction: column;
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--line-1);
  min-width: 0;
  transition: background var(--dur-1) var(--ease);
}

.list-row:first-child {
  border-top: 0;
}

.list-row.clickable {
  cursor: pointer;
}

.list-row.clickable:hover {
  background: var(--surface-2);
}

.list-row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.list-row-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--fg-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row-sub {
  font-size: 12px;
  color: var(--fg-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}

.list-row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* --- Thumbnails & avatars ------------------------------------------------ */

.thumb {
  position: relative;
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: 1px solid var(--line-1);
  color: var(--fg-4);
  flex-shrink: 0;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb.contain img {
  object-fit: contain;
  padding: 3px;
  background: #fff;
}

.thumb.clickable {
  cursor: zoom-in;
}

.thumb.clickable:hover {
  border-color: var(--line-3);
}

.thumb .tlabel {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
  text-align: center;
  padding: 2px;
}

.thumb.missing {
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface-3) 6px 7px);
}

.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--surface-4);
  color: var(--fg-1);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  border: 1px solid var(--line-1);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.round {
  border-radius: 50%;
}

.avatar.sm {
  width: 22px;
  height: 22px;
  font-size: 10.5px;
}

.avatar.lg {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.avatar.inv {
  background: var(--inv-bg);
  color: var(--inv-fg);
  border-color: transparent;
}

.favicon-box {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-1);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* --- Key-value ----------------------------------------------------------- */

.kv {
  display: grid;
  grid-template-columns: minmax(110px, 34%) minmax(0, 1fr);
  border-top: 1px solid var(--line-1);
}

.kv > dt,
.kv > dd {
  margin: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-1);
  font-size: 12.5px;
  min-width: 0;
}

.kv > dt {
  color: var(--fg-3);
  padding-right: 12px;
}

.kv > dd {
  color: var(--fg-1);
  overflow-wrap: anywhere;
}

.kv > dd.mono {
  font-size: 12px;
}

/* --- Timeline ------------------------------------------------------------ */

.timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.tl-item {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  padding-bottom: 16px;
}

.tl-item::before {
  content: "";
  position: absolute;
  left: 8.5px;
  top: 14px;
  bottom: -2px;
  width: 1px;
  background: var(--line-2);
}

.tl-item:last-child::before {
  display: none;
}

.tl-marker {
  margin-top: 4px;
  width: 9px;
  height: 9px;
  justify-self: center;
  border-radius: 50%;
  border: 1.5px solid var(--fg-3);
  background: var(--surface-1);
  position: relative;
  z-index: 1;
}

.tl-item.solid .tl-marker {
  background: var(--fg-1);
  border-color: var(--fg-1);
}

.tl-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-1);
}

.tl-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  margin-top: 1px;
}

.tl-body {
  font-size: 12.5px;
  color: var(--fg-2);
  margin-top: 4px;
  white-space: pre-wrap;
}

/* --- Callouts ------------------------------------------------------------ */

.callout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  font-size: 13px;
  color: var(--fg-2);
}

.callout > svg {
  color: var(--fg-1);
  width: 16px;
  height: 16px;
}

.callout b {
  color: var(--fg-1);
  font-weight: 500;
}

.callout.strong {
  border-color: var(--line-4);
}

.callout .spacer {
  flex: 1 1 auto;
}

.callout.stripe {
  background:
    repeating-linear-gradient(135deg, transparent 0 9px, var(--line-1) 9px 10px),
    var(--surface-1);
}

.note-list {
  display: flex;
  flex-direction: column;
}

.note-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line-1);
  font-size: 12.5px;
  color: var(--fg-2);
}

.note-item:first-child {
  border-top: 0;
}

.note-item .idx {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  min-width: 20px;
}

/* --- Empty states & skeletons ------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 44px 24px;
  color: var(--fg-3);
}

.empty-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-3);
  border-radius: var(--r-lg);
  color: var(--fg-2);
}

.empty-icon svg {
  width: 18px;
  height: 18px;
}

.empty-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-1);
}

.empty-text {
  font-size: 12.5px;
  max-width: 420px;
}

.empty.compact {
  padding: 24px 16px;
}

.skeleton {
  border-radius: var(--r-md);
  background: linear-gradient(90deg, var(--skeleton-a) 25%, var(--skeleton-b) 50%, var(--skeleton-a) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* --- Drawer -------------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 60;
  animation: fade-in var(--dur-2) var(--ease) both;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--drawer-w), 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-left: 1px solid var(--line-2);
  box-shadow: var(--shadow-drawer);
  z-index: 61;
  animation: drawer-in var(--dur-3) var(--ease) both;
}

.drawer.wide {
  --drawer-w: 760px;
}

@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line-1);
}

.drawer-head-main {
  flex: 1 1 auto;
  min-width: 0;
}

.drawer-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.drawer-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.drawer-sub {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--fg-3);
}

.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Scrolling flex column: children keep their size instead of shrinking. */
.drawer-body > *,
.modal-body > * {
  flex-shrink: 0;
}

.drawer-section > .micro {
  display: block;
  margin-bottom: 10px;
}

.drawer-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--line-1);
  background: var(--surface-1);
}

.drawer-foot .spacer {
  flex: 1 1 auto;
}

/* --- Modal --------------------------------------------------------------- */

.modal-wrap {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* The wrap is its own stacking context: the scrim must sit under the dialog,
   or every click inside the dialog lands on the scrim and closes it. */
.modal-wrap .scrim {
  position: absolute;
  z-index: 0;
}

.modal {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  animation: modal-in var(--dur-3) var(--ease) both;
}

.modal.wide {
  width: min(820px, 100%);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 20px 14px;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.modal-sub {
  font-size: 12.5px;
  color: var(--fg-3);
  margin-top: 3px;
}

.modal-body {
  padding: 4px 20px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line-1);
}

.lightbox {
  position: relative;
  z-index: 1;
  max-width: min(1100px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: modal-in var(--dur-3) var(--ease) both;
}

.lightbox-img {
  min-height: 0;
  overflow: auto;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--surface-2);
}

.lightbox-img img {
  max-width: 100%;
}

.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #f3f3f3;
  font-size: 13px;
}

.lightbox-bar .mono {
  color: #9a9a9a;
  font-size: 11.5px;
}

/* --- Toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 90;
  pointer-events: none;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px 9px 12px;
  border-radius: var(--r-md);
  background: var(--inv-bg);
  color: var(--inv-fg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  animation: toast-in var(--dur-3) var(--ease) both;
}

.toast svg {
  width: 15px;
  height: 15px;
}

.toast.leaving {
  animation: toast-out var(--dur-2) var(--ease) both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* --- Command palette ----------------------------------------------------- */

#cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.cmdk-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fade-in var(--dur-2) var(--ease) both;
}

.cmdk-panel {
  position: absolute;
  top: 14vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100vw - 32px));
  background: var(--surface-2);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  animation: modal-in var(--dur-3) var(--ease) both;
}

.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line-1);
  color: var(--fg-3);
}

#cmdk-input {
  flex: 1 1 auto;
  height: 52px;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 15px;
  color: var(--fg-1);
}

#cmdk-input::placeholder {
  color: var(--fg-4);
}

#cmdk-results {
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
}

.cmdk-group {
  padding: 8px 10px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-4);
}

.cmdk-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  text-align: left;
  color: var(--fg-2);
  font-size: 13.5px;
}

.cmdk-item svg {
  color: var(--fg-3);
  width: 15px;
  height: 15px;
}

.cmdk-item.active {
  background: var(--surface-4);
  color: var(--fg-1);
}

.cmdk-item.active svg {
  color: var(--fg-1);
}

.cmdk-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cmdk-kind {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
}

.cmdk-empty {
  padding: 28px;
  text-align: center;
  color: var(--fg-3);
  font-size: 13px;
}

.cmdk-foot {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 14px;
  border-top: 1px solid var(--line-1);
  font-size: 11.5px;
  color: var(--fg-3);
}

.cmdk-foot span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* --- Popover (notifications) -------------------------------------------- */

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  background: var(--surface-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  z-index: 50;
  overflow: hidden;
  animation: modal-in var(--dur-2) var(--ease) both;
}

.popover[hidden] {
  display: none;
}

.popover-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-1);
  font-size: 13px;
  font-weight: 600;
}

.notif {
  display: flex;
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-1);
  width: 100%;
  text-align: left;
  transition: background var(--dur-1) var(--ease);
}

.notif:last-child {
  border-bottom: 0;
}

.notif:hover {
  background: var(--surface-3);
}

.notif-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  color: var(--fg-1);
  flex-shrink: 0;
}

.notif-icon svg {
  width: 14px;
  height: 14px;
}

.notif-title {
  font-size: 13px;
  color: var(--fg-1);
  font-weight: 500;
}

.notif-text {
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 2px;
}

/* --- Steps / checklist --------------------------------------------------- */

.steps {
  display: flex;
  flex-direction: column;
}

.step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line-1);
}

.step:first-child {
  border-top: 0;
}

.step-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line-3);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-3);
}

.step.done .step-mark {
  background: var(--fg-1);
  border-color: var(--fg-1);
  color: var(--canvas);
}

.step.done .step-title {
  color: var(--fg-3);
  text-decoration: line-through;
  text-decoration-color: var(--line-3);
}

.step-title {
  font-size: 13.5px;
  font-weight: 500;
}

.step-text {
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 1px;
}

/* --- Legends ------------------------------------------------------------- */

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--fg-3);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-item b {
  color: var(--fg-1);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 11px;
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--viz-1);
  flex-shrink: 0;
}

.swatch.line {
  height: 2px;
  width: 12px;
  border-radius: 1px;
}

.swatch.t2 { background: var(--viz-2); }
.swatch.t3 { background: var(--viz-3); }
.swatch.t4 { background: var(--viz-4); }
.swatch.t5 { background: var(--viz-5); }

.swatch.hatch {
  background: repeating-linear-gradient(135deg, var(--viz-2) 0 1.5px, transparent 1.5px 3.5px);
  border: 1px solid var(--viz-3);
}

.swatch.ring {
  background: transparent;
  border: 1.5px solid var(--viz-3);
}

/* --- Misc ---------------------------------------------------------------- */

.divider {
  height: 1px;
  background: var(--line-1);
  margin: 4px 0;
}

.vr {
  width: 1px;
  align-self: stretch;
  background: var(--line-1);
}

.error-box {
  padding: 16px;
  border: 1px solid var(--line-4);
  border-radius: var(--r-lg);
  font-size: 13px;
  color: var(--fg-1);
  background: var(--surface-1);
}

.hint-copy {
  font-size: 12px;
  color: var(--fg-3);
}

.code-chip {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  background: var(--surface-3);
  color: var(--fg-1);
  user-select: all;
  overflow-wrap: anywhere;
}

.ext-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--fg-2);
  font-size: 12.5px;
}

.ext-link:hover {
  color: var(--fg-1);
}

.ext-link svg {
  width: 12px;
  height: 12px;
}

.stars {
  display: inline-flex;
  gap: 1px;
  color: var(--fg-1);
}

.stars svg {
  width: 12px;
  height: 12px;
}

.stars .off {
  color: var(--fg-4);
}

/* --- Site logo avatar ------------------------------------------------------ */

.favicon-box.logo {
  background: var(--logo-tile);
  border-color: var(--line-2);
  padding: 3px;
  overflow: hidden;
}

.favicon-box.logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(1) contrast(1.08);
}

.drawer-avatar {
  flex-shrink: 0;
  padding-top: 2px;
}

.drawer-avatar .favicon-box {
  border-radius: var(--r-md);
  font-size: 16px;
}

.drawer-avatar .favicon-box.logo {
  padding: 6px;
}

.icon-btn.xs {
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  vertical-align: middle;
}

.icon-btn.xs svg {
  width: 12px;
  height: 12px;
}

.notif[disabled] {
  cursor: default;
}

.notif[disabled]:hover {
  background: none;
}

/* --- Switch ---------------------------------------------------------------- */

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: var(--r-full);
  background: var(--surface-5);
  border: 1px solid var(--line-3);
  flex-shrink: 0;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--fg-3);
  transition: transform var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

.switch[aria-checked="true"] {
  background: var(--inv-bg);
  border-color: var(--inv-bg);
}

.switch[aria-checked="true"] .switch-knob {
  transform: translateX(14px);
  background: var(--inv-fg);
}

.switch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch:disabled {
  opacity: 0.6;
}

/* --- Thin meter ------------------------------------------------------------ */

.meter-bar {
  height: 6px;
  margin-top: 8px;
  border-radius: var(--r-full);
  background: var(--surface-4);
  overflow: hidden;
}

.meter-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--viz-1);
}

/* --- File chips (evidence) ------------------------------------------------- */

.file-chips {
  display: inline-flex;
  gap: 4px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-1);
  letter-spacing: 0.02em;
}

a.file-chip:hover {
  background: var(--surface-4);
}

.file-chip.missing {
  border-style: dashed;
  border-color: var(--line-2);
  color: var(--fg-4);
}

@media (max-width: 600px) {
  .kpi-label {
    flex-wrap: wrap;
    white-space: normal;
  }

  .kpi-foot {
    overflow-wrap: anywhere;
  }
}
