:root {
  --bg:        #0f0f0f;
  --surface:   #1a1a1a;
  --surface2:  #222222;
  --border:    #2e2e2e;
  --text:      #e8e8e8;
  --muted:     #888;
  --accent:    #f59e0b;
  --accent-bg: #1c1608;
  --green:     #22c55e;
  --green-bg:  #0a1f10;
  --blue:      #3b82f6;
  --blue-bg:   #0d1826;
  --red:       #ef4444;
  --red-bg:    #1f0a0a;
  --teal:      #14b8a6;
  --teal-bg:   #071918;
  --purple:    #a855f7;
  --purple-bg: #160d1f;
  --radius:    8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.3px;
}
.sidebar-logo p { font-size: 11px; color: var(--muted); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }
.nav-item .icon { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.main { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h2 { font-size: 16px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

.page { padding: 24px; flex: 1; }
.page.hidden { display: none; }

/* ── Cards ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi-up { color: var(--green); }
.kpi-down { color: var(--red); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 16px;
}

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 16px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }

/* ── Chart containers ── */
.chart-wrap { position: relative; }

/* ── Proporções ── */
.prop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
}
.prop-name { width: 110px; color: var(--muted); flex-shrink: 0; }
.prop-bar-bg { flex: 1; background: var(--surface2); border-radius: 4px; height: 6px; overflow: hidden; }
.prop-bar-fill { height: 6px; border-radius: 4px; transition: width 0.4s; }
.prop-val { width: 48px; text-align: right; font-weight: 600; font-size: 13px; }
.prop-pct { width: 44px; text-align: right; font-size: 11px; color: var(--muted); }

/* ── Tabelas ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  padding: 8px 12px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th:first-child { text-align: left; }
td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
td:first-child { text-align: left; font-weight: 500; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.td-muted { color: var(--muted); font-weight: 400 !important; }
.td-bold { font-weight: 700; }
.td-warn { color: var(--accent); }
.td-danger { color: var(--red); }
.td-ok { color: var(--green); }

/* Cabeçalho de categoria na tabela */
.tr-cat td {
  background: var(--surface2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-a { background: var(--green-bg); color: var(--green); }
.badge-b { background: var(--accent-bg); color: var(--accent); }
.badge-c { background: var(--red-bg); color: var(--red); }
.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-warn { background: var(--accent-bg); color: var(--accent); }
.badge-err { background: var(--red-bg); color: var(--red); }

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.btn-primary:hover { background: #d97706; border-color: #d97706; }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Upload ── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--accent); }
.upload-icon { font-size: 36px; margin-bottom: 12px; }
.upload-text { color: var(--muted); font-size: 13px; }
.upload-text strong { color: var(--text); }

/* ── Toggle / Checkbox ── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-label { font-size: 13px; }
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; top: 2px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent-bg); border-color: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(16px); background: var(--accent); }

/* ── Alert ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-warn { background: var(--accent-bg); border: 1px solid var(--accent); color: var(--accent); }
.alert-ok { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.alert-err { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }

/* ── Seletor de mês ── */
.mes-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.mes-chip {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 12px;
  cursor: pointer;
  background: var(--surface2);
  color: var(--muted);
  transition: all 0.15s;
}
.mes-chip.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.mes-chip:hover:not(.active) { border-color: var(--muted); color: var(--text); }

/* ── Meta bar ── */
.meta-wrap { margin-top: 8px; }
.meta-bar-bg { background: var(--surface2); border-radius: 4px; height: 8px; overflow: hidden; margin: 6px 0; }
.meta-bar-fill { height: 8px; border-radius: 4px; background: var(--accent); transition: width 0.5s; }
.meta-bar-fill.atingida { background: var(--green); }
.meta-info { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 1000;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.ok  { background: var(--green); color: #000; }
#toast.err { background: var(--red);   color: #fff; }
#toast.warn { background: var(--accent); color: #000; }

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Responsivo ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .nav-item span, .sidebar-logo p, .sidebar-logo h1 { display: none; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
