/** Reset, primitives and shared form controls. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.45;
  color: var(--text-primary);
  background: var(--surface-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/**
 * The `hidden` attribute must beat component display rules.
 *
 * The UA stylesheet sets `[hidden] { display: none }`, but any author rule such
 * as `.chip { display: inline-flex }` outranks it — so `element.hidden = true`
 * silently did nothing for several components (the timeline focus chip showed
 * as an empty pill at all times). Everything that toggles visibility through
 * `.hidden` depends on this.
 */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--accent-soft);
}

h1, h2, h3, h4, h5 {
  margin: 0;
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
}

p { margin: 0; }

/* ---------------- Scrollbars ---------------- */

.scroll-thin {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.scroll-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
.scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); background-clip: content-box; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
}
.btn:hover { background: var(--surface-4); border-color: var(--text-tertiary); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-inverse);
  font-weight: var(--weight-semibold);
}
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn--ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text-primary); }

.btn--danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn--danger:hover { background: rgba(248, 113, 113, 0.12); }

.btn--icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: var(--text-md);
}

.btn--block { width: 100%; }

/* ---------------- Inputs ---------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input,
.select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--text-primary);
  font: inherit;
  font-size: var(--text-sm);
}
.input:hover,
.select:hover { border-color: var(--text-tertiary); }

.select {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 12px top 15px, right 7px top 15px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
.select optgroup { background: var(--surface-2); color: var(--text-tertiary); font-style: normal; }
.select option { background: var(--surface-2); color: var(--text-primary); }

input[type='datetime-local'],
input[type='number'] { color-scheme: inherit; }

/* ---------------- Toggle switch ---------------- */

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 34px;
  height: 19px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch__track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
  border: 1px solid var(--border-strong);
  transition: background var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
  pointer-events: none;
}
.switch__track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform var(--duration-fast) var(--ease), background var(--duration-fast) var(--ease);
}
.switch input:checked + .switch__track {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked + .switch__track::after {
  transform: translateX(15px);
  background: var(--text-inverse);
}
.switch input:focus-visible + .switch__track {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ---------------- Range slider ---------------- */

.range {
  --range-fill: var(--accent);
  width: 100%;
  height: 18px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
}
.range::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
}
.range::-webkit-slider-thumb {
  appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: var(--range-fill);
  border: 2px solid var(--surface-1);
  box-shadow: var(--shadow-sm);
}
.range::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--range-fill);
  border: 2px solid var(--surface-1);
}
.range:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------------- Utility ---------------- */

.row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.row--between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.muted { color: var(--text-secondary); }
.dim { color: var(--text-tertiary); }
.tiny { font-size: var(--text-xs); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border-subtle);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}
.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.chip--live .chip__dot { background: var(--ok); animation: pulse 2s var(--ease) infinite; }
.chip--stale .chip__dot { background: var(--warn); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

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

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
