:root {
  --bg: #fcfaf7;
  --text: #1c0f0d;
  --muted: #687076;
  --card: #ffffff;
  --accent: #9c5c4a;
  --on-accent: #ffffff;
  --border: #e5e0db;
  --risk-high: #9b2c2c;
  --risk-medium: #9c6b24;
  --risk-low: #4d6b57;
}

* {
  box-sizing: border-box;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

img {
  max-width: 100%;
  height: auto;
}

main {
  width: min(100%, 420px);
  min-width: 0;
}

main.wide {
  width: min(100%, 720px);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}

.brand img {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 10px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 14px;
}

.nav a,
.foot a {
  color: var(--accent);
  text-decoration: none;
}

.header-tools {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 14px;
  min-width: 0;
  margin-left: auto;
}

.lang {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.lang-btn,
button.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 5px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.lang-btn.is-active,
button.lang-btn.is-active {
  background: var(--border);
  color: var(--text);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-block;
  margin: 0 0 16px;
  padding: 6px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(24px, 7vw, 28px);
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

main.wide h1 {
  text-align: left;
  font-size: clamp(26px, 6vw, 40px);
  line-height: 1.15;
}

.lead {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: clamp(16px, 2.4vw, 18px);
  line-height: 1.5;
}

main.wide .card {
  margin-bottom: 16px;
}

main.wide h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.features {
  margin: 0 0 12px;
  padding-left: 1.2em;
  line-height: 1.5;
  font-size: 16px;
}

.features li + li {
  margin-top: 10px;
}

.plan-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0 0 12px;
}

.plan {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.plan h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.plan .price {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}

.plan p:last-child {
  margin-bottom: 0;
  font-size: 15px;
}

.prose p:last-child {
  margin-bottom: 0;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.foot {
  margin-top: 28px;
  text-align: center;
}

.foot p {
  margin: 0 0 8px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.tag {
  margin: 0 0 24px;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

p {
  margin: 0 0 16px;
  line-height: 1.45;
  font-size: 16px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.store-actions {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

a.store-badge {
  display: inline-block;
  line-height: 0;
  text-decoration: none;
}

a.store-badge img {
  display: block;
  height: 40px;
  width: 135px;
  object-fit: contain;
  object-position: left center;
}

a.button,
button:not(.lang-btn) {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: var(--on-accent);
}

.secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.steps {
  margin: 0 0 16px;
  padding-left: 1.2em;
  line-height: 1.5;
  font-size: 16px;
}

.steps li + li {
  margin-top: 8px;
}

.hint {
  margin-top: 16px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

details.help {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

details.help summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

details.help ol {
  margin: 10px 0 0;
  padding-left: 1.2em;
}

details.help li + li {
  margin-top: 6px;
}

.hidden {
  display: none;
}

.pin-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.pin-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 13rem;
  height: 48px;
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  line-height: 48px;
  letter-spacing: 0.35em;
  text-align: center;
  background: var(--bg);
  color: var(--text);
}

#gate form {
  margin: 0;
}

#gate .hint {
  margin-top: 0;
  margin-bottom: 16px;
}

#gate .actions {
  width: 100%;
  max-width: 13rem;
  flex-direction: column;
  flex-wrap: nowrap;
}

#gate .actions button {
  width: 100%;
  min-width: 0;
  flex: none;
  height: 48px;
  padding: 0 16px;
  font-size: 16px;
  line-height: 48px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.stat {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.stat-value {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

@media (max-width: 639px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) {
  body {
    padding: 40px 24px 56px;
  }

  .card {
    padding: 24px;
  }

  main.wide .card {
    margin-bottom: 20px;
  }

  .plan-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
  }

  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  a.button,
  button:not(.lang-btn) {
    width: auto;
    min-width: 200px;
    flex: 1 1 200px;
  }

  #gate .actions {
    flex-direction: column;
  }

  #gate .actions button {
    width: 100%;
    min-width: 0;
    flex: none;
    height: 48px;
    padding: 0 16px;
  }
}

@media (min-width: 880px) {
  main.wide {
    width: min(100%, 880px);
  }

  .features {
    columns: 2;
    column-gap: 28px;
  }

  .features li {
    break-inside: avoid;
  }

  .features li + li {
    margin-top: 0;
    padding-top: 10px;
  }
}

main.dashboard {
  width: min(100%, 1040px);
}

main.dashboard:not(.is-open) {
  width: min(100%, 560px);
}

main.dashboard.is-open .eyebrow,
main.dashboard.is-open > h1,
main.dashboard.is-open > .lead {
  display: none;
}

main.dashboard.is-open .top {
  margin-bottom: 16px;
}

#report .stat-grid {
  margin: 0 0 16px;
}

#report .stat-value {
  font-size: clamp(22px, 3.2vw, 30px);
  font-variant-numeric: tabular-nums;
}

#report .stat .hint {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.dash-identity {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px 24px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

main.dashboard .dash-identity h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 32px);
  line-height: 1.15;
}

.dash-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.dash-meta:empty {
  display: none;
}

.dash-identity-end {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.dash-period {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.dash-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.risk-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.risk-chip-high {
  background: #f8e4e4;
  color: var(--risk-high);
}

.risk-chip-medium {
  background: #f6ebda;
  color: var(--risk-medium);
}

.risk-chip-low {
  background: #e4eee8;
  color: var(--risk-low);
}

.risk-chip-quiet {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}

.dash-high {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

main.dashboard .dash-panel {
  margin: 0;
  min-width: 0;
}

main.dashboard .med-panel {
  margin-bottom: 24px;
}

.dash-kicker {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dash-body {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
}

.dash-muted {
  color: var(--muted);
}

.dash-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 15px;
  line-height: 1.45;
}

.dash-list li + li {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.dash-comorbidity-severe {
  font-weight: 600;
}

.med-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.med-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.45;
}

.med-table th,
.med-table td {
  text-align: left;
  vertical-align: top;
  padding: 10px 12px 10px 0;
}

.med-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.med-table td {
  border-bottom: 1px solid var(--border);
}

.med-table tbody tr:last-child td {
  border-bottom: none;
}

.med-table th:last-child,
.med-table td:last-child {
  padding-right: 0;
}

.as-needed-group + .as-needed-group {
  margin-top: 16px;
}

.as-needed-title {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.as-needed-list {
  margin: 0;
  padding-left: 1.1em;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.as-needed-list li + li {
  margin-top: 6px;
}

.dash-alerts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  background: var(--bg);
}

.alert-row-high {
  border-left-color: var(--risk-high);
}

.alert-row-medium {
  border-left-color: var(--risk-medium);
}

.alert-row-low {
  border-left-color: var(--risk-low);
}

.alert-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.alert-severity {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.alert-row-high .alert-severity {
  background: #f8e4e4;
  color: var(--risk-high);
}

.alert-row-medium .alert-severity {
  background: #f6ebda;
  color: var(--risk-medium);
}

.alert-row-low .alert-severity {
  background: #e4eee8;
  color: var(--risk-low);
}

.alert-cat {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.alert-desc {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
}

.dash-disclaimer {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

/* =========================================
   DASHBOARD MÉDICO (Classes geradas pelo JS)
   ========================================= */

   .dashboard.is-open {
    width: min(100%, 960px); /* Expande um pouco mais para a visão de grid */
  }
  
  /* Identidade do Paciente (Cabeçalho) */
  .dash-identity {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border);
  }
  
  .dash-identity h2 {
    margin: 0 0 4px 0;
    font-size: 24px;
    color: var(--text);
  }
  
  .dash-meta {
    margin: 0;
    color: var(--muted);
    font-size: 16px;
  }
  
  .dash-identity-end {
    text-align: right;
  }
  
  .dash-period {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
  }
  
  /* Chips de Risco (Contadores do Cabeçalho) */
  .dash-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  
  .risk-chip {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  
  .risk-chip-high { background: #fee2e2; color: #991b1b; border: 1px solid #f87171; }
  .risk-chip-medium { background: #fef9c3; color: #854d0e; border: 1px solid #facc15; }
  .risk-chip-low { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
  .risk-chip-quiet { background: #f1f5f9; color: #94a3b8; }
  
  /* Grid de Informações (Comorbidades, Síntese, Vitais, Humor) */
  .dash-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 24px 0;
  }
  
  @media (min-width: 768px) {
    .dash-grid {
      grid-template-columns: 1fr 1fr;
    }
  }
  
  .dash-panel {
    display: flex;
    flex-direction: column;
  }
  
  .dash-kicker {
    margin: 0 0 12px 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
  }
  
  .dash-body {
    font-size: 15px;
    line-height: 1.6;
    margin: 0;
    color: var(--text);
  }
  
  .dash-muted {
    color: var(--muted);
    font-style: italic;
  }
  
  /* Lista de Comorbidades */
  .dash-list {
    margin: 0;
    padding: 0 0 0 20px;
    font-size: 15px;
    color: var(--text);
  }
  
  .dash-list li {
    margin-bottom: 6px;
  }
  
  .dash-comorbidity-severe {
    color: #991b1b;
    font-weight: 600;
  }
  
  /* Alertas */
  .dash-high {
    margin: 24px 0;
    border: 2px solid #f87171;
    border-radius: 12px;
    padding: 16px;
    background: #fffafa;
  }
  
  .dash-alerts {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .alert-row {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
  }
  
  .alert-row-high { border-left: 4px solid #ef4444; }
  .alert-row-medium { border-left: 4px solid #eab308; }
  .alert-row-low { border-left: 4px solid #94a3b8; }
  
  .alert-head {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 4px;
  }
  
  .alert-severity {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    background: #f1f5f9;
    color: #475569;
  }
  
  .alert-row-high .alert-severity { background: #fee2e2; color: #991b1b; }
  .alert-row-medium .alert-severity { background: #fef9c3; color: #854d0e; }
  
  .alert-cat {
    font-size: 12px;
    color: var(--muted);
    font-weight: 600;
  }
  
  .alert-desc {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
  }
  
  /* Rodapé / Disclaimer */
  .dash-disclaimer {
    margin-top: 32px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
  }

@media (max-width: 639px) {
  #report .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  #report .stat {
    padding: 10px 8px;
  }

  #report .stat-value {
    font-size: 20px;
  }
}

@media (max-width: 640px) {
  .med-table thead {
    display: none;
  }

  .med-table,
  .med-table tbody,
  .med-table tr,
  .med-table td {
    display: block;
    width: 100%;
  }

  .med-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }

  .med-table tbody tr:last-child {
    border-bottom: none;
  }

  .med-table td {
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 8px;
    padding: 4px 0;
    border-bottom: none;
  }

  .med-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
}

@media (min-width: 720px) {
  .dash-identity-end {
    align-items: flex-end;
  }

  .dash-chips {
    justify-content: flex-end;
  }

  .dash-grid {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: stretch;
  }
}

@media print {
  body {
    background: #fff;
    padding: 12px;
  }

  .top,
  .eyebrow,
  main.dashboard > h1,
  main.dashboard > .lead,
  #gate {
    display: none !important;
  }

  main.dashboard {
    width: 100%;
  }

  .card,
  .alert-row,
  .stat {
    break-inside: avoid;
  }
}
