/* ═══════════════════════════════════════════════════════════════
   OPTCORE — folha global
   Mesma família de tokens do OptPulse (oklch, Plus Jakarta Sans),
   para o ecossistema Opt parecer um produto só.
   Dark mode via classe .dark no <html> (js/tema.js).
═══════════════════════════════════════════════════════════════ */

:root {
    --background: oklch(0.9824 0.0013 286.3757);
    --foreground: oklch(0.3211 0 0);
    --card: oklch(1 0 0);
    --primary: oklch(0.6487 0.1538 150.3071);
    --primary-foreground: oklch(1 0 0);
    --secondary: oklch(0.6746 0.1414 261.3380);
    --muted: oklch(0.9500 0.0060 98.1033);
    --muted-foreground: oklch(0.5382 0 0);
    --destructive: oklch(0.6368 0.2078 25.3313);
    --aviso: oklch(0.7686 0.1647 70.0804);
    --border: oklch(0.8899 0 0);
    --sidebar: oklch(0.9700 0.0030 286.3757);
    --font-sans: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --radius: 0.5rem;
    --shadow: 0 1px 3px hsl(0 0% 0% / .08), 0 1px 2px -1px hsl(0 0% 0% / .08);
    --sidebar-largura: 250px;
    --topo-altura: 56px;
}

.dark {
    --background: oklch(0.2303 0.0125 264.2926);
    --foreground: oklch(0.9219 0 0);
    --card: oklch(0.2810 0.0100 250);
    --muted: oklch(0.3300 0.0050 250);
    --muted-foreground: oklch(0.7155 0 0);
    --border: oklch(0.3800 0 0);
    --sidebar: oklch(0.2550 0.0110 260);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: var(--font-sans);
    font-size: 14px;
    background: var(--background);
    color: var(--foreground);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h1:focus { outline: none; } /* FocusOnNavigate foca o h1 para leitores de tela — sem contorno visual */
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code, .opt-mono { font-family: var(--font-mono); font-size: .9em; font-variant-numeric: tabular-nums; }

/* ── Layout ─────────────────────────────────────────────────── */
.opt-layout { display: flex; min-height: 100vh; }

.opt-sidebar {
    width: var(--sidebar-largura);
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: width 200ms ease;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.opt-sidebar.recolhida { width: 64px; }
.opt-sidebar.recolhida .opt-nav-rotulo,
.opt-sidebar.recolhida .opt-nav-secao,
.opt-sidebar.recolhida .opt-logo { display: none; }

.opt-sidebar-cabecalho {
    height: var(--topo-altura);
    display: flex; align-items: center; gap: .6rem;
    padding: 0 1.1rem;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
}
.opt-logo-icone { width: 26px; height: 26px; flex-shrink: 0; }
.opt-logo { font-weight: 700; font-size: 1.2rem; color: var(--foreground); }
.opt-logo span, .opt-login-logo span { color: var(--primary); }

.opt-nav { padding: .75rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.opt-nav-secao {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--muted-foreground); padding: 1rem .6rem .35rem;
}
.opt-nav-item {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .6rem; border-radius: var(--radius);
    color: var(--foreground); text-decoration: none; white-space: nowrap;
}
.opt-nav-item:hover { background: var(--muted); }
.opt-nav-item.active { background: color-mix(in oklch, var(--primary) 14%, transparent); color: var(--primary); font-weight: 600; }
.opt-nav-icone {
    width: 18px; height: 18px; flex-shrink: 0;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.opt-principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.opt-topo {
    height: var(--topo-altura);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    position: sticky; top: 0; z-index: 10;
}
.opt-topo-direita { display: flex; align-items: center; gap: .9rem; }
.opt-topo form { margin: 0; }
.opt-usuario { display: flex; flex-direction: column; line-height: 1.15; text-align: right; }
.opt-usuario small { color: var(--muted-foreground); font-size: .75rem; }
.opt-conteudo { padding: 1.5rem; max-width: 1400px; width: 100%; }

.opt-cabecalho-pagina {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
    margin-bottom: 1.25rem;
}
.opt-subtitulo { color: var(--muted-foreground); margin: .3rem 0 0; max-width: 75ch; }
.opt-cabecalho-pagina > select { width: auto; }

/* ── Botões ─────────────────────────────────────────────────── */
.opt-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .55rem 1rem;
    border: 1px solid transparent; border-radius: var(--radius);
    background: var(--primary); color: var(--primary-foreground);
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: filter 150ms ease, background 150ms ease;
}
.opt-btn:hover { filter: brightness(1.06); }
.opt-btn:disabled { opacity: .55; cursor: not-allowed; }
.opt-btn-secundario { background: var(--card); color: var(--foreground); border-color: var(--border); }
.opt-btn-fantasma { background: transparent; color: var(--foreground); }
.opt-btn-fantasma:hover { background: var(--muted); filter: none; }
.opt-btn-perigo { background: transparent; color: var(--destructive); }
.opt-btn-perigo:hover { background: color-mix(in oklch, var(--destructive) 10%, transparent); filter: none; }
.opt-btn-pequeno { padding: .3rem .6rem; font-size: .8rem; font-weight: 500; }
.opt-btn-bloco { width: 100%; margin-top: .5rem; }
.opt-btn-icone {
    background: transparent; border: 0; color: var(--foreground);
    font-size: 1.15rem; width: 34px; height: 34px; border-radius: var(--radius); cursor: pointer;
    display: inline-grid; place-items: center;
}
.opt-btn-icone:hover { background: var(--muted); }

/* ── Formulários ────────────────────────────────────────────── */
.opt-campo { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .9rem; flex: 1; }
.opt-campo > span { font-size: .8rem; font-weight: 600; color: var(--muted-foreground); }
input:not([type=checkbox]):not([type=radio]), select, textarea {
    font: inherit; color: var(--foreground); background: var(--card);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in oklch, var(--primary) 45%, transparent); outline-offset: 1px; }
input:disabled { background: var(--muted); color: var(--muted-foreground); }
.opt-check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; white-space: nowrap; }
.opt-linha { display: flex; gap: .75rem; }
.opt-flex-1 { flex: 1; } .opt-flex-3 { flex: 3; }

.opt-filtros { display: flex; gap: .6rem; align-items: center; margin-bottom: .9rem; flex-wrap: wrap; }
.opt-filtros select { width: auto; }
.opt-busca { max-width: 380px; }

/* ── Tabelas ────────────────────────────────────────────────── */
.opt-tabela-container {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow);
}
.opt-tabela { width: 100%; border-collapse: collapse; }
.opt-tabela th {
    text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted-foreground); font-weight: 600;
    padding: .7rem .75rem; border-bottom: 1px solid var(--border); background: var(--muted);
}
.opt-tabela td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.opt-tabela tbody tr:hover { background: color-mix(in oklch, var(--muted) 60%, transparent); }
.opt-tabela tbody tr:last-child td { border-bottom: 0; }
.opt-tabela tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.opt-tabela td small { display: block; }
.opt-dir { text-align: right !important; }
.opt-acoes { text-align: right; white-space: nowrap; }
.opt-inativo td { opacity: .5; }
.opt-tabela-vazia { text-align: center; color: var(--muted-foreground); padding: 2rem; margin: 0; }
.opt-rodape-tabela { color: var(--muted-foreground); font-size: .8rem; margin: .5rem 0 0; }
.opt-secundario { color: var(--muted-foreground); }
.opt-arvore .opt-nivel-1 td { background: color-mix(in oklch, var(--muted) 55%, transparent); }
/* recuo por nível em classe (e não em style inline): em pt-BR, 2.25 viraria "2,25rem" e o CSS ignoraria */
.opt-arvore .opt-nivel-2 .opt-recuo { padding-left: 2rem; }
.opt-arvore .opt-nivel-3 .opt-recuo { padding-left: 3.5rem; }
.opt-arvore .opt-nivel-4 .opt-recuo { padding-left: 5rem; }

/* ── Selos ──────────────────────────────────────────────────── */
.opt-selo {
    display: inline-block; padding: .12rem .5rem; border-radius: 999px;
    font-size: .72rem; font-weight: 600; background: var(--muted); color: var(--foreground);
    margin-right: .25rem;
}
.opt-selo-primario, .opt-natureza-receita, .opt-status-ativo { background: color-mix(in oklch, var(--primary) 16%, transparent); color: var(--primary); }
.opt-selo-secundario { background: color-mix(in oklch, var(--secondary) 16%, transparent); color: var(--secondary); }
.opt-natureza-despesa, .opt-status-cancelado { background: color-mix(in oklch, var(--destructive) 14%, transparent); color: var(--destructive); }
.opt-status-suspenso { background: color-mix(in oklch, var(--aviso) 20%, transparent); color: oklch(0.55 0.13 70); }

/* ── Alertas ────────────────────────────────────────────────── */
.opt-alerta {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem;
    border: 1px solid; font-size: .9rem;
}
.opt-alerta-sucesso { background: color-mix(in oklch, var(--primary) 10%, transparent); border-color: color-mix(in oklch, var(--primary) 35%, transparent); }
.opt-alerta-erro { background: color-mix(in oklch, var(--destructive) 10%, transparent); border-color: color-mix(in oklch, var(--destructive) 35%, transparent); }
.opt-alerta-aviso { background: color-mix(in oklch, var(--aviso) 14%, transparent); border-color: color-mix(in oklch, var(--aviso) 45%, transparent); }
.opt-alerta-fechar { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: inherit; }

/* ── Cartões e KPIs ─────────────────────────────────────────── */
.opt-cartao {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.opt-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.opt-kpi {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .35rem;
    color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
a.opt-kpi:hover { border-color: var(--primary); }
.opt-kpi-rotulo { font-size: .78rem; color: var(--muted-foreground); font-weight: 600; }
.opt-kpi-valor { font-size: clamp(1.1rem, 1.5vw, 1.6rem); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt-positivo { color: var(--primary); }
.opt-lista { margin: 0 0 1rem; padding-left: 1.2rem; line-height: 1.7; }

.opt-ciclo { counter-reset: etapa; list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; }
.opt-ciclo li {
    counter-increment: etapa; border: 1px solid var(--border); border-radius: var(--radius);
    padding: .75rem .85rem; display: flex; flex-direction: column; gap: .2rem;
}
.opt-ciclo li::before { content: counter(etapa); font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.opt-ciclo span { color: var(--muted-foreground); font-size: .8rem; }

/* ── Painel lateral (drawer) ────────────────────────────────── */
.opt-painel-fundo { position: fixed; inset: 0; background: hsl(0 0% 0% / .35); z-index: 40; }
.opt-painel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
    background: var(--card); border-left: 1px solid var(--border); z-index: 50;
    display: flex; flex-direction: column; box-shadow: -8px 0 24px hsl(0 0% 0% / .12);
    animation: deslizar 180ms ease-out;
}
@keyframes deslizar { from { transform: translateX(30px); opacity: 0; } }
.opt-painel-cabecalho { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.opt-painel-cabecalho h2 { margin: 0; }
.opt-painel-corpo { padding: 1.25rem; overflow-y: auto; flex: 1; }
.opt-painel-acoes { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.25rem; }

/* ── Login / páginas vazias ─────────────────────────────────── */
.opt-vazio-layout, .opt-login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.opt-login-cartao {
    width: min(400px, 100%); background: var(--card); border: 1px solid var(--border);
    border-radius: calc(var(--radius) * 2); padding: 2rem; box-shadow: 0 10px 30px hsl(0 0% 0% / .08);
}
.opt-login-logo { font-size: 2rem; font-weight: 700; text-align: center; }
.opt-login-subtitulo { text-align: center; color: var(--muted-foreground); margin: .25rem 0 1.5rem; }
.opt-login-rodape { text-align: center; color: var(--muted-foreground); font-size: .75rem; margin: 1.5rem 0 0; }
.opt-vazio { text-align: center; padding: 4rem 1rem; }
.opt-vazio-icone { font-size: 2.5rem; }
.opt-vazio p { color: var(--muted-foreground); }
.opt-carregando { padding: 2rem; color: var(--muted-foreground); }

.opt-erro-circuito {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: var(--destructive); color: #fff; padding: .7rem 1.25rem;
}
.opt-erro-circuito a { color: #fff; font-weight: 700; }

/* ── F1: faturamento, ranking, importação ───────────────────── */
.opt-cartao-cabecalho { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .5rem; }
.opt-cartao-cabecalho h2 { margin: 0; }
.opt-cartao-cabecalho select, .opt-linha select { width: auto; }
.opt-negativo { color: var(--destructive); }
.opt-tabela-compacta td, .opt-tabela-compacta th { padding: .4rem .6rem; }
.opt-linha-total td { font-weight: 700; border-top: 2px solid var(--border); }
.opt-tabela-rolavel { max-height: 60vh; overflow-y: auto; }
.opt-tabela-rolavel thead th { position: sticky; top: 0; z-index: 1; }
.opt-lista-rolavel { max-height: 280px; overflow-y: auto; font-size: .8rem; }
.opt-input-curto { max-width: 130px; }
.opt-item { align-items: center; margin-bottom: .4rem; }
.opt-item select { flex: 1.2; } .opt-item input { flex: 1; }
.opt-total-painel { text-align: right; margin: .5rem 0 0; }
.opt-btn-perigo-cheio { background: var(--destructive); color: #fff; }
details.opt-cartao summary { cursor: pointer; }

.opt-ranking { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-direction: column; gap: .7rem; }
.opt-ranking li { display: flex; gap: .8rem; align-items: flex-start; }
.opt-ranking-pos {
    width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
    background: var(--muted); font-weight: 700; font-size: .85rem;
}
.opt-ranking li:nth-child(-n+3) .opt-ranking-pos { background: color-mix(in oklch, var(--primary) 18%, transparent); color: var(--primary); }
.opt-ranking-corpo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .25rem; }
.opt-ranking-topo { display: flex; align-items: center; gap: .4rem; }
.opt-ranking-valor { margin-left: auto; font-weight: 600; }
.opt-barra { height: 6px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.opt-barra > div { height: 100%; background: var(--primary); border-radius: 999px; }

.opt-seletor { list-style: none; padding: 0; margin: 0 0 1rem; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.opt-seletor li + li { border-top: 1px solid var(--border); }
.opt-seletor button { width: 100%; text-align: left; background: none; border: 0; padding: .55rem .7rem; font: inherit; color: inherit; cursor: pointer; }
.opt-seletor button:hover { background: var(--muted); }
.opt-seletor small { display: block; }

/* ── F2: financeiro ─────────────────────────────────────────── */
.opt-mes-titulo { min-width: 170px; text-align: center; text-transform: capitalize; }
.opt-kpi-destaque { border-color: var(--primary); background: color-mix(in oklch, var(--primary) 7%, var(--card)); }
.opt-col-barra { width: 28%; }
.opt-barra-negativa > div { background: var(--destructive); }
.opt-dre td, .opt-dre th { white-space: nowrap; font-size: .82rem; }
.opt-dre td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; min-width: 260px; }
.opt-dre .opt-nivel-1 td:first-child { background: color-mix(in oklch, var(--muted) 55%, var(--card)); }
.opt-recuo-dre-2 { padding-left: 1.6rem !important; }
.opt-recuo-dre-3 { padding-left: 2.8rem !important; }
.opt-linha-resultado td { font-weight: 700; font-size: .9rem; border-top: 2px solid var(--foreground); background: var(--muted); }

@media (max-width: 800px) {
    .opt-sidebar { width: 64px; }
    .opt-sidebar .opt-nav-rotulo, .opt-sidebar .opt-nav-secao, .opt-sidebar .opt-logo { display: none; }
    .opt-cabecalho-pagina { flex-direction: column; }
    .opt-conteudo { padding: 1rem; }
    .opt-usuario { display: none; }
}

/* ── F3 ─────────────────────────────────────────────────────────────── */
/* barra fixa de seleção (À faturar): aparece quando há tarefas marcadas */
.opt-barra-selecao {
    position: sticky; bottom: 1rem; z-index: 5;
    display: flex; align-items: center; justify-content: flex-end; gap: .75rem;
    margin-top: 1rem; padding: .75rem 1rem;
    background: var(--card); border: 1px solid var(--primary); border-radius: var(--radius);
    box-shadow: 0 6px 24px color-mix(in oklch, var(--foreground) 15%, transparent);
}
.opt-barra-selecao span { margin-right: auto; }
.opt-cronograma { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .35rem; margin-top: .6rem; }
.opt-parcela { border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px); padding: .3rem .45rem; font-size: .75rem; line-height: 1.3; }
.opt-parcela strong { display: block; font-family: var(--font-mono); font-size: .8rem; }
.opt-parcela-paga { background: color-mix(in oklch, var(--primary) 10%, transparent); color: var(--muted-foreground); }
.opt-parcela-gerada { border-color: var(--primary); }
.opt-parcela-marcador { background: var(--muted); color: var(--muted-foreground); font-style: italic; }
.opt-parcela-atual { outline: 2px solid color-mix(in oklch, var(--aviso) 70%, transparent); }
.opt-legenda { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .75rem; color: var(--muted-foreground); }
.opt-check-quebra { white-space: normal; align-items: flex-start; }

/* ── F4 Placar ──────────────────────────────────────────────────────── */
.opt-progresso { position: relative; height: 8px; margin: .45rem 0 .2rem; border-radius: 999px; background: var(--muted); overflow: visible; }
.opt-progresso-barra { height: 100%; border-radius: 999px; background: var(--primary); }
.opt-progresso-barra.atrasado { background: var(--aviso); }
.opt-progresso-marca { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--foreground); opacity: .55; }
.opt-coluna-agora { background: color-mix(in oklch, var(--primary) 7%, transparent); }
.opt-placar th { vertical-align: bottom; white-space: nowrap; }
.opt-grade-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-top: 1rem; }
.opt-grade-2 > .opt-cartao { margin: 0; }
.opt-tabela input.opt-mono { text-align: right; }
.opt-grade-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.2rem; }
.opt-grupo-orfas { border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .6rem; }
.opt-grupo-orfas:first-of-type { border-top: 0; }

/* condições de pagamento e prazos (OptPropostas, só leitura) */
.opt-condicoes { margin-top: .5rem; font-size: .875rem; }
.opt-condicoes summary { cursor: pointer; color: var(--muted-foreground); }
.opt-condicoes-painel { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius, 6px); margin-bottom: .5rem; }
.opt-condicoes-texto p { margin: .15rem 0 .5rem; white-space: pre-wrap; }
/* alerta com título + texto + lista: empilhado (o .opt-alerta padrão é uma linha) */
.opt-alerta-bloco { display: block; margin: .75rem 0 0; }
.opt-alerta-bloco > small { display: block; margin: .25rem 0; }
.opt-alerta-bloco ul { margin: .25rem 0 0; padding-left: 1.2rem; }
