/* ============================================================
   COMPONENTS — chrome + reusable primitives
   ============================================================ */

/* ── App shell ── */
.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}
.app[data-mode="admin"] {
  grid-template-rows: var(--header-h) 1fr;
  height: auto;
  min-height: 100vh;
  overflow: auto;
}

/* ── Top header ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s5);
  height: var(--header-h);
  flex-shrink: 0;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 10;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--s4); min-width: 0; }
.topbar-left { flex: 1 1 auto; min-width: 0; }
.topbar-right { flex: 0 0 auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}
.brand-mark { flex-shrink: 0; }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent), color-mix(in srgb, var(--accent) 60%, #000) 70%);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.brand-mark::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent-fg) 80%, transparent);
}
.brand-mark::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-fg);
}
.brand-name { font-size: 16px; }

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--fg-1);
  padding: 3px 8px 3px 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.live-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent);
  animation: livePulse 2s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 0%, transparent); }
}

.version-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
}

/* ── Admin nav ── */
.admin-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}
.admin-nav a {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-2);
  border-radius: var(--r-sm);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.admin-nav a:hover { color: var(--fg-0); background: var(--bg-2); }
.admin-nav a.active { color: var(--fg-0); background: var(--bg-2); }

/* ── Icon button ── */
.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg-2);
  transition: all var(--dur-fast);
}
.icon-btn:hover { color: var(--fg-0); background: var(--bg-2); border-color: var(--line-strong); }
.icon-btn svg { width: 16px; height: 16px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  line-height: 1;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  color: var(--fg-1);
  background: var(--bg-1);
  transition: all var(--dur-fast);
}
.btn:hover { background: var(--bg-2); color: var(--fg-0); border-color: var(--line-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); border-color: var(--accent); color: var(--accent-fg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-2); }
.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: var(--err-bg); border-color: var(--err); color: var(--err); }

/* ── Card / Surface ── */
.surface {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.surface-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.surface-body { flex: 1; min-height: 0; }
.surface-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
}

/* ── Status dot ── */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-ok { background: var(--ok); box-shadow: 0 0 6px color-mix(in srgb, var(--ok) 50%, transparent); }
.dot-warn { background: var(--warn); box-shadow: 0 0 6px color-mix(in srgb, var(--warn) 50%, transparent); }
.dot-err { background: var(--err); box-shadow: 0 0 6px color-mix(in srgb, var(--err) 50%, transparent); animation: dotPulse 1.6s ease-in-out infinite; }
.dot-info { background: var(--info); }
.dot-neutral { background: var(--neutral); }
@keyframes dotPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.7); opacity: 0.6; }
}

/* ── Chip / Badge ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--fg-1);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.chip-ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.chip-warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.chip-err { color: var(--err); background: var(--err-bg); border-color: transparent; }
.chip-info { color: var(--info); background: var(--info-bg); border-color: transparent; }
.chip-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* ── KPI card ── */
.kpi {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  min-width: 0;
}
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-size: clamp(28px, 4.4vw, 64px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--fg-0);
  font-variant-numeric: tabular-nums;
}
.kpi-value.kpi-mono { font-family: var(--font-mono); }
.kpi-sub {
  font-size: 11px;
  color: var(--fg-2);
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
}
.kpi-trend {
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.kpi-trend.up { color: var(--err); }
.kpi-trend.down { color: var(--ok); }
.kpi-trend.flat { color: var(--fg-2); }

/* Status accent rail (left edge) */
.kpi-rail {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--rail-color, var(--accent));
}
.kpi.is-ok    { --rail-color: var(--ok); }
.kpi.is-warn  { --rail-color: var(--warn); }
.kpi.is-err   { --rail-color: var(--err); }
.kpi.is-info  { --rail-color: var(--info); }
.kpi.is-accent { --rail-color: var(--accent); }
.kpi.is-neutral { --rail-color: var(--neutral); }

/* Clickable KPI card — focus ring for keyboard users */
.card-clickable { cursor: pointer; }
.card-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* .trend-good / .trend-bad (matches freshness.js naming) */
.kpi-trend.trend-good { color: var(--ok); }
.kpi-trend.trend-bad  { color: var(--err); }

/* Sparkline — inline SVG rendered by sparkline.js into data-spark elements */
.sparkline {
  display: block;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40px;
  opacity: 0.7;
  pointer-events: none;
}
.sparkline svg { width: 100%; height: 100%; display: block; }

/* Sparkline area */
.kpi-spark {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 36px;
  opacity: 0.7;
  pointer-events: none;
}

/* ── Section header ── */
.section-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s4);
}
.section-h-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-0);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-h-sub {
  font-size: 12px;
  color: var(--fg-2);
}
.section-h-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Tabular table ── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl thead th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.tbl tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--fg-1);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: var(--bg-2); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* ── Tooltip-ish small label ── */
.kicker {
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Field controls ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.field-help { font-size: 12px; color: var(--fg-2); }
.input, .select, .textarea {
  height: 36px;
  padding: 0 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg-0);
  font-size: 13px;
  transition: border-color var(--dur-fast);
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { height: auto; padding: 10px 12px; resize: vertical; }
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-1);
}
.checkbox input { accent-color: var(--accent); width: 14px; height: 14px; }

/* ── Avatars ── */
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--fg-0);
}
.avatar-sm { width: 22px; height: 22px; font-size: 9px; }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp var(--dur-base) var(--ease) both; }

@keyframes scanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100%); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
[data-motion="minimal"] *, [data-motion="minimal"] *::before, [data-motion="minimal"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
}
