:root {
    /* ----- Tema escuro (padrao) ----- */
    /* Faz o navegador renderizar widgets nativos (popup do <select>, date picker,
       scrollbars) no esquema escuro. Sem isto eles vem claros no Windows/Chrome. */
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #161a22;
    --surface-2: #1d222c;
    --border: #2a313e;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --accent: #e4bc49;        /* dourado Orcenter vivido (fills + texto no escuro) */
    --accent-2: #d3a22f;      /* dourado principal (hover) */
    --accent-ink: #2a2410;    /* texto escuro sobre fundos dourados */
    --accent-fg: #e7c257;     /* dourado como texto (links/totais) no escuro */
    --focus-ring: rgba(228,188,73,.30);
    --info: #4f8cff;          /* azul semantico (info) preservado */
    --info-2: #2f6bdc;
    --success: #2ecc71;
    --warn: #f1c40f;
    --danger: #e74c3c;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.18);

    /* Hover de linhas (overlay sobre superficie) + textos sobre fundos translucidos de status.
       Tokenizados porque mudam de cor entre os temas (no claro o branco translucido some). */
    --row-hover: rgba(255,255,255,.02);
    --ok-fg: var(--ok-fg);
    --warn-fg: var(--warn-fg);
    --danger-fg: var(--danger-fg);
    --info-fg: var(--info-fg);
    --strong-fg: var(--strong-fg);
}

/* ----- Tema claro ----- */
[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --border: #d7dde7;
    --text: #1b212b;
    --muted: #5c6675;
    --accent: #c9971f;        /* dourado vivido p/ fills (botoes) no claro */
    --accent-2: #a87e18;
    --accent-ink: #2a2410;
    --accent-fg: #8a6410;     /* dourado escuro legivel como texto sobre branco */
    --focus-ring: rgba(201,151,31,.30);
    --info: #2f6bdc;
    --info-2: #1f57c4;
    --success: #1f9d57;
    --warn: #b7860b;
    --danger: #d33a2c;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 10px 24px rgba(16,24,40,.08);

    --row-hover: rgba(16,24,40,.035);
    --ok-fg: #157f3c;
    --warn-fg: #8a630a;
    --danger-fg: #b3271b;
    --info-fg: #1d4ed8;
    --strong-fg: #8a630a;
}

/* Transicao de cor suave apenas durante a troca de tema (a classe e adicionada
   pelo JS por ~300ms). Evita animar hovers e outras interacoes do dia a dia. */
html.theme-transition,
html.theme-transition * {
    transition: background-color .25s ease, border-color .25s ease, color .2s ease !important;
}
@media (prefers-reduced-motion: reduce) {
    html.theme-transition, html.theme-transition * { transition: none !important; }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header .brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: .2px;
}

.app-footer {
    margin-top: 80px;
    padding: 24px 0;
    border-top: 1px solid var(--border);
    color: var(--muted);
}

main.container { padding-top: 32px; padding-bottom: 32px; }

.hero h1 {
    font-size: 32px;
    margin: 0 0 8px;
    letter-spacing: -.2px;
}
.lead { font-size: 17px; color: var(--text); margin: 0 0 4px; }
.muted { color: var(--muted); margin: 0 0 24px; }

.diag {
    list-style: none;
    padding: 16px;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.diag li + li { margin-top: 6px; }
.diag a { color: var(--accent-fg); text-decoration: none; }
.diag a:hover { text-decoration: underline; }

.error h1 { font-size: 56px; margin: 24px 0 0; }
.error p { color: var(--muted); }
.error a { color: var(--accent-fg); }

@media (max-width: 600px) {
    .hero h1 { font-size: 26px; }
    .container { padding: 0 16px; }
}

/* ----- Auth shell ----- */
body.auth { min-height: 100vh; display: grid; place-items: center; background:
    radial-gradient(1200px 600px at 20% -10%, rgba(211,162,47,.16), transparent 60%),
    radial-gradient(800px 500px at 90% 110%, rgba(160,162,158,.10), transparent 60%),
    var(--bg);
}
.auth-shell { width: 100%; max-width: 420px; padding: 24px; }
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; padding: 28px 28px 24px;
    box-shadow: var(--shadow);
}
.auth-brand { font-weight: 700; letter-spacing: .3px; color: var(--accent-fg); font-size: 14px; margin-bottom: 20px; }
.auth-title { margin: 0 0 4px; font-size: 22px; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.auth-foot { margin: 16px 0 0; text-align: center; color: var(--muted); }
.auth-link { text-align: center; margin: 16px 0 0; }
.auth-link a { color: var(--accent-fg); text-decoration: none; font-size: 14px; }
.auth-link a:hover { text-decoration: underline; }

/* ----- Form ----- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="number"],
.field select, .field textarea {
    width: 100%; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font: inherit; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent-fg);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* ----- Button ----- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 10px 16px; border-radius: 8px; cursor: pointer;
    font: inherit; font-weight: 500; border: 1px solid transparent;
    transition: background .15s, border-color .15s, color .15s;
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-2); }
.btn-block { width: 100%; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--muted); }

/* Botao primario com peso visual extra: sombra sutil + leve transicao no hover. */
.btn-primary {
    box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 2px 6px var(--focus-ring);
    font-weight: 600;
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 1px 0 rgba(255,255,255,.1) inset, 0 4px 12px rgba(211,162,47,.30); }
.btn-primary:active { transform: translateY(1px); }

/* ----- Alerts ----- */
.alert {
    padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
    border: 1px solid transparent;
    display: flex; align-items: flex-start; gap: 10px;
}
.alert-error   { background: rgba(231,76,60,.12);  border-color: rgba(231,76,60,.4);  color: var(--danger-fg); }
.alert-success { background: rgba(46,204,113,.12); border-color: rgba(46,204,113,.4); color: var(--ok-fg); }
.alert-warn    { background: rgba(241,196,15,.12); border-color: rgba(241,196,15,.4); color: var(--warn-fg); }
.alert .alert-content { flex: 1; }
.alert .alert-dismiss {
    background: transparent; border: none; color: inherit; cursor: pointer;
    font-size: 18px; line-height: 1; padding: 0 4px; opacity: .6;
}
.alert .alert-dismiss:hover { opacity: 1; }

/* ----- Read-only banner (planilha de orcamento bloqueada apos baseline) ----- */
.readonly-banner {
    display: flex; align-items: flex-start; gap: 16px;
    background: linear-gradient(180deg, rgba(241,196,15,.12), rgba(241,196,15,.04));
    border: 1px solid rgba(241,196,15,.45);
    border-left: 4px solid rgba(241,196,15,.9);
    padding: 14px 18px; border-radius: 10px;
    margin: 16px 0 20px;
    color: var(--warn-fg);
}
.readonly-banner-icon { font-size: 22px; line-height: 1; padding-top: 2px; }
.readonly-banner-body { flex: 1; }
.readonly-banner-body strong { font-size: 15px; color: var(--strong-fg); }
.readonly-banner-body p { margin: 4px 0 0; font-size: 13px; line-height: 1.5; opacity: .9; }
.readonly-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Feedback visual claro em containers read-only: cursor not-allowed nos campos. */
[data-readonly="true"] input:disabled,
[data-readonly="true"] select:disabled,
[data-readonly="true"] textarea:disabled,
[data-readonly="true"] button:disabled {
    cursor: not-allowed;
}
[data-readonly="true"] .qty-input:disabled,
[data-readonly="true"] .coef-input:disabled,
[data-readonly="true"] .pct-input:disabled {
    background: var(--row-hover);
    color: var(--muted);
}

/* ----- Fieldsets em modais e forms longos ----- */
.form-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px 6px;
    margin: 0 0 14px;
}
.form-section > legend {
    padding: 0 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--muted);
    font-weight: 600;
}

/* Causa "classificar depois" destacada visualmente quando esta selecionada */
select#re-causa:has(option[value="classificar_depois"]:checked) {
    border-color: rgba(241,196,15,.5);
    background-color: rgba(241,196,15,.06);
}

/* ----- Empty hero (estado vazio com 3 passos guiados) ----- */
.empty-hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 32px;
    text-align: center;
    margin: 24px 0;
}
.empty-hero h3 { margin: 0 0 8px; font-size: 20px; }
.empty-hero > p.muted { max-width: 560px; margin: 0 auto 18px; }
.empty-hero-steps {
    list-style: none;
    counter-reset: step;
    padding: 0;
    margin: 0 auto 20px;
    max-width: 480px;
    text-align: left;
}
.empty-hero-steps li {
    counter-increment: step;
    padding: 10px 12px 10px 44px;
    margin-bottom: 6px;
    background: var(--surface-2);
    border-radius: 8px;
    position: relative;
    font-size: 14px;
}
.empty-hero-steps li::before {
    content: counter(step);
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
}
.empty-hero-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ----- Spinner em inputs de autocomplete ----- */
@keyframes spin-rotate { to { transform: rotate(360deg); } }
input.is-loading {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><circle cx='8' cy='8' r='6' stroke='%23999' stroke-width='2' fill='none' stroke-dasharray='10 30' /></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 16px 16px;
    animation: spin-rotate 1s linear infinite;
    animation-name: none; /* anima so o BG via outro pseudo (fallback) */
}
/* Fallback simples: borda colorida durante loading */
input.is-loading {
    border-color: rgba(211,162,47,.5);
    padding-right: 32px;
}

/* Item ativo no autocomplete (navegacao por teclado). */
.autocomplete-list li.is-active {
    background: rgba(211,162,47,.18);
    color: var(--accent-fg);
}

/* ----- Header / nav ----- */
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.header-nav { display: flex; align-items: center; gap: 12px; }
/* O utilitario .muted carrega margin-bottom:24px (pensado p/ paragrafos). No header
   isso desalinha o nome verticalmente; zera dentro da barra de navegacao. */
.header-nav .muted { margin: 0; }
/* Nome do usuario clicavel (abre o perfil). */
.user-name { color: var(--muted); text-decoration: none; transition: color .15s; }
.user-name:hover { color: var(--accent-fg); text-decoration: underline; }
.inline { display: inline; }

/* Nav principal: lista horizontal em desktop, dropdown em mobile. */
.primary-nav { flex: 1; }
.primary-nav-list {
    list-style: none; padding: 0; margin: 0;
    display: flex; gap: 4px; flex-wrap: wrap;
    justify-content: center;
}
.primary-nav-list .nav-link {
    display: inline-block; padding: 6px 12px; border-radius: 6px;
    color: var(--muted); text-decoration: none; font-size: 14px;
    transition: background .15s, color .15s;
}
.primary-nav-list .nav-link:hover { background: var(--surface-2); color: var(--text); }
.primary-nav-list .nav-link.active {
    background: rgba(79,140,255,.16);
    color: var(--info-fg);
}
.primary-nav-mobile { display: none; }
.primary-nav-mobile > summary {
    list-style: none;
    cursor: pointer; user-select: none;
    padding: 4px 10px; border-radius: 6px;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 18px; line-height: 1;
}
.primary-nav-mobile > summary::-webkit-details-marker { display: none; }
.primary-nav-mobile[open] > ul {
    list-style: none; padding: 8px; margin: 8px 0 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    position: absolute;
    z-index: 20;
    min-width: 220px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.primary-nav-mobile[open] > ul .nav-link {
    display: block; padding: 8px 12px; color: var(--text);
    text-decoration: none; border-radius: 6px;
}
.primary-nav-mobile[open] > ul .nav-link:hover { background: var(--surface-2); }
.primary-nav-mobile[open] > ul .nav-link.active { background: rgba(79,140,255,.16); color: var(--info-fg); }

@media (max-width: 820px) {
    .primary-nav-list { display: none; }
    .primary-nav-mobile { display: block; }
}
.btn-sm { padding: 6px 10px; font-size: 13px; }
.small { font-size: 13px; }

/* ----- Cards ----- */
.card-grid {
    margin-top: 28px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    position: relative;
    transition: transform .15s, border-color .15s;
}
.card:hover { transform: translateY(-1px); border-color: var(--accent-fg); }
.card.disabled { opacity: .65; }
.card.disabled:hover { transform: none; border-color: var(--border); }
.card-link { text-decoration: none; color: inherit; display: block; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }
.card .badge {
    position: absolute; top: 12px; right: 12px;
    background: var(--surface-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 999px;
    font-size: 11px; padding: 2px 8px;
}

/* ----- Admin layout ----- */
.brand-group { display: flex; align-items: baseline; gap: 8px; }
.brand-tag {
    background: var(--accent); color: var(--accent-ink); font-size: 11px;
    padding: 2px 8px; border-radius: 999px; letter-spacing: .5px;
    text-transform: uppercase;
}
.admin-tabs {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.admin-tabs .container { display: flex; gap: 4px; }
.admin-tabs a {
    padding: 12px 16px; color: var(--muted); text-decoration: none;
    border-bottom: 2px solid transparent; font-size: 14px;
    transition: color .15s, border-color .15s;
}
.admin-tabs a:hover { color: var(--text); }
.admin-tabs a.active { color: var(--accent-fg); border-bottom-color: var(--accent-fg); }

/* ----- Page head ----- */
.page-head { padding: 28px 0 12px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-head .muted { margin: 0; }
.page-head.with-action { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 4px; }
.back-link:hover { color: var(--text); }

.page-section { margin-top: 28px; }
.section-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px;
}
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.action-group { display: flex; gap: 8px; }

/* ----- Stats ----- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 16px; }
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 26px; font-weight: 600; }

/* ----- Tables ----- */
.data-table {
    width: 100%; border-collapse: collapse;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.data-table th, .data-table td {
    padding: 10px 14px; text-align: left;
    border-bottom: 1px solid var(--border); font-size: 14px;
    vertical-align: middle;
}
.data-table th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
/* Cabecalho: top:0 (nao 60px). O overflow:hidden do .data-table torna a propria tabela o scroll-container do sticky,
   entao top:60px empurrava o thead pra baixo sobrepondo a 1a linha. Com top:0 o cabecalho fica no lugar. */
.data-table thead th { position: sticky; top: 0; z-index: 5; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--row-hover); }
.data-table .num { text-align: right; }
.data-table code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
/* Larguras de coluna fixas (via <colgroup>): mantem as colunas iguais entre
   paginas, independente do tamanho dos nomes. Texto longo quebra em linha. */
.data-table-fixed { table-layout: fixed; }
.data-table-fixed th, .data-table-fixed td { overflow-wrap: break-word; word-break: break-word; }

/* Tabelas responsivas: em telas pequenas, scroll horizontal interno em vez de quebrar layout.
   Trade-off: thead sticky desativa em mobile (display:block remove participacao no fluxo de table). */
@media (max-width: 768px) {
    .page-section .data-table,
    section .data-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .data-table thead th { position: static; }
}
.link { color: var(--accent-fg); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ----- Pills ----- */
.pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 12px; border: 1px solid transparent;
}
.pill-active     { background: rgba(46,204,113,.15); color: var(--ok-fg); border-color: rgba(46,204,113,.4); }
.pill-suspended  { background: rgba(231,76,60,.15); color: var(--danger-fg); border-color: rgba(231,76,60,.4); }
.pill-inactive   { background: rgba(154,163,178,.15); color: var(--muted); border-color: var(--border); }
.badge-inline {
    display: inline-block; margin-left: 6px;
    background: rgba(241,196,15,.15); color: var(--warn-fg);
    border: 1px solid rgba(241,196,15,.4);
    font-size: 11px; padding: 1px 6px; border-radius: 4px;
}

/* ----- Form card ----- */
.form-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px;
    display: grid; gap: 14px; max-width: 640px;
}
.form-section {
    margin: 8px 0 0; padding-top: 12px; padding-bottom: 4px;
    font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
    border-top: 1px solid var(--border);
}
.form-section:first-child { border-top: none; padding-top: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.empty {
    background: var(--surface); border: 1px dashed var(--border);
    border-radius: var(--radius); padding: 32px; text-align: center;
}
.empty p { color: var(--muted); margin: 0 0 12px; }

.big-code {
    display: inline-block; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 14px; font-size: 16px; letter-spacing: 1px;
    user-select: all;
}

/* ----- Permissoes matrix ----- */
.perm-matrix code.muted { font-size: 11px; }
.perm-matrix .check { color: var(--success); font-size: 18px; }

/* ----- Filter bar ----- */
.filter-bar {
    display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
    margin: 16px 0;
}
.inline-field { flex: 1; min-width: 140px; }
.filter-actions { display: flex; gap: 6px; }

/* ----- Audit table ----- */
.audit-table code.small { font-size: 11px; }
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: center; }
/* Barra de paginacao equilibrada: botoes nas pontas, info ao centro.
   Estavel mesmo quando falta um dos lados (primeira/ultima pagina). */
.pagination-bar {
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    flex-wrap: wrap;
}
.pagination-bar .pagination-side { flex: 1 1 0; display: flex; gap: 8px; align-items: center; }
.pagination-bar .pagination-side-end { justify-content: flex-end; }
.pagination-bar .pagination-info { flex: 0 1 auto; text-align: center; color: var(--text); font-size: 14px; white-space: nowrap; }
select {
    width: 100%; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font: inherit; outline: none;
}
select:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

textarea {
    width: 100%; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font: inherit; outline: none; resize: vertical;
    transition: border-color .15s, box-shadow .15s;
}
textarea:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

input[type="search"] {
    width: 100%; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font: inherit; outline: none;
}
input[type="search"]:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

/* ----- Stat cards clicaveis ----- */
.stat-link { text-decoration: none; color: inherit; transition: border-color .15s; }
.stat-link:hover { border-color: var(--accent-fg); }
.stat-active { border-color: var(--accent-fg); box-shadow: 0 0 0 1px var(--accent) inset; }

/* ----- Pills extras de obra status ----- */
.pill-planejamento { background: rgba(79,140,255,.15); color: var(--info-fg); border-color: rgba(79,140,255,.4); }
.pill-em_obra      { background: rgba(46,204,113,.15); color: var(--ok-fg); border-color: rgba(46,204,113,.4); }
.pill-pausada      { background: rgba(241,196,15,.15); color: var(--warn-fg); border-color: rgba(241,196,15,.4); }
.pill-concluida    { background: rgba(154,163,178,.15); color: var(--muted); border-color: var(--border); }
.pill-cancelada    { background: rgba(231,76,60,.15); color: var(--danger-fg); border-color: rgba(231,76,60,.4); }

/* ----- Form rows ----- */
.form-card-wide { max-width: 820px; }
.form-row { display: flex; gap: 12px; }
.form-row > .field { flex: 1; }

/* ----- Detail grid ----- */
.detail-grid {
    display: grid; gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.detail-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.detail-card h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.detail-card dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 14px; }
.detail-card dt { color: var(--muted); }
.detail-card dd { margin: 0; }
.detail-card p { margin: 0; line-height: 1.5; }
.detail-card-wide { grid-column: 1 / -1; }

.hidden { display: none !important; }

/* ----- Receita (composicao show) ----- */
.receita-title { font-size: 24px; line-height: 1.3; }
.receita-quantidade { color: var(--accent-fg); font-weight: 700; }
.receita-unidade { color: var(--accent-fg); font-weight: 600; }
.receita-descricao { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; margin: 8px 0 16px; }
.receita-descricao p { margin: 0; color: var(--muted); line-height: 1.5; }

.receita-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); margin-top: 24px;
    box-shadow: var(--shadow); overflow: hidden;
}
.receita-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.receita-header h2 { margin: 0; font-size: 16px; }

.receita-table { width: 100%; border-collapse: collapse; }
.receita-table th, .receita-table td {
    padding: 10px 16px; text-align: left; vertical-align: middle;
    border-bottom: 1px solid var(--border); font-size: 14px;
}
.receita-table th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.receita-table .num { text-align: right; }
.receita-table tbody tr:hover td { background: var(--row-hover); }
.receita-table tfoot td { background: var(--surface-2); padding: 14px 16px; font-size: 15px; }
.receita-total { color: var(--accent-fg); font-size: 20px !important; font-weight: 700; }
.receita-empty { text-align: center !important; color: var(--muted); padding: 32px !important; }

.coef-input {
    width: 100px; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 8px; font: inherit; outline: none; text-align: right;
    transition: border-color .15s, box-shadow .15s;
}
.coef-input:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

.btn-remove-item { background: transparent; border: 1px solid var(--border); color: var(--danger); padding: 4px 10px; font-size: 16px; line-height: 1; }
.btn-remove-item:hover { border-color: var(--danger); background: rgba(231,76,60,.1); }

.receita-disclaimer { padding: 14px 20px; margin: 0; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }

/* ----- Add form (autocomplete) ----- */
.add-form { padding: 16px 20px; border-bottom: 1px solid var(--border); background: rgba(211,162,47,.05); }
.add-form-row { display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap; }
.add-form-row > .autocomplete { flex: 1; min-width: 280px; position: relative; }
.add-form-row input[type="text"] {
    width: 100%; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 10px; font: inherit; outline: none;
}
.add-form-row input[type="text"]:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

/* Ancora do dropdown: sem isto, a lista (position:absolute) se posiciona
   relativa ao ancestral posicionado mais proximo (ex.: o .modal fixed),
   caindo fora da tela. Vale para qualquer contexto, nao so a planilha. */
.autocomplete { position: relative; }
.autocomplete-list {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; margin: 4px 0 0; padding: 4px 0;
    list-style: none; max-height: 280px; overflow: auto;
    z-index: 100; box-shadow: var(--shadow);
}
.autocomplete-list li { padding: 8px 12px; cursor: pointer; }
.autocomplete-list li:hover { background: var(--surface-2); }
.autocomplete-list li code.small { font-size: 11px; padding: 1px 4px; background: var(--surface-2); border-radius: 3px; }
.autocomplete-empty { color: var(--muted); cursor: default !important; padding: 12px !important; text-align: center; }

/* ================ Orcamento (planilha + sidebar) ================ */
.orc-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    margin-top: 20px;
    align-items: start;
}
@media (max-width: 980px) { .orc-layout { grid-template-columns: 1fr; } }

.orc-planilha {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}
.orc-planilha-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.orc-planilha-head h2 { margin: 0; font-size: 16px; }
.orc-planilha-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.orc-table { width: 100%; border-collapse: collapse; }
.orc-table th, .orc-table td {
    padding: 10px 14px; vertical-align: middle;
    border-bottom: 1px solid var(--border); font-size: 13px;
}
.orc-table th { background: var(--surface-2); color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.orc-table .num { text-align: right; }
.orc-table tr:hover td { background: var(--row-hover); }

.grupo-row td { background: rgba(211,162,47,.07) !important; padding: 10px 14px !important; }
.grupo-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grupo-head strong { font-size: 13px; }
.grupo-head code { background: var(--surface-2); padding: 1px 6px; border-radius: 3px; font-size: 11px; margin-right: 6px; }

.qty-input {
    width: 110px; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 5px 8px; font: inherit; outline: none; text-align: right;
    transition: border-color .15s, box-shadow .15s;
}
.qty-input:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }

.badge-tipo {
    display: inline-block; padding: 1px 6px; border-radius: 4px;
    font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
    margin-left: 6px;
}
.badge-tipo-composicao { background: rgba(46,204,113,.15); color: var(--ok-fg); }
.badge-tipo-insumo { background: rgba(241,196,15,.15); color: var(--warn-fg); }

/* Pulse highlight ao recalcular */
@keyframes rowPulse {
    0%   { background-color: var(--focus-ring); }
    100% { background-color: transparent; }
}
.row-pulse > td { animation: rowPulse .6s ease-out; }
.row-loading { opacity: .6; pointer-events: none; }

/* ----- Sidebar ----- */
.orc-sidebar {
    position: sticky;
    top: 80px;
    align-self: start;
    /* Permite rolar internamente quando a sidebar tem mais conteudo do que cabe na viewport. */
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    /* scrollbar discreta */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.orc-sidebar::-webkit-scrollbar { width: 6px; }
.orc-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.orc-sidebar-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px;
    box-shadow: var(--shadow);
}
.orc-sidebar-card h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.orc-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 14px; }
.orc-line-input label { display: flex; align-items: center; gap: 4px; flex: 1; }
.orc-line-label { color: var(--muted); font-size: 13px; }
.orc-line-value { font-weight: 500; }
.orc-line-final { padding: 12px 0; }
.orc-line-final .orc-line-label { color: var(--text); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: .5px; }
.orc-line-final .orc-line-value { font-size: 22px; font-weight: 700; color: var(--accent-fg); }
.orc-divider { height: 1px; background: var(--border); margin: 8px 0; }
.orc-status { padding: 12px 0; font-size: 13px; color: var(--muted); }

.pct-input {
    width: 60px; background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 4px 6px; font: inherit; outline: none; text-align: right;
    font-size: 13px;
}
.pct-input:focus { border-color: var(--accent-fg); box-shadow: 0 0 0 3px var(--focus-ring); }
.pct-input:disabled { opacity: .5; }

button[disabled] { cursor: not-allowed; opacity: .55; }

.btn-block { width: 100%; }

/* ----- Modal ----- */
.modal {
    position: fixed; inset: 0; background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; padding: 20px;
}
.modal-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow); max-width: 520px; width: 100%;
    display: grid; gap: 12px;
}
.modal-card h3 { margin: 0; font-size: 18px; }

/* ----- Comparacao deltas ----- */
.delta-up   { color: var(--danger); font-weight: 600; }
.delta-down { color: var(--success); font-weight: 600; }

/* ----- Composicao detalhe (versao show) ----- */
.comp-detail {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px;
}
.comp-detail summary {
    cursor: pointer; display: flex; gap: 12px; align-items: center;
    flex-wrap: wrap;
}
.comp-detail summary > strong:last-child { margin-left: auto; color: var(--accent-fg); }

/* ----- Baseline badge ----- */
.baseline-badge {
    display: inline-block; vertical-align: middle;
    background: linear-gradient(135deg, rgba(46,204,113,.25), rgba(46,204,113,.10));
    color: var(--ok-fg); border: 1px solid rgba(46,204,113,.5);
    border-radius: 999px; padding: 4px 12px; font-size: 13px;
    font-weight: 600; letter-spacing: .3px;
    margin-left: 8px;
    box-shadow: 0 0 0 1px rgba(46,204,113,.15) inset;
}
.baseline-badge-sm { font-size: 11px; padding: 2px 8px; margin-left: 0; }

/* ----- Realizado ----- */
.btn-grande { padding: 14px 24px; font-size: 15px; font-weight: 600; }
.badge-tipo-extra { background: rgba(241,196,15,.15); color: var(--warn-fg); }
.causa-select {
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 4px 8px; font: inherit; font-size: 12px;
}
.causa-select:focus { border-color: var(--accent-fg); outline: none; }

/* ----- Status pills (planejado x realizado) ----- */
.pill-ok       { background: rgba(46,204,113,.15);  color: var(--ok-fg); border-color: rgba(46,204,113,.4); }
.pill-atencao  { background: rgba(241,196,15,.15);  color: var(--warn-fg); border-color: rgba(241,196,15,.4); }
.pill-critico  { background: rgba(231,76,60,.15);   color: var(--danger-fg); border-color: rgba(231,76,60,.4); }

.etapa-detail summary { cursor: pointer; }
.etapa-detail summary:hover { color: var(--accent-fg); }
.etapa-detail[open] summary { color: var(--accent-fg); }

/* ----- Theme toggle (Dia/Noite) ----- */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; padding: 0;
    background: transparent; color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; line-height: 1;
    transition: color .15s, border-color .15s, background .15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle::before { content: "\263E"; font-size: 16px; } /* lua (tema escuro ativo) */
[data-theme="light"] .theme-toggle::before { content: "\2600"; } /* sol (tema claro ativo) */

/* Variante para a tela de login: flutua no canto superior direito. */
.theme-toggle-floating { position: fixed; top: 16px; right: 16px; z-index: 50; background: var(--surface); }

/* ----- Logomarca Orcenter (header + login) -----
   Duas imagens por marca: a normal (texto cinza-escuro, p/ fundo claro) e a
   variante "-light" (clareada via gamma, p/ fundo escuro). O CSS alterna pelo
   data-theme. data-theme e sempre definido pelo theme-head antes do paint. */
.brand { display: inline-flex; align-items: center; }
.brand-logo { display: block; height: 36px; width: auto; }
.brand-logo-light { display: none; }
[data-theme="dark"] .brand-logo-dark { display: none; }
[data-theme="dark"] .brand-logo-light { display: block; }

/* Logo completa centralizada no card de login. */
.auth-logo { text-align: center; margin: 0 0 22px; }
.auth-logo .brand-logo { height: 88px; margin: 0 auto; }
