/* =============================================================================
   Carballo e Faro — UI (CSS puro, sem build)
   Tema claro/escuro via [data-theme] no <html>. Cor principal: azul índigo.
   ============================================================================= */

/* ---------- Tokens ---------- */
:root {
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --radius: 14px;
    --sidebar-w: 272px;

    --bg: #f3f4fa;
    --surface: #ffffff;
    --surface-2: #f7f8fd;
    --border: #e2e5f0;
    --border-strong: #cdd2e3;
    --text: #161a2d;
    --muted: #5f6888;

    --primary: #4f46e5;
    --primary-ink: #4338ca;
    --primary-soft: #ecedff;
    --btn: #4f46e5;
    --btn-hover: #4338ca;
    --ok: #15803d;
    --ok-hover: #166534;

    --success: #15803d;  --success-soft: #e5f6ec;
    --danger: #b91c1c;   --danger-soft: #fdecec;
    --warning: #b45309;  --warning-soft: #fdf2dc;
    --info: #1d4ed8;     --info-soft: #e7efff;

    --shadow-sm: 0 1px 2px rgba(22, 26, 45, .06), 0 1px 1px rgba(22, 26, 45, .03);
    --shadow-md: 0 10px 28px rgba(22, 26, 45, .10);
    --shadow-lg: 0 28px 70px rgba(10, 12, 30, .35);
    --ring: 0 0 0 3px rgba(79, 70, 229, .22);
    --chev: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235f6888' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #0a0d1b;
    --surface: #121730;
    --surface-2: #171d3b;
    --border: #242b4d;
    --border-strong: #353e69;
    --text: #e9ebfb;
    --muted: #98a2c9;

    --primary: #a5b4fc;
    --primary-ink: #c7d2fe;
    --primary-soft: #1d2350;
    --btn: #6366f1;
    --btn-hover: #7b7ff5;
    --ok: #16a34a;
    --ok-hover: #22b457;

    --success: #4ade80;  --success-soft: rgba(74, 222, 128, .12);
    --danger: #f87171;   --danger-soft: rgba(248, 113, 113, .12);
    --warning: #fbbf24;  --warning-soft: rgba(251, 191, 36, .12);
    --info: #93c5fd;     --info-soft: rgba(147, 197, 253, .12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, .45);
    --ring: 0 0 0 3px rgba(129, 140, 248, .35);
    --chev: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2398a2c9' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Logo (PNG 16:9 com margem: recorta no conteúdo) */
.brand-logo {
    width: 100%;
    max-width: 190px;
    aspect-ratio: 1710 / 600;
    background: url("/img/logo.png") center / 112.3% auto no-repeat;
}
:root[data-theme="dark"] .brand-logo { filter: invert(1) hue-rotate(180deg); mix-blend-mode: screen; }

/* ---------- Estrutura (sidebar + conteúdo) ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 20px 14px 16px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.sidebar-brand { padding: 2px 8px 18px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }

.nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-label { padding: 6px 12px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 14.5px;
    font-weight: 500;
    cursor: pointer;
    list-style: none;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
summary.nav-link::-webkit-details-marker { display: none; }
summary.nav-link::after {
    content: "";
    margin-left: auto;
    width: 7px; height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    opacity: .6;
    transition: transform .2s;
}
details[open] > summary.nav-link::after { transform: rotate(-135deg); }
.nav-sub { margin: 2px 0 8px 22px; padding-left: 10px; border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.nav-sub .nav-link { padding: 8px 10px; font-size: 14px; }

.sidebar-foot { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.avatar {
    flex: none; width: 38px; height: 38px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 14px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #6366f1, #4338ca);
}
.who { min-width: 0; flex: 1; line-height: 1.25; }
.who b, .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { font-size: 13.5px; }
.who span { font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 30;
    height: 64px; padding: 0 28px;
    display: flex; align-items: center; gap: 12px;
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-width: 0; }
.crumbs b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.content { width: 100%; max-width: 1320px; margin: 0 auto; padding: 28px; }
.content > * + * { margin-top: 20px; }
.scrim { display: none; }
.icon-btn.only-mobile { display: none; }

.icon-btn {
    width: 40px; height: 40px; flex: none;
    display: inline-grid; place-items: center;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted);
    cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
:root[data-theme="dark"] .i-moon { display: none; }
:root:not([data-theme="dark"]) .i-sun { display: none; }

/* ---------- Cabeçalho de página, cartões ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.page-sub { margin-top: 4px; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 16px; font-weight: 600; }
.card-body { padding: 22px; }
.card-foot { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- Formulários ---------- */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: end; }
.form-grid > * { grid-column: span 12; }
@media (min-width: 720px) {
    .form-grid > .col-6, .form-grid > .col-4, .form-grid > .col-3, .form-grid > .col-8 { grid-column: span 6; }
}
@media (min-width: 1100px) {
    .form-grid > .col-3 { grid-column: span 3; }
    .form-grid > .col-4 { grid-column: span 4; }
    .form-grid > .col-6 { grid-column: span 6; }
    .form-grid > .col-8 { grid-column: span 8; }
}
.form-grid > .col-12 { grid-column: span 12; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); }

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
select, textarea {
    width: 100%; height: 42px; padding: 0 14px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; -webkit-appearance: none; padding-right: 38px; background-image: var(--chev); background-repeat: no-repeat; background-position: right 12px center; }
select[multiple] { height: auto; min-height: 108px; padding: 8px; background-image: none; }
select[multiple] option { padding: 6px 8px; border-radius: 6px; }
textarea { height: auto; min-height: 96px; padding: 10px 14px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--btn); flex: none; }
.check { display: inline-flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; min-height: 42px; }

.input-group { position: relative; }
.input-group input { padding-right: 46px !important; }
.input-group .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; background: transparent; }

/* ---------- Botões ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px;
    border: 1px solid transparent; border-radius: 10px;
    font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--btn); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .35); }
.btn-primary:hover { background: var(--btn-hover); }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover { background: var(--ok-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-soft { background: var(--primary-soft); color: var(--primary-ink); }
.btn-soft:hover { filter: brightness(.97); }
.btn-soft-warning { background: var(--warning-soft); color: var(--warning); }
.btn-soft-danger { background: var(--danger-soft); color: var(--danger); }
.btn-soft-warning:hover, .btn-soft-danger:hover { filter: brightness(.96); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 46px; font-size: 15px; }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: nowrap; justify-content: flex-end; align-items: center; gap: 6px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn-icon .icon { width: 18px; height: 18px; }
.btn-soft-success { background: var(--success-soft); color: var(--success); }
.btn-soft-success:hover { filter: brightness(.96); }
.actions form { margin: 0; }

/* ---------- Badges e alertas ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; margin-bottom: 16px;
    border: 1px solid transparent; border-radius: 10px; font-size: 14px;
}
.alert .icon { margin-top: 1px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); }
.content > .alert { margin-bottom: 0; }
.page-head + .alert { margin-top: 20px; margin-bottom: 0; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th {
    padding: 12px 16px; text-align: left; white-space: nowrap;
    font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { padding: 14px 16px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .t-center { text-align: center; }
.table .t-right { text-align: right; }
.table .nowrap { white-space: nowrap; }
.table .empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.table .strong { font-weight: 600; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }
.log-msg { min-width: 220px; max-width: 460px; overflow-wrap: anywhere; }
.log-err { min-width: 200px; max-width: 420px; overflow-wrap: anywhere; font-size: 13px; color: var(--muted); }

.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty-state .icon { width: 40px; height: 40px; margin-bottom: 10px; opacity: .6; }

/* ---------- Modais ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(8, 10, 24, .58);
    -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.modal {
    width: 100%; max-width: 580px; max-height: calc(100vh - 40px); overflow: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
}
.modal-sm { max-width: 440px; }
.modal-lg { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; }

/* ---------- Permissões ---------- */
.perm-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.perm { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s; }
.perm:hover { border-color: var(--border-strong); }
.perm:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.perm input { margin-top: 2px; }
.perm b { display: block; font-size: 14px; font-weight: 600; }
.perm small { display: block; font-size: 12px; color: var(--muted); }

/* ---------- Dashboard ---------- */
.welcome {
    position: relative; overflow: hidden; padding: 30px; border-radius: 18px; color: #fff;
    background:
        radial-gradient(600px 260px at 100% 0%, rgba(165, 180, 252, .45), transparent 60%),
        linear-gradient(135deg, #312e81, #4f46e5);
}
.welcome h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.welcome p { margin-top: 6px; color: rgba(255, 255, 255, .85); }
.section-title { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.shortcuts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.shortcut {
    display: flex; align-items: center; gap: 14px; padding: 18px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s;
}
.shortcut:hover { text-decoration: none; border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.shortcut .ico { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: var(--primary-soft); color: var(--primary-ink); }
.shortcut b { display: block; font-size: 15px; }
.shortcut small { display: block; color: var(--muted); font-size: 12.5px; }

/* ---------- Cards de totais (relatório de logs) ---------- */
.stats { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat {
    --c: var(--primary); --c-soft: var(--primary-soft);
    position: relative; overflow: hidden; padding: 20px 22px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.stat::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 4px; background: var(--c); }
.stat-success { --c: var(--success); --c-soft: var(--success-soft); }
.stat-danger { --c: var(--danger); --c-soft: var(--danger-soft); }
.stat-info { --c: var(--info); --c-soft: var(--info-soft); }
.stat-top { display: flex; align-items: center; gap: 10px; }
.stat-ico { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--c-soft); color: var(--c); }
.stat-label { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat-value { margin-top: 14px; font-size: 32px; font-weight: 700; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-bar { margin-top: 16px; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.stat-bar span { display: block; height: 100%; border-radius: inherit; background: var(--c); }
.stat-foot { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
@media (max-width: 820px) { .stats { grid-template-columns: 1fr; } }

/* ---------- Paginação ---------- */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager-info { font-size: 13.5px; color: var(--muted); }
.pager-info b { color: var(--text); font-weight: 600; }
.pager-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pager-num {
    min-width: 32px; height: 32px; padding: 0 8px;
    display: inline-grid; place-items: center;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 13px; font-weight: 600; color: var(--text); background: var(--surface);
}
.pager-num:hover { text-decoration: none; background: var(--surface-2); border-color: var(--border-strong); }
.pager-num.atual { background: var(--btn); border-color: var(--btn); color: #fff; }
.pager-gap { padding: 0 4px; color: var(--muted); }

/* ---------- Acesso negado ---------- */
.denied { max-width: 520px; margin: 40px auto; padding: 40px 28px; text-align: center; }
.denied .ico { width: 64px; height: 64px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 18px; background: var(--danger-soft); color: var(--danger); }
.denied .ico .icon { width: 30px; height: 30px; }
.denied h1 { font-size: 24px; font-weight: 700; }
.denied p { margin: 8px 0 22px; color: var(--muted); }

/* ---------- Telas de autenticação ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-hero {
    position: relative; overflow: hidden; color: #fff;
    display: flex; flex-direction: column; justify-content: space-between; gap: 32px; padding: 48px;
    background:
        radial-gradient(900px 520px at 0% 0%, rgba(129, 140, 248, .55), transparent 60%),
        radial-gradient(720px 520px at 100% 100%, rgba(99, 102, 241, .65), transparent 60%),
        linear-gradient(135deg, #1e1b4b, #312e81 52%, #4338ca);
}
.auth-hero::before {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .07) 1px, transparent 1px);
    background-size: 44px 44px;
    -webkit-mask-image: linear-gradient(to bottom, #000, transparent 85%);
    mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.auth-hero > * { position: relative; }
.auth-plate { width: fit-content; padding: 14px 20px; border-radius: 18px; background: #fff; box-shadow: 0 12px 32px rgba(10, 12, 40, .35); }
:root .auth-plate .brand-logo { width: 210px; filter: none; mix-blend-mode: normal; }
.auth-hero h2 { font-size: 36px; font-weight: 700; line-height: 1.15; letter-spacing: -.025em; max-width: 14ch; }
.auth-hero p { margin-top: 14px; max-width: 42ch; font-size: 16px; color: rgba(255, 255, 255, .82); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.pill { padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .22); }
.auth-hero small { color: rgba(255, 255, 255, .6); }

.auth-panel { position: relative; display: flex; align-items: center; justify-content: center; padding: 32px; background: var(--bg); }
.auth-tools { position: absolute; top: 20px; right: 20px; }
.auth-card {
    width: 100%; max-width: 420px; padding: 34px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-md);
}
.auth-card.wide { max-width: 520px; }
.auth-card h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.auth-card .lead { margin: 6px 0 22px; color: var(--muted); }
.auth-card .brand-logo { margin: 0 auto 22px; max-width: 170px; }
.auth-hero ~ .auth-panel .auth-card .brand-logo { display: none; }
.auth-links { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; text-align: center; font-size: 14px; color: var(--muted); }
.auth-links a { font-weight: 600; }
.auth.simple { grid-template-columns: 1fr; }
.auth.simple .auth-panel {
    background:
        radial-gradient(700px 360px at 50% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 70%),
        var(--bg);
}
.success-ico { width: 64px; height: 64px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--success-soft); color: var(--success); }
.success-ico .icon { width: 30px; height: 30px; }

/* ---------- Responsivo ---------- */
@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 60;
        width: min(var(--sidebar-w), 86vw);
        transform: translateX(-102%); transition: transform .25s ease;
    }
    .nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(8, 10, 24, .55); }
    .nav-open .scrim { display: block; }
    .icon-btn.only-mobile { display: inline-grid; }
    .topbar { padding: 0 16px; }
    .content { padding: 20px 16px; }
}
@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .auth-hero ~ .auth-panel .auth-card .brand-logo { display: block; }
    .auth-panel { padding: 72px 16px 32px; align-items: flex-start; }
}
@media (max-width: 520px) {
    .auth-card { padding: 26px 20px; }
    .page-head h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ---------- Permissões (lista de usuários + grupos com chave) ---------- */
.perm-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.perm-users { position: sticky; top: 84px; overflow: hidden; }
.perm-users-search { padding: 14px; border-bottom: 1px solid var(--border); }
.perm-users-list { max-height: calc(100vh - 220px); overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.perm-user {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
    border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer;
    transition: background .15s;
}
.perm-user:hover { background: var(--surface-2); }
.perm-user.active { background: var(--primary-soft); }
.perm-user.active b { color: var(--primary-ink); }
.perm-user-txt { min-width: 0; line-height: 1.3; }
.perm-user-txt b, .perm-user-txt small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-user-txt b { font-size: 14px; font-weight: 600; }
.perm-user-txt small { font-size: 12px; color: var(--muted); }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }

.perm-groups { display: flex; flex-direction: column; gap: 16px; }
.perm-group { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.perm-group-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.perm-group-ico { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--primary-soft); color: var(--primary-ink); }
.perm-group-ico .icon { width: 18px; height: 18px; }
.perm-group-txt { flex: 1; min-width: 0; line-height: 1.3; }
.perm-group-txt b { display: block; font-size: 14.5px; font-weight: 600; }
.perm-group-txt small { display: block; font-size: 12.5px; color: var(--muted); }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; cursor: pointer; transition: background .15s; }
.perm-row + .perm-row { border-top: 1px solid var(--border); }
.perm-row:hover { background: var(--surface-2); }
.perm-row-txt { min-width: 0; line-height: 1.3; }
.perm-row-txt b { display: block; font-size: 14px; font-weight: 500; }
.perm-row-txt small { display: block; font-size: 12px; color: var(--muted); }

/* Chave liga/desliga (checkbox real por baixo) */
.switch { position: relative; flex: none; width: 40px; height: 22px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; }
.switch-track::after {
    content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--btn); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }

@media (max-width: 900px) {
    .perm-layout { grid-template-columns: 1fr; }
    .perm-users { position: static; }
    .perm-users-list { max-height: 260px; }
}

/* ---------- Seleção em blocos (filiais) ---------- */
fieldset.opt-field { border: 0; margin: 0; padding: 0; min-width: 0; }
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-head legend { padding: 0; float: left; }
.link-btn { padding: 0; border: 0; background: none; color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.opt-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.opt-grid-1 { grid-template-columns: 1fr; }
.opt {
    display: flex; align-items: center; gap: 12px; padding: 10px 14px;
    border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface);
    cursor: pointer; transition: border-color .15s, background .15s;
}
.opt:hover { border-color: var(--muted); }
.opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.opt-ico { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); color: var(--muted); transition: background .15s, color .15s; }
.opt-ico .icon { width: 17px; height: 17px; }
.opt:has(input:checked) .opt-ico { background: var(--btn); color: #fff; }
.opt-txt { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.switch-field {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: 42px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 10px;
    background: var(--surface); font-size: 14px; font-weight: 500; cursor: pointer;
}

/* ---------- Dashboard operacional ---------- */
:root { --chart-ok: #4f46e5; --chart-fail: #dc2626; }
:root[data-theme="dark"] { --chart-ok: #6366f1; --chart-fail: #ef4444; }

.welcome-sm { padding: 24px 28px; }
.welcome-sm h1 { font-size: 22px; }
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-primary { --c: var(--primary); --c-soft: var(--primary-soft); }
.stat-warning { --c: var(--warning); --c-soft: var(--warning-soft); }
.stat-foot a { font-weight: 600; }
@media (max-width: 1100px) { .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .stats-4 { grid-template-columns: 1fr; } }

/* Mesma grade de 4 colunas dos indicadores: gráfico e filiais ocupam 2 cada,
   com as bordas alinhadas aos cartões de cima e a mesma altura. */
.dash-grid { display: grid; gap: 16px; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: stretch; }
.dash-grid > .card { grid-column: span 2; display: flex; flex-direction: column; }
.dash-grid > .card > .card-body { flex: 1; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } .dash-grid > .card { grid-column: auto; } }

.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-ok { background: var(--chart-ok); }
.sw-fail { background: var(--chart-fail); }

/* Barras empilhadas em HTML/CSS: sucesso embaixo, falha em cima, 2px de respiro */
.chart { position: relative; padding-top: 18px; }
.chart-max { position: absolute; top: 0; left: 0; font-size: 11.5px; color: var(--muted); }
.chart-plot {
    height: 190px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; align-items: end;
    border-top: 1px dashed var(--border); border-bottom: 1px solid var(--border-strong);
    background-image: linear-gradient(var(--border) 1px, transparent 1px);
    background-size: 100% 50%; background-position: 0 50%;
}
.chart-col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; }
.chart-stack { width: min(42px, 70%); height: 100%; display: flex; flex-direction: column-reverse; gap: 2px; }
.seg { display: block; min-height: 2px; }
.seg-ok { background: var(--chart-ok); }
.seg-fail { background: var(--chart-fail); }
.chart-stack .seg:last-child { border-radius: 4px 4px 0 0; }
.chart-col:hover .chart-stack, .chart-col:focus-visible .chart-stack { filter: brightness(1.12); }
.chart-tip {
    position: absolute; bottom: calc(100% - 8px); left: 50%; transform: translateX(-50%);
    display: none; z-index: 5; min-width: 120px; padding: 8px 10px; border-radius: 8px;
    background: var(--text); color: var(--bg); font-size: 12.5px; line-height: 1.5; box-shadow: var(--shadow-md);
    pointer-events: none; white-space: nowrap;
}
.chart-tip b { display: block; }
.chart-col:hover .chart-tip, .chart-col:focus-visible .chart-tip { display: block; }
.chart-x { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; margin-top: 8px; text-align: center; font-size: 12px; color: var(--muted); }
.chart-table { margin-top: 14px; font-size: 13px; }
.chart-table summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.chart-table .table { margin-top: 10px; }

/* Ranking de filiais */
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.rank-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rank-top b { font-size: 14px; font-weight: 600; }
.rank small { display: block; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.hbar { margin-top: 8px; height: 8px; display: flex; gap: 2px; border-radius: 999px; background: var(--border); overflow: hidden; }
.hbar span { display: block; height: 100%; }
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }

/* Lista de últimas falhas */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: flex-start; gap: 14px; padding: 14px 22px; }
.feed li + li { border-top: 1px solid var(--border); }
.feed-ico { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: var(--danger-soft); color: var(--danger); }
.feed-ico .icon { width: 17px; height: 17px; }
.feed-txt { flex: 1; min-width: 0; }
.feed-txt b { display: block; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.feed-txt small { display: block; margin-top: 2px; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.feed-meta { flex: none; text-align: right; font-size: 12.5px; }
.feed-meta small { display: block; color: var(--muted); }
@media (max-width: 640px) { .feed li { flex-wrap: wrap; } .feed-meta { text-align: left; width: 100%; padding-left: 46px; } }

.cell-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }

/* ---------- Auditoria ---------- */
.audit { list-style: none; margin: 0; padding: 0; }
.audit li { display: flex; align-items: flex-start; gap: 14px; padding: 16px 22px; }
.audit li + li { border-top: 1px solid var(--border); }
.audit-body { flex: 1; min-width: 0; }
.audit-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 14px; }
.audit-tag { font-size: 12px; color: var(--muted); padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; }
.audit-meta { flex: none; text-align: right; font-size: 12.5px; }
.audit-meta small { display: block; color: var(--muted); }
.diff { margin-top: 10px; border-collapse: collapse; font-size: 13px; width: 100%; max-width: 720px; }
.diff th { width: 130px; padding: 4px 12px 4px 0; text-align: left; vertical-align: top; font-weight: 600; color: var(--muted); white-space: nowrap; }
.diff td { padding: 4px 0; overflow-wrap: anywhere; }
.diff-old { color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff-arrow { margin: 0 8px; color: var(--muted); }
.diff-new { color: var(--success); font-weight: 600; }
@media (max-width: 640px) { .audit li { flex-wrap: wrap; } .audit-meta { text-align: left; width: 100%; padding-left: 46px; } }

/* ---------- Botão enviando (trava + indicador) ---------- */
.btn.carregando { cursor: progress; opacity: .85; }
.btn.carregando::before {
    content: ""; width: 14px; height: 14px; flex: none;
    border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
    animation: girar .7s linear infinite;
}
.btn-icon.carregando::before { position: absolute; }
.btn-icon.carregando { position: relative; }
.btn-icon.carregando .icon { visibility: hidden; }
@keyframes girar { to { transform: rotate(360deg); } }
