/* Tema: segue o sistema (Automático) ou o que o usuário escolheu (data-theme="light|dark"). */
:root { --bg: #f4f6f8; --card: #fff; --ink: #14202b; --muted: #5d6b78; --line: #dbe2e8; --brand: #0b5cad; --brand-ink: #fff; --ok: #1a7f4b; --warn: #b26a00; --bad: #b3261e; --side-bg: #fff; --radius: 10px; --side-w: 248px; color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) { --bg: #0f1419; --card: #171e26; --ink: #e8eef3; --muted: #93a1ae; --line: #2a3541; --brand: #4a9eed; --brand-ink: #06121e; --ok: #4cc38a; --warn: #e0a030; --bad: #ff8a80; --side-bg: #121920; color-scheme: dark; }
}
:root[data-theme=dark] { --bg: #0f1419; --card: #171e26; --ink: #e8eef3; --muted: #93a1ae; --line: #2a3541; --brand: #4a9eed; --brand-ink: #06121e; --ok: #4cc38a; --warn: #e0a030; --bad: #ff8a80; --side-bg: #121920; color-scheme: dark; }
:root[data-theme=light] { color-scheme: light; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .9rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.login { max-width: 400px; margin: 10vh auto 0; padding: 0 16px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]), select {
  width: 100%; padding: 11px 12px; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button { font: inherit; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); }
button.small { min-height: 36px; padding: 0 10px; font-size: .88rem; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 200px; }
.error { color: var(--bad); margin: 10px 0 0; min-height: 1.2em; }
.notice { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid var(--warn); border-radius: 8px; padding: 12px; margin-bottom: 14px; }
.notice code { font-size: 1.05rem; user-select: all; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: .88rem; min-height: 36px; }
.chip input { margin: 0; }
.scale-row { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.scale-row .row { justify-content: space-between; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.bad { color: var(--bad); border-color: var(--bad); }
.badge.soon { color: var(--warn); border-color: var(--warn); }
details.card > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 8px; align-items: center; min-height: 44px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.scroll { overflow-x: auto; }
.mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin-top: 8px; }
.mods > div { display: flex; justify-content: space-between; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.mods select { width: auto; min-height: 36px; }

/* ---------- estrutura com menu lateral ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.side {
  width: var(--side-w); flex: 0 0 var(--side-w); background: var(--side-bg); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
  padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
}
.brand { font-weight: 700; font-size: 1.05rem; padding: 4px 10px 14px; line-height: 1.2; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 0 10px; min-height: 44px; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: .95rem;
}
.nav a:hover { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.nav a[aria-current=page] { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 4px; }
.nav-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px 2px; }
.spacer { flex: 1; min-height: 16px; }
.user { border-top: 1px solid var(--line); padding: 12px 6px 0; }
.user .who { font-size: .85rem; word-break: break-all; }
.user button { width: 100%; margin-top: 8px; }
.main { flex: 1; min-width: 0; }
.content { max-width: 1040px; margin: 0 auto; padding: 20px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.topbar { display: none; }
.scrim { display: none; }
.subnav { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0; padding-bottom: 2px; }
.subnav a { white-space: nowrap; padding: 0 14px; min-height: 40px; display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); text-decoration: none; background: var(--card); }
.subnav a[aria-current=page] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }

@media (max-width: 820px) {
  .shell { display: block; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--side-bg);
    border-bottom: 1px solid var(--line); padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top));
  }
  .topbar .title { font-weight: 700; }
  .side {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: min(84vw, 300px); height: auto;
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(0,0,0,.35);
  }
  body.nav-open .side { transform: none; }
  body.nav-open { overflow: hidden; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); }
  .content { padding: 14px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

/* ---------- componentes das fases 2 e 3 ---------- */
a.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font: inherit; cursor: pointer; }
a.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
a.btn.small { min-height: 36px; padding: 0 10px; font-size: .88rem; }
textarea { width: 100%; padding: 11px 12px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
textarea:focus-visible, a.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.req { color: var(--bad); }
.pad { padding: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.filters { margin-top: 4px; }
.list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
a.item.link { color: inherit; text-decoration: none; }
a.item.link:hover { border-color: var(--brand); }
.item .row { margin-top: 4px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; margin: 6px 0; }
.facts dt { font-size: .75rem; color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.pager { justify-content: center; margin: 10px 0; }
.seg { min-height: 40px; }
.seg[aria-pressed=true] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
nav.subnav > button.seg { white-space: nowrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.toolbar input[type=search] { flex: 1 1 240px; }
.seg-group { display: flex; gap: 6px; }
.only-mobile { display: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.mapwrap { display: grid; grid-template-columns: 380px 1fr; gap: 12px; height: calc(100vh - 250px); min-height: 420px; }
.mapwrap #list { overflow-y: auto; margin: 0; padding-right: 4px; }
#map { border: 1px solid var(--line); border-radius: var(--radius); min-height: 320px; z-index: 0; }
.mini { height: 200px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; z-index: 0; }
.mini.tall { height: 280px; margin: 10px 0 4px; }
.pin { background: none; border: 0; }
.count { margin-left: auto; min-width: 22px; padding: 1px 7px; text-align: center; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--bad); color: #fff; }
.count.warn { background: var(--warn); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-bottom: 14px; }
a.card.stat { display: flex; gap: 14px; align-items: center; text-decoration: none; color: var(--ink); margin: 0; border-left: 5px solid var(--ok); }
a.card.stat.warn { border-left-color: var(--warn); }
a.card.stat.bad { border-left-color: var(--bad); }
a.card.stat .n { font-size: 2rem; font-weight: 700; line-height: 1; min-width: 2ch; text-align: center; }
a.modlink { text-decoration: none; color: inherit; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; min-height: 40px; }
.cal { margin: 6px 0; padding: 8px 10px; border-radius: 8px; border: 1px dashed var(--line); }
.cal.ok { border-style: solid; border-color: var(--ok); }
.cal.warn { border-style: solid; border-color: var(--warn); }
.cal.bad { border-style: solid; border-color: var(--bad); }
button.x { min-height: 24px; width: 24px; padding: 0; border-radius: 50%; line-height: 1; }
.offline { background: var(--warn); color: #fff; text-align: center; padding: 6px 12px; font-size: .9rem; }
#toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 12px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); box-shadow: 0 4px 20px rgba(0,0,0,.35); }
.toast.bad { background: var(--bad); color: #fff; }
.actions { margin: 12px 0; }
.leaflet-container { font: inherit; }

@media (max-width: 820px) {
  .only-mobile { display: flex; }
  .mapwrap { display: block; height: auto; }
  .mapwrap #list, .mapwrap #map { display: none; }
  .mapwrap[data-view=list] #list { display: flex; }
  .mapwrap[data-view=map] #map { display: block; height: 62vh; }
  .grid { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 440px) { .grid { grid-template-columns: 1fr; } }

/* ---------- histórico ---------- */
.hist { margin-top: 8px; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.hist[hidden] { display: none; }
ul.events { margin: 6px 0 0; padding-left: 18px; }
ul.events li { margin: 3px 0; }

/* ---------- seletor de tema ---------- */
.theme-seg { display: flex; gap: 4px; margin-top: 10px; }
.theme-seg button { flex: 1; min-height: 34px; padding: 0 6px; font-size: .8rem; }
.theme-seg button[aria-pressed=true] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.login-theme { position: fixed; top: 12px; right: 12px; width: 220px; }
.item.mine { border-left: 4px solid var(--ok); }

.empresa { margin: 6px 0; padding: 8px 10px; border-radius: 8px; border: 1px dashed var(--line); font-size: .9rem; }

/* ---------- Início personalizável ---------- */
.home { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; align-items: stretch; }
.home > .card { margin: 0; }
.home > .wide { grid-column: 1 / -1; }
.wlist { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wlist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
