/* =============================================
   BASE.CSS — Reset, Variaveis, Grid, Dark Mode
   BI Desafio v1.0
   ============================================= */

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
table { border-collapse: collapse; width: 100%; }

/* --- CSS Variables (Light) --- */
:root {
  --bg: #f5f7fa;
  --bg-subtle: #edf0f5;
  --card: #ffffff;
  --card-hover: #f8f9fc;
  --text: #2c3e50;
  --text-secondary: #4a5568;
  --muted: #6c757d;
  --border: #e9ecef;
  --border-light: #f0f0f0;

  --primary: #667eea;
  --primary-light: #8c9ef5;
  --primary-dark: #4c63d2;
  --primary-bg: rgba(102, 126, 234, 0.08);
  --primary2: #764ba2;

  --success: #28a745;
  --success-bg: rgba(40, 167, 69, 0.08);
  --danger: #dc3545;
  --danger-bg: rgba(220, 53, 69, 0.08);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.08);
  --info: #17a2b8;
  --info-bg: rgba(23, 162, 184, 0.08);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  --text-muted: #6c757d;
  --bg-secondary: #edf0f5;
  --bg-card: #ffffff;

  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bottom-nav-h: 64px;

  --transition: 0.2s ease;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-subtle: #1a1d2e;
  --card: #1e2235;
  --card-hover: #252a40;
  --text: #e2e8f0;
  --text-secondary: #a0aec0;
  --muted: #718096;
  --border: #2d3348;
  --border-light: #252a3e;
  --text-muted: #718096;
  --bg-secondary: #1a1d2e;
  --bg-card: #1e2235;

  --primary-bg: rgba(102, 126, 234, 0.12);
  --success-bg: rgba(40, 167, 69, 0.12);
  --danger-bg: rgba(220, 53, 69, 0.12);
  --warning-bg: rgba(245, 158, 11, 0.12);
  --info-bg: rgba(23, 162, 184, 0.12);

  --shadow: 0 2px 10px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --bg-subtle: #1a1d2e;
    --card: #1e2235;
    --card-hover: #252a40;
    --text: #e2e8f0;
    --text-secondary: #a0aec0;
    --muted: #718096;
    --border: #2d3348;
    --border-light: #252a3e;
    --primary-bg: rgba(102, 126, 234, 0.12);
    --success-bg: rgba(40, 167, 69, 0.12);
    --danger-bg: rgba(220, 53, 69, 0.12);
    --warning-bg: rgba(245, 158, 11, 0.12);
    --info-bg: rgba(23, 162, 184, 0.12);
    --shadow: 0 2px 10px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  }
}

/* --- Layout --- */
.hidden { display: none !important; }

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}
.brand-icon { font-size: 1.3rem; }

.edition-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  max-width: 220px;
}

/* --- Shell Grid --- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

/* --- Sidebar --- */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
  height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
}

.nav-list { list-style: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-item:hover {
  background: var(--primary-bg);
  color: var(--primary);
}
.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.nav-item .nav-icon { font-size: 1.1rem; width: 24px; text-align: center; }
.nav-item .nav-label { white-space: nowrap; }

/* --- Main Content --- */
.main {
  padding: 20px 24px;
  overflow-y: auto;
  min-height: calc(100vh - var(--topbar-h));
  background: var(--bg);
}

/* --- KPI Grid --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* --- Chart Grid --- */
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
.chart-full { grid-column: 1 / -1; }

/* --- Section --- */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Date Filter --- */
.filtro-data-box {
  display: flex;
  align-items: center;
  gap: 8px;
}
.date-input {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
}
.date-sep { color: var(--muted); font-size: 0.8rem; }
.date-shortcuts { display: flex; gap: 4px; margin-left: 8px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-block { width: 100%; }
.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--primary-bg); color: var(--primary); }
.btn-chip {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}
.btn-chip:hover, .btn-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* --- Alert Bar --- */
.alert-bar {
  display: flex;
  gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.alert-bar::-webkit-scrollbar { display: none; }
.alert-bar:empty { display: none; padding: 0; }
.alert-bar:not(:empty) { padding: 8px 16px; background: var(--bg-subtle); border-bottom: 1px solid var(--border); }

/* --- Bottom Nav (mobile) --- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  justify-content: space-around;
  align-items: center;
  padding: 6px 0;
  z-index: 100;
  height: var(--bottom-nav-h);
}
.bottom-nav .bnav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  color: var(--muted);
  padding: 4px 8px;
  cursor: pointer;
  transition: color var(--transition);
}
.bottom-nav .bnav-item .bnav-icon { font-size: 1.2rem; }
.bottom-nav .bnav-item.active { color: var(--primary); }

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 80px; right: 20px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
  font-size: 0.85rem;
  animation: toastIn 0.3s ease;
  pointer-events: auto;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* --- Login --- */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 40px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo { margin-bottom: 32px; }
.login-icon { font-size: 3rem; display: block; margin-bottom: 8px; }
.login-card h1 { font-size: 1.8rem; color: var(--text); margin-bottom: 4px; }
.login-subtitle { color: var(--muted); font-size: 0.95rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-form label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }
.login-form input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.login-msg { text-align: center; font-size: 0.85rem; color: var(--muted); min-height: 20px; }
.login-msg.success { color: var(--success); }
.login-msg.error { color: var(--danger); }

/* --- Freshness Badge --- */
.freshness-badge {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 4px 10px;
  background: var(--bg-subtle);
  border-radius: 20px;
  white-space: nowrap;
}

/* --- Responsive --- */
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .main { padding-bottom: calc(var(--bottom-nav-h) + 16px); }
  /* Topbar: stack into 2 rows */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
  }
  .topbar-left { flex: 1; min-width: 0; }
  .topbar-center {
    order: 3;
    flex: 0 0 100%;
    justify-content: flex-start;
  }
  .topbar-right { flex-shrink: 0; }
  .filtro-data-box { flex-wrap: wrap; gap: 4px; width: 100%; }
  .date-input { flex: 1; min-width: 90px; max-width: 120px; }
  .date-shortcuts { margin-left: 0; flex-wrap: wrap; }
  .edition-select { max-width: 160px; font-size: 0.78rem; }
}
@media (max-width: 768px) {
  .chart-row { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .topbar { padding: 6px 10px; }
  .main { padding: 12px 10px; padding-bottom: calc(var(--bottom-nav-h) + 12px); }
  .brand-text { display: none; }
  .brand-icon { font-size: 1.1rem; }
  .edition-select { max-width: 140px; font-size: 0.75rem; padding: 4px 6px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-grid-2 { grid-template-columns: 1fr; }
  .kpi-grid-3, .kpi-grid-4, .kpi-grid-5 { grid-template-columns: 1fr 1fr; gap: 8px; }
  /* Hide date inputs on very small screens, keep shortcuts only */
  .date-input { display: none; }
  .date-sep { display: none; }
  .date-shortcuts { gap: 3px; }
  .btn-chip { padding: 4px 10px; font-size: 0.72rem; }
  /* Topbar actions compact */
  .btn-icon { padding: 4px; font-size: 1rem; }
  .freshness-badge { font-size: 0.65rem; padding: 2px 6px; }
  /* Section titles */
  .section-title-icon { font-size: 0.9rem; margin-top: 16px; margin-bottom: 8px; }
}
@media (max-width: 360px) {
  .edition-select { max-width: 110px; }
  .freshness-badge { display: none; }
}

/* --- 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); }

/* --- Utility --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
