/* css/base.css — layout, global header, and the app-wide primitives:
   buttons, fields, segmented control, badges, banners. */

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

html {
  -webkit-text-size-adjust: 100%;
  /* On the root on purpose: touch-action intersects upward, so it cannot
     loosen a drag handle's `none` further down (mobile-web.md §2). */
  touch-action: manipulation;
}
/* The overlay scroll lock writes body's overflow; <html> must follow it or
   the page still scrolls behind the modal. */
html:has(> body[style*="overflow: hidden"]) { overflow: hidden; }

body {
  margin: 0;
  /* `clip`, not `hidden`: a hidden overflow-x turns <body> into a scroll
     container with no height, and every position: sticky then rides away. */
  overflow-x: clip;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-0);
  color: var(--ink);
  font: 400 15px/1.5 var(--font-sans);
}

a { color: var(--accent-ink); }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0; }
code, .bit-mono { font-family: var(--font-mono); font-size: 0.92em; }
.hidden { display: none !important; }
.bit-vis-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ── Icons: a 0,0,0 floor so a component's own size rule always wins ──────── */
:where(svg[data-icon]) { width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }

/* ── Global header (z: header 30) ──────────────────────────────────────────── */
.bit-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-height);
  background: color-mix(in srgb, var(--bg-0) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bit-header__inner {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  max-width: var(--col-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.bit-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-right: auto;
  color: var(--ink);
  text-decoration: none;
  font: 800 19px/1 var(--font-display);
  letter-spacing: 0.02em;
}
.bit-brand svg { width: 30px; height: 30px; color: var(--accent); }
.bit-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-muted);
  font: 600 14px/1 var(--font-sans);
  cursor: pointer;
  text-decoration: none;
}
.bit-nav-link.active { color: var(--ink); background: var(--bg-2); }
.bit-nav-link:active { background: var(--bg-2); }
.bit-nav-link--icon { width: 44px; padding: 0; justify-content: center; }
.bit-nav-link--icon svg { width: 22px; height: 22px; }

/* ── Main column ───────────────────────────────────────────────────────────── */
.bit-main {
  max-width: var(--col-max);
  margin: 0 auto;
  padding: var(--s-5) var(--gutter) var(--s-7);
}
.bit-view { animation: bitFade 160ms ease both; }

.bit-screen-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.bit-screen-head h1 { font-size: 26px; font-weight: 750; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.bit-section { margin-top: var(--s-6); }
.bit-section > h2 { font-size: 17px; font-weight: 700; margin-bottom: var(--s-3); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.bit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--bg-1);
  color: var(--ink);
  font: 600 15px/1 var(--font-sans);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.bit-btn:active:not(:disabled) { transform: scale(0.98); }
.bit-btn:disabled, .bit-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.bit-btn--primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
.bit-btn--commit { min-height: 52px; padding: 0 24px; }
.bit-btn--ghost { background: transparent; border-color: transparent; color: var(--accent-ink); }
.bit-btn--danger { background: var(--rust-fill); border-color: var(--rust-fill); color: var(--on-accent); }
.bit-btn--quiet-danger { background: transparent; color: var(--rust); border-color: var(--rust-quiet); }
.bit-btn--sm { min-height: 44px; padding: 0 14px; font-size: 14px; }
.bit-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}
.bit-icon-btn svg { width: 22px; height: 22px; }
.bit-icon-btn:active { background: var(--bg-2); }
.bit-btn:focus-visible, .bit-icon-btn:focus-visible, .bit-nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (hover: hover) {
  .bit-btn:hover:not(:disabled) { border-color: var(--accent); }
  .bit-btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
  .bit-nav-link:hover, .bit-icon-btn:hover { background: var(--bg-2); color: var(--ink); }
}

/* ── Fields ────────────────────────────────────────────────────────────────── */
.bit-field { display: grid; gap: 6px; margin-bottom: var(--s-4); }
.bit-field > label, .bit-field__label { font-weight: 600; font-size: 14px; }
.bit-field__hint { color: var(--ink-faint); font-size: 13px; }
.bit-field__error { color: var(--rust); font-size: 13px; font-weight: 500; }
.bit-input, .bit-textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--well);
  color: var(--ink);
  font: 400 16px/1.4 var(--font-sans);
}
.bit-textarea { min-height: 96px; resize: vertical; }
.bit-input:focus, .bit-textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.bit-input[aria-invalid="true"], .bit-textarea[aria-invalid="true"] { border-color: var(--rust); }
.bit-input--mono { font-family: var(--font-mono); }

/* ── Segmented control ─────────────────────────────────────────────────────── */
.bit-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: var(--well);
  border: 1px solid var(--line);
}
.bit-seg__opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-muted);
  font: 600 14px/1 var(--font-sans);
  cursor: pointer;
}
.bit-seg__opt[aria-checked="true"] { background: var(--bg-2); color: var(--ink); box-shadow: var(--sh-1); }
.bit-seg__opt:active { transform: scale(0.97); }
.bit-seg__opt:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.bit-seg--sm .bit-seg__opt { padding: 0 12px; font-size: 13px; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.bit-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--ink-muted);
  font: 600 12px/1.4 var(--font-sans);
  white-space: nowrap;
}
.bit-badge svg { width: 13px; height: 13px; }

/* ── Banners ───────────────────────────────────────────────────────────────── */
.bit-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-4);
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--bg-1);
}
.bit-banner__body { flex: 1 1 240px; min-width: 0; }
.bit-banner__title { font-weight: 700; }
.bit-banner__text { color: var(--ink-muted); font-size: 14px; }
.bit-banner > svg { width: 22px; height: 22px; }
.bit-banner--accent { background: var(--accent-quiet); border-color: transparent; }
.bit-banner--accent > svg { color: var(--accent-ink); }
.bit-banner--warn { background: var(--warn-quiet); border-color: transparent; }
.bit-banner--warn > svg { color: var(--warn); }
.bit-banner--error { background: var(--rust-quiet); border-color: transparent; }
.bit-banner--error > svg, .bit-banner--error .bit-banner__title { color: var(--rust); }
.bit-banner--ok { background: var(--ok-quiet); border-color: transparent; }
.bit-banner--ok > svg { color: var(--ok); }

@keyframes bitFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes bitSpin { to { transform: rotate(360deg); } }
.bit-spin { animation: bitSpin 0.9s linear infinite; }
