:root {
    --indigo: #4f46e5;
    --indigo-600: #4338ca;
    --indigo-50: #eef2ff;
    --navy: #0f1535;
    --navy-2: #1a2350;
    --ink: #1e293b;
    --muted: #64748b;
    --line: #e7e9f1;
    --bg: #f4f5fa;
    --green: #16a34a;
    --red: #dc2626;
    --amber: #d97706;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 248px;
    background: linear-gradient(180deg, var(--navy), var(--navy-2));
    color: #cdd3ec;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand { font-size: 22px; font-weight: 800; color: #fff; padding: 4px 10px 18px; }
.brand-tag {
    background: var(--indigo); color: #fff; font-size: 11px; font-weight: 700;
    padding: 2px 6px; border-radius: 6px; margin-left: 4px; vertical-align: middle;
}
.nav-group-title {
    text-transform: uppercase; font-size: 10px; letter-spacing: .08em;
    color: #7681ad; margin: 18px 10px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 9px; color: #cdd3ec;
    margin-bottom: 2px; cursor: pointer; font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.is-active { background: var(--indigo); color: #fff; box-shadow: 0 6px 16px rgba(79,70,229,.4); }
.nav-item.is-disabled { color: #5b658f; cursor: default; }
.nav-item.is-disabled:hover { background: transparent; color: #5b658f; }
.nav-ico { width: 18px; text-align: center; opacity: .9; }
.soon {
    margin-left: auto; font-size: 9px; background: rgba(255,255,255,.08);
    color: #8b94c0; padding: 1px 6px; border-radius: 20px;
}

/* Main */
.main { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 28px; background: #fff; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
}
.page-title { font-size: 20px; margin: 0; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.avatar {
    width: 38px; height: 38px; border-radius: 50%; background: var(--indigo-50);
    color: var(--indigo); display: grid; place-items: center; font-weight: 700;
}
.content { padding: 26px 28px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 16px; border-radius: 10px; font-weight: 600; cursor: pointer;
    border: 1px solid transparent; font-size: 14px;
}
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-600); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Cards */
.card {
    background: #fff; border: 1px solid var(--line); border-radius: 16px;
    padding: 20px; box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.grid { display: grid; gap: 18px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 22px; }
.kpi .kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 26px; font-weight: 800; margin-top: 6px; }
.kpi .kpi-ico {
    width: 40px; height: 40px; border-radius: 10px; background: var(--indigo-50);
    color: var(--indigo); display: grid; place-items: center; font-size: 18px; margin-bottom: 10px;
}

/* Table */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.search { flex: 1; max-width: 420px; }
.input, .select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line);
    border-radius: 10px; font-size: 14px; background: #fff;
}
.input:focus, .select:focus { outline: 2px solid var(--indigo-50); border-color: var(--indigo); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #fafbff; }
.badge {
    display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600;
    background: var(--indigo-50); color: var(--indigo-600);
}
.muted { color: var(--muted); }
.empty { text-align: center; padding: 40px; color: var(--muted); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field .req { color: var(--red); }
.section-title { font-weight: 700; margin: 22px 0 4px; font-size: 15px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-weight: 500; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* Pagination */
.pager { display: flex; gap: 6px; justify-content: flex-end; margin-top: 16px; }
.pager a, .pager span {
    padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
}
.pager .current { background: var(--indigo); color: #fff; border-color: var(--indigo); }

/* Detail */
.detail-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 30px; }
.detail-grid .row .k { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.detail-grid .row .v { font-weight: 600; margin-top: 2px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }

@media (max-width: 880px) {
    .sidebar { display: none; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
}

/* ===== Dashboard fiel ao mockup ===== */
.nav-badge { margin-left:auto; background:#22c55e; color:#fff; font-size:10px; font-weight:700; padding:1px 7px; border-radius:20px; }
.sidebar-foot { margin-top:18px; border-top:1px solid rgba(255,255,255,.08); padding-top:10px; }

.topbar-right { display:flex; align-items:center; gap:12px; }
.ic-btn { width:38px; height:38px; border-radius:10px; background:#fff; border:1px solid var(--line); display:grid; place-items:center; font-size:16px; cursor:pointer; position:relative; color:var(--ink); }
.ic-badge { position:absolute; top:-5px; right:-5px; background:#dc2626; color:#fff; font-size:10px; font-weight:700; min-width:16px; height:16px; border-radius:10px; display:grid; place-items:center; padding:0 3px; }
.user-chip { display:flex; align-items:center; gap:10px; }
.user-meta { display:flex; flex-direction:column; line-height:1.1; }
.user-meta strong { font-size:13px; }
.user-meta span { font-size:11px; color:var(--muted); }

.dash-topbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:18px; }
.act-row { display:flex; align-items:center; gap:12px; padding:10px 0; border-bottom:1px solid var(--line); font-size:13px; }
.act-row:last-child { border-bottom:0; }
.act-ico { width:30px; height:30px; border-radius:8px; background:var(--indigo-50); color:var(--indigo); display:grid; place-items:center; flex-shrink:0; }
.act-text { flex:1; } .act-when { font-size:12px; white-space:nowrap; }
.dash-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:22px; flex-wrap:wrap; gap:14px; }
.greet { font-size:24px; margin:0; font-weight:800; }
.dash-header-right { display:flex; align-items:center; gap:12px; }
.date-pill { background:#fff; border:1px solid var(--line); border-radius:10px; padding:9px 14px; font-size:13px; font-weight:600; }

.kpi-row { display:grid; grid-template-columns:repeat(6, 1fr); gap:16px; margin-bottom:18px; }
.kpi2 { padding:16px; }
.kpi2-ico { width:38px; height:38px; border-radius:10px; display:grid; place-items:center; font-size:16px; margin-bottom:10px; }
.kpi2-ico.green { background:#ecfdf5; color:#16a34a; } .kpi2-ico.blue { background:#eff6ff; color:#2563eb; }
.kpi2-ico.red { background:#fef2f2; color:#dc2626; } .kpi2-ico.amber { background:#fffbeb; color:#d97706; } .kpi2-ico.indigo { background:var(--indigo-50); color:var(--indigo); }
.kpi2-label { font-size:10px; color:var(--muted); letter-spacing:.04em; font-weight:600; }
.kpi2-value { font-size:22px; font-weight:800; margin:4px 0 6px; }
.kpi-delta { font-size:12px; font-weight:600; }
.kpi-delta.up { color:#16a34a; } .kpi-delta.down { color:#dc2626; }
.kpi-delta .muted { font-weight:400; }

.dash-grid-3 { display:grid; grid-template-columns:repeat(3,1fr); gap:18px; margin-bottom:18px; align-items:stretch; }
.dash-grid-3 > .card { display:flex; flex-direction:column; min-height:340px; }
.chart-box { position:relative; height:240px; flex:1 1 auto; }
.chart-box canvas { max-height:100%; }
.card-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:14px; }
.card-head h3 { margin:0; font-size:16px; }
.pill-soft { background:#f1f5f9; color:var(--muted); border-radius:8px; padding:5px 10px; font-size:12px; }
.link { color:var(--indigo); font-size:13px; font-weight:600; }

.at-row { display:flex; align-items:center; gap:12px; padding:11px 0; border-bottom:1px solid var(--line); }
.at-ico { width:34px; height:34px; border-radius:9px; display:grid; place-items:center; font-size:15px; }
.at-ico.blue{background:#eff6ff;color:#2563eb;} .at-ico.green{background:#ecfdf5;color:#16a34a;} .at-ico.amber{background:#fffbeb;color:#d97706;} .at-ico.indigo{background:var(--indigo-50);color:var(--indigo);}
.at-lbl { flex:1; } .at-val { font-size:18px; }
.at-row.total { border-bottom:0; } .at-row.total .at-val { color:var(--indigo); }

.next-row { display:flex; align-items:center; gap:12px; padding:9px 0; border-bottom:1px solid var(--line); }
.next-time { font-weight:700; width:46px; } .next-info { flex:1; display:flex; flex-direction:column; }
.next-info span { font-size:12px; }
.badge2 { font-size:11px; font-weight:700; padding:3px 9px; border-radius:20px; }
.badge-wait { background:#eff6ff; color:#2563eb; } .badge-conf { background:#ecfdf5; color:#047857; } .badge-prog { background:#fef9c3; color:#a16207; } .badge-red { background:#fef2f2; color:#dc2626; }

.donut-wrap { max-height:200px; }
.bar-row { display:flex; align-items:center; gap:10px; margin:9px 0; }
.bar-lbl { width:110px; font-size:13px; } .bar-track { flex:1; height:8px; background:#eef2f7; border-radius:6px; overflow:hidden; }
.bar-fill { height:100%; background:var(--indigo); border-radius:6px; } .bar-pct { width:38px; text-align:right; font-size:13px; font-weight:600; }

.flux-row { display:flex; justify-content:space-between; margin-bottom:14px; }
.flux-val { font-size:18px; font-weight:800; } .flux-val.green{color:#16a34a;} .flux-val.red{color:#dc2626;} .flux-val.blue{color:#2563eb;}
.flux-bar { height:10px; border-radius:6px; overflow:hidden; display:flex; background:#eef2f7; }
.wa-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:12px; }
.wa-box { background:#eff6ff; border-radius:12px; padding:14px; text-align:center; }
.wa-box strong { display:block; font-size:24px; margin-top:4px; } .wa-lbl { font-size:12px; color:var(--muted); }
.wa-box.amber{background:#fffbeb;} .wa-box.purple{background:#faf5ff;} .wa-box.green{background:#ecfdf5;}
.alert-row { display:flex; align-items:center; gap:10px; padding:11px 0; border-bottom:1px solid var(--line); font-size:13px; }
.alert-row .link { margin-left:auto; }
.alert-ico { width:30px; height:30px; border-radius:8px; display:grid; place-items:center; }
.alert-ico.amber{background:#fffbeb;color:#d97706;} .alert-ico.green{background:#ecfdf5;color:#16a34a;}

@media (max-width: 1200px) { .kpi-row { grid-template-columns:repeat(3,1fr); } .dash-grid-3 { grid-template-columns:1fr; } }

/* ===== Agenda fiel ao mockup ===== */
.ag-head { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; margin-bottom:16px; flex-wrap:wrap; }
.ag-controls { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.view-toggle { display:flex; background:#eef2f7; border-radius:10px; padding:3px; }
.view-toggle .vt-on { background:var(--indigo); color:#fff; border-radius:8px; padding:6px 14px; font-weight:600; font-size:13px; }
.view-toggle .vt { padding:6px 14px; font-size:13px; color:var(--muted); }
.ag-filters { display:grid; grid-template-columns:repeat(5,1fr); gap:12px; margin-bottom:16px; }
.ag-filters .field label { font-size:11px; }

.ag-layout { display:grid; grid-template-columns: 1fr 360px; gap:18px; align-items:start; }
.ag-layout.solo { grid-template-columns: 1fr; }
.ag-daybar { text-align:center; padding:12px; font-weight:700; border-bottom:1px solid var(--line); background:#fafbff; }
.ag-grid { display:grid; grid-template-columns: 72px 1fr; }
.ag-time { padding:14px 10px; color:var(--muted); font-size:13px; border-bottom:1px solid var(--line); border-right:1px solid var(--line); }
.ag-slot { display:flex; align-items:center; gap:12px; padding:10px 14px; border-bottom:1px solid var(--line); border-left:4px solid #cbd5e1; cursor:pointer; text-decoration:none; color:var(--ink); }
.ag-slot:hover { background:#fafbff; }
.ag-slot.is-sel { box-shadow: inset 3px 0 0 var(--indigo); background:#f5f6ff; }
.ag-range { width:96px; font-size:12px; color:var(--muted); font-weight:600; }
.ag-pt { flex:1; display:flex; flex-direction:column; } .ag-pt small { font-size:12px; }
.ag-slot.sc-green { border-left-color:#16a34a; background:#f6fef9; }
.ag-slot.sc-amber { border-left-color:#f59e0b; background:#fffdf5; }
.ag-slot.sc-indigo { border-left-color:#4f46e5; background:#f6f6ff; }
.ag-slot.sc-gray { border-left-color:#94a3b8; }
.ag-slot.sc-red { border-left-color:#dc2626; background:#fef6f6; }
.ag-slot.sc-brown { border-left-color:#92400e; background:#fbf7f2; }
.sb-sc-green{background:#ecfdf5;color:#047857;} .sb-sc-amber{background:#fffbeb;color:#b45309;}
.sb-sc-indigo{background:#eef2ff;color:#4338ca;} .sb-sc-gray{background:#f1f5f9;color:#475569;}
.sb-sc-red{background:#fef2f2;color:#b91c1c;} .sb-sc-brown{background:#fdf3ec;color:#92400e;}

.ag-legend { display:flex; flex-wrap:wrap; gap:18px; padding:14px; border-top:1px solid var(--line); }
.ag-legend span { display:flex; align-items:center; gap:7px; font-size:12px; color:var(--muted); }
.ag-legend i { width:10px; height:10px; border-radius:50%; display:inline-block; }

.ag-detail { position:sticky; top:90px; }
.ag-detail-head { display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:12px; }
.ag-tabs { display:flex; gap:14px; border-bottom:1px solid var(--line); padding-bottom:8px; margin-bottom:14px; font-size:13px; }
.ag-tabs .on { color:var(--indigo); font-weight:700; border-bottom:2px solid var(--indigo); padding-bottom:8px; margin-bottom:-9px; }
.ag-fields > div { padding:8px 0; border-bottom:1px solid var(--line); }
.ag-fields .k { font-size:11px; color:var(--muted); text-transform:uppercase; } .ag-fields .v { font-weight:600; margin-top:2px; }
.ag-contact { margin:14px 0; padding:12px; background:#f8fafc; border-radius:10px; font-size:13px; display:flex; flex-direction:column; gap:6px; }
.ag-contact .k { font-weight:700; color:var(--muted); text-transform:uppercase; font-size:11px; }
.ag-actions { display:flex; flex-direction:column; gap:8px; margin-top:14px; }
.ag-actions form { margin:0; } .ag-actions .btn { width:100%; justify-content:center; }

/* Contato + observações + botões do painel */
.ag-contact-row { display:flex; align-items:center; justify-content:space-between; }
.wa-mini { width:28px; height:28px; border-radius:8px; background:#ecfdf5; color:#16a34a; display:grid; place-items:center; }
.ag-obs { margin:14px 0; }
.ag-obs-head { display:flex; justify-content:space-between; align-items:center; }
.ag-obs .k { font-weight:700; color:var(--muted); text-transform:uppercase; font-size:11px; }
.ag-btn-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:8px; }
.ag-btn-grid form { margin:0; }
.btn-ag { display:flex; align-items:center; justify-content:center; gap:6px; width:100%; padding:11px 10px; border-radius:12px; font-weight:600; font-size:13px; cursor:pointer; border:1px solid transparent; text-decoration:none; }
.btn-ag[disabled] { opacity:.45; cursor:not-allowed; }
.btn-ag.green { background:#ecfdf5; color:#047857; border-color:#a7f3d0; }
.btn-ag.blue  { background:#eff6ff; color:#1d4ed8; border-color:#bfdbfe; }
.btn-ag.amber { background:#fffbeb; color:#b45309; border-color:#fde68a; }
.btn-ag.red   { background:#fef2f2; color:#b91c1c; border-color:#fecaca; }
.btn-ag.brown { background:#fef3c7; color:#92400e; border-color:#fde68a; }
.btn-ag.full  { width:100%; margin-top:10px; background:#16a34a; color:#fff; border-color:#16a34a; }
.ag-resched { margin-top:10px; }
.ag-resched summary { text-align:center; }
.ag-resched summary::-webkit-details-marker { display:none; }

@media (max-width: 1100px) { .ag-layout { grid-template-columns:1fr; } .ag-filters { grid-template-columns:repeat(2,1fr); } }

/* ===== CRM Kanban ===== */
.kb-board { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; }
.kb-col { background:#f4f5fa; border:1px solid var(--line); border-radius:14px; padding:10px; min-height:120px; }
.kb-col-head { font-weight:700; font-size:13px; padding:4px 6px 10px; display:flex; justify-content:space-between; align-items:center; }
.kb-count { background:var(--indigo-50); color:var(--indigo); border-radius:20px; font-size:11px; padding:1px 8px; }
.kb-card { background:#fff; border:1px solid var(--line); border-radius:10px; padding:10px; margin-bottom:8px; box-shadow:0 1px 2px rgba(16,24,40,.04); }
.kb-actions { display:flex; gap:6px; margin-top:8px; flex-wrap:wrap; }
.kb-actions form { margin:0; }
@media (max-width: 1100px) { .kb-board { grid-template-columns:repeat(2,1fr); } }

/* ===== Modo escuro (toggle) ===== */
body.dark { --bg:#0b1020; --ink:#e5e9f5; --muted:#94a3b8; --line:#23304d; }
body.dark .topbar, body.dark .card, body.dark .ic-btn, body.dark .input, body.dark .select, body.dark .date-pill { background:#131a2e; color:var(--ink); border-color:var(--line); }
body.dark .ag-daybar, body.dark .ag-slot:hover, body.dark tr:hover td { background:#0f1730; }
body.dark .view-toggle, body.dark .pill-soft { background:#1b2643; }
body.dark .ag-contact { background:#0f1730; }

/* ===== Onda 19 — Construtor de automações visual ===== */
.btn-danger { background:#fef2f2; color:#dc2626; border-color:#fecaca; }
.btn-danger:hover { background:#fee2e2; }
.flow-tag { display:inline-block; font-size:11px; font-weight:800; letter-spacing:.04em; padding:2px 8px; border-radius:6px; }
.flow-se { background:#eef2ff; color:#4f46e5; } .flow-e { background:#fffbeb; color:#b45309; } .flow-entao { background:#ecfdf5; color:#047857; }
.builder-block { background:#f8fafc; border:1px solid var(--line); border-radius:12px; padding:14px; margin-bottom:14px; font-size:13px; }
.cond-row { display:flex; gap:6px; margin-bottom:6px; align-items:center; }
.cond-row .select { flex:1; } .cond-row .cond-val { flex:1; }
.cond-row .rm { padding:6px 10px; line-height:1; }
.chip-row { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.chip { background:#eef2ff; color:#4f46e5; border-radius:6px; padding:3px 9px; font-size:12px; font-weight:600; cursor:pointer; user-select:none; }
.chip:hover { background:#e0e7ff; }
.auto-rule { border:1px solid var(--line); border-radius:12px; padding:14px; margin-bottom:12px; }
.auto-rule.is-off { opacity:.6; }
.auto-rule-top { display:flex; justify-content:space-between; align-items:center; margin-bottom:8px; }
.auto-flow { font-size:13px; line-height:1.9; color:var(--ink); }
.auto-flow code { background:#f1f5f9; padding:1px 6px; border-radius:5px; font-size:12px; }
.auto-rule-foot { display:flex; justify-content:space-between; align-items:center; margin-top:12px; padding-top:10px; border-top:1px solid var(--line); }
body.dark .builder-block, body.dark .auto-flow code { background:#0f1730; }
body.dark .chip { background:#1b2643; color:#a5b4fc; }

/* ===== Régua alfabética (lista de pacientes) ===== */
.az-ruler {
    display:flex; flex-wrap:wrap; gap:5px; align-items:center;
    margin:16px 0 10px; padding:8px; border:1px solid var(--line);
    border-radius:12px; background:#f8fafc;
}
.az {
    min-width:30px; height:30px; padding:0 9px; display:inline-flex; align-items:center; justify-content:center;
    border-radius:8px; font-size:13px; font-weight:600; color:var(--muted);
    background:transparent; transition:background .12s, color .12s, box-shadow .12s; line-height:1;
}
.az:hover { background:#fff; color:var(--indigo); box-shadow:0 1px 3px rgba(16,24,40,.08); }
.az.is-on { background:var(--indigo); color:#fff; box-shadow:0 4px 10px rgba(79,70,229,.30); }
.az:first-child { font-weight:700; padding:0 12px; } /* "Todos" */
.az-sep { width:1px; align-self:stretch; background:var(--line); margin:2px 4px; }
body.dark .az-ruler { background:#0f1730; }
body.dark .az:hover { background:#1b2643; color:#a5b4fc; }

/* ===== Perfil do paciente — ações verticais ===== */
.pt-actions { display:flex; flex-direction:column; gap:8px; }
.pt-actions .btn { width:100%; justify-content:flex-start; }

/* ===== Camada global de refinamento (acessibilidade + polimento) ===== */
/* Foco visível e consistente em TODOS os elementos interativos (WCAG). */
a:focus-visible, button:focus-visible, .btn:focus-visible, .nav-item:focus-visible,
.input:focus-visible, .select:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible, summary:focus-visible {
    outline: 3px solid rgba(79,70,229,.45);
    outline-offset: 2px;
    border-radius: 8px;
}
button { font-family: inherit; }
/* Transições suaves e consistentes (150–200ms). */
.btn, .nav-item, .ic-btn, .card, .az, .badge2 { transition: background .16s ease, color .16s ease, box-shadow .16s ease, transform .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
tr:hover td { transition: background .12s ease; }

/* Skip link (teclado/leitor de tela). */
.skip-link { position:absolute; left:-9999px; top:0; z-index:1000; background:var(--indigo); color:#fff; padding:10px 16px; border-radius:0 0 10px 0; font-weight:600; }
.skip-link:focus { left:0; }

/* Cursor de ponteiro em tudo que é clicável. */
.nav-item, .ic-btn, summary, .az, [role="button"] { cursor: pointer; }

/* Respeita preferência de movimento reduzido. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Centralização de ícones SVG nos contêineres (nav, topbar, KPIs). */
.nav-ico { display:inline-grid; place-items:center; width:20px; height:20px; opacity:.95; }
.nav-item.is-active .nav-ico { opacity:1; }
.ic-btn svg { display:block; }
.kpi2-ico svg, .at-ico svg, .act-ico svg, .alert-ico svg, .f-ic svg, .fic svg { display:block; }

/* ===== Navegação mobile (drawer) ===== */
.nav-toggle { display:none; }
.nav-scrim { display:none; }
@media (max-width: 880px) {
    .nav-toggle {
        display:grid; place-items:center; position:fixed; top:12px; left:12px; z-index:80;
        width:44px; height:44px; border-radius:11px; background:#fff; border:1px solid var(--line);
        color:var(--ink); box-shadow:0 4px 14px rgba(16,24,40,.12); cursor:pointer;
    }
    /* Sidebar vira gaveta deslizante. */
    .sidebar {
        display:flex !important; flex-direction:column; position:fixed; top:0; left:0; bottom:0;
        width:264px; transform:translateX(-100%); transition:transform .22s ease; z-index:90;
    }
    body.nav-open .sidebar { transform:none; box-shadow:0 0 60px rgba(0,0,0,.4); }
    body.nav-open .nav-scrim { display:block; position:fixed; inset:0; background:rgba(8,12,28,.5); z-index:85; }
    /* Espaço para o botão não cobrir o título. */
    .topbar { padding-left:68px; }
    .dash-topbar { padding-left:56px; }
    .content { padding:18px 16px; }
}

/* ===== Modo escuro — cobertura ampla (todas as telas) ===== */
body.dark { background:#0b1020; color:#e5e9f5; }
body.dark .topbar, body.dark .dash-topbar { background:#0b1020; }
body.dark .topbar { border-color:#23304d; }
body.dark .card, body.dark .ic-btn, body.dark .input, body.dark .select,
body.dark textarea, body.dark .date-pill, body.dark .pager a, body.dark .pager span,
body.dark .btn-ghost { background:#131a2e; color:#e5e9f5; border-color:#23304d; }
body.dark .btn-ghost:hover { background:#1b2643; }
body.dark .page-title, body.dark .page-head h2, body.dark .page-head h1,
body.dark h2, body.dark h3, body.dark h4, body.dark .kpi2-value, body.dark .at-val,
body.dark .flux-val, body.dark strong { color:#f1f5f9; }
body.dark th { color:#94a3b8; }
body.dark th, body.dark td { border-color:#23304d; }
body.dark tr:hover td { background:#0f1730; }
body.dark .muted, body.dark .nav-group-title, body.dark .detail-grid .row .k { color:#94a3b8; }
body.dark .pill-soft, body.dark .badge { background:#1b2643; color:#a5b4fc; }
body.dark .empty { color:#94a3b8; }
body.dark .nav-badge { color:#fff; }
body.dark .bar-track { background:#1b2643; }
body.dark .auto-rule, body.dark .builder-block, body.dark .cond-row .select { border-color:#23304d; }
body.dark .chip { background:#1b2643; color:#a5b4fc; }
body.dark .nav-toggle { background:#131a2e; color:#e5e9f5; border-color:#23304d; }

/* ===== Alvos de toque / dados (medium) ===== */
@media (max-width: 880px) { .btn-sm { min-height:40px; } .btn { min-height:44px; } }
.kpi2-value, .at-val, .flux-val, .mk-kpi .v, td .badge2 { font-variant-numeric: tabular-nums; }

/* Legenda do fluxo de caixa (dashboard). */
.flux-legend { display:flex; justify-content:center; gap:24px; margin-top:12px; font-size:13px; color:var(--muted); flex-wrap:wrap; }
.flux-legend i { display:inline-block; width:11px; height:11px; border-radius:3px; vertical-align:middle; margin-right:6px; }
.flux-legend strong { color:var(--ink); margin-left:4px; }
body.dark .flux-legend strong { color:#f1f5f9; }

/* ===== Agenda — visão Semana ===== */
.ag-week { display:grid; grid-template-columns:repeat(7,1fr); }
.ag-wcol { border-right:1px solid var(--line); min-height:380px; }
.ag-wcol:last-child { border-right:0; }
.ag-wcol.is-today { background:#fafbff; }
.ag-whead { display:flex; flex-direction:column; align-items:center; gap:1px; padding:10px 4px; border-bottom:1px solid var(--line); color:var(--ink); position:relative; }
.ag-whead:hover { background:var(--indigo-50); }
.ag-whead .wd { font-size:11px; text-transform:uppercase; color:var(--muted); letter-spacing:.04em; }
.ag-whead .wn { font-size:18px; font-weight:800; }
.ag-wcol.is-today .ag-whead .wn { color:var(--indigo); }
.ag-whead .wc { position:absolute; top:8px; right:8px; background:var(--indigo); color:#fff; font-size:10px; font-weight:700; min-width:16px; height:16px; border-radius:9px; display:grid; place-items:center; padding:0 4px; }
.ag-wbody { padding:6px; display:flex; flex-direction:column; gap:5px; }
.ag-wempty { text-align:center; color:#cbd5e1; padding:10px 0; font-size:12px; }
.ag-wslot { display:block; border-radius:8px; padding:6px 8px; font-size:11px; line-height:1.35; border-left:3px solid var(--indigo); background:#fff; box-shadow:0 1px 2px rgba(16,24,40,.05); }
.ag-wslot strong { font-variant-numeric:tabular-nums; }
.ag-wslot small { display:block; color:var(--muted); }
.ag-wslot.is-sel { outline:2px solid var(--indigo); }
.ag-wslot.sc-green { border-left-color:#16a34a; } .ag-wslot.sc-amber { border-left-color:#f59e0b; }
.ag-wslot.sc-indigo { border-left-color:#4f46e5; } .ag-wslot.sc-gray { border-left-color:#94a3b8; }
.ag-wslot.sc-red { border-left-color:#dc2626; } .ag-wslot.sc-brown { border-left-color:#92400e; }
body.dark .ag-wcol { border-color:#23304d; } body.dark .ag-wcol.is-today { background:#0f1730; }
body.dark .ag-whead, body.dark .ag-wslot { background:#131a2e; color:#e5e9f5; border-color:#23304d; }
@media (max-width:880px){ .ag-week { grid-template-columns:repeat(2,1fr); } .ag-wcol { min-height:auto; } }

/* ============================================================
   Layer de polimento global (v2) — melhora todas as páginas
   de uma vez: tipografia, formulários, botões, tabelas, badges.
   Aditivo e de baixa especificidade; não quebra telas existentes.
   ============================================================ */

/* Tipografia + render */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; line-height: 1.55; text-rendering: optimizeLegibility; }
h1, h2, h3, h4 { color: var(--ink); line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 22px; } h3 { font-size: 17px; }
::selection { background: rgba(79,70,229,.18); }

/* Links com contraste e affordance */
a.link, .card a:not(.btn):not(.badge):not(.az) { color: var(--indigo-600); text-decoration: none; }
a.link:hover, .card a:not(.btn):not(.badge):not(.az):hover { text-decoration: underline; }

/* Formulários — 16px evita zoom automático no iOS; estados claros */
.input, .select, textarea.input, input[type="date"], input[type="email"], input[type="tel"], input[type="number"], input[type="password"], input[type="search"] {
    font-size: 16px; min-height: 42px; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:hover, .select:hover { border-color: #c7cbe0; }
.input:focus, .select:focus, textarea.input:focus { box-shadow: 0 0 0 3px rgba(79,70,229,.14); border-color: var(--indigo); outline: none; }
.input[aria-invalid="true"], .input.is-error { border-color: var(--red); }
.field label { display:inline-block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 5px; }
::placeholder { color: #9aa3b8; }

/* Botões — alvo de toque, estados de press/disabled, sombra sutil */
.btn { min-height: 40px; transition: background .15s ease, box-shadow .15s ease, transform .06s ease, border-color .15s ease; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--indigo); color: #fff; box-shadow: 0 1px 2px rgba(79,70,229,.25); }
.btn-primary:hover { background: var(--indigo-600); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #c7cbe0; background: #fafbff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn:disabled, .btn[disabled], button:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Cards — transição suave; cabeçalho padronizado */
.card { transition: box-shadow .18s ease, border-color .18s ease; }
.card-head { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom: 12px; }

/* Tabelas — cabeçalho destacado, zebra, números tabulares */
thead th { background: #f8f9fe; }
tbody tr:nth-child(even) td { background: #fcfcff; }
tbody tr:hover td { background: #f3f4ff; }
td { font-variant-numeric: tabular-nums; }

/* Badges consistentes */
.badge { display:inline-flex; align-items:center; gap:4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.6; }

/* Empty state amigável */
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* Alerts com respiro */
.alert { border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; font-size: 14px; }

/* page-head — ritmo vertical */
.page-head { margin-bottom: 18px; }

/* KPIs / valores monetários — fonte tabular p/ não "dançar" */
.kpi-value, .kpi2-value, .flux-val { font-variant-numeric: tabular-nums; }

/* Scrollbar discreta */
* { scrollbar-width: thin; scrollbar-color: #cbd2e6 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #cbd2e6; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }

/* Paridade dark do polimento */
body.dark h1, body.dark h2, body.dark h3, body.dark h4 { color: var(--ink); }
body.dark thead th { background: #131a2e; }
body.dark tbody tr:nth-child(even) td { background: #0e1426; }
body.dark .btn-ghost { background:#131a2e; color:var(--ink); }
body.dark .btn-ghost:hover { background:#1b2643; border-color:#2c3a5e; }
body.dark .input:hover, body.dark .select:hover { border-color:#2c3a5e; }
body.dark ::placeholder { color:#6b7694; }
body.dark * { scrollbar-color: #2c3a5e transparent; }
body.dark *::-webkit-scrollbar-thumb { background: #2c3a5e; }

/* Toque confortável no mobile: alvos mínimos 44px */
@media (max-width: 768px) {
    .btn, .ic-btn, .az, .nav-item { min-height: 44px; }
    .btn-sm { padding: 8px 12px; }
}
