/* Reset, typography and shared controls (buttons, fields, chips, cards, toast, sheet). */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
html.scroll-locked, html.scroll-locked body { overflow: hidden; }

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

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

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

/* Typography */
.h1, .h2, .h3 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.h1 { font-size: var(--fs-2xl); }
.h2 { font-size: var(--fs-xl); }
.h3 { font-size: var(--fs-lg); font-weight: 500; }
.eyebrow {
  font-size: var(--fs-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
}
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.icon { width: var(--icon); height: var(--icon); flex: none; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  font-weight: 500;
  font-size: var(--fs-sm);
  border: 1px solid transparent;
  transition: background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
}
.btn-primary { background: var(--accent-deep); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { border-color: var(--border-hi); color: var(--accent-deep); background: var(--surface); }
.btn-ghost:hover { background: var(--accent-tint); }
.btn-danger { background: var(--danger); color: var(--on-accent); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }

/* Fields */
.field { display: grid; gap: var(--space-1); }
.field > span { font-size: var(--fs-sm); color: var(--text-dim); font-weight: 500; }
.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--fs-md);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.input[aria-invalid="true"] { border-color: var(--danger); }
/* Selects: own chevron, inset like the text. The data-URI stroke can't read a CSS variable —
   %238D929B is --muted; change both together. */
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: calc(var(--space-3) + var(--space-4) + var(--space-3));
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238D929B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: var(--space-4) var(--space-4);
  text-overflow: ellipsis;
  cursor: pointer;
}
select.input:hover { border-color: var(--accent); }
select.input:disabled { opacity: .6; cursor: not-allowed; }
.field-error { color: var(--danger); font-size: var(--fs-sm); }
.field-error:empty { display: none; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 500;
  background: var(--accent-tint); color: var(--accent-deep);
}
.badge-ok { background: var(--success-tint); color: var(--text); }
.badge-warn { background: var(--gold-tint); color: var(--text); }
.badge-bad { background: var(--danger-tint); color: var(--text); }

/* Empty / loading states */
.empty { color: var(--muted); font-size: var(--fs-sm); padding: var(--space-4) 0; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--bg-alt), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: var(--radius-sm); min-height: var(--space-6); }
.skeleton-text { display: inline-block; width: 70%; min-height: 0; color: transparent; } /* one text line tall, sized by the parent's font */
@keyframes shimmer { to { background-position: -200% 0; } }

/* Toast */
.toasts {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  display: grid; gap: var(--space-2);
  width: min(92vw, 420px);
}
.toast {
  background: var(--text); color: var(--surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hi);
  font-size: var(--fs-sm);
  animation: rise .25s var(--ease-out);
}
.toast-error { background: var(--danger); color: var(--on-accent); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* In-page confirmation sheet (no browser dialogs) */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 50;
  background: var(--scrim);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  animation: fade .2s var(--ease);
}
.sheet {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hi);
  padding: var(--space-6);
  width: min(100%, 440px);
  display: grid; gap: var(--space-4);
  animation: rise .25s var(--ease-out);
}
.sheet-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }

@media (max-width: 480px) {
  .sheet-scrim { align-items: flex-end; padding: 0; }
  .sheet {
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  }
  .sheet-actions .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
