/*
 * Superfícies: L0 = fundo da página, L1 = cartões, tabelas e barra superior (borda de 1px),
 * L3 = painéis e diálogos. Um só tom de destaque (azul) para ações, links e foco.
 * Espaços em múltiplos de 8px (4px nos detalhes). Tipos: 16px corpo, 14px secundário, 12px meta.
 */
:root {
  color-scheme: light;
  --accent: #0047cc;
  --accent-strong: #0033a0;
  --accent-soft: #e8eeff;
  --on-accent: #fff;
  --danger: #c8102e;
  --danger-strong: #a50d26;
  --text: #172033;
  --muted: #5b6577;
  --bg: #f4f6fa;
  --surface: #fff;
  --surface-2: #eef1f6;
  --line: rgb(23 32 51 / 0.1);
  --line-strong: rgb(23 32 51 / 0.22);
  --shadow-overlay: 0 8px 24px rgb(0 0 0 / 0.08);
  --scrim: rgb(10 20 50 / 0.4);
  --edge: none;

  --dur-fast: 150ms;
  --dur-base: 200ms;
  --ease-out: cubic-bezier(0.2, 0, 0, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  --vp-wide: 1280px;
  --hit: 44px;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --accent: #9dbbff;
    --accent-strong: #c3d5ff;
    --accent-soft: #1e2b4a;
    --on-accent: #0b1a3d;
    --danger: #ff8a8a;
    --danger-strong: #ffb0b0;
    --text: #e3e7ef;
    --muted: #a9b2c3;
    --bg: #0f1420;
    --surface: #171d2b;
    --surface-2: #222a3b;
    --line: rgb(227 231 239 / 0.1);
    --line-strong: rgb(227 231 239 / 0.24);
    --shadow-overlay: 0 8px 24px rgb(0 0 0 / 0.4);
    --scrim: rgb(0 0 0 / 0.55);
    --edge: inset 0 1px 0 rgb(255 255 255 / 0.05);
  }
}

* { box-sizing: border-box; }
html, body { width: 100%; }
body { margin: 0; font: 400 16px/1.5 system-ui, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.2; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
strong, b, th { font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small-text { font-size: 14px; }
.meta { font-size: 12px; color: var(--muted); }
.prose { max-width: 70ch; }
.error { color: var(--danger); }
.right { margin-left: auto; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { align-items: end; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- foco: sempre visível no teclado, nos dois temas ---- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- barra superior (L1, largura total) ---- */
header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 0 24px; min-height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--edge);
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
header.top .brand img { width: 32px; height: 32px; border-radius: var(--radius); }
header.top nav { display: flex; gap: 4px; flex: 1; }
header.top nav a {
  display: inline-flex; align-items: center; min-height: var(--hit); padding: 0 12px;
  color: var(--muted); text-decoration: none; white-space: nowrap; border-radius: var(--radius);
}
header.top nav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
header.top .account { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
header.top .menu-toggle { display: none; }

main { width: 100%; max-width: var(--vp-wide); margin: 0 auto; padding: 24px; display: grid; gap: 16px; }
.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.page-head > div { display: grid; gap: 4px; flex: 1; min-width: 0; }
.page-head h1:focus { outline: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--edge); }
.card.flush { padding: 0; overflow: hidden; }

/* ---- campos ---- */
.field { display: grid; gap: 4px; align-content: start; min-width: 0; }
.field > label, .field > .label { font-size: 14px; font-weight: 500; color: var(--text); }
.field .hint { font-size: 12px; color: var(--muted); }
.field .field-error { font-size: 14px; color: var(--danger); }
.field .field-error:empty { display: none; }
input, select, textarea {
  font: inherit; min-height: var(--hit); padding: 8px 12px; min-width: 0; width: 100%;
  color: inherit; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--accent); }
input[type="file"] { padding: 8px; }
[aria-invalid="true"] { border-color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--hit); cursor: pointer; }
.search { position: relative; }
.search input { padding-left: 40px; }
.search svg { position: absolute; left: 12px; bottom: 12px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }

/* ---- botões ---- */
button, .button {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--hit); padding: 0 16px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.danger { color: var(--danger); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
button.quiet { border-color: transparent; background: transparent; }
button.link { min-height: var(--hit); padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
button.icon { width: var(--hit); padding: 0; }
button.icon svg { width: 20px; height: 20px; }
button:disabled { color: var(--muted); cursor: default; background: var(--surface-2); border-color: var(--line); }
button[aria-busy="true"] { cursor: progress; }
@media (hover: hover) {
  button:not(:disabled):hover { border-color: var(--accent); }
  button.primary:not(:disabled):hover { background: var(--accent-strong); border-color: var(--accent-strong); }
  button.danger.solid:not(:disabled):hover { background: var(--danger-strong); border-color: var(--danger-strong); }
  button.quiet:not(:disabled):hover { background: var(--surface-2); border-color: transparent; }
  header.top nav a:hover { color: var(--text); }
  tbody tr.click:hover { background: var(--accent-soft); }
}
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.segmented button { border: 0; border-radius: 0; }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---- dica dos botões só de ícone (aparece com o mouse e com o foco do teclado) ---- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; z-index: 100;
  padding: 4px 8px; border-radius: 4px; background: var(--text); color: var(--bg);
  font-size: 12px; font-weight: 500; line-height: 1.4; white-space: nowrap; pointer-events: none;
  opacity: 0; transform: translateX(-50%); transition: opacity var(--dur-fast) var(--ease-in);
}
[data-tip]:focus-visible::after { opacity: 1; transition: opacity var(--dur-fast) var(--ease-out) 100ms; }
@media (hover: hover) { [data-tip]:hover::after { opacity: 1; transition: opacity var(--dur-fast) var(--ease-out) 300ms; } }
kbd { font: 500 12px/1 ui-monospace, monospace; padding: 2px 4px; border: 1px solid var(--line-strong); border-radius: 4px; }

/* ---- filtros ---- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.toolbar .search { flex: 1 1 280px; }
.filters-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; align-items: end; padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); }
.filters-panel[hidden] { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.chips:empty { display: none; }
.chip { min-height: 32px; padding: 0 8px 0 12px; border-radius: 16px; font-size: 14px; font-weight: 400; background: var(--accent-soft); border-color: transparent; color: var(--text); }
.chip svg { width: 16px; height: 16px; }

/* ---- menu suspenso (exportar, menu do celular) ---- */
.menu { position: relative; }
.menu [role="menu"] {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 100; min-width: 220px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 4px 12px rgb(0 0 0 / 0.06), var(--edge);
}
.menu [role="menu"][hidden] { display: none; }
.menu [role="menuitem"] { width: 100%; justify-content: flex-start; border: 0; font-weight: 400; }

/* ---- tabela: dentro do cartão (L1), com linhas finas ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; background: var(--surface-2); }
td { font-size: 16px; }
td.num { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
td .row { flex-wrap: nowrap; }
.table-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; border-top: 1px solid var(--line); }
.table-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
td.empty { padding: 48px 16px; text-align: center; }
.empty-state { display: grid; gap: 8px; justify-items: center; max-width: 60ch; margin: 0 auto; }
.empty-state .button, .empty-state button { margin-top: 8px; }

/* Esqueleto: mesma geometria da tabela; sem brilho animado. */
.skel { display: block; height: 16px; border-radius: 4px; background: var(--surface-2); }

/* ---- painel lateral (tarefa curta) e diálogo de confirmação ---- */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-overlay), var(--edge); padding: 0; }
dialog::backdrop { background: var(--scrim); }
dialog.sheet { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(560px, 100vw); border-width: 0 0 0 1px; }
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-in var(--dur-base) var(--ease-out); }
dialog.sheet.closing { animation: sheet-out var(--dur-fast) var(--ease-in) forwards; }
dialog.sheet > header { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 24px; border-bottom: 1px solid var(--line); }
dialog.sheet > header h2 { flex: 1; }
dialog.sheet > .body { flex: 1; overflow-y: auto; padding: 24px; display: grid; gap: 16px; align-content: start; }
dialog.confirm { width: min(480px, calc(100vw - 32px)); border-radius: var(--radius); padding: 24px; }
dialog.confirm[open] { animation: fade-in var(--dur-fast) var(--ease-out); }
dialog.confirm.closing { animation: fade-out var(--dur-fast) var(--ease-in) forwards; }
dialog[open]::backdrop { animation: fade-in var(--dur-base) var(--ease-out); }
dialog.closing::backdrop { animation: fade-out var(--dur-fast) var(--ease-in) forwards; }
dialog.confirm h2 { margin-bottom: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 24px; }
dialog.sheet .actions { margin-top: 8px; }

@keyframes sheet-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes sheet-out { from { transform: none; } to { transform: translateX(100%); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }

dl { display: grid; grid-template-columns: minmax(96px, max-content) minmax(0, 1fr); gap: 8px 16px; margin: 0; }
dt { color: var(--muted); font-size: 14px; }
dd { margin: 0; overflow-wrap: anywhere; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photos a { display: block; width: 152px; height: 152px; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.notice { padding: 12px 16px; border-radius: var(--radius); background: var(--surface-2); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

#map { height: calc(100dvh - 320px); min-height: 400px; }
.report li { margin-bottom: 4px; }
.status-closed { color: var(--muted); }

/* ---- editor do formulário ---- */
.field-row { display: grid; grid-template-columns: 2fr 1.3fr auto 2fr auto; gap: 16px; align-items: end; padding: 16px 0; border-bottom: 1px solid var(--line); }
.field-row:first-child { padding-top: 0; }
.field-row .options[hidden] { visibility: hidden; display: grid; }

/* ---- celular (narrow) ---- */
@media (max-width: 767.98px) {
  header.top { padding: 0 8px 0 16px; flex-wrap: wrap; }
  header.top .menu-toggle { display: inline-flex; margin-left: auto; }
  header.top nav, header.top .account { display: none; }
  header.top.open nav { display: grid; flex-basis: 100%; padding-bottom: 8px; }
  header.top.open .account { display: flex; flex-basis: 100%; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
  header.top nav a[aria-current="page"] { box-shadow: inset 2px 0 0 var(--accent); }
  main { padding: 16px; }
  th, td { padding: 8px 12px; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .field-row .options[hidden] { display: none; }
  dl { grid-template-columns: minmax(0, 1fr); gap: 0 16px; }
  dd { margin-bottom: 8px; }
  dialog.sheet > .body { padding: 16px; }
}

/* ---- movimento reduzido: sem deslizar, sem atraso ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::backdrop { animation: none !important; transition: none !important; }
}

/* Classes usadas pelo app.js atual que o redesenho de 14/10 não cobre. */
.login { width: min(400px, calc(100vw - 32px)); margin: 12vh auto 0; display: grid; gap: 16px; box-sizing: border-box; }
.login * { box-sizing: border-box; max-width: 100%; }
.login img { width: 72px; height: 72px; border-radius: var(--radius); }
.login label { display: grid; gap: 4px; }
.login input { width: 100%; }
nav a.on { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }
.who { color: var(--muted, inherit); white-space: nowrap; }
button.small { padding: 4px 12px; font-size: 0.875rem; }
dialog#dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
header.top > img { width: 32px; height: 32px; border-radius: var(--radius); flex: none; }
header.top > strong { white-space: nowrap; }
header.top nav { overflow-x: auto; }
