/* ============================================================
   Reset enxuto + primitivas de UI (botões, campos, badges)
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
h1, h2, h3, h4, h5, h6,
p, figure, blockquote, dl, dd, ul, ol {
  margin: 0;
}

ul, ol { padding: 0; list-style: none; }

/* O atributo hidden precisa vencer as classes de layout (display:grid/flex) */
[hidden] { display: none !important; }

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--text-body);
  background: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-ligatures: common-ligatures;
}

img, svg, video, canvas { display: block; max-width: 100%; }
img, video { height: auto; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--text-brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--blue-800); }

h1, h2, h3, h4 {
  color: var(--text-strong);
  line-height: var(--lh-tight);
  font-weight: 600;
  text-wrap: balance;
}

:where(button, a, [role="button"], summary):not(:disabled) { cursor: pointer; }

/* ---------- Foco visível e consistente ---------- */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}
:focus:not(:focus-visible) { outline: none; }

/* ---------- Utilitários ---------- */
.sr-only {
  position: absolute;
  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: var(--space-4);
  top: -100px;
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  background: var(--blue-800);
  color: var(--white);
  border-radius: var(--radius-md);
  font-weight: 600;
  box-shadow: var(--shadow-3);
  transition: top var(--dur-base) var(--ease-out);
}
.skip-link:focus { top: var(--space-4); color: var(--white); }

.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.hidden { display: none !important; }

.eyebrow {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- Ícones ---------- */
.icon {
  width: 20px; height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon--sm { width: 16px; height: 16px; stroke-width: 1.75; }
.icon--lg { width: 24px; height: 24px; }

/* ============================================================
   Botões
   ============================================================ */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--text-body);
  --btn-bd: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-5);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.005em;
  text-decoration: none;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    color var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  --btn-bg: var(--action);
  --btn-fg: var(--white);
  --btn-bd: var(--action);
  box-shadow: var(--shadow-2);
}
.btn--primary:hover:not(:disabled) { --btn-bg: var(--action-hover); --btn-bd: var(--action-hover); box-shadow: var(--shadow-3); }
.btn--primary:active:not(:disabled) { --btn-bg: var(--action-active); }

.btn--secondary {
  --btn-bg: var(--bg-surface);
  --btn-fg: var(--slate-800);
  --btn-bd: var(--border-strong);
  box-shadow: var(--shadow-1);
}
.btn--secondary:hover:not(:disabled) { --btn-bg: var(--slate-50); --btn-bd: var(--slate-400); }

.btn--ghost { --btn-fg: var(--slate-700); }
.btn--ghost:hover:not(:disabled) { --btn-bg: var(--slate-100); --btn-fg: var(--slate-900); }

.btn--danger { --btn-fg: var(--red-600); --btn-bd: #f3cfcb; --btn-bg: var(--bg-surface); }
.btn--danger:hover:not(:disabled) { --btn-bg: var(--red-100); --btn-fg: var(--red-700); }

.btn--sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-xs); border-radius: var(--radius-sm); }
/* No toque, mesmo os botões compactos precisam do alvo mínimo de 44px. */
@media (max-width: 900px) {
  .btn--sm { min-height: 44px; }
}
.btn--lg { min-height: 50px; padding: 0 var(--space-6); font-size: var(--fs-base); }
.btn--block { width: 100%; }
.btn--icon { padding: 0; width: 44px; min-height: 44px; }
.btn--icon.btn--sm { width: 36px; }

/* Estado de carregamento */
.btn[data-loading="true"] { color: transparent !important; pointer-events: none; }
.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 18px; height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  color: var(--white);
  animation: spin 620ms linear infinite;
}
.btn--secondary[data-loading="true"]::after,
.btn--ghost[data-loading="true"]::after { color: var(--slate-600); }

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

/* ============================================================
   Campos de formulário
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field__label {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--slate-800);
}
.field__req { color: var(--red-600); font-weight: 700; }

.field__control { position: relative; display: flex; align-items: center; }

.input,
.select,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-strong);
  font-size: var(--fs-base); /* 16px evita zoom automático no iOS */
  line-height: 1.4;
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.03);
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.textarea { min-height: 96px; padding-top: var(--space-3); resize: vertical; }

.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }

.input:hover:not(:disabled),
.select:hover:not(:disabled) { border-color: var(--slate-400); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: var(--shadow-focus);
}

.input:disabled,
.select:disabled { background: var(--slate-100); color: var(--text-muted); cursor: not-allowed; }
.input[readonly] { background: var(--slate-50); color: var(--slate-700); }

.select {
  appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px 18px;
}

.input--mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }

/* ============================================================
   Combobox pesquisável (curso) — busca + input oculto + painel
   ============================================================ */
.combo { position: relative; }

.combo__control { position: relative; display: flex; align-items: center; }
.combo__icon {
  position: absolute;
  left: 13px;
  color: var(--text-faint);
  pointer-events: none;
}
.combo__input { padding-left: 40px; padding-right: 44px; cursor: text; }
.combo__input[aria-expanded="true"] { border-color: var(--blue-500); box-shadow: var(--shadow-focus); }

.combo__clear {
  position: absolute;
  right: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
}
.combo__clear:hover { background: var(--slate-100); color: var(--slate-700); }

.combo__panel {
  position: absolute;
  z-index: var(--z-overlay);
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(340px, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-2);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-4);
  animation: combo-in var(--dur-base) var(--ease-out) both;
}
@keyframes combo-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.combo__group {
  padding: var(--space-2) var(--space-3) 4px;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps-wide);
  text-transform: uppercase;
  color: var(--text-faint);
}
.combo__group:not(:first-child) { margin-top: var(--space-1); border-top: 1px solid var(--border); }

.combo__option {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--slate-700);
  line-height: var(--lh-snug);
  cursor: pointer;
}
.combo__option.is-active { background: var(--action-soft); color: var(--blue-800); }
.combo__option.is-selected { font-weight: 650; color: var(--blue-800); }
.combo__option.is-selected::after {
  content: "";
  width: 8px; height: 8px;
  margin-left: auto;
  flex: none;
  border-radius: 50%;
  background: var(--teal-500);
}

.combo__empty {
  padding: var(--space-4) var(--space-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: center;
}

.field__affix {
  position: absolute;
  right: 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
}
.field__affix:hover { background: var(--slate-100); color: var(--slate-700); }

.field__help {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  line-height: var(--lh-snug);
}

.field__error {
  display: none;
  align-items: flex-start;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: var(--lh-snug);
  color: var(--red-600);
}
.field__error .icon { width: 15px; height: 15px; margin-top: 1px; }

.field[data-invalid="true"] .input,
.field[data-invalid="true"] .select {
  border-color: var(--red-600);
  box-shadow: inset 0 1px 1px rgba(180, 35, 24, 0.06);
}
.field[data-invalid="true"] .input:focus,
.field[data-invalid="true"] .select:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.20); }
.field[data-invalid="true"] .field__error { display: flex; }
.field[data-invalid="true"] .field__help { display: none; }

.fieldset { border: 0; padding: 0; margin: 0; }
.fieldset__legend {
  padding: 0;
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: var(--tracking-caps-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}

.field-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.field-grid > .field--full { grid-column: 1 / -1; }
@media (max-width: 560px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-grid > .field--full { grid-column: auto; }
}

/* ---------- Checkbox ---------- */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) 0;
  font-size: var(--fs-sm);
  color: var(--slate-700);
}
.check input {
  flex: none;
  width: 20px; height: 20px;
  margin: 1px 0 0;
  accent-color: var(--blue-600);
  cursor: pointer;
}

/* ============================================================
   Selos, chips e cartões
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2xs);
  font-weight: 650;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.badge .icon { width: 14px; height: 14px; stroke-width: 2; }
.badge--success { background: var(--green-100); color: var(--green-700); border-color: #b9e7d1; }
.badge--warn { background: var(--amber-100); color: var(--amber-700); border-color: #f6dcae; }
.badge--danger { background: var(--red-100); color: var(--red-700); border-color: #f5cdc9; }
.badge--neutral { background: var(--slate-100); color: var(--slate-600); border-color: var(--border); }
.badge--brand { background: var(--blue-50); color: var(--blue-700); border-color: var(--blue-200); }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.card__title { font-size: var(--fs-base); font-weight: 650; color: var(--text-strong); }
.card__sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.card__body { padding: var(--space-6); }

@media (max-width: 640px) {
  .card__head { padding: var(--space-4) var(--space-4); }
  .card__body { padding: var(--space-4); }
}

/* ============================================================
   Skeletons
   ============================================================ */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--slate-150);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  animation: shimmer 1.45s ease-in-out infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; opacity: 0.45; transform: none; }
}
:root[data-motion="reduced"] .skeleton::after { animation: none; opacity: 0.45; transform: none; }

/* ============================================================
   Toasts
   ============================================================ */
.toaster {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(420px, calc(100vw - var(--space-8)));
  pointer-events: none;
}
@media (min-width: 900px) {
  .toaster { left: auto; right: var(--space-6); bottom: var(--space-6); transform: none; }
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--slate-900);
  color: var(--white);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  box-shadow: var(--shadow-4);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease-spring) both;
}
.toast[data-leaving="true"] { animation: toast-out 180ms var(--ease-in) both; }
.toast .icon { flex: none; margin-top: 1px; }
.toast--success .icon { color: #6ee7b7; }
.toast--error .icon { color: #fca5a5; }
.toast__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  margin: -6px -6px -6px 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.62);
  border-radius: var(--radius-sm);
}
.toast__close:hover { color: var(--white); }

@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
