/* =============================================================================
   BLOCKZILLA DESIGN SYSTEM — components.css
   Shared primitive classes. Everything here is built ONLY from tokens.css custom
   properties, so each primitive restyles itself under every [data-theme].
   ============================================================================= */

/* ---- reset / base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
::selection { background: var(--accent); color: var(--on-accent); }

* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: var(--r-pill); border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

/* shared focus ring */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
  border-radius: var(--r-sm);
}

/* =============================================================================
   ICONOGRAPHY & MARK
   ============================================================================= */
svg.mark, .mark {
  display: inline-block;
  width: 28px;
  height: 28px;
  color: var(--mark);
  flex: none;
}
svg.ic, .ic {
  display: inline-block;
  width: 24px;
  height: 24px;
  color: currentColor;
  flex: none;
  vertical-align: middle;
}

/* =============================================================================
   TYPOGRAPHY UTILITIES
   ============================================================================= */
.t-display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-3xl);
  line-height: .95;
  letter-spacing: -.025em;
}
.t-h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-2xl);
  line-height: 1.04;
  letter-spacing: -.022em;
}
.t-h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-xl);
  line-height: 1.1;
  letter-spacing: -.015em;
}
.t-h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-lg);
  line-height: 1.2;
  letter-spacing: -.01em;
}
.t-body { font-family: var(--font-body); font-size: var(--fs-md); line-height: 1.6; }
.t-mono { font-family: var(--font-mono); font-size: var(--fs-sm); letter-spacing: -.01em; }
.t-muted { color: var(--muted); }
.t-faint { color: var(--faint); }
.t-accent { color: var(--accent); }

/* eyebrow — mono uppercase tracked label */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow::before {
  content: "";
  width: 18px;
  height: 1px;
  background: var(--accent);
}
.eyebrow--plain::before { display: none; }

/* =============================================================================
   LAYOUT HELPERS
   ============================================================================= */
.stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--sp-4)); }
.row { display: flex; align-items: center; gap: var(--row-gap, var(--sp-3)); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--top { align-items: flex-start; }
.grid { display: grid; gap: var(--grid-gap, var(--sp-5)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 880px) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
}

/* =============================================================================
   BUTTONS
   ============================================================================= */
.btn {
  --_bg: var(--surface-2);
  --_fg: var(--fg);
  --_bd: var(--line-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 42px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--_bd);
  border-radius: var(--r-md);
  background: var(--_bg);
  color: var(--_fg);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1;
  letter-spacing: .005em;
  white-space: nowrap;
  user-select: none;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
    border-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn .ic { width: 18px; height: 18px; }
.btn:hover { transform: translateY(-1px); border-color: var(--muted); }
.btn:active { transform: translateY(0); }
.btn[disabled], .btn:disabled { opacity: .45; pointer-events: none; }

.btn--primary {
  --_bg: var(--accent);
  --_fg: var(--on-accent);
  --_bd: transparent;
  font-weight: 700;
}
.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, white);
  box-shadow: 0 8px 24px -10px color-mix(in srgb, var(--accent) 60%, transparent);
}
.btn--ghost { --_bg: transparent; --_bd: transparent; }
.btn--ghost:hover { --_bg: var(--surface); border-color: var(--line); }
.btn--outline { --_bg: transparent; --_bd: var(--line-2); }
.btn--outline:hover { border-color: var(--accent); color: var(--accent); }

.btn--sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.btn--sm .ic { width: 15px; height: 15px; }
.btn--lg { height: 50px; padding: 0 var(--sp-5); font-size: var(--fs-md); }
.btn--lg .ic { width: 20px; height: 20px; }
.btn--icon { width: 42px; padding: 0; }
.btn--icon.btn--sm { width: 32px; }
.btn--block { display: flex; width: 100%; }

/* =============================================================================
   BADGES & STATUS
   ============================================================================= */
.badge {
  --_c: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: .45em;
  padding: 3px 9px;
  border: 1px solid color-mix(in srgb, var(--_c) 34%, transparent);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--_c) 12%, transparent);
  color: var(--_c);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  line-height: 1.3;
}
.badge--solid {
  background: var(--_c);
  color: var(--on-accent);
  border-color: transparent;
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--_c);
  flex: none;
}
.badge--solid::before { background: var(--on-accent); }
.badge--nodot::before { display: none; }
.badge--accent { --_c: var(--accent); }
.badge--success { --_c: var(--success); }
.badge--warning { --_c: var(--warning); }
.badge--danger { --_c: var(--danger); }
.badge--info { --_c: var(--info); }
.badge--neutral { --_c: var(--muted); }

/* =============================================================================
   CHIPS / PILLS
   ============================================================================= */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 34px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.chip .ic { width: 16px; height: 16px; }
.chip:hover { color: var(--fg); border-color: var(--muted); }
.chip[aria-pressed="true"], .chip.is-active {
  color: var(--on-accent);
  background: var(--accent);
  border-color: transparent;
}
.chip--dismiss { padding-right: var(--sp-2); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px var(--sp-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: .04em;
}

/* =============================================================================
   FORM CONTROLS
   ============================================================================= */
.input, .textarea, .select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.input, .select { height: 44px; padding: 0 var(--sp-4); }
.textarea { min-height: 112px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:disabled, .textarea:disabled, .select:disabled { opacity: .5; cursor: not-allowed; }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--sp-8);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 50%,
    calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  cursor: pointer;
}

/* input with leading icon */
.input-group { position: relative; display: flex; align-items: center; }
.input-group .ic { position: absolute; left: var(--sp-4); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.input-group .input { padding-left: calc(var(--sp-4) + 18px + var(--sp-3)); }

/* field wrapper: label + control + help */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field > label, .field .field__label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg);
}
.field .field__help { font-size: var(--fs-xs); color: var(--muted); }
.field .field__help--error { color: var(--danger); }
.field.is-error .input, .field.is-error .select, .field.is-error .textarea { border-color: var(--danger); }
.field.is-error .input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }

/* toggle / switch */
.toggle, .checkbox, .radio {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
  font-size: var(--fs-sm);
  user-select: none;
}
.toggle input, .checkbox input, .radio input {
  position: absolute;
  opacity: 0;
  width: 1px; height: 1px;
  pointer-events: none;
}
.toggle__track {
  position: relative;
  width: 46px; height: 26px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.toggle__track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform var(--dur) var(--ease-out), background var(--dur) var(--ease);
}
.toggle input:checked + .toggle__track { background: var(--accent); border-color: transparent; }
.toggle input:checked + .toggle__track::after { transform: translateX(20px); background: var(--on-accent); }
.toggle input:focus-visible + .toggle__track { box-shadow: 0 0 0 3px var(--accent-soft); }

/* checkbox */
.checkbox__box, .radio__box {
  position: relative;
  width: 20px; height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.checkbox__box { border-radius: 6px; }
.checkbox__box .ic { width: 14px; height: 14px; stroke-width: 2.4; }
.checkbox input:checked + .checkbox__box {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
}
.checkbox input:focus-visible + .checkbox__box,
.radio input:focus-visible + .radio__box { box-shadow: 0 0 0 3px var(--accent-soft); }

/* radio */
.radio__box { border-radius: 50%; }
.radio__box::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--on-accent);
  transform: scale(0);
  transition: transform var(--dur) var(--ease-out);
}
.radio input:checked + .radio__box { background: var(--accent); border-color: transparent; }
.radio input:checked + .radio__box::after { transform: scale(1); }

/* =============================================================================
   TABS / SEGMENTED CONTROL
   ============================================================================= */
.tabs {
  display: inline-flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--line);
}
.tab {
  position: relative;
  padding: var(--sp-3) var(--sp-4);
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-sm);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"], .tab.is-active { color: var(--fg); border-color: var(--accent); }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}
.segmented__item {
  padding: 7px var(--sp-4);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.segmented__item:hover { color: var(--fg); }
.segmented__item[aria-selected="true"], .segmented__item.is-active {
  background: var(--accent);
  color: var(--on-accent);
}

/* =============================================================================
   CARD
   ============================================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  overflow: hidden;
}
.card--pad { padding: var(--sp-5); }
.card--glass {
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  backdrop-filter: blur(12px);
}
.card--hover { transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.card--hover:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: var(--sh-3);
}

/* =============================================================================
   STAT / KPI
   ============================================================================= */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.stat__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat__value {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.025em;
  color: var(--fg);
}
.stat__row { display: flex; align-items: baseline; gap: var(--sp-3); flex-wrap: wrap; }
.stat__delta {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  font-size: var(--fs-sm);
  font-weight: 600;
  font-family: var(--font-mono);
}
.stat__delta--up { color: var(--success); }
.stat__delta--down { color: var(--danger); }

/* =============================================================================
   TABLE
   ============================================================================= */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--dur) var(--ease); }
.table tbody tr:hover { background: var(--surface); }
.table tbody tr:last-child td { border-bottom: 0; }
.table--card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table--card th { background: var(--bg-2); }

/* =============================================================================
   ALERT
   ============================================================================= */
.alert {
  --_c: var(--info);
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border: 1px solid color-mix(in srgb, var(--_c) 38%, transparent);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--_c) 10%, var(--surface));
}
.alert .ic { color: var(--_c); width: 20px; height: 20px; margin-top: 1px; }
.alert__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alert__title { font-weight: 700; color: var(--fg); }
.alert__text { color: var(--muted); font-size: var(--fs-sm); }
.alert--info { --_c: var(--info); }
.alert--success { --_c: var(--success); }
.alert--warn, .alert--warning { --_c: var(--warning); }
.alert--danger { --_c: var(--danger); }

/* =============================================================================
   PROGRESS
   ============================================================================= */
.progress {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width var(--dur-slow) var(--ease-out);
}

/* =============================================================================
   AVATAR
   ============================================================================= */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--fg);
  font-weight: 600;
  font-size: var(--fs-sm);
  overflow: hidden;
  flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 28px; height: 28px; font-size: var(--fs-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-lg); }
.avatar--accent { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { margin-left: -10px; box-shadow: 0 0 0 2px var(--bg); }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* =============================================================================
   TOOLTIP  (pure CSS via data-tip)
   ============================================================================= */
.tooltip { position: relative; display: inline-flex; }
.tooltip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 6px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--fg);
  font-size: var(--fs-xs);
  white-space: nowrap;
  box-shadow: var(--sh-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 40;
}
.tooltip:hover::after, .tooltip:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =============================================================================
   LOGO LOCKUP
   ============================================================================= */
.logo { display: inline-flex; align-items: center; gap: var(--sp-3); }
.logo .mark { width: 30px; height: 30px; filter: drop-shadow(0 3px 12px rgba(0, 0, 0, .45)); }
.logo__word {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-lg);
  letter-spacing: .02em;
  color: var(--fg);
  line-height: 1;
}
.logo__tag {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 3px 6px;
  line-height: 1;
}

/* =============================================================================
   SWATCH (token / color spec)
   ============================================================================= */
.swatch { display: flex; flex-direction: column; gap: var(--sp-2); }
.swatch__chip {
  height: 56px;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
}
.swatch__name { font-size: var(--fs-sm); font-weight: 600; color: var(--fg); line-height: 1.2; }
.swatch__val { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--muted); }

/* =============================================================================
   MISC
   ============================================================================= */
.hr { height: 1px; border: 0; background: var(--line); margin: var(--sp-5) 0; }
.kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
  background: var(--bg-2);
}
