/* Base + shared components for the docs and console prototypes. Requires tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.012em; font-weight: 600; color: var(--text); }
p { margin: 0; }
a { color: var(--accent-text); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }
img, svg { display: block; max-width: 100%; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--text); color: var(--bg); font-weight: 600; text-decoration: none;
  transition: top 120ms var(--ease);
}
.skip-link:focus { top: 12px; }

/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent; color: var(--text);
  font: inherit; font-size: var(--text-base); font-weight: 550; line-height: 1;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-control); color: var(--text); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: var(--on-danger); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: var(--text-sm); }
.btn[aria-disabled="true"], .btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn-icon { width: 36px; padding: 0; }

/* Badges ------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; line-height: 1.6; letter-spacing: 0.01em; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-secondary);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.badge-test { background: var(--test-soft); color: var(--test-ink); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }

/* Callouts ----------------------------------------------------------------- */
.callout {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-lg);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: var(--text-sm); line-height: 1.55;
}
.callout strong { color: var(--text); font-weight: 600; }
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.callout-test { background: var(--test-soft); border-color: var(--test-border); color: var(--test-ink); }
.callout-test strong { color: var(--test-ink); }

/* Cards -------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: var(--text-md); font-weight: 600; }
.card-sub { color: var(--text-secondary); font-size: var(--text-sm); }

/* Forms -------------------------------------------------------------------- */
.field { display: grid; gap: 6px; }
.field + .field { margin-top: 16px; }
.label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.hint { font-size: var(--text-sm); color: var(--text-secondary); }
.error-text { font-size: var(--text-sm); color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  border: 1px solid var(--border-control); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-md);
}
.textarea { min-height: 88px; resize: vertical; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.choice { display: flex; align-items: flex-start; gap: 10px; font-size: var(--text-md); }
.choice input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }

/* Segmented control (radio group) ------------------------------------------- */
.segmented { display: inline-flex; padding: 3px; border-radius: var(--r-md); background: var(--surface-sunken); border: 1px solid var(--border); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; border-radius: 6px; font-size: var(--text-sm); font-weight: 550; color: var(--text-secondary); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Tables ------------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; font-size: var(--text-base); }
.table caption { text-align: left; padding: 0 0 8px; color: var(--text-secondary); font-size: var(--text-sm); }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-tertiary); background: var(--surface); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: 0.93em; }
.muted { color: var(--text-secondary); }

/* Code --------------------------------------------------------------------- */
.code {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  background: var(--code-bg); color: var(--code-ink);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  font-family: var(--font-mono); font-size: 13px; line-height: 1.65; tab-size: 2;
}
.tok-key { color: var(--tok-key); }
.tok-str { color: var(--tok-str); }
.tok-num, .tok-bool { color: var(--tok-num); }
.tok-com { color: var(--tok-com); font-style: italic; }

/* Dialog ------------------------------------------------------------------- */
dialog.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: var(--r-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.dialog::backdrop { background: rgba(23, 22, 21, 0.45); }
.dialog-head { padding: 20px 20px 0; }
.dialog-title { font-size: var(--text-xl); font-weight: 600; }
.dialog-body { padding: 16px 20px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px 20px; }

/* Toast -------------------------------------------------------------------- */
.toast-region { position: fixed; z-index: 80; right: 20px; bottom: 20px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 40px)); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--r-lg);
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: var(--text-sm); font-weight: 500;
  animation: toast-in 180ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .badge, .btn, .card, .callout { border: 1px solid CanvasText; }
}
