/* ==========================================================================
   ProntMed · Design system ("Clínica boutique": tokens + componentes base)
   Fontes auto-hospedadas (CSP: font-src 'self').
   Contraste WCAG AA verificado (mín. 4.5:1 texto, 3:1 bordas/ícones):
   - --ink (#111917) em --canvas (#f6f5f1): 16.5:1 | em --surface (#ffffff): 17.9:1
   - --ink-2 (#24302d) em --canvas: 12.1:1 | em --surface: 13.2:1
   - --muted (#56625e) em --canvas: 5.7:1 | em --surface: 6.2:1
   - --subtle (#5f6965) em --canvas: 5.0:1 | em --surface: 5.4:1
   - --accent (#0e5f55) em --surface: 7.4:1 | branco em --accent: 7.4:1
   - --gold (#846233) em --canvas: 5.05:1 | em --surface: 5.5:1 | em --gold-soft: 4.7:1
   - --warn (#8c5308) em --warn-soft: 5.5:1 | --danger (#9e2432) em --danger-soft: 6.5:1
   - --ok (#1b6e4b) em --ok-soft: 5.4:1 | --info (#1e4e79) em --info-soft: 7.3:1
   ========================================================================== */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../fonts/inter-latin.woff2") format("woff2");
}
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("../fonts/fraunces-latin.woff2") format("woff2");
}

:root {
  color-scheme: light;

  /* Tipografia e escala */
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --text-xs: .75rem;
  --text-sm: .875rem;
  --text-base: .9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;

  /* Superfícies e texto — marfim acolhedor */
  --canvas: #f6f5f1;
  --canvas-tint: #eef3f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --surface-3: #f1efe9;
  --white: #ffffff;
  --line: #e7e5de;
  --line-strong: #d4d1c7;
  --ink: #111917;
  --ink-2: #24302d;
  --muted: #56625e;
  --subtle: #5f6965;
  --ink-inverse: #ffffff;
  --ink-inverse-muted: rgba(255, 255, 255, .82);
  --ink-inverse-subtle: rgba(255, 255, 255, .56);

  /* Marca — verde-petróleo + champanhe dourado */
  --accent: #0e5f55;
  --accent-hover: #0b4f47;
  --accent-dark: #09453e;
  --accent-bright: #168a7b;
  --accent-soft: #e6f2ef;
  --accent-soft-2: #f1f8f6;
  --accent-border: #b8dbd2;
  --accent-ring: rgba(14, 95, 85, .18);
  --gold: #846233;
  --gold-bright: #b69156;
  --gold-soft: #f5efe4;
  --gold-border: #e0cfa9;

  /* Estados clínicos */
  --ok: #1b6e4b;
  --ok-soft: #e7f4ed;
  --ok-border: #bfe3d1;
  --warn: #8c5308;
  --warn-soft: #fbf2e1;
  --warn-border: #edd5a3;
  --danger: #9e2432;
  --danger-soft: #fbecef;
  --danger-hover: #f7dce1;
  --danger-border: #ebbcc3;
  --danger-ring: rgba(158, 36, 50, .14);
  --info: #1e4e79;
  --info-soft: #eaf1f8;
  --info-border: #c4d9ed;

  /* Tons de apoio (login hero, linha do tempo, estrelas, switch) */
  --hero-bg-1: #0c3d37;
  --hero-bg-2: #062f2a;
  --hero-gold: #dfc08c;
  --hero-mint: #89e0cf;
  --hero-tint: rgba(255, 255, 255, .07);
  --hero-border: rgba(255, 255, 255, .14);
  --tone-followup: #b45309;
  --tone-followup-ring: #fde68a;
  --tone-rx: #1e4e79;
  --tone-rx-ring: #d6e6f5;
  --tone-exam: #4b479c;
  --tone-exam-ring: #e0dff7;
  --tone-guidance: #0e5f55;
  --tone-guidance-ring: #cbe7e1;
  --tone-attachment: #1a658c;
  --tone-attachment-ring: #d6edf8;
  --tone-lab: #6b46a8;
  --tone-lab-ring: #e7def7;
  --tone-intake: #47626b;
  --tone-intake-ring: #dae5e8;
  --star-active: #c27803;
  --star-bg: #fbf2e1;
  --star-idle: #9ca5a1;
  --switch-off: #cbc9bf;
  --backdrop: rgba(17, 25, 23, .46);
  --topbar-bg: rgba(246, 245, 241, .84);

  /* Impressão A4 */
  --print-ink: #151817;
  --print-muted: #4b5451;
  --print-line: #c8c6be;
  --print-soft: #f4f3ee;

  /* Gráficos (lidos por JS via getComputedStyle) */
  --chart-1: #0e5f55;
  --chart-2: #846233;
  --chart-3: #1e4e79;
  --chart-4: #6b46a8;
  --chart-5: #b85d19;
  --chart-6: #9e2432;
  --chart-7: #1b6e4b;
  --chart-grid: #ece9e2;
  --chart-target: #846233;

  /* Espaçamento e layout */
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --sidebar-w: 244px;
  --sidebar-collapsed: 72px;
  --topbar-h: 56px;
  --container-max: 1180px;

  /* Raios, sombras e movimento */
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius: 14px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(17, 25, 23, .04);
  --shadow-sm: 0 1px 2px rgba(17, 25, 23, .04), 0 4px 12px -4px rgba(17, 25, 23, .06);
  --shadow-md: 0 2px 6px rgba(17, 25, 23, .04), 0 12px 28px -10px rgba(17, 25, 23, .10);
  --shadow-lg: 0 4px 12px rgba(17, 25, 23, .06), 0 24px 56px -16px rgba(17, 25, 23, .18);
  --shadow-xl: 0 8px 24px rgba(17, 25, 23, .08), 0 32px 72px -20px rgba(17, 25, 23, .24);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --dur-fast: 140ms;
  --dur-base: 220ms;
  --dur-slow: 340ms;
  --focus-ring: 0 0 0 3px var(--accent-ring);

  font-family: var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, dl, dd { margin: 0; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.015em; }
a { color: var(--accent-dark); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
::selection { background: rgba(14, 95, 85, .18); }
button, select, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
:focus-visible,
.button:focus-visible,
.chip:focus-visible,
.patient-row:focus-visible,
.attention-row:focus-visible,
.link-inline:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* Utilitários tipográficos e de espaçamento ------------------------------ */
.tabular, .num { font-variant-numeric: tabular-nums; }
.eyebrow {
  font-size: .6875rem;
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold);
  line-height: 1.2;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 2.4vw, 2rem);
  font-weight: 600;
  letter-spacing: -.025em;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.mt-sm { margin-top: var(--space-2); }
.mt-md { margin-top: var(--space-4); }
.mb-sm { margin-bottom: var(--space-3); }
.mb-md { margin-bottom: var(--space-4); }

.icon, .icon-svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke-width: 1.75;
}

/* Botões ---------------------------------------------------------------- */
.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 40px;
  padding: .5rem 1.05rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--ink-inverse);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -.005em;
  text-decoration: none;
  text-align: center;
  line-height: 1.25;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--ink-inverse);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.button:active:not(:disabled) { transform: translateY(0); }

.button.secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}
.button.secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--muted);
  color: var(--accent-dark);
}

.button.ghost, .button.quiet {
  border-color: transparent;
  background: transparent;
  color: var(--accent-dark);
  box-shadow: none;
}
.button.ghost:hover:not(:disabled), .button.quiet:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: transparent;
  color: var(--accent-dark);
  box-shadow: none;
  transform: none;
}

.button.danger {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}
.button.danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger);
  color: var(--danger);
  box-shadow: none;
}

.button.sm {
  min-height: 32px;
  padding: .34rem .75rem;
  font-size: .8125rem;
  border-radius: var(--radius-xs);
}
.button.lg {
  min-height: 48px;
  padding: .68rem 1.35rem;
  font-size: var(--text-base);
  border-radius: var(--radius-md);
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--ink);
}

.button.is-loading {
  color: transparent !important;
  pointer-events: none;
}
.button.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  color: var(--ink-inverse);
  animation: pm-spin .65s linear infinite;
}
.button.secondary.is-loading::after,
.button.ghost.is-loading::after,
.button.quiet.is-loading::after {
  color: var(--accent-dark);
}

/* Links inline e consentimento discreto ---------------------------------- */
.link-inline {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-dark);
  font: inherit;
  font-weight: 550;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}
.link-inline:hover { color: var(--accent); }

.consent-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: var(--space-4);
  padding: 2px 0;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--muted);
  cursor: pointer;
}
.consent-line input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex: 0 0 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.consent-line.is-invalid {
  color: var(--danger);
}
.consent-line.is-invalid input[type="checkbox"] {
  outline: 2px solid var(--danger);
  outline-offset: 1px;
}
.consent-error {
  display: block;
  margin: calc(var(--space-1) * -1) 0 var(--space-4) 28px;
  color: var(--danger);
  font-size: .8125rem;
  font-weight: 600;
}

/* Campos de formulário -------------------------------------------------- */
.field { display: grid; align-content: start; gap: .36rem; min-width: 0; }
.field label, .field > span:first-child {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: -.003em;
}
.field small, .muted { color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=file]),
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: .48rem .78rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-base);
  box-shadow: inset 0 1px 1px rgba(17, 25, 23, .02);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
select {
  appearance: none;
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2356625e' stroke-width='1.75' 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 .7rem center;
  background-size: 16px;
}
input:not([type=checkbox]):not([type=radio]):not([type=file]):hover,
select:hover,
textarea:hover {
  border-color: var(--muted);
}
input:not([type=checkbox]):not([type=radio]):not([type=file]):focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
  outline: none;
}
.is-invalid,
[aria-invalid="true"] {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-ring);
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-3);
  color: var(--subtle);
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
textarea { resize: vertical; min-height: 5.25rem; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--subtle); opacity: .88; }

.field-unit {
  position: relative;
  display: flex;
  align-items: center;
}
.field-unit input { padding-right: 3.1rem; }
.field-unit > span {
  position: absolute;
  right: 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--subtle);
  pointer-events: none;
}
.form-grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--space-3);
}

@media (max-width: 640px) {
  input:not([type=checkbox]):not([type=radio]):not([type=file]),
  select {
    min-height: 44px;
    font-size: 1rem;
  }
}

/* Avisos, badges, estados vazios e skeleton ----------------------------- */
.notice, .empty {
  padding: .85rem 1.05rem;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}
.notice.error, .error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger-border);
}
.empty {
  border: 1px dashed var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
}
.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--muted);
}
.empty-state-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--accent-dark);
  margin-bottom: var(--space-1);
}
.empty-state strong {
  font-size: var(--text-base);
  font-weight: 650;
  color: var(--ink);
}
.empty-state p {
  max-width: 44ch;
  font-size: var(--text-sm);
  color: var(--muted);
}
.empty-state .button { margin-top: var(--space-2); }

.skeleton {
  display: block;
  min-height: 16px;
  border-radius: var(--radius-xs);
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: pm-shimmer 1.4s ease-in-out infinite;
}
.skeleton-title { width: 45%; height: 24px; }
.skeleton-line { width: 75%; }

.badge, .pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .18rem .6rem;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .005em;
  line-height: 1.4;
  white-space: nowrap;
}
.pill.has-dot::before, .badge.has-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 6px;
}
.pill.ok, .badge.ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok); }
.pill.info, .badge.info { background: var(--info-soft); border-color: var(--info-border); color: var(--info); }
.pill.gold, .badge.gold { background: var(--gold-soft); border-color: var(--gold-border); color: var(--gold); }
.pill.soft { background: var(--surface-3); border-color: var(--line); color: var(--ink-2); }
.pill.warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn); }
.pill.danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }
.error-inline { display: block; color: var(--danger); font-size: .8125rem; font-weight: 600; margin-top: .25rem; }

/* Foto de rosto --------------------------------------------------------- */
.photo-picker {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: 14px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.photo-preview-box {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line), var(--shadow-sm);
  flex: 0 0 72px;
  font-weight: 700;
}
.photo-preview-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-picker-controls { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 200px; }
.photo-picker-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@keyframes pm-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pm-spin { to { transform: rotate(360deg); } }
@keyframes pm-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
