/* =============================================
   LeadIBGE — Global Styles
   ============================================= */

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

:root {
  --primary:    #4F46E5;
  --primary-light: #EEF2FF;
  --primary-dark:  #3730A3;
  --success:    #10B981;
  --warning:    #F59E0B;
  --danger:     #EF4444;
  --purple:     #8B5CF6;
  --bg:         #F8FAFC;
  --surface:    #FFFFFF;
  --border:     #E2E8F0;
  --text:       #1E293B;
  --text-muted: #64748B;
  --sidebar-w:  240px;
  --radius:     12px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 25px rgba(0,0,0,.1);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Sidebar ──────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 28px; }
.logo-text  { font-size: 18px; font-weight: 700; color: var(--primary); }

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--border); }
.db-status { display: flex; align-items: center; gap: 8px; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  &.online  { background: var(--success); box-shadow: 0 0 5px var(--success); }
  &.offline { background: var(--danger); }
  &.connecting { background: var(--warning); animation: pulse 1.2s infinite; }
}
.status-text { font-size: 12px; color: var(--text-muted); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Main Content ─────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 0 24px 40px;
  max-width: calc(100vw - var(--sidebar-w));
}

/* ── Top Bar ──────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}

.topbar-title h1 { font-size: 20px; font-weight: 700; }
.topbar-title .subtitle { font-size: 12px; color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-btn { background: none; border: none; font-size: 20px; cursor: pointer; display: none; }

/* ── Buttons ──────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-outline  { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── KPI Cards ────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  box-shadow: var(--shadow);
}

.kpi-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.kpi-icon.blue   { background: #EEF2FF; }
.kpi-icon.green  { background: #ECFDF5; }
.kpi-icon.orange { background: #FFF7ED; }
.kpi-icon.purple { background: #F5F3FF; }

.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.kpi-value { font-size: 26px; font-weight: 800; line-height: 1.1; margin-bottom: 4px; }
.kpi-delta { font-size: 11px; color: var(--text-muted); }
.kpi-delta.positive { color: var(--success); }
.kpi-delta.negative { color: var(--danger); }

/* ── Charts ───────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-card.large { }

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.chart-header h3 { font-size: 15px; font-weight: 600; }
.chart-actions { display: flex; gap: 4px; }
.chip {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.chip.active, .chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Table ────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.table-header h3 { font-size: 15px; font-weight: 600; }
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: var(--bg); }
.data-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg); }
.loading-row { text-align: center; color: var(--text-muted); padding: 30px !important; }

/* ── Badges ───────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green  { background: #ECFDF5; color: #059669; }
.badge-blue   { background: #EEF2FF; color: #4F46E5; }
.badge-orange { background: #FFF7ED; color: #D97706; }
.badge-red    { background: #FEF2F2; color: #DC2626; }
.badge-gray   { background: #F1F5F9; color: #475569; }
.badge-purple { background: #F5F3FF; color: #7C3AED; }

/* ── Score Bar ────────────────────────────── */
.score-bar { display: flex; align-items: center; gap: 8px; }
.score-track {
  flex: 1; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden;
}
.score-fill {
  height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, #EF4444, #F59E0B, #10B981);
}
.score-num { font-size: 12px; font-weight: 700; min-width: 28px; text-align: right; }

/* ── Form ─────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-hint  { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }

/* ── Modal ────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted);
  line-height: 1;
}
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 0 24px 20px;
}

/* ── Filter Bar ───────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
}
.filter-bar .form-input { width: auto; }
.filter-search { flex: 1; min-width: 200px; }
.filter-bar select { width: auto; padding: 8px 12px; }

/* ── Analysis ─────────────────────────────── */
.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.info-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing:.5px; }
.info-row { display:flex; justify-content:space-between; padding:8px 0; border-bottom:1px solid var(--border); font-size:13px; }
.info-row:last-child { border-bottom: none; }
.info-row strong { color: var(--text); }

/* ── Responsive ───────────────────────────── */
@media(max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }
}
@media(max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; max-width: 100vw; }
  .menu-btn { display: flex; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}
@media(max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Toast ────────────────────────────────── */
#toastContainer {
  position: fixed; bottom: 20px; right: 20px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; min-width: 200px;
  box-shadow: var(--shadow-md);
  animation: slideIn .3s ease;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger);  }
.toast.warning { background: var(--warning); }
@keyframes slideIn {
  from { transform: translateX(60px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Ibge Analysis Widgets ───────────────── */
.ibge-widget {
  background: linear-gradient(135deg, var(--primary) 0%, var(--purple) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.ibge-widget h2 { font-size: 14px; opacity: .8; margin-bottom: 4px; }
.ibge-widget .big { font-size: 32px; font-weight: 800; }
.ibge-widget .sub { font-size: 12px; opacity: .7; }

.progress-label { display:flex; justify-content:space-between; font-size:12px; margin-bottom:4px; }
.progress-track { height:8px; background:var(--border); border-radius:99px; overflow:hidden; margin-bottom:12px; }
.progress-fill  { height:100%; border-radius:99px; background:var(--primary); }

/* ── Tabs ─────────────────────────────────── */
.tabs { display:flex; gap:4px; border-bottom:2px solid var(--border); margin-bottom:20px; }
.tab-btn {
  padding:10px 16px; background:none; border:none;
  font-size:14px; font-weight:500; cursor:pointer; color:var(--text-muted);
  border-bottom:2px solid transparent; margin-bottom:-2px;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color:var(--primary); border-bottom-color:var(--primary); font-weight:600; }

/* ── Empty State ──────────────────────────── */
.empty-state {
  text-align:center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.empty-state p  { font-size: 14px; }
