:root {
  --petrol: #1e4a47;
  --petrol-700: #173836;
  --petrol-100: #e3edeb;
  --terracotta: #c97b4a;
  --terracotta-700: #a8602f;
  --terracotta-100: #f6e6da;
  --bg: #f7f4ef;
  --surface: #ffffff;
  --ink: #1f2a29;
  --muted: #5b6866;
  --line: #e1ddd5;
  --primary: var(--petrol);
  --primary-ink: #ffffff;
  --accent: var(--terracotta);
  --danger: #b3402e;
  --danger-100: #f8e3df;
  --ok: #2b7656;
  --ok-100: #dff1e8;
  --warn: #9a6513;
  --warn-100: #faefd6;
  --info: #2d5f8a;
  --info-100: #e1edf7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 74, 71, 0.06), 0 4px 14px rgba(30, 74, 71, 0.05);
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a19;
    --surface: #1a2625;
    --ink: #e8eeed;
    --muted: #9db0ad;
    --line: #2b3b39;
    --primary: #3b7f79;
    --petrol-100: #213836;
    --terracotta-100: #3a2a20;
    --danger-100: #3b211d;
    --ok-100: #1b3328;
    --warn-100: #38300f;
    --info-100: #1a2d3f;
    --danger: #e0705d;
    --ok: #62c597;
    --warn: #e0b45c;
    --info: #7fb2de;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui);
  font-size: 16px; line-height: 1.45; min-height: 100dvh;
}
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-family: var(--font-display); font-style: italic; font-weight: 500; font-size: 1.75rem; color: var(--primary); }
@media (prefers-color-scheme: dark) { h1 { color: #cfe3e0; } }
h2 { font-size: 1.05rem; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
p { margin: 0 0 0.75rem; }
a { color: var(--primary); text-underline-offset: 2px; }
@media (prefers-color-scheme: dark) { a { color: #8fc6c0; } }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--petrol-100); padding: 0.1rem 0.35rem; border-radius: 6px; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.block { display: block; }
.center { display: flex; justify-content: center; margin: 1.25rem 0; }
.prewrap { white-space: pre-wrap; }
.icon { display: inline-flex; vertical-align: middle; flex: none; }

/* ---------- Estrutura ---------- */
.shell { min-height: 100dvh; display: grid; grid-template-columns: 1fr; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.side { display: none; }
.main-col { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: calc(0.5rem + env(safe-area-inset-top)) 1rem 0.5rem; background: var(--primary); color: #fff;
}
.top-brand { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-display); font-style: italic; font-size: 1.15rem; }
.top-actions { display: flex; gap: 0.25rem; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
.icon-btn.on { background: var(--accent); }
.view { padding: 1rem; max-width: 980px; margin: 0 auto; width: 100%; }

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--terracotta) 0 50%, #fff 50% 100%); border: 2px solid var(--terracotta); display: inline-block; flex: none; }
.top .brand-mark { border-color: #fff; background: linear-gradient(135deg, var(--terracotta) 0 55%, #fff 55% 100%); }
.brand h1 { font-size: 1.6rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .nav-link { flex: 1; flex-direction: column; gap: 2px; font-size: 0.72rem; padding: 0.5rem 0.25rem; min-height: 56px; justify-content: center; border-radius: 0; }

.nav-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.9rem; color: var(--muted); text-decoration: none; border-radius: 10px; font-weight: 500; }
.nav-link.active { color: var(--primary); background: var(--petrol-100); }
@media (prefers-color-scheme: dark) { .nav-link.active { color: #cfe3e0; } }
.nav-link:hover { background: var(--petrol-100); }

@media (min-width: 900px) {
  .shell { grid-template-columns: 250px 1fr; padding-bottom: 0; }
  .side { display: flex; flex-direction: column; gap: 1.5rem; padding: 1.5rem 1rem; background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100dvh; }
  .brand-side { font-family: var(--font-display); font-style: italic; font-size: 1.4rem; color: var(--primary); padding: 0 0.5rem; }
  .nav { display: flex; flex-direction: column; gap: 0.25rem; }
  .side-foot { margin-top: auto; padding: 0.75rem 0.5rem; border-top: 1px solid var(--line); }
  .who { display: flex; flex-direction: column; }
  .tabbar { display: none; }
  .top { background: transparent; color: var(--ink); justify-content: flex-end; padding-top: 0.5rem; }
  .top-brand { display: none; }
  .icon-btn:hover { background: var(--petrol-100); }
  .view { padding: 1rem 2rem 3rem; }
}

.page-head { margin-bottom: 1.25rem; }
.page-head.split { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.idle-banner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 1rem; background: var(--warn-100); color: var(--warn); font-weight: 600; }

/* ---------- Cartões, listas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 800px) { .grid-2 { grid-template-columns: 1.15fr 1fr; } }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 0.25rem; color: inherit; text-decoration: none; min-height: 56px; width: 100%; }
a.row:hover, .row-btn:hover { background: var(--petrol-100); border-radius: 10px; }
.row-btn { background: transparent; border: 0; font: inherit; text-align: left; cursor: pointer; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }
.empty { color: var(--muted); padding: 1rem 0.25rem; text-align: center; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--terracotta-100); color: var(--terracotta-700); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; flex: none; letter-spacing: 0.02em; }
@media (prefers-color-scheme: dark) { .avatar { color: #f0b48d; } }

.badge { display: inline-flex; align-items: center; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge-neutral { background: var(--petrol-100); color: var(--muted); }
.badge-ok { background: var(--ok-100); color: var(--ok); }
.badge-warn { background: var(--warn-100); color: var(--warn); }
.badge-info { background: var(--info-100); color: var(--info); }

.date-block { width: 48px; text-align: center; display: flex; flex-direction: column; line-height: 1.1; flex: none; }
.date-block strong { font-size: 1.25rem; color: var(--primary); }
.note-flag { color: var(--terracotta); display: inline-flex; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem; text-decoration: none; color: inherit; display: flex; flex-direction: column; box-shadow: var(--shadow); }
a.stat:hover { border-color: var(--accent); }
.stat-value { font-family: var(--font-display); font-size: 2rem; color: var(--primary); line-height: 1; }
@media (prefers-color-scheme: dark) { .stat-value { color: #cfe3e0; } }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }
.small-stats { grid-template-columns: repeat(4, 1fr); }
.small-stats .stat { padding: 0.6rem; box-shadow: none; }
.small-stats .stat-value { font-size: 1.4rem; }
.small-stats .stat-label { font-size: 0.7rem; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: 0.85rem; padding-top: 0.1rem; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tag { background: var(--petrol-100); color: var(--primary); border-radius: 6px; padding: 0.05rem 0.5rem; font-size: 0.8rem; }
@media (prefers-color-scheme: dark) { .tag { color: #cfe3e0; } }

/* ---------- Abas, barra de ferramentas ---------- */
.tabs { display: flex; gap: 0.25rem; background: var(--petrol-100); padding: 0.25rem; border-radius: 12px; overflow-x: auto; max-width: 100%; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 0.5rem 0.9rem; border-radius: 9px; cursor: pointer; white-space: nowrap; min-height: 40px; }
.tab.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .tab.on { color: #cfe3e0; } }
.toolbar { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.search-wrap { position: relative; flex: 1; min-width: 220px; display: flex; align-items: center; }
.search-wrap .icon { position: absolute; left: 0.8rem; color: var(--muted); pointer-events: none; }
.search { padding-left: 2.5rem !important; }

.chart-head { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.back { display: inline-flex; align-items: center; gap: 0.25rem; text-decoration: none; color: var(--muted); font-weight: 600; width: fit-content; }
.chart-title { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.chart-title .avatar { width: 52px; height: 52px; font-size: 1.1rem; }
.chart-title h1 { font-size: 1.6rem; }
.chart-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.chart-body { margin-top: 1rem; }

/* ---------- Botões e formulários ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; min-height: 44px; padding: 0.55rem 1rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--petrol-700); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-link { border: 0; background: transparent; color: var(--primary); }
.btn-small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-left { margin-right: auto; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.busy { opacity: 0.7; cursor: progress; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field-label { font-size: 0.85rem; font-weight: 600; }
.field-hint { font-size: 0.78rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 0.75rem; min-height: 44px; width: 100%;
}
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); flex: none; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0.9rem; }
.form-grid.inner { gap: 0.9rem; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: 1 / -1; } }
.fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 0.75rem; margin: 0; }
.fieldset legend { padding: 0 0.4rem; font-weight: 600; font-size: 0.85rem; }
.form-error { color: var(--danger); background: var(--danger-100); padding: 0.55rem 0.75rem; border-radius: 8px; margin: 0; font-weight: 500; }
.notice { background: var(--warn-100); color: var(--warn); padding: 0.6rem 0.8rem; border-radius: 10px; font-weight: 500; }
.inline-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 0.75rem; }
.inline-form .field { flex: 1; min-width: 200px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 0.4rem 0.9rem; font: inherit; cursor: pointer; min-height: 40px; }
.chip-on { background: var(--primary); color: #fff; border-color: var(--primary); }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.5rem 0; flex-wrap: wrap; }
.pref.check { justify-content: flex-start; align-items: flex-start; cursor: pointer; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.6rem 0; }
.user-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.bullets { padding-left: 1.1rem; margin: 0; display: grid; gap: 0.5rem; }
.danger-zone { border-color: var(--danger); }
.big-code { font-size: 1.4rem; text-align: center; letter-spacing: 0.04em; }
.big-code code { padding: 0.5rem 0.9rem; }
.qr { display: flex; justify-content: center; background: #fff; border-radius: 12px; padding: 0.5rem; width: fit-content; margin: 0 auto; }

/* ---------- Diálogos e avisos ---------- */
dialog.dlg { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35); overflow: auto; }
dialog.dlg-wide { width: min(760px, calc(100vw - 1.5rem)); }
dialog.dlg::backdrop { background: rgba(10, 25, 24, 0.55); }
dialog.dlg > * { padding: 1.25rem; }
.dlg-body { display: flex; flex-direction: column; gap: 0.75rem; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 0.5rem; }
.dlg h2 { font-size: 1.2rem; }
@media (max-width: 640px) {
  dialog.dlg, dialog.dlg-wide { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
}
.note-box { border-top: 1px dashed var(--line); padding-top: 0.75rem; display: flex; flex-direction: column; gap: 0.6rem; }
.note-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.note-head h3 { margin: 0; display: flex; align-items: center; gap: 0.35rem; }

#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.5rem; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 0.7rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; }
.toast-error { background: var(--danger); color: #fff; }
dialog[open] ~ #toasts { z-index: 1000; }
@media (min-width: 900px) { #toasts { bottom: 1.5rem; } }

/* ---------- Registro de acessos ---------- */
.audit-row { display: flex; gap: 1rem; padding: 0.65rem 0.25rem; align-items: flex-start; }
.audit-row.warn strong { color: var(--danger); }
.audit-time { width: 7.5rem; flex: none; }
.audit-main { display: flex; flex-direction: column; min-width: 0; }
@media (max-width: 520px) { .audit-row { flex-direction: column; gap: 0.1rem; } .audit-time { width: auto; } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; background: radial-gradient(1200px 500px at 50% -10%, var(--petrol-100), transparent), var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 1.75rem; width: min(420px, 100%); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1.1rem; }
.login-foot { display: flex; flex-direction: column; gap: 0.75rem; align-items: center; text-align: center; }
.lang-switch { display: flex; gap: 0.4rem; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .tab, .nav-link, .row, .stat { transition: background-color 0.15s, border-color 0.15s, color 0.15s; }
}

/* Backup / primeira configuração */
.notice-link { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; text-decoration: none; margin-bottom: 1rem; }
.cred { margin: 0.5rem 0; }
.cred .big-code { margin: 0.2rem 0; word-break: break-all; }
