:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #1b2230; --muted: #667085; --line: #e3e7ef;
  --brand: #1F3864; --brand-text: #ffffff; --accent: #0b57d0;
  --ok: #137333; --warn: #b26a00; --bad: #b00020; --doing: #0b57d0;
  --ok-bg: #e6f4ea; --warn-bg: #fdf1dc; --bad-bg: #fce8ea; --doing-bg: #e8f0fe; --gray-bg: #eef0f4;
  --radius: 14px; --nav-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --card: #181f2e; --text: #e8ecf4; --muted: #9aa5b8; --line: #2a3347;
    --brand: #8fb0ee; --brand-text: #0f1420; --accent: #8ab4f8;
    --ok: #81c995; --warn: #fdd663; --bad: #f28b82; --doing: #8ab4f8;
    --ok-bg: #16301f; --warn-bg: #3a2e12; --bad-bg: #3d1b1f; --doing-bg: #1b2a47; --gray-bg: #232b3d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.noscript { padding: 24px; text-align: center; }

/* estrutura */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-text);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; display: flex; align-items: center; gap: 8px; }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar button { background: transparent; border: 0; color: inherit; font-size: 1.3rem; min-width: 44px; min-height: 44px;
  border-radius: 10px; }
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 16px calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center; }
nav.tabs .inner { display: flex; width: 100%; max-width: 760px; }
nav.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; min-height: var(--nav-h); }
nav.tabs a span.ico { font-size: 1.35rem; line-height: 1; }
nav.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* componentes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2, h2.section { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px;
  text-align: center; text-decoration: none; color: inherit; display: block; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.stat.bad b { color: var(--bad); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.row { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; min-height: 56px; }
.row .t { font-weight: 600; word-break: break-word; }
.row .m { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.row.overdue { border-left: 5px solid var(--bad); }
.row.done .t { text-decoration: line-through; color: var(--muted); }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--gray-bg); color: var(--muted); }
.chip.doing { background: var(--doing-bg); color: var(--doing); }
.chip.blocked { background: var(--warn-bg); color: var(--warn); }
.chip.done { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; min-height: 40px; }
.chips button[aria-pressed="true"] { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* formulários e botões */
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 16px; }
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px; font-weight: 600; background: var(--brand); color: var(--brand-text); }
.btn.sec { background: var(--gray-bg); color: var(--text); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .55; }
.btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: .85rem; margin-top: 6px; }
.btns.three { grid-template-columns: repeat(3, 1fr); }
.btns .full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 6px; }
.error { color: var(--bad); font-size: .9rem; margin-top: 10px; min-height: 1.3em; }
.fab { position: fixed; right: max(16px, calc(50% - 360px)); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 4;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 2rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.28); }

/* login */
.login { max-width: 400px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px 40px; }
.login h1 { text-align: center; color: var(--brand); margin-bottom: 4px; }
.login p.sub { text-align: center; color: var(--muted); margin-top: 0; }

/* folha (dialog) */
dialog.sheet { border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; border-radius: 20px 20px 0 0;
  background: var(--bg); color: var(--text); overflow: hidden; }
dialog.sheet::backdrop { background: rgba(8, 12, 20, .55); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
.sheet .head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet .head h3 { margin: 0; flex: 1; font-size: 1.05rem; word-break: break-word; }
.sheet .head button { border: 0; background: var(--gray-bg); border-radius: 50%; width: 40px; height: 40px; font-size: 1.1rem; }
.sheet .body { padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; max-height: calc(92dvh - 70px); }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222a3a; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
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; font-size: .78rem; }
td.num, th.num { text-align: right; white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.on { background: var(--ok); } .dot.off { background: var(--muted); } .dot.rev { background: var(--bad); }
.day { font-weight: 700; margin: 16px 0 8px; }
.day::first-letter { text-transform: uppercase; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.row.event { border-left: 5px solid var(--accent); }
label.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 1rem; margin: 8px 0; }
label.check input { width: 22px; height: 22px; min-height: 0; flex: none; }
.code { font: 700 2rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .18em; text-align: center; padding: 14px;
  background: var(--card); border: 2px dashed var(--line); border-radius: 12px; user-select: all; margin: 12px 0; }
.notice { border: 1px solid var(--warn); background: var(--warn-bg); color: var(--text); border-radius: 12px; padding: 12px; margin: 10px 0; }
.notice .btn { margin-top: 10px; width: 100%; }
