:root {
  --azul: #0057b8;
  --azul-escuro: #003d82;
  --azul-oceano: #002d62;
  --laranja: #f39200;
  --laranja-escuro: #d67d00;
  --laranja-botao: #b45309;
  --laranja-botao-hover: #9a3412;
  --fundo: #eef3f9;
  --card: #ffffff;
  --ink: #1a2a3a;
  --muted: #3d4f61;
  --line: #d5deea;
  --danger: #b42318;
  --ok: #0b6b3a;
  --shadow: 0 10px 28px rgba(0, 45, 98, 0.08);
  --tap: 2.75rem;
  --col-mes: 3.75rem;
  --page: min(1320px, calc(100% - 32px));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "Nunito Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--fundo);
  min-height: 100vh;
}

h1,
h2,
h3,
.brand-mark {
  font-family: "Jost", "Century Gothic", sans-serif;
}

.skip-links {
  position: absolute;
  left: 0.75rem;
  top: 0.75rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.skip-links:not(:focus-within) {
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.skip-link {
  padding: 0.6rem 1rem;
  border-radius: 6px;
  background: #fff;
  color: var(--azul-oceano);
  font-weight: 700;
  text-decoration: none;
}

.topbar {
  background: linear-gradient(90deg, var(--azul-oceano), var(--azul));
  color: #fff;
  border-bottom: 5px solid var(--laranja);
}

.topbar-inner {
  width: var(--page);
  margin: 0 auto;
  padding: 12px 0 14px;
}

.brand-mark {
  margin: 0 0 6px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffd59a;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  font-weight: 600;
  letter-spacing: 0;
}

.topbar .lede {
  margin: 4px 0 0;
  max-width: 70ch;
  color: #eaf2fb;
  font-size: 0.92rem;
}

.aviso-didatico {
  background: #fff6e8;
  border-bottom: 1px solid #f0d4a8;
  color: #7a4b00;
  font-size: 0.92rem;
}

.aviso-didatico p {
  width: var(--page);
  margin: 0 auto;
  padding: 10px 0;
}

.page {
  width: var(--page);
  margin: 0 auto;
  padding: 22px 0 48px;
}

.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 12px;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
}

.form-card,
.result-stack {
  padding: 20px;
}

.form-card h2,
.panel h2,
.panel h3 {
  margin: 0 0 6px;
  color: var(--azul-escuro);
  font-weight: 600;
}

.hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.oculto {
  display: none !important;
}

fieldset {
  border: 0;
  margin: 0 0 18px;
  padding: 0;
}

legend {
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--azul-escuro);
}

.bloco {
  margin-bottom: 22px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.bloco:last-of-type {
  border-bottom: 0;
}

.passo {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--azul);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  vertical-align: middle;
}

.grid {
  display: grid;
  gap: 10px;
}

.grid.two {
  grid-template-columns: 1fr 1fr;
}

label {
  position: relative;
  display: grid;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--muted);
}

.rotulo {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ajuda {
  flex: 0 0 auto;
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.ajuda::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0.625rem;
  border-radius: 50%;
  background: var(--azul);
}

.ajuda[aria-expanded="true"]::before {
  background: var(--azul-escuro);
  outline: 2px solid var(--laranja);
  outline-offset: 1px;
}

.ajuda-texto {
  display: none;
  position: absolute;
  z-index: 4;
  left: 0;
  top: 2.4rem;
  width: min(280px, calc(100% - 4px));
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--azul-oceano);
  color: #fff;
  font-size: 0.8125rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
}

.ajuda-texto.aberta {
  display: block;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 10px 12px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
.table-wrap:focus-visible {
  outline: 2px solid var(--azul);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible {
  border-color: var(--azul);
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 8px;
}

button,
.ghost {
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  min-height: var(--tap);
  cursor: pointer;
}

button[type="submit"] {
  background: var(--laranja-botao);
  color: #fff;
  font-weight: 700;
}

button[type="submit"]:hover {
  background: var(--laranja-botao-hover);
}

.ghost {
  background: transparent;
  color: var(--azul);
  border: 1px solid var(--line);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

details {
  margin: 8px 0 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

details p {
  color: var(--muted);
  font-size: 0.92rem;
}

details summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  cursor: pointer;
}

.error,
.alert,
.winner {
  border-radius: 4px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.error,
.alert {
  background: #fdecec;
  border: 1px solid #f2c2c0;
  color: var(--danger);
}

.winner {
  background: #eef6ff;
  border: 1px solid #b9d4f3;
}

.winner .eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--laranja-botao);
}

.winner h2 {
  margin: 0 0 10px;
  color: var(--azul-escuro);
}

.winner strong {
  color: var(--azul);
}

.winner-metricas {
  display: grid;
  gap: 6px;
}

.winner-metricas p {
  margin: 0;
}

.winner-nota {
  color: var(--muted);
  font-size: 0.92rem;
}

.ranking {
  display: grid;
  gap: 12px;
}

.rank-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.rank-card.best {
  border-color: var(--azul);
  box-shadow: inset 0 0 0 1px var(--azul);
}

.rank-info,
.rank-valor {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.rank-valor {
  text-align: right;
}

.rank-card span {
  color: var(--muted);
  font-size: 0.88rem;
}

.rank-card .status-ok,
.rank-card .status-alerta {
  display: block;
  margin-top: 2px;
}

.status-ok {
  color: var(--ok) !important;
}

.status-alerta {
  color: var(--danger) !important;
}

.badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #e6eef8;
  color: var(--azul-escuro);
  font-weight: 700;
}

.rank-card.best .badge {
  background: var(--laranja-botao);
  color: #fff;
}

.panel {
  padding: 20px 22px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
  background:
    linear-gradient(to right, var(--card), var(--card)),
    linear-gradient(to right, var(--card), var(--card)),
    linear-gradient(to right, rgba(0, 45, 98, 0.16), transparent),
    linear-gradient(to left, rgba(0, 45, 98, 0.16), transparent);
  background-position: left center, right center, left center, right center;
  background-repeat: no-repeat;
  background-size: 1.25rem 100%, 1.25rem 100%, 0.9rem 100%, 0.9rem 100%;
  background-attachment: local, local, scroll, scroll;
}

.table-wrap-mensal {
  max-height: min(70dvh, 32rem);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
}

caption {
  caption-side: top;
  padding: 8px 0;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: normal;
  position: sticky;
  left: 0;
  max-width: min(36rem, 70vw);
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  background: var(--card);
}

th {
  color: var(--azul-escuro);
  font-weight: 700;
}

.tabela-resumo thead th,
.tabela-mensal thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f4f8fc;
}

.tabela-resumo .col-cenario,
.tabela-mensal .col-mes {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
}

.tabela-resumo thead .col-cenario,
.tabela-mensal thead .col-mes {
  z-index: 5;
  background: #f4f8fc;
}

.tabela-mensal .col-mes {
  min-width: var(--col-mes);
  width: var(--col-mes);
}

.tabela-resumo .col-cenario {
  min-width: 11rem;
  box-shadow: 4px 0 8px -6px rgba(0, 45, 98, 0.35);
}

.tabela-mensal .col-parcela-cheia {
  position: sticky;
  left: var(--col-mes);
  z-index: 1;
  background: #fff4e4;
  box-shadow: inset 2px 0 0 var(--laranja), 4px 0 8px -6px rgba(0, 45, 98, 0.28);
  font-variant-numeric: tabular-nums;
}

.tabela-mensal th.col-parcela-cheia {
  background: #ffe3b8;
  color: var(--azul-oceano);
  z-index: 4;
}

.tabela-mensal td.col-parcela-cheia {
  font-weight: 700;
  color: var(--azul-oceano);
}

.tabela-mensal tbody tr:hover td.col-parcela-cheia {
  background: #ffe9c7;
}

.tabela-mensal tbody tr:hover .col-mes {
  background: #f7fafc;
}

.charts {
  display: grid;
  gap: 18px;
}

.chart-box {
  min-height: 280px;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin: 12px 0;
}

.toolbar label {
  min-width: min(100%, 16rem);
}

.empty {
  padding: 48px 28px;
  text-align: left;
}

.empty h2 {
  margin-top: 0;
}

footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

footer strong {
  color: var(--azul-escuro);
}

@media (max-width: 1099px) {
  .layout {
    grid-template-columns: minmax(280px, 34%) minmax(0, 1fr);
    gap: 16px;
  }

  .form-card,
  .panel,
  .result-stack {
    padding: 16px;
  }
}

@media (max-width: 759px) {
  :root {
    --page: min(1320px, calc(100% - 24px));
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .page {
    padding: 16px 0 calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .ajuda-texto,
  .ajuda-texto.aberta {
    position: static;
    width: auto;
    margin-top: 4px;
    z-index: 1;
  }

  .actions {
    position: sticky;
    bottom: 0;
    z-index: 8;
    background: var(--card);
    border-top: 1px solid var(--line);
    margin: 8px -16px -16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 18px rgba(0, 45, 98, 0.08);
  }

  .rank-card {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .rank-valor {
    grid-column: 2;
    text-align: left;
  }

  .chart-box {
    min-height: 200px;
  }

  .tabela-resumo .col-cenario {
    min-width: 8.5rem;
  }
}

@media (max-width: 559px) {
  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
