:root {
  --bg: #EDEFE9;
  --surface: #FFFFFF;
  --ink: #17231F;
  --muted: #6B7570;
  --line: #D5DAD3;
  --primary: #1E6B57;
  --primary-ink: #FFFFFF;
  --you: #22C55E;
  --coletivo-a: #E6F2EB;
  --coletivo-b: #B5D9C6;
  --coletivo-ink: #3F7D64;
  --danger: #A8321F;
  --radius: 14px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ---- cabeçalho ---- */
.topo {
  display: flex;
  margin-bottom: 20px;
}
.topo h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.topo .sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.3;
}

/* ---- escolha do apto (na página e dentro da folha) ---- */
.aptos { margin-bottom: 20px; }
.aptos h2 { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.grade-aptos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.btn-apto {
  height: 60px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  transition: transform 120ms ease, background 120ms ease;
}
.btn-apto:active { transform: scale(0.96); }
.btn-apto.atual { background: var(--you); border-color: transparent; }

/* ---- calendário ---- */
.cal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px 12px;
}
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-nav h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}
.cal-nav button {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink);
}
.cal-nav button:active { background: #F0F2EE; }
.cal-nav button:disabled { opacity: 0.3; cursor: default; }

.semana, .dias {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.semana span {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 4px 0 6px;
}
.semana span:last-child { color: var(--coletivo-ink); }

.dia {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 17px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  background: #F6F8F4;
  transition: transform 100ms ease;
}
.dia:active:not(:disabled) { transform: scale(0.94); }
.dia.vazio { background: transparent; }
.dia.passado { color: #B4BBB6; background: #FAFBF9; cursor: default; }
.dia.hoje::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--primary);
}
.dia.hoje.reservado::after, .dia.hoje.seu::after { display: none; }
.dia.coletivo {
  color: var(--coletivo-ink);
  background: repeating-linear-gradient(
    135deg,
    var(--coletivo-a) 0 5px,
    var(--coletivo-b) 5px 6px
  );
}
.dia.reservado {
  background: var(--ink);
  color: #FFFFFF;
}
.dia.seu {
  background: var(--you);
  color: var(--ink);
}
.dia .tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1;
  opacity: 0.85;
}

.legenda {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 12px 4px 0;
  font-size: 13px;
  color: var(--muted);
}
.legenda span { display: inline-flex; align-items: center; gap: 6px; }
.legenda i {
  width: 14px; height: 14px; border-radius: 4px; display: inline-block;
  background: #F6F8F4; border: 1px solid var(--line);
}
.legenda i.seu { background: var(--you); border-color: transparent; }
.legenda i.reservado { background: var(--ink); border-color: transparent; }
.legenda i.coletivo {
  border-color: transparent;
  background: repeating-linear-gradient(135deg, var(--coletivo-a) 0 4px, var(--coletivo-b) 4px 5px);
}

/* ---- lista de reservas do apto ---- */
.minhas { margin-top: 24px; }
.minhas h2 { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.minhas p.vazia { color: var(--muted); margin: 0; font-size: 15px; }
.minhas ul { list-style: none; margin: 0; padding: 0; }
.minhas li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.minhas li:last-child { border-bottom: 0; }
.minhas .quando { font-weight: 500; display: flex; flex-direction: column; gap: 2px; }
.minhas .quando small { font-size: 13px; font-weight: 400; color: var(--muted); }
.link-cancelar { color: var(--danger); font-weight: 500; font-size: 15px; padding: 6px 0; }

/* ---- histórico do apto ---- */
.historico { margin-top: 24px; }
.historico h2 { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.historico ul { list-style: none; margin: 0; padding: 0; }
.historico li { padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.historico li:last-child { border-bottom: 0; }
.historico .quando { display: flex; flex-direction: column; gap: 2px; font-weight: 500; }
.historico .quando small { font-size: 13px; font-weight: 400; }
.quando.cancelada > span { text-decoration: line-through; }

/* ---- folha de confirmação ---- */
.veu {
  position: fixed; inset: 0;
  background: rgba(23, 35, 31, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
  animation: aparecer 160ms ease;
}
.folha {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  animation: subir 220ms cubic-bezier(.2,.8,.2,1);
}
.folha .alca {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 0 auto 14px;
}
.folha h3 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.folha p { margin: 6px 0 18px; color: var(--muted); font-size: 16px; }
.folha p.erro { color: var(--danger); }
.acoes { display: flex; flex-direction: column; gap: 10px; }
.btn {
  height: 52px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  display: grid; place-items: center;
  transition: transform 100ms ease, opacity 100ms ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primario { background: var(--primary); color: var(--primary-ink); }
.btn-perigo { background: #FBEBE7; color: var(--danger); }
.btn-neutro { background: #F0F2EE; color: var(--ink); }

@keyframes subir { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .veu, .folha, .dia, .btn, .btn-apto { animation: none; transition: none; }
}
