:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #151922;
  --muted: #6c7480;
  --line: #e3e7ed;
  --accent: #d71920;
  --accent-dark: #aa1016;
  --positive: #13795b;
  --negative: #c4333d;
  --warning: #a96500;
  --sidebar: #11151c;
  --shadow: 0 14px 38px rgba(20, 28, 40, 0.075);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 254px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 28px 22px;
  display: flex; flex-direction: column; color: #fff; background: var(--sidebar);
}
.brand-mark {
  width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 23px; font-weight: 900;
  box-shadow: 0 12px 28px rgba(215, 25, 32, 0.28);
}
.brand-copy { margin-top: 13px; display: flex; flex-direction: column; letter-spacing: .08em; }
.brand-copy small { margin-top: 3px; color: #919aa6; font-size: 12px; letter-spacing: 0; }
.sidebar nav { margin-top: 42px; display: grid; gap: 7px; }
.nav-item {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 14px;
  display: flex; align-items: center; gap: 12px; background: transparent; color: #aeb5bf; text-align: left;
}
.nav-item:hover, .nav-item.active { background: #202630; color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 4px; color: #d6dae0; font-size: 12px; }
.sidebar-footer small { color: #7f8792; }

.main-content { min-width: 0; padding: 32px 40px 60px; }
.topbar { margin-bottom: 22px; display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 7px 0; font-size: clamp(28px, 3vw, 34px); line-height: 1.08; letter-spacing: -.025em; }
h2 { margin: 5px 0 0; font-size: 19px; }
.topbar p, .lead { margin: 0; color: var(--muted); line-height: 1.55; }

.primary-button, .filter-button, .table-action {
  border: 0; border-radius: 11px; background: var(--accent); color: #fff; text-decoration: none;
  font-weight: 780; display: inline-flex; align-items: center; justify-content: center;
}
.primary-button { padding: 13px 18px; }
.primary-button.compact { padding: 11px 16px; }
.primary-button:hover, .filter-button:hover, .table-action:hover { background: var(--accent-dark); }

.filter-panel {
  margin-bottom: 22px; padding: 15px; display: grid;
  grid-template-columns: .65fr 1fr 1.2fr .85fr .9fr auto; gap: 10px; align-items: end;
  background: rgba(255, 255, 255, .9); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 8px 25px rgba(20, 28, 40, .04);
}
.filter-panel label, .setup-form label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter-panel label span, .setup-form label span {
  color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
}
.filter-panel select, .setup-form input, .search-input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  background: #fff; color: var(--ink); outline: none;
}
.filter-panel select:focus, .setup-form input:focus, .search-input:focus { border-color: rgba(215, 25, 32, .55); box-shadow: 0 0 0 3px rgba(215, 25, 32, .08); }
.filter-button { height: 42px; padding: 0 17px; }

.loading-card, .panel, .kpi-card, .upload-card, .setup-card {
  background: var(--panel); border: 1px solid rgba(224, 228, 234, .94); border-radius: 18px; box-shadow: var(--shadow);
}
.loading-card { padding: 24px; }
.hidden { display: none !important; }
.dashboard-section { display: none; }
.dashboard-section.active { display: block; }

.kpi-grid { margin-bottom: 18px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.kpi-card { position: relative; overflow: hidden; padding: 19px; }
.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .055em; text-transform: uppercase; }
.kpi-value { margin: 10px 0 8px; font-size: 24px; font-weight: 870; letter-spacing: -.03em; }
.kpi-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.delta { padding: 4px 7px; border-radius: 999px; font-weight: 800; }
.delta.positive { background: #e7f5ef; color: var(--positive); }
.delta.negative { background: #fdebed; color: var(--negative); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, .8fr); gap: 18px; }
.quality-grid { display: grid; grid-template-columns: 1.4fr .8fr; gap: 18px; }
.panel { min-width: 0; padding: 22px; }
.panel-heading { margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.context-chip { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; white-space: nowrap; }

.comparison-bars { display: grid; gap: 17px; }
.bar-row { display: grid; grid-template-columns: 180px 1fr 105px; align-items: center; gap: 14px; }
.bar-label { font-size: 13px; font-weight: 720; }
.bar-track { position: relative; height: 10px; overflow: hidden; border-radius: 999px; background: #edf0f4; }
.bar-fill { height: 100%; min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #f05a60); }
.budget-marker { position: absolute; top: -3px; bottom: -3px; left: 80%; width: 1px; background: #757d89; opacity: .55; }
.bar-value { text-align: right; font-size: 12px; font-weight: 800; }
.bar-value.positive { color: var(--positive); }
.bar-value.negative { color: var(--negative); }

.insight-list { display: grid; gap: 12px; }
.insight { padding: 14px; border: 1px solid var(--line); border-radius: 13px; }
.insight strong { display: block; margin-bottom: 5px; font-size: 13px; }
.insight p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.insight.positive { border-left: 4px solid var(--positive); }
.insight.negative { border-left: 4px solid var(--negative); }
.insight.neutral { border-left: 4px solid #667085; }

.trend-panel { margin-top: 18px; }
.trend-chart { min-height: 270px; }
.trend-legend { display: flex; justify-content: flex-end; gap: 18px; color: var(--muted); font-size: 12px; }
.trend-legend span { display: inline-flex; align-items: center; gap: 7px; }
.trend-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.actual-dot { background: var(--accent); }
.budget-dot { background: #aeb5bf; }
.trend-bars { height: 230px; padding-top: 18px; display: flex; align-items: stretch; justify-content: space-around; gap: 12px; border-bottom: 1px solid var(--line); }
.trend-column { min-width: 44px; flex: 1; display: grid; grid-template-rows: 1fr auto auto; gap: 5px; text-align: center; }
.trend-pair { height: 165px; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.trend-pair span { width: min(22px, 34%); border-radius: 5px 5px 0 0; }
.trend-actual { background: var(--accent); }
.trend-budget { background: #b9c0c9; }
.trend-column strong { font-size: 12px; }
.trend-column small { color: var(--muted); font-size: 10px; }

.table-heading { align-items: flex-end; }
.search-input { min-width: 220px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; min-width: 980px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; background: #f8f9fb; color: #59616d; font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
th:first-child, td:first-child { text-align: left; }
tbody tr { background: #fff; }
tbody tr:hover { background: #fafbfc; }
tbody tr.total td { background: #f5f6f8; font-weight: 800; }
.cell-positive { color: var(--positive); font-weight: 700; }
.cell-negative { color: var(--negative); font-weight: 700; }
.history-table { min-width: 1050px; }
.history-table td:last-child, .history-table th:last-child { text-align: center; }
.table-action { padding: 7px 10px; font-size: 11px; }
.selected-row td { background: #fff5f5 !important; }

.warning-card { margin-bottom: 12px; padding: 15px; border: 1px solid var(--line); border-left: 4px solid var(--warning); border-radius: 13px; }
.warning-card.severity-critical { border-left-color: var(--negative); }
.warning-card.severity-high { border-left-color: #d36d00; }
.warning-card h3 { margin: 0 0 7px; font-size: 14px; }
.warning-card p { margin: 0 0 7px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.warning-card code { padding: 3px 5px; border-radius: 5px; background: #f2f3f5; font-size: 11px; white-space: normal; }
.stats-list { display: grid; gap: 10px; }
.stat-row { padding: 11px 0; display: flex; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); font-size: 13px; }
.stat-row span { color: var(--muted); }
.empty-state { min-height: 150px; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { margin: 5px 0 0; }

.notice { margin: 12px 0; padding: 13px 15px; border-radius: 12px; }
.notice.error { background: #fdebed; color: #8f2027; }
.notice.success { background: #e8f6f0; color: #106846; }
.notice small { opacity: .8; }

.upload-page, .setup-page { min-height: 100vh; padding: 30px; display: grid; place-items: center; }
.upload-shell { width: min(720px, 100%); }
.setup-shell { width: min(700px, 100%); }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--muted); text-decoration: none; }
.upload-card, .setup-card { padding: 32px; }
.upload-card p, .setup-card p { color: var(--muted); line-height: 1.6; }
.file-drop { margin: 20px 0; padding: 22px; display: flex; flex-direction: column; gap: 10px; border: 1px dashed #bdc3cc; border-radius: 14px; background: #f8f9fb; }
.command-box { margin-top: 22px; padding: 16px; display: grid; gap: 9px; border-radius: 13px; background: #11151c; color: #fff; }
.command-box code { color: #d7dde6; font-size: 12px; white-space: normal; overflow-wrap: anywhere; }
.brand-row { display: flex; align-items: center; gap: 15px; }
.brand-row h1 { margin: 4px 0 0; }
.setup-form { margin-top: 22px; display: grid; gap: 14px; }
.form-grid.two { display: grid; grid-template-columns: 1fr 140px; gap: 12px; }
.setup-note { margin-top: 20px; padding: 14px; border-radius: 12px; background: #f6f7f9; color: var(--muted); font-size: 12px; line-height: 1.55; }

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid, .quality-grid { grid-template-columns: 1fr; }
  .filter-panel { grid-template-columns: repeat(3, 1fr); }
  .filter-button { width: 100%; }
  .app-shell { grid-template-columns: 84px minmax(0, 1fr); }
  .brand-copy, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; }
  .nav-item span { font-size: 16px; }
  .sidebar { padding: 24px 15px; }
  .sidebar-footer { display: none; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 12px 16px; flex-direction: row; align-items: center; }
  .sidebar nav { margin: 0 0 0 auto; display: flex; gap: 2px; overflow-x: auto; }
  .nav-item { width: auto; padding: 10px; }
  .brand-copy, .sidebar-footer { display: none; }
  .main-content { padding: 24px 16px 45px; }
  .topbar { display: block; }
  .topbar .primary-button { margin-top: 16px; }
  .filter-panel { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; gap: 7px; }
  .bar-value { text-align: left; }
  .panel { padding: 16px; }
  .table-heading { display: block; }
  .table-heading .search-input { margin-top: 14px; min-width: 0; }
  .form-grid.two { grid-template-columns: 1fr; }
  .upload-page, .setup-page { padding: 18px; }
  .upload-card, .setup-card { padding: 22px; }
}
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.user-chip { padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); font-size: 12px; font-weight: 750; }
.secondary-button { border: 1px solid var(--line); border-radius: 11px; background: #fff; color: var(--ink); text-decoration: none; font-weight: 750; display: inline-flex; align-items: center; justify-content: center; }
.secondary-button.compact { padding: 10px 14px; }
.secondary-button:hover { border-color: #c8cdd5; background: #f7f8fa; }
.form-divider { position: relative; margin: 7px 0 1px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.form-divider::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line); }
.form-divider span { position: relative; z-index: 1; padding-right: 10px; background: #fff; }
.login-shell { width: min(480px, 100%); }
@media (max-width: 760px) { .topbar-actions { margin-top: 16px; flex-wrap: wrap; } .user-chip { display: none; } }

/* v3 — pacote completo, realizado ajustado e comparativo de unidades */
.disabled { opacity: .48; pointer-events: none; cursor: not-allowed; }
.kpi-adjusted { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.kpi-adjusted strong { color: var(--ink); font-size: 12px; }
.adjusted-dot, .trend-adjusted { background: #5b6574; }
.ranking-heading { align-items: end; }
.inline-control { display: flex; flex-direction: column; gap: 6px; min-width: 230px; }
.inline-control span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.inline-control select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink); }
.ranking-summary { margin-bottom: 18px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.ranking-card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #f8f9fb; }
.ranking-card span, .ranking-card small { display: block; color: var(--muted); }
.ranking-card span { font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.ranking-card strong { display: block; margin: 8px 0 4px; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.ranking-card small { font-size: 11px; }
.ranking-table { min-width: 1050px; }
.unit-link { padding: 0; border: 0; background: transparent; color: var(--accent); font-weight: 800; text-align: left; }
.unit-link:hover { text-decoration: underline; }
.status-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 86px; padding: 5px 9px; border-radius: 999px; background: #eef1f5; color: #5b6470; font-size: 10px; font-weight: 850; text-transform: uppercase; }
.status-completed { background: #e7f5ef; color: var(--positive); }
.status-processing { background: #fff4dd; color: var(--warning); }
.status-failed { background: #fdebed; color: var(--negative); }
.check-row { display: flex !important; flex-direction: row !important; align-items: center; gap: 9px !important; }
.check-row input { width: auto !important; }
.check-row span { letter-spacing: 0 !important; text-transform: none !important; font-size: 12px !important; }

@media (max-width: 900px) {
  .ranking-summary { grid-template-columns: 1fr; }
  .ranking-heading { align-items: stretch; flex-direction: column; }
  .inline-control { min-width: 0; width: 100%; }
}

/* v4 — metas, alertas automáticos e resumo executivo */
.executive-grid { display: grid; grid-template-columns: minmax(280px, .55fr) minmax(0, 1.45fr); gap: 18px; }
.score-panel { display: flex; flex-direction: column; }
.score-gauge {
  --score: 0; width: 190px; height: 190px; margin: 8px auto 18px; border-radius: 50%;
  display: grid; place-content: center; text-align: center; position: relative;
  background: conic-gradient(var(--accent) calc(var(--score) * 1%), #e9edf2 0);
}
.score-gauge::before { content: ""; position: absolute; inset: 15px; border-radius: 50%; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.score-gauge strong, .score-gauge span { position: relative; z-index: 1; }
.score-gauge strong { font-size: 42px; letter-spacing: -.05em; }
.score-gauge span { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.score-gauge.score-excellent { background: conic-gradient(var(--positive) calc(var(--score) * 1%), #e9edf2 0); }
.score-gauge.score-good { background: conic-gradient(#34836c calc(var(--score) * 1%), #e9edf2 0); }
.score-gauge.score-attention { background: conic-gradient(var(--warning) calc(var(--score) * 1%), #e9edf2 0); }
.score-gauge.score-critical { background: conic-gradient(var(--negative) calc(var(--score) * 1%), #e9edf2 0); }
.score-note { margin: auto 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; text-align: center; }
.executive-metrics { display: grid; gap: 11px; }
.execution-row { padding: 12px 13px; display: grid; grid-template-columns: minmax(150px, .8fr) minmax(140px, 1fr) minmax(155px, .75fr); align-items: center; gap: 14px; border: 1px solid var(--line); border-radius: 13px; }
.execution-row > div:first-child strong, .execution-row > div:last-child strong { display: block; font-size: 12px; }
.execution-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.execution-row > div:last-child { text-align: right; }
.execution-progress { height: 9px; overflow: hidden; border-radius: 999px; background: #edf0f4; }
.execution-progress span { display: block; height: 100%; border-radius: inherit; background: var(--positive); }
.execution-row.status-attention .execution-progress span { background: #c58a28; }
.execution-row.status-warning .execution-progress span { background: var(--warning); }
.execution-row.status-critical .execution-progress span { background: var(--negative); }
.executive-content { margin-top: 18px; }
.automatic-alerts { display: grid; gap: 11px; }
.automatic-alert { padding: 14px; border: 1px solid var(--line); border-left: 4px solid var(--warning); border-radius: 13px; }
.automatic-alert.severity-critical { border-left-color: var(--negative); }
.automatic-alert.severity-high { border-left-color: #d36d00; }
.automatic-alert > div { display: flex; align-items: center; gap: 9px; }
.automatic-alert > div span { padding: 3px 6px; border-radius: 999px; background: #f2f3f5; color: var(--muted); font-size: 9px; font-weight: 850; text-transform: uppercase; }
.automatic-alert strong { font-size: 13px; }
.automatic-alert p { margin: 7px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.automatic-alert small { color: var(--ink); font-size: 11px; font-weight: 650; }
.executive-ranking { display: grid; gap: 20px; }
.executive-ranking h3 { margin: 0 0 9px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.executive-unit { width: 100%; padding: 10px 0; display: grid; grid-template-columns: 25px minmax(0, 1fr) auto; align-items: center; gap: 10px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.executive-unit > span { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 8px; background: #e8f6f0; color: var(--positive); font-size: 10px; font-weight: 850; }
.executive-unit.warning > span { background: #fdebed; color: var(--negative); }
.executive-unit strong, .executive-unit small { display: block; }
.executive-unit strong { font-size: 12px; }
.executive-unit small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.executive-unit b { font-size: 11px; }
.empty-state.compact { min-height: 75px; }
.executive-status.status-excellent, .target-status.status-good { background: #e7f5ef; color: var(--positive); }
.executive-status.status-good { background: #e9f3ef; color: #286d59; }
.executive-status.status-attention, .target-status.status-attention { background: #fff4dd; color: var(--warning); }
.executive-status.status-critical, .target-status.status-critical { background: #fdebed; color: var(--negative); }
.executive-status.status-unknown, .target-status.status-unknown { background: #eef1f5; color: #5b6470; }
.target-status.status-warning { background: #fff0df; color: #b15a00; }
.target-help { margin: -5px 0 17px; padding: 12px 14px; border-radius: 11px; background: #f6f7f9; color: var(--muted); font-size: 12px; }
.target-table { min-width: 1050px; }
.target-status { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 9px; font-weight: 850; text-transform: uppercase; }
.danger-link { padding: 5px; border: 0; background: transparent; color: var(--negative); font-size: 10px; font-weight: 800; }
.target-editor-panel { margin-top: 18px; }
.target-form { display: grid; grid-template-columns: 1.15fr 1fr .85fr .85fr 1.4fr auto; align-items: end; gap: 12px; }
.target-form label { display: flex; flex-direction: column; gap: 6px; }
.target-form label span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.target-form input, .target-form select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; color: var(--ink); }
.target-form small { color: var(--muted); font-size: 9px; }
.target-form .primary-button { min-height: 42px; }

@media (max-width: 1180px) {
  .executive-grid { grid-template-columns: 1fr; }
  .target-form { grid-template-columns: repeat(2, 1fr); }
  .target-notes { grid-column: span 2; }
}
@media (max-width: 760px) {
  .execution-row { grid-template-columns: 1fr; }
  .execution-row > div:last-child { text-align: left; }
  .target-form { grid-template-columns: 1fr; }
  .target-notes { grid-column: auto; }
  .score-gauge { width: 160px; height: 160px; }
}
