:root {
  --navy: #1d3061;
  --navy-2: #2a4285;
  --blue: #0a74c4;
  --green: #79bc00;
  --green-d: #5a8f00;
  --night: #3b3f8f;
  --bg: #f3f5f9;
  --card: #ffffff;
  --card-2: #f7f9fc;
  --ink: #16213d;
  --muted: #5c6782;
  --line: #e2e7f0;
  --title: #1d3061;
  --sel-bg: #1d3061;
  --sel-ink: #ffffff;
  --sel-count: #b8e86a;
  --rnum-bg: #eef2fa;
  --dia-bg: #fff4d6; --dia-ink: #8a5a00;
  --noite-bg: #e6e8fb; --noite-ink: #3b3f8f;
  --freq-bg: #eaf6d6; --freq-ink: #5a8f00;
  --topbar: rgba(255, 255, 255, .94);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(22, 33, 61, .06), 0 4px 14px rgba(22, 33, 61, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="escuro"] {
  --bg: #10141d; --card: #1a2030; --card-2: #212839; --ink: #e7eaf2; --muted: #9ba5bd; --line: #2b3346;
  --title: #c9d5f5; --sel-bg: #c9d5f5; --sel-ink: #10141d; --sel-count: #4f7a00; --rnum-bg: #252d42;
  --dia-bg: #3a2f14; --dia-ink: #f0c869; --noite-bg: #262a4d; --noite-ink: #b4b8f5; --freq-bg: #24341a; --freq-ink: #a6d65a;
  --topbar: rgba(22, 27, 39, .94); --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="claro"]) {
    --bg: #10141d; --card: #1a2030; --card-2: #212839; --ink: #e7eaf2; --muted: #9ba5bd; --line: #2b3346;
    --title: #c9d5f5; --sel-bg: #c9d5f5; --sel-ink: #10141d; --sel-count: #4f7a00; --rnum-bg: #252d42;
    --dia-bg: #3a2f14; --dia-ink: #f0c869; --noite-bg: #262a4d; --noite-ink: #b4b8f5; --freq-bg: #24341a; --freq-ink: #a6d65a;
    --topbar: rgba(22, 27, 39, .94); --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}

* { 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, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- Topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
  max-width: 960px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; background: #fff; border-radius: 10px; padding: 4px 8px; }
.logo { height: 30px; width: auto; }
.brand-sep { width: 1px; height: 24px; background: #e2e7f0; }
.actions { display: flex; align-items: center; gap: 8px; }
.btn-install {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 8px 14px;
  background: var(--navy); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn-install svg { width: 16px; height: 16px; }
.btn-theme {
  width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.theme { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; min-width: 150px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.menu button:hover { background: var(--card-2); }
.menu button[aria-checked="true"] { font-weight: 700; color: var(--title); }

.wrap { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(32px + var(--safe-b)); outline: none; }

/* ---------- Cabeçalho da página ---------- */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 60%, var(--blue) 140%);
  color: #fff; border-radius: var(--radius); padding: 20px 18px 18px;
}
.hero h1 { font-size: 24px; line-height: 1.15; margin: 0; }

/* ---------- Busca ---------- */
.search { position: relative; margin-top: 14px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search input {
  width: 100%; height: 48px; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 0 14px 0 40px; font-size: 16px; outline: none; box-shadow: var(--shadow);
}
.search input:focus { border-color: var(--blue); }

/* ---------- Seletor de semanas ---------- */
.section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 2px 10px; }
.weeks {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(118px, 1fr); gap: 10px;
  overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 2px 8px; margin: 0 -16px; padding-inline: 16px;
  scrollbar-width: none;
}
.weeks::-webkit-scrollbar { display: none; }
.week {
  scroll-snap-align: start;
  text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; text-decoration: none;
}
.week b { font-size: 15px; }
.week .w-date { font-size: 13px; color: var(--muted); }
.week .w-count { font-size: 12px; color: var(--freq-ink); font-weight: 700; margin-top: 4px; }
.week[aria-current="true"] { background: var(--sel-bg); border-color: var(--sel-bg); color: var(--sel-ink); }
.week[aria-current="true"] .w-date { color: inherit; opacity: .8; }
.week[aria-current="true"] .w-count { color: var(--sel-count); }

.week-head { margin: 18px 2px 10px; }
.week-head .top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.week-head h2 { font-size: 19px; margin: 0; }
.week-head .top span { color: var(--muted); font-size: 14px; }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.totals div { background: var(--card); border-radius: 12px; padding: 8px 10px; box-shadow: var(--shadow); }
.totals b { display: block; font-size: 17px; color: var(--title); }
.totals span { font-size: 12px; color: var(--muted); }

/* ---------- Lista de regiões ---------- */
.list { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
.rcard {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); padding: 14px; text-decoration: none;
  box-shadow: var(--shadow); border: 1px solid transparent; transition: border-color .15s, transform .15s;
}
.rcard:active { transform: scale(.985); }
.rcard:hover { border-color: var(--line); }
.rnum {
  width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center;
  background: var(--rnum-bg); color: var(--title); font-weight: 800; font-size: 18px;
}
.rcard h3 { margin: 0 0 4px; font-size: 16px; }
.rmeta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; color: var(--muted); align-items: center; }
.chev { color: var(--muted); }
.empty { padding: 18px 14px; color: var(--muted); font-size: 14px; text-align: center; background: var(--card); border-radius: var(--radius); }

/* ---------- Detalhe ---------- */
.back {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--title);
  font-weight: 600; font-size: 15px; padding: 6px 2px; margin-bottom: 8px;
}
.dhead { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.dhead .rnum { width: 56px; height: 56px; font-size: 21px; background: var(--navy); color: #fff; }
.dhead h1 { margin: 0; font-size: 23px; line-height: 1.15; }
.dhead p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card + .card, .card + .section-label { margin-top: 14px; }

.map-thumb { position: relative; display: block; width: 100%; border: 0; padding: 0; background: #e9edf4; cursor: zoom-in; aspect-ratio: 1191 / 842; }
.map-thumb img { width: 100%; height: 100%; object-fit: cover; }
.map-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 8px;
  font-weight: 600; font-size: 14px; cursor: pointer; color: var(--title); min-height: 44px; text-align: center;
}
.map-actions .btn { flex-direction: column; gap: 4px; font-size: 13px; padding: 10px 4px; line-height: 1.2; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }

.info { display: grid; grid-template-columns: 1fr 1fr; }
.info .it { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.info .it:nth-child(odd):not(.full) { border-right: 1px solid var(--line); }
.info .it.full { grid-column: 1 / -1; }
.info .k { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 3px; }
.info .v { font-size: 16px; font-weight: 700; color: var(--title); }
.info .v.big { font-size: 22px; }
.info .it:last-child, .info .it.pair-last { border-bottom: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--card-2); }
td.n { color: var(--muted); width: 1%; white-space: nowrap; }
td b { color: var(--title); }
tr:last-child td { border-bottom: 0; }

/* ---------- Visão geral ---------- */
.overview-frame { width: 100%; height: calc(100vh - 230px); min-height: 380px; border: 0; display: block; }
.overview-actions { padding: 10px; }
.overview-actions .btn { width: 100%; }

.notfound { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- Visualizador ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: #0e1424; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  color: #fff; background: rgba(14, 20, 36, .9); position: relative; z-index: 2;
}
.viewer-title { flex: 1; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vbtn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255, 255, 255, .12); color: #fff;
  display: grid; place-items: center; cursor: pointer; text-decoration: none;
}
.vbtn:active { background: rgba(255, 255, 255, .22); }
.viewer-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.viewer-stage.dragging { cursor: grabbing; }
.viewer-stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-select: none; will-change: transform; background: #fff; }
.viewer-loading {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 13px; padding: 6px 12px; border-radius: 999px; pointer-events: none;
}
.viewer-zoom { position: absolute; right: 12px; bottom: calc(16px + var(--safe-b)); display: flex; gap: 8px; z-index: 2; }
.viewer-zoom .vbtn { background: rgba(14, 20, 36, .75); }

/* ---------- Folha iOS ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(10, 16, 32, .5); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.sheet-card { background: var(--card); border-radius: 20px; padding: 20px; width: 100%; max-width: 420px; margin-bottom: var(--safe-b); }
.sheet-card h2 { margin: 0 0 10px; font-size: 18px; color: var(--title); }
.sheet-card ol { margin: 0 0 16px; padding-left: 20px; line-height: 1.8; }
.sheet-card .btn { width: 100%; }

@media (min-width: 768px) {
  .hero { padding: 26px 28px; }
  .hero h1 { font-size: 30px; }
  .logo { height: 36px; }
  .detail-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; align-items: start; }
  .detail-grid .card + .card { margin-top: 0; }
}
@media (max-width: 360px) {
  .logo { height: 24px; }
}
