/* KOMVET Despesas — mobile first, mesmos tokens visuais do Gestor de Eventos */
:root {
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --ink: #1b1f24;
  --muted: #5b636e;
  --line: #e1e4e8;
  --brand: #d9531e;
  --brand-ink: #ffffff;
  --brand-soft: #fbe9e1;
  --danger: #b91c1c;
  --pagar: #b45309;
  --pagar-bg: #fef3c7;
  --focus: #2563eb;
  --sombra: 0 6px 20px rgb(27 31 36 / .18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417;
    --surface: #1b1e23;
    --surface-2: #22262c;
    --ink: #eceef1;
    --muted: #a0a7b1;
    --line: #2c3138;
    --brand: #f07a45;
    --brand-ink: #1b1f24;
    --brand-soft: #3a2419;
    --danger: #fca5a5;
    --pagar: #fbbf24;
    --pagar-bg: #3a2d10;
    --focus: #7aa7ff;
    --sombra: 0 6px 20px rgb(0 0 0 / .5);
  }
}

* { box-sizing: border-box; }
html, body { overflow-x: clip; } /* nunca rolagem lateral */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
h1, h2, p { margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h2:focus { outline: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.erro { color: var(--danger); font-weight: 500; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }

/* Campos */
label { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; font-size: 14px; font-weight: 600; flex: 1; min-width: 0; }
input, select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; color: inherit; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 48px; width: 100%; min-width: 0; max-width: 100%;
}
/* Campo de data tem largura mínima própria no Chrome/Safari: deixa encolher. */
input[type="date"] { -webkit-appearance: none; appearance: none; display: block; padding-inline: 10px 6px; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
textarea { resize: vertical; min-height: 64px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.linha { display: flex; gap: 10px; min-width: 0; }
.linha > * { min-width: 0; }

/* Botões */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px; min-height: 44px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.perigo { color: var(--danger); }
.btn.grande { min-height: 52px; font-size: 17px; width: 100%; }
.btn.pequeno { min-height: 40px; font-size: 14px; flex: 1; }
.btn.icone { width: 44px; padding: 0; font-size: 22px; }
.btn.claro { background: rgb(255 255 255 / .18); border-color: transparent; color: inherit; }
.btn:disabled { opacity: .6; cursor: wait; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand img { width: 28px; height: 28px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); display: grid; gap: 16px; padding: 24px; }

/* Layout principal */
.topo {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 12px 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
}
.topo .brand { margin-right: auto; }
.usuario { font-size: 14px; color: var(--muted); max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conteudo { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(110px + var(--safe-b)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.resumo {
  background: var(--brand); color: var(--brand-ink); border-radius: 18px; padding: 12px 12px 18px;
  text-align: center; display: grid; gap: 2px; box-shadow: var(--sombra);
}
.mes { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mes strong { font-size: 16px; }
.resumo-total { font-size: 36px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.resumo-qtd { font-size: 14px; opacity: .85; }

.filtros summary {
  list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; gap: 8px; align-items: center;
}
.filtros summary::-webkit-details-marker { display: none; }
.filtros summary::after { content: "▾"; margin-left: auto; color: var(--muted); }
.filtros[open] summary::after { content: "▴"; }
.filtros summary .muted { font-weight: 400; font-size: 14px; }
.filtro { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 0 16px 16px; }

/* Lista agrupada por dia */
.lista { display: grid; gap: 6px; }
.dia { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin: 10px 4px 0; display: flex; }
.dia span:last-child { margin-left: auto; font-variant-numeric: tabular-nums; }
.item {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; width: 100%;
  padding: 12px; text-align: left; font: inherit; color: inherit; cursor: pointer; touch-action: manipulation;
}
.item:active { background: var(--surface-2); }
.item-icone { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); display: grid; place-items: center; font-size: 22px; }
.item-info { display: grid; min-width: 0; }
.item-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-info span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-valor { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.vazio { text-align: center; padding: 40px 16px; color: var(--muted); display: grid; gap: 6px; }
.vazio strong { font-size: 40px; }

/* Botão flutuante */
.fab {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b));
  width: min(420px, calc(100% - 32px)); min-height: 58px; border: 0; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); font: inherit; font-size: 18px; font-weight: 700;
  box-shadow: var(--sombra); cursor: pointer; touch-action: manipulation;
}
.fab:active { transform: translateX(-50%) scale(.98); }

/* Folha (bottom sheet no celular, modal no desktop) */
.folha {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 100%; max-height: 88dvh;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
}
.folha::backdrop { background: rgb(0 0 0 / .45); }
.folha[open] { animation: subir .22s ease-out; }
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
/* Só o corpo rola (na vertical); a folha nunca rola para os lados. */
.folha { overflow: hidden; }
.folha > form { display: flex; flex-direction: column; max-height: 88dvh; }
.folha-corpo { overflow-x: hidden; }
.folha-topo { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 4px 16px; }
.folha-corpo { overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.folha-rodape {
  display: flex; gap: 10px; padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--surface);
}
.folha-rodape .grande { flex: 1; }

.foto { display: grid; gap: 8px; }
.foto-area {
  border: 2px dashed var(--line); border-radius: 14px; background: var(--surface-2); color: var(--muted);
  min-height: 150px; padding: 0; overflow: hidden; display: grid; place-items: center; cursor: pointer; font: inherit; font-weight: 600;
}
.foto-area img { width: 100%; max-height: 240px; object-fit: contain; display: block; }
.foto-area img:not(.hidden) + .foto-vazia { display: none; }
.foto-vazia { font-size: 15px; line-height: 1.6; }
.foto-vazia::first-line { font-size: 34px; }
.ia-status { font-size: 14px; background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; }

.campo-reais { position: relative; display: block; }
.campo-reais span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; font-size: 20px; }
.campo-reais input { padding-left: 50px; font-size: 26px; font-weight: 700; min-height: 60px; font-variant-numeric: tabular-nums; }

.categorias { border: 0; padding: 0; margin: 0; min-width: 0; }
.categorias legend { font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.chip { display: block; position: relative; font-weight: 500; } /* prende o rádio escondido dentro do chip */
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px; padding: 6px 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 14px; text-align: center; cursor: pointer;
}
.chip span b { font-size: 22px; font-weight: 400; line-height: 1.1; }
.chip input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--ink); font-weight: 700; box-shadow: inset 0 0 0 1px var(--brand); }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); z-index: 20;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px);
  box-shadow: var(--sombra); font-size: 15px;
}
.toast.erro { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  .folha { margin: auto; width: min(520px, calc(100% - 32px)); border-radius: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .folha[open] { animation: none; }
}

/* Relatório: lista de eventos selecionáveis */
.eventos-lista { display: grid; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.evento-opcao {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; font-weight: 500;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer;
}
.evento-opcao input { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--brand); }
.evento-opcao span { display: grid; min-width: 0; }
.evento-opcao strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.evento-opcao small { color: var(--muted); }

/* Mesmo aviso do sistema de eventos (despesa sem comprovante) */
.aviso { display: grid; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--pagar-bg); color: var(--pagar); }
