:root {
    --bg:#f6f7fb;
    --card:#fff;
    --text:#1f2937;
    --muted:#6b7280;
    --line:#e5e7eb;
    --primary:#2563eb;
    --danger:#dc2626;
    --success:#16a34a;
    --warning:#d97706;
    --topbar:#111827;
}
* { box-sizing:border-box; }
html { -webkit-text-size-adjust:100%; }
body { margin:0; font-family:Arial, Helvetica, sans-serif; background:var(--bg); color:var(--text); font-size:15px; }
a { color:var(--primary); text-decoration:none; }
a:hover { text-decoration:underline; }

.topbar {
    background:var(--topbar);
    color:#fff;
    padding:12px 18px;
    display:flex;
    gap:14px;
    justify-content:space-between;
    align-items:center;
    flex-wrap:wrap;
    position:sticky;
    top:0;
    z-index:20;
    box-shadow:0 4px 18px rgba(0,0,0,.18);
}
.brand { display:flex; align-items:center; gap:12px; min-width:240px; flex:1 1 auto; }
.brand-logo { width:auto; max-width:130px !important; max-height:48px; object-fit:contain; }
.brand-text { min-width:0; }
.brand strong { display:block; line-height:1.2; overflow-wrap:anywhere; }
.main-nav { display:flex; gap:8px; flex-wrap:wrap; align-items:center; justify-content:flex-end; }
.topbar a { color:#fff; padding:8px 9px; border-radius:8px; }
.topbar a:hover { background:#374151; text-decoration:none; }
.nav-toggle { display:none; border:1px solid rgba(255,255,255,.25); background:#1f2937; color:#fff; border-radius:8px; padding:9px 12px; font-weight:700; cursor:pointer; }

.container { width:min(1180px, 94vw); margin:22px auto; }
.footer { color:var(--muted); text-align:center; padding:30px 0; }
.card { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:18px; box-shadow:0 5px 18px rgba(0,0,0,.04); margin-bottom:18px; }
.grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(220px,1fr)); gap:14px; }
.kpi { font-size:24px; font-weight:700; margin-top:6px; }
.muted { color:var(--muted); font-size:13px; }
.muted.light { color:#d1d5db; display:block; margin-top:3px; }
.help { font-size:13px; color:var(--muted); margin-top:4px; line-height:1.45; }
.warning-box { border:1px solid #fde68a; background:#fffbeb; color:#92400e; border-radius:12px; padding:12px; margin:12px 0; }

h1 { font-size:28px; margin:0 0 18px; }
h2 { font-size:20px; margin-top:0; }
h3 { font-size:17px; }
label { display:block; font-weight:600; margin-bottom:6px; }
input, select, textarea { width:100%; padding:11px 10px; border:1px solid var(--line); border-radius:8px; background:#fff; font-size:16px; max-width:100%; }
textarea { min-height:90px; }
.form-row { display:grid; grid-template-columns:repeat(auto-fit, minmax(190px,1fr)); gap:14px; margin-bottom:12px; }
.search-row { display:grid; grid-template-columns:minmax(220px, 1fr) auto auto; gap:10px; align-items:end; margin-bottom:14px; }

.btn { display:inline-block; border:0; background:var(--primary); color:#fff; padding:10px 14px; border-radius:8px; cursor:pointer; font-weight:600; font-size:14px; line-height:1.2; text-align:center; }
.btn:hover { opacity:.9; text-decoration:none; }
.btn.secondary { background:#4b5563; }
.btn.danger { background:var(--danger); }
.btn.success { background:var(--success); }
.btn:disabled { opacity:.55; cursor:not-allowed; }

.table-wrap { overflow:auto; -webkit-overflow-scrolling:touch; }
table { width:100%; border-collapse:collapse; background:#fff; }
th, td { border-bottom:1px solid var(--line); padding:10px; text-align:left; vertical-align:top; }
th { background:#f3f4f6; font-size:13px; }
tfoot th { background:#f9fafb; }
.actions { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }
.actions form { margin:0; }
.badge { display:inline-block; border-radius:999px; padding:4px 8px; font-size:12px; background:#e5e7eb; color:#374151; }
.badge.success { background:#dcfce7; color:#166534; }
.badge.warning { background:#fef3c7; color:#92400e; }
.badge.danger { background:#fee2e2; color:#991b1b; }
.alert { border-radius:10px; padding:12px 14px; margin-bottom:14px; border:1px solid var(--line); background:#fff; }
.alert-success { background:#ecfdf5; border-color:#bbf7d0; }
.alert-error { background:#fef2f2; border-color:#fecaca; }
.alert-warning { background:#fffbeb; border-color:#fde68a; }
.login-box { max-width:420px; margin:70px auto; }
.login-logo { text-align:center; margin-bottom:18px; }
.login-logo img { max-width:220px; max-height:120px; object-fit:contain; }

/* Alertas com tema de gatinhos */
.cat-alert { display:flex; gap:12px; align-items:flex-start; border-width:1px; box-shadow:0 5px 18px rgba(0,0,0,.06); }
.cat-alert-icon { width:38px; height:38px; border-radius:999px; display:flex; align-items:center; justify-content:center; font-size:22px; background:rgba(255,255,255,.75); flex:0 0 auto; }
.cat-alert-content { display:flex; flex-direction:column; gap:3px; }
.cat-alert-content strong { font-size:14px; }
.alert-success.cat-alert { background:#ecfdf5; border-color:#bbf7d0; }
.alert-error.cat-alert { background:#fff1f2; border-color:#fecdd3; }
.cat-confirm-backdrop { position:fixed; inset:0; background:rgba(17,24,39,.58); display:flex; align-items:center; justify-content:center; padding:18px; z-index:999; }
.cat-confirm-backdrop[hidden] { display:none; }
.cat-confirm-box { width:min(430px, 100%); background:#fff; color:var(--text); border-radius:18px; padding:22px; box-shadow:0 22px 70px rgba(0,0,0,.32); border:1px solid var(--line); text-align:center; }
.cat-confirm-icon { width:62px; height:62px; margin:0 auto 12px; border-radius:999px; display:flex; align-items:center; justify-content:center; background:#fff7ed; font-size:34px; border:1px solid #fed7aa; }
.cat-confirm-text h2 { margin:0 0 8px; font-size:22px; }
.cat-confirm-text p { margin:0; color:var(--muted); line-height:1.45; }
.cat-confirm-actions { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:20px; }
body.modal-open { overflow:hidden; }

@media (max-width: 820px) {
    body { font-size:15px; }
    .topbar { align-items:flex-start; gap:10px; padding:10px 12px; }
    .brand { min-width:0; flex:1 1 calc(100% - 105px); gap:8px; }
    .brand-logo { max-width:96px !important; max-height:38px; }
    .brand strong { font-size:14px; line-height:1.15; }
    .nav-toggle { display:inline-block; margin-left:auto; flex:0 0 auto; }
    .main-nav { display:none !important; width:100%; flex-direction:column; align-items:stretch; gap:6px; padding-top:8px; }
    .main-nav.nav-open { display:flex !important; }
    .main-nav a { display:block; width:100%; padding:12px; background:#1f2937; }
    .container { width:100%; margin:14px auto; padding:0 10px; }
    h1 { font-size:23px; margin-bottom:14px; }
    h2 { font-size:18px; }
    .card { padding:14px; border-radius:12px; margin-bottom:12px; }
    .grid { grid-template-columns:1fr; gap:10px; }
    .form-row, .search-row { grid-template-columns:1fr; gap:10px; }
    .btn { width:100%; padding:12px 14px; }
    .actions { display:grid; grid-template-columns:1fr; width:100%; gap:8px; }
    .actions .btn, .actions form, .actions button { width:100%; }
    .table-wrap { overflow:visible; }
    table.responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table tfoot,
    .responsive-table th,
    .responsive-table td,
    .responsive-table tr { display:block; width:100%; }
    .responsive-table thead { display:none; }
    .responsive-table tr { background:#fff; border:1px solid var(--line); border-radius:12px; padding:10px; margin-bottom:12px; box-shadow:0 3px 12px rgba(0,0,0,.04); }
    .responsive-table td { border:0; padding:8px 0; display:grid; grid-template-columns:108px 1fr; gap:10px; align-items:start; word-break:break-word; }
    .responsive-table td::before { content:attr(data-label); color:var(--muted); font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.02em; }
    .responsive-table td.actions { display:block; }
    .responsive-table td.actions::before { display:block; margin-bottom:8px; }
    .responsive-table tfoot tr { background:#f9fafb; }
    .responsive-table tfoot th { display:grid; grid-template-columns:108px 1fr; gap:10px; border:0; padding:8px 0; }
    .responsive-table tfoot th:first-child::before { content:'Resumo'; color:var(--muted); font-size:12px; font-weight:700; text-transform:uppercase; }
    .responsive-table tfoot th:last-child::before { content:'Total'; color:var(--muted); font-size:12px; font-weight:700; text-transform:uppercase; }
}

@media (max-width: 520px) {
    .cat-confirm-box { padding:18px; }
    .cat-confirm-actions { grid-template-columns:1fr; }
    .cat-alert { padding:12px; }
    .cat-alert-icon { width:34px; height:34px; font-size:20px; }
}

@media (max-width: 420px) {
    .brand-logo { max-width:82px !important; }
    .brand strong { font-size:13px; }
    .muted.light { font-size:12px; }
    .responsive-table td { grid-template-columns:96px 1fr; }
}

/* Atualização 06: dashboard financeiro e orçamento público */
.mini-card {
    background:#fff;
    border:1px solid var(--line);
    border-radius:14px;
    padding:16px;
    box-shadow:0 4px 14px rgba(0,0,0,.035);
}
.mini-card.positive { border-color:#bbf7d0; background:#f0fdf4; }
.mini-card.warning { border-color:#fde68a; background:#fffbeb; }
.mini-card.danger { border-color:#fecaca; background:#fef2f2; }
.two-cols { grid-template-columns:repeat(auto-fit, minmax(320px,1fr)); align-items:start; }
.compact-table th, .compact-table td { padding:8px; }
.quote-head { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; flex-wrap:wrap; }
.quote-info strong { font-size:13px; color:var(--muted); text-transform:uppercase; letter-spacing:.02em; }
.public-quote { border-top:4px solid var(--primary); }
.quote-actions .actions { margin-top:8px; }

@media (max-width: 820px) {
    .dashboard-grid { grid-template-columns:1fr; }
    .two-cols { grid-template-columns:1fr; }
    .mini-card { padding:14px; }
    .quote-head { display:block; }
    .quote-head .badge { margin-top:10px; }
}

/* Atualização 13: funil comercial, gráficos e custo de produção */
.panel-head {
    display:flex;
    justify-content:space-between;
    align-items:flex-end;
    gap:16px;
    margin-bottom:16px;
}
.panel-head h2 { margin-bottom:4px; }
.period-filter { width:min(220px, 100%); }
.period-filter label { font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; }
.pipeline-grid {
    display:grid;
    grid-template-columns:repeat(3, minmax(170px, 1fr));
    gap:12px;
    margin-bottom:16px;
}
.stage-card {
    border-radius:14px;
    padding:16px;
    background:#eff6ff;
    border:1px solid #bfdbfe;
}
.stage-card.advanced { background:#fffbeb; border-color:#fde68a; }
.stage-card.closed { background:#f0fdf4; border-color:#bbf7d0; }
.stage-label { color:var(--muted); font-size:13px; font-weight:700; margin-bottom:8px; }
.stage-number { font-size:30px; line-height:1; font-weight:800; margin-bottom:7px; }
.stage-value { font-size:15px; font-weight:700; margin-bottom:12px; }
.bar-track { width:100%; height:8px; background:rgba(15,23,42,.08); border-radius:999px; overflow:hidden; }
.bar-fill { display:block; height:100%; border-radius:999px; background:#2563eb; }
.stage-card.advanced .bar-fill { background:#d97706; }
.stage-card.closed .bar-fill { background:#16a34a; }
.outcome-grid { grid-template-columns:repeat(4, minmax(190px,1fr)); }
.dashboard-warning { margin-bottom:18px; }
.chart-legend { display:flex; gap:18px; margin:0 0 16px; color:var(--muted); font-size:13px; font-weight:700; }
.chart-legend span::before { content:''; display:inline-block; width:12px; height:12px; border-radius:3px; margin-right:6px; vertical-align:-1px; }
.legend-orcado::before { background:#bfdbfe; }
.legend-fechado::before { background:#22c55e; }
.monthly-chart { display:flex; flex-direction:column; gap:13px; }
.month-row { display:grid; grid-template-columns:60px 1fr; gap:12px; align-items:center; }
.month-label { font-size:12px; font-weight:700; color:var(--muted); text-transform:capitalize; }
.month-bars { display:flex; flex-direction:column; gap:5px; }
.monthly-track { height:24px; border-radius:7px; background:#f3f4f6; position:relative; overflow:hidden; }
.monthly-bar { display:block; position:absolute; inset:0 auto 0 0; min-width:0; border-radius:7px; }
.monthly-bar.orcado { background:#bfdbfe; }
.monthly-bar.fechado { background:#22c55e; }
.monthly-track small { position:relative; z-index:1; line-height:24px; padding-left:8px; color:#111827; font-size:11px; font-weight:700; }
.compact-kpis { grid-template-columns:repeat(2, minmax(145px,1fr)); }
.compact-kpis .kpi { font-size:20px; }
.compact-kpis .balance-card { grid-column:span 2; }
.summary-simple { margin-top:0; }
.production-cost-card { border-top:4px solid var(--success); }
.cost-head { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; flex-wrap:wrap; }
.cost-head h2 { margin-bottom:4px; }
.cost-summary { background:#f0fdf4; border:1px solid #bbf7d0; padding:12px; border-radius:10px; margin:4px 0 16px; }

@media (max-width: 980px) {
    .outcome-grid { grid-template-columns:repeat(2, minmax(180px,1fr)); }
}
@media (max-width: 820px) {
    .panel-head { display:block; }
    .period-filter { margin-top:14px; width:100%; }
    .pipeline-grid, .outcome-grid, .compact-kpis { grid-template-columns:1fr; }
    .compact-kpis .balance-card { grid-column:auto; }
    .stage-number { font-size:28px; }
    .month-row { grid-template-columns:54px 1fr; gap:8px; }
}
.checkbox-alert { display:flex; gap:10px; align-items:flex-start; background:#fffbeb; border:1px solid #fde68a; border-radius:10px; padding:12px; margin:0 0 14px; font-weight:400; }
.checkbox-alert input { width:auto; margin-top:3px; flex:0 0 auto; }
.checkbox-alert strong { display:block; color:#92400e; }
.checkbox-alert small { display:block; color:#92400e; margin-top:3px; line-height:1.4; }

/* Atualização 14: filtros de competência e período */
.filter-grid {
    display:grid;
    grid-template-columns:minmax(230px, 2fr) minmax(150px, 1fr) minmax(135px, 1fr) minmax(135px, 1fr) auto;
    gap:12px;
    align-items:end;
    margin-bottom:8px;
}
.filter-grid .filter-search { min-width:0; }
.filter-actions { display:flex; gap:8px; align-items:end; white-space:nowrap; }
.period-note {
    margin:10px 0 16px;
    padding:9px 12px;
    border-radius:9px;
    background:#f8fafc;
    border:1px solid var(--line);
    color:var(--muted);
    font-size:13px;
}
.period-summary { grid-template-columns:repeat(3, minmax(160px, 1fr)); margin:12px 0 18px; }
.dashboard-period-filter {
    display:grid;
    grid-template-columns:minmax(145px,1.2fr) minmax(128px,1fr) minmax(128px,1fr) auto;
    gap:9px;
    align-items:end;
    min-width:min(565px, 100%);
}
.dashboard-period-filter label { font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; }
.carryover-box { margin:0 0 18px; }

@media (max-width: 980px) {
    .filter-grid { grid-template-columns:repeat(2, minmax(0,1fr)); }
    .filter-grid .filter-search, .filter-actions { grid-column:span 2; }
    .dashboard-period-filter { min-width:100%; margin-top:14px; grid-template-columns:repeat(2, minmax(0,1fr)); }
    .dashboard-period-filter .btn { width:100%; }
}
@media (max-width: 620px) {
    .filter-grid, .dashboard-period-filter, .period-summary { grid-template-columns:1fr; }
    .filter-grid .filter-search, .filter-actions { grid-column:auto; }
    .filter-actions { display:grid; grid-template-columns:1fr 1fr; }
    .filter-actions .btn { width:100%; text-align:center; }
}
