:root {
  color-scheme: light dark;
  --fundo: #f6f6f8;
  --superficie: #ffffff;
  --campo: #ffffff;
  --texto: #1b1b20;
  --texto-2: #54555e;
  --borda: #dcdce3;
  --borda-forte: #8a8b96;
  --linha: #ececf1;
  --suave-bg: #f0f0f4;
  --acento: #2950b8;
  --acento-hover: #2346a3;
  --acento-sobre: #ffffff;
  --acento-suave: #e6ecfb;
  --hoje: #f2f5fd;
  --foco: #2950b8;
  --perigo: #b42318;
  --verde-bg: #e3f4e8; --verde-bd: #2f8a55; --verde-tx: #12452a;
  --roxo-bg: #efe8fc; --roxo-bd: #7a4fd0; --roxo-tx: #43228a;
  --ambar-bg: #fff3d6; --ambar-bd: #b7791f; --ambar-tx: #5f3b00;
  --verm-bg: #fdeaea; --verm-bd: #c53b3b; --verm-tx: #7a1d1d;
  --cinza-bg: #efeff2; --cinza-bd: #8b8c96; --cinza-tx: #43444c;
  --hora: 3.5rem;
  --raio: 10px;
  --suave: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --fundo: #121216;
    --superficie: #1b1b21;
    --campo: #15151a;
    --texto: #ececf1;
    --texto-2: #a6a7b3;
    --borda: #2f2f38;
    --borda-forte: #6b6c78;
    --linha: #24242c;
    --suave-bg: #24242c;
    --acento: #8fb0ff;
    --acento-hover: #a9c2ff;
    --acento-sobre: #0d1630;
    --acento-suave: #1e2a4a;
    --hoje: #181d2b;
    --foco: #8fb0ff;
    --perigo: #ff8a80;
    --verde-bg: #10301f; --verde-bd: #4cc38a; --verde-tx: #bff2d6;
    --roxo-bg: #251a3f; --roxo-bd: #a98bf0; --roxo-tx: #e0d4ff;
    --ambar-bg: #33270b; --ambar-bd: #e3a83c; --ambar-tx: #ffe3a6;
    --verm-bg: #3a1717; --verm-bd: #f07171; --verm-tx: #ffd2d2;
    --cinza-bg: #23232a; --cinza-bd: #6c6c78; --cinza-tx: #cfd0d8;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fundo);
  color: var(--texto);
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.25; font-weight: 650; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 650; }
h3 { font-size: .875rem; font-weight: 600; color: var(--texto-2); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; }
h1:focus, main:focus { outline: none; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.pular { position: absolute; left: 1rem; top: -4rem; z-index: 20; padding: .75rem 1rem; border-radius: var(--raio); background: var(--acento); color: var(--acento-sobre); }
.pular:focus { top: 1rem; }

/* Botões */
button {
  font: inherit;
  color: inherit;
  min-height: 44px;
  padding: .5rem 1rem;
  border: 1px solid var(--borda-forte);
  border-radius: var(--raio);
  background: var(--superficie);
  cursor: pointer;
  transition: background-color 150ms var(--suave), border-color 150ms var(--suave), box-shadow 150ms var(--suave);
}
button:hover { background: var(--suave-bg); }
button:disabled { opacity: .6; cursor: default; }
.primario { background: var(--acento); border-color: var(--acento); color: var(--acento-sobre); font-weight: 600; }
.primario:hover { background: var(--acento-hover); border-color: var(--acento-hover); }
.fantasma { background: transparent; border-color: transparent; }
.perigo { color: var(--perigo); }
.fechar { width: 44px; padding: 0; background: transparent; border-color: transparent; font-size: 1.5rem; line-height: 1; }

/* Topo */
.topo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1.5rem;
  padding: .75rem 1.5rem;
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
}
.marca { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; color: var(--texto); text-decoration: none; }
.menu { display: flex; gap: .25rem; flex: 1; }
.menu a {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  padding: 0 .75rem;
  border-radius: 8px;
  color: var(--texto-2);
  font-weight: 500;
  text-decoration: none;
}
.menu a:hover { color: var(--texto); background: var(--suave-bg); }
.menu a[aria-current="page"] { color: var(--texto); background: var(--acento-suave); }
.selo { min-width: 1.5rem; padding: 0 .4rem; border-radius: 999px; background: var(--acento); color: var(--acento-sobre); font-size: .75rem; font-weight: 700; line-height: 1.5rem; text-align: center; }
.conta { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-left: auto; }
#nome-usuario { color: var(--texto-2); font-size: .9375rem; }

main { max-width: 80rem; margin: 0 auto; padding: 1.5rem; }
section > h1 { margin-bottom: 1rem; }
section > .sub { margin: -.5rem 0 1rem; }
.sub { color: var(--texto-2); font-size: .9375rem; }
.vazio { color: var(--texto-2); padding: 2rem 0; }
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }

/* Semana */
.barra { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.nav-semana { display: flex; gap: .5rem; }
.seta { width: 44px; padding: 0; font-size: 1.375rem; line-height: 1; }
.legenda { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; color: var(--texto-2); font-size: .875rem; }
.legenda li { display: flex; align-items: center; gap: .4rem; }
.amostra { width: 1rem; height: 1rem; border-radius: 4px; background: var(--bg); border: 2px solid var(--bd); }
#semana-corpo { view-transition-name: semana; }

.grade {
  display: grid;
  grid-template-columns: 3.5rem repeat(var(--cols), minmax(0, 1fr));
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: 12px;
  overflow: hidden;
}
.canto, .dia-cab { border-bottom: 1px solid var(--borda); }
.dia-cab { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: .35rem; padding: .6rem .25rem; border-left: 1px solid var(--linha); color: var(--texto-2); font-size: .875rem; }
.dia-cab strong { color: var(--texto); font-size: 1rem; }
.dia-cab.hoje strong { color: var(--acento); }
.dia-cab.hoje, .dia.hoje { background-color: var(--hoje); }
.hoje-tag { padding: .1rem .5rem; border-radius: 999px; background: var(--acento); color: var(--acento-sobre); font-size: .75rem; font-weight: 700; }
.horas span { display: block; height: var(--hora); padding: .15rem .5rem 0 0; text-align: right; font-size: .75rem; color: var(--texto-2); font-variant-numeric: tabular-nums; }
.dia {
  position: relative;
  height: calc(var(--horas) * var(--hora));
  border-left: 1px solid var(--linha);
  background-image: repeating-linear-gradient(to bottom, var(--linha) 0 1px, transparent 1px var(--hora));
}

.ev {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .1rem;
  min-height: 0;
  padding: .25rem .45rem;
  overflow: hidden;
  text-align: left;
  font-size: .8125rem;
  line-height: 1.35;
  border: 1px solid var(--bd);
  border-radius: 6px;
  background: var(--bg);
  color: var(--tx);
}
/* flex: none: cada linha mantém a altura e o botão corta por baixo (senão todas encolhem juntas). */
.ev > span { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .i { vertical-align: -.15em; margin-right: .25rem; }
.ev-titulo { font-weight: 650; }
.ev:hover { background: var(--bg); box-shadow: 0 2px 10px rgb(0 0 0 / .14); z-index: 1; }
.ev:focus-visible { z-index: 2; }

.lista-dias { display: none; }
.dia-lista { margin-bottom: 1.5rem; }
.dia-lista h2 { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; font-size: 1rem; }
.dia-lista ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.dia-lista .vazio { padding: 0; font-size: .875rem; }
.lista-dias .ev { position: static; width: 100%; min-height: 44px; padding: .6rem .8rem; font-size: .9375rem; border-radius: var(--raio); }
.lista-dias .ev > span { white-space: normal; }

/* Cartões (decisões, choques, minhas) */
.cartao {
  display: grid;
  justify-items: start;
  gap: .15rem;
  width: 100%;
  padding: .75rem 1rem;
  text-align: left;
  border: 1px solid var(--bd);
  border-radius: var(--raio);
  background: var(--bg);
  color: var(--tx);
  transition: background-color 250ms var(--suave), border-color 250ms var(--suave), color 250ms var(--suave), box-shadow 250ms var(--suave);
}
button.cartao:hover { background: var(--bg); box-shadow: 0 2px 10px rgb(0 0 0 / .1); }
.quando { font-size: .875rem; }
.pista { display: inline-flex; align-items: center; gap: .35rem; font-size: .8125rem; font-weight: 600; }
.descricao { white-space: pre-wrap; }
.selo-status { display: inline-flex; padding: .2rem .7rem; border: 1px solid var(--bd); border-radius: 999px; background: var(--bg); color: var(--tx); }

/* Status: cor + borda + ícone/texto (cor nunca sozinha) */
.aprovada { --bg: var(--verde-bg); --bd: var(--verde-bd); --tx: var(--verde-tx); }
.fixa { --bg: var(--roxo-bg); --bd: var(--roxo-bd); --tx: var(--roxo-tx); }
.pendente { --bg: var(--ambar-bg); --bd: var(--ambar-bd); --tx: var(--ambar-tx); }
.recusada { --bg: var(--verm-bg); --bd: var(--verm-bd); --tx: var(--verm-tx); }
.cancelada { --bg: var(--cinza-bg); --bd: var(--cinza-bd); --tx: var(--cinza-tx); }
.ev.pendente, .cartao.pendente, .amostra.pendente, .selo-status.pendente { border-style: dashed; }

/* Decisões */
.choque { display: grid; gap: 1rem; padding: 1.25rem; background: var(--superficie); border: 1px solid var(--borda); border-radius: 14px; }
.lados { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 1rem; }
.lado { display: grid; gap: .6rem; justify-items: start; }
.vs { align-self: center; color: var(--texto-2); font-size: .875rem; }
.vence .cartao { box-shadow: 0 0 0 3px var(--bd); }

/* Pessoas */
.pessoa { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1rem; padding: .75rem 1rem; background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); }
.pessoa > div { display: grid; flex: 1; min-width: 12rem; }
.papel { padding: .1rem .6rem; border-radius: 999px; background: var(--suave-bg); color: var(--texto-2); font-size: .8125rem; font-weight: 600; }

/* Diálogos e formulários */
dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--borda);
  border-radius: 16px;
  background: var(--superficie);
  color: var(--texto);
  box-shadow: 0 20px 50px rgb(0 0 0 / .25);
}
dialog[open] { animation: abre 200ms var(--suave); }
dialog::backdrop { background: rgb(10 10 20 / .45); }
dialog[open]::backdrop { animation: esmaece 200ms var(--suave); }
.dlg-topo { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1rem 0 1.5rem; }
.corpo { display: grid; gap: 1rem; padding: 1rem 1.5rem 1.5rem; }
.acoes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; padding: 0 1.5rem 1.5rem; }
.pergunta { flex-basis: 100%; font-weight: 600; }
.abas { display: flex; gap: .25rem; }
.abas [role="tab"] { background: transparent; border-color: transparent; color: var(--texto-2); font-weight: 600; }
.abas [aria-selected="true"] { background: var(--acento-suave); color: var(--texto); }

label { display: grid; gap: .3rem; font-size: .9375rem; font-weight: 500; }
input, textarea {
  width: 100%;
  min-height: 44px;
  padding: .55rem .75rem;
  font: inherit;
  font-weight: 400;
  color: inherit;
  border: 1px solid var(--borda-forte);
  border-radius: 8px;
  background: var(--campo);
}
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: .6rem; min-height: 44px; }
.check input { width: 1.25rem; height: 1.25rem; min-height: 0; accent-color: var(--acento); }
.dica { color: var(--texto-2); font-size: .8125rem; font-weight: 400; }
.erro { color: var(--perigo); font-weight: 500; }
.linha3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1rem; }
#bloco-fixa { display: grid; gap: .5rem; }
.sugestoes { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 1.5rem; z-index: 10; display: grid; justify-items: center; gap: .5rem; width: max-content; max-width: calc(100vw - 2rem); transform: translateX(-50%); pointer-events: none; }
.toast { padding: .7rem 1.1rem; border-radius: var(--raio); background: var(--texto); color: var(--fundo); box-shadow: 0 8px 24px rgb(0 0 0 / .2); animation: sobe 200ms var(--suave); }

/* Toque (tablet com grade): 30 min = 44px */
@media (pointer: coarse) { :root { --hora: 5.5rem; } }

/* Celular: semana vira lista por dia */
@media (max-width: 699.98px) {
  .topo { padding: .5rem 1rem; gap: .25rem 1rem; }
  .menu { order: 3; flex: 1 1 100%; overflow-x: auto; scrollbar-width: thin; }
  .menu a { flex: none; }
  main { padding: 1rem; }
  .grade { display: none; }
  .lista-dias { display: block; }
  .lados { grid-template-columns: 1fr; }
  .vs { justify-self: center; }
}

/* Animações */
@keyframes abre { from { opacity: 0; transform: scale(.96); } }
@keyframes esmaece { from { opacity: 0; } }
@keyframes sobe { from { opacity: 0; transform: translateY(8px); } }
@keyframes pousa { from { opacity: 0; transform: translateY(-12px) scale(.96); } }
@keyframes sai { to { opacity: 0; transform: translateX(24px) scale(.96); } }
.pousa { animation: pousa 300ms var(--suave) both; }
.sai { animation: sai 250ms var(--suave) forwards; }

@keyframes vt-sai-esq { to { opacity: 0; transform: translateX(-40px); } }
@keyframes vt-sai-dir { to { opacity: 0; transform: translateX(40px); } }
@keyframes vt-entra-dir { from { opacity: 0; transform: translateX(40px); } }
@keyframes vt-entra-esq { from { opacity: 0; transform: translateX(-40px); } }
::view-transition-old(semana), ::view-transition-new(semana) { animation-duration: 250ms; animation-timing-function: var(--suave); animation-fill-mode: both; }
html[data-dir="next"]::view-transition-old(semana) { animation-name: vt-sai-esq; }
html[data-dir="next"]::view-transition-new(semana) { animation-name: vt-entra-dir; }
html[data-dir="prev"]::view-transition-old(semana) { animation-name: vt-sai-dir; }
html[data-dir="prev"]::view-transition-new(semana) { animation-name: vt-entra-esq; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  ::backdrop { animation: none !important; } /* * não pega ::backdrop */
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
