/* ============================================================
   AG.Gestor Métricas — Design System CSS
   Dark/Light theme, premium glassmorphism aesthetic
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Custom Properties (Tokens) ─────────────────────────── */
:root {
  /* Spacing */
  --sidebar-width: 240px;
  --topbar-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark Theme (default) ────────────────────────────────────── */
[data-theme="dark"] {
  --bg-base: #0c0e14;
  --bg-surface: #13161f;
  --bg-card: #1a1e2a;
  --bg-card-hover: #1f2435;
  --bg-elevated: #222840;
  --bg-input: #0f111a;

  --border: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(99, 102, 241, 0.6);

  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --text-faint: #334155;

  --chart-grid: rgba(255, 255, 255, 0.06);

  --sidebar-bg: #0f1219;
  --sidebar-border: rgba(255,255,255,0.06);
  --topbar-bg: rgba(15, 18, 25, 0.85);

  --accent-primary: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.25);

  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-elevated: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ── Light Theme ─────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-elevated: #f0f4ff;
  --bg-input: #f8fafc;

  --border: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(99, 102, 241, 0.4);

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-faint: #cbd5e1;

  --chart-grid: rgba(0, 0, 0, 0.06);

  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(0,0,0,0.08);
  --topbar-bg: rgba(255, 255, 255, 0.9);

  --accent-primary: #4f46e5;
  --accent-glow: rgba(79, 70, 229, 0.15);

  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow-elevated: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ── App Shell Layout ────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  transition: var(--transition-slow);
}

.app-shell.sidebar-hidden {
  grid-template-columns: 0 1fr;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  transition: var(--transition-slow);
  position: relative;
  z-index: 100;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  white-space: nowrap;
}

.brand-tag {
  font-size: 0.7rem;
  color: var(--accent-primary);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 16px 16px 6px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(139,92,246,0.08));
  color: #818cf8;
  border: 1px solid rgba(99,102,241,0.2);
}

.nav-item.active .nav-icon {
  color: #818cf8;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  transition: var(--transition);
}

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  padding: 1px 6px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-user:hover { background: var(--bg-elevated); }

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.user-plan {
  font-size: 0.7rem;
}

.data-source-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 20px;
  color: #f59e0b;
}

.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  animation: pulse-glow 2s infinite;
  flex-shrink: 0;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(245,158,11,0); }
}

/* ── Main Area ────────────────────────────────────────────────── */
.main-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-breadcrumb {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Content Area ────────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.content-area::-webkit-scrollbar { width: 6px; }
.content-area::-webkit-scrollbar-track { background: transparent; }
.content-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.page-content {
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* Sem "transform" aqui de propósito: mesmo translateY(0) cria um novo
   containing block pra descendentes com position:fixed (spec do CSS) — os
   modais (.modal-overlay), que são renderizados dentro de #page-content,
   ficavam "fixos" relativos a este container em vez da viewport, abrindo
   fora da tela em páginas longas (achado em 2026-07-14 testando o aviso de
   SKUs sem custo, que deixa a página comprida o bastante pra expor o bug). */
.page-content.page-enter { opacity: 0; }
.page-content.page-visible { opacity: 1; }

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Filter Groups ───────────────────────────────────────────── */
.filter-group {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.filter-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.filter-btn.active { background: var(--accent-primary); color: white; box-shadow: 0 2px 8px rgba(99,102,241,0.3); }

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

.kpi-grid-4 {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.kpi-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

.kpi-indigo::before { background: linear-gradient(90deg, #6366f1, #818cf8); }
.kpi-emerald::before { background: linear-gradient(90deg, #10b981, #34d399); }
.kpi-violet::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.kpi-amber::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.kpi-cyan::before { background: linear-gradient(90deg, #06b6d4, #22d3ee); }
.kpi-pink::before { background: linear-gradient(90deg, #ec4899, #f472b6); }
.kpi-rose::before { background: linear-gradient(90deg, #f43f5e, #fb7185); }

.kpi-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-indigo .kpi-icon-wrap { background: rgba(99,102,241,0.15); color: #818cf8; }
.kpi-emerald .kpi-icon-wrap { background: rgba(16,185,129,0.15); color: #34d399; }
.kpi-violet .kpi-icon-wrap { background: rgba(139,92,246,0.15); color: #a78bfa; }
.kpi-amber .kpi-icon-wrap { background: rgba(245,158,11,0.15); color: #fbbf24; }
.kpi-cyan .kpi-icon-wrap { background: rgba(6,182,212,0.15); color: #22d3ee; }
.kpi-pink .kpi-icon-wrap { background: rgba(236,72,153,0.15); color: #f472b6; }
.kpi-rose .kpi-icon-wrap { background: rgba(244,63,94,0.15); color: #fb7185; }

.kpi-icon { width: 20px; height: 20px; }

.kpi-content { flex: 1; min-width: 0; }
.kpi-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; margin-bottom: 4px; }
.kpi-value { font-size: 1.35rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.kpi-delta { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

/* ── Charts Grid ─────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 340px);
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card-wide { grid-column: 1; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: var(--transition);
}

.card-wide { grid-column: 1; }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.chart-wrapper {
  height: 260px;
  padding: 16px;
  position: relative;
}

.chart-wrapper-sm { height: 160px; }

.legend-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Channel Breakdown ───────────────────────────────────────── */
.channel-breakdown {
  padding: 12px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.channel-stat {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.channel-stat-info {
  flex: 1;
  display: flex;
  justify-content: space-between;
}

/* ── Cost Bars ────────────────────────────────────────────────── */
.cost-bars { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }

.cost-bar-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
}

.cost-bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.cost-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cost-bar-track {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.cost-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}

.cost-bar-values {
  display: flex;
  gap: 8px;
  font-size: 0.78rem;
  text-align: right;
  white-space: nowrap;
}

/* ── Data Tables ─────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th.text-right { text-align: right; }
.data-table th.text-center { text-align: center; }

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr {
  transition: var(--transition);
}

.data-table tr:hover td {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.data-table td.text-right { text-align: right; }
.data-table td.text-center { text-align: center; }

/* ── Rank Badge ──────────────────────────────────────────────── */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--bg-elevated);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.badge-ml { background: rgba(255,230,0,0.15); color: #d4a017; border: 1px solid rgba(255,230,0,0.3); }
.badge-amz { background: rgba(255,153,0,0.15); color: #ff9900; border: 1px solid rgba(255,153,0,0.3); }
.badge-count { background: var(--bg-elevated); color: var(--text-muted); font-size: 0.75rem; padding: 4px 10px; border-radius: 20px; }
.badge-success { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.badge-warn { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
.badge-error { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
.badge-neutral { background: var(--bg-elevated); color: var(--text-muted); border: 1px solid var(--border); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-ml { background: #ffe600; }
.dot-amz { background: #ff9900; }

/* ── Status Indicators ───────────────────────────────────────── */
.status-active { color: #10b981; font-size: 0.78rem; font-weight: 600; }
.status-paused { color: var(--text-muted); font-size: 0.78rem; }

/* ── Stats Row ───────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ── ACOS Scale ──────────────────────────────────────────────── */
.acos-scale { padding: 12px 20px 16px; }

.acos-bar {
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 5px;
  position: relative;
  overflow: hidden;
}

.acos-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
}

.acos-needle {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 16px;
  background: white;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 6px rgba(255,255,255,0.5);
}

.acos-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  margin-top: 6px;
}

.ads-channel-bar { width: 100%; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary:hover {
  background: #4f46e5;
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
  transform: translateY(-1px);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: rgba(239,68,68,0.1);
  color: #f87171;
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.btn-icon:hover { border-color: var(--border); }

.w-full { width: 100%; }

/* ── Form Elements ───────────────────────────────────────────── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-group label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: var(--transition);
  width: 100%;
}

.field-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.field-input::-webkit-inner-spin-button { display: none; }

.input-search {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  width: 200px;
  transition: var(--transition);
}

.input-search:focus { outline: none; border-color: var(--border-focus); }

.input-with-suffix, .input-with-prefix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-suffix .field-input { padding-right: 36px; }
.input-with-prefix .field-input { padding-left: 36px; }

.input-suffix, .input-prefix {
  position: absolute;
  font-size: 0.82rem;
  color: var(--text-muted);
  pointer-events: none;
  font-weight: 500;
}

.input-suffix { right: 10px; }
.input-prefix { left: 10px; }

/* ── Formula Card ────────────────────────────────────────────── */
.formula-card { margin-bottom: 24px; }
.formula-steps { padding: 16px 20px; display: flex; flex-direction: column; gap: 0; }

.formula-step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.formula-step:last-child { border-bottom: none; }

.formula-operator {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.formula-positive .formula-operator { background: rgba(16,185,129,0.15); color: #10b981; }
.formula-negative .formula-operator { background: rgba(239,68,68,0.1); color: #f87171; }
.formula-result .formula-operator { background: rgba(99,102,241,0.15); color: #818cf8; }

.formula-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.formula-content strong { font-size: 0.85rem; color: var(--text-primary); }
.formula-content span { font-size: 0.75rem; color: var(--text-muted); }

.formula-value { font-weight: 700; font-size: 0.9rem; white-space: nowrap; }

.formula-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.formula-result { background: var(--bg-elevated); border-radius: var(--radius-sm); padding: 14px 12px; margin-top: 4px; border: 1px solid rgba(99,102,241,0.15); }

/* ── Margin Simulator ────────────────────────────────────────── */
.simulator-form { padding: 16px 20px; }
.sim-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.sim-result { margin: 12px 0; padding: 16px; background: var(--bg-elevated); border-radius: var(--radius-sm); }
.sim-result-grid { display: flex; flex-direction: column; gap: 6px; }
.sim-line { display: flex; justify-content: space-between; font-size: 0.82rem; }
.sim-deduct { color: var(--text-muted); }
.sim-total { font-weight: 700; font-size: 0.9rem; padding-top: 4px; }
.sim-divider { height: 1px; background: var(--border); margin: 4px 0; }
.sim-badges { display: flex; gap: 12px; margin-top: 8px; }
.sim-badge { flex: 1; text-align: center; padding: 8px; background: var(--bg-card); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.sim-badge-label { display: block; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 2px; }
.sim-badge strong { font-size: 1.1rem; font-weight: 700; }

/* ── Settings Layout ─────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.settings-full-width { grid-column: 1 / -1; }

.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.section-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-icon {
  width: 20px;
  height: 20px;
  color: var(--accent-primary);
  flex-shrink: 0;
  margin-top: 2px;
}

.section-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.section-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Connection Cards ────────────────────────────────────────── */
.connection-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  transition: var(--transition);
}

.connection-card:hover { background: var(--bg-elevated); }

.connection-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ml-logo { background: #ffe600; }
.amz-logo { background: #232f3e; }

.connection-info { flex: 1; }
.connection-actions { flex-shrink: 0; }

/* ── Tax Config ──────────────────────────────────────────────── */
.tax-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.tax-preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.78rem;
}

.tax-preset strong { font-size: 1rem; color: var(--text-primary); }
.tax-preset span { color: var(--text-muted); font-size: 0.68rem; text-align: center; }
.tax-preset:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.tax-preset.active { border-color: var(--accent-primary); background: rgba(99,102,241,0.1); color: #818cf8; }
.tax-preset.active strong { color: #818cf8; }

/* ── Fixed Costs ─────────────────────────────────────────────── */
.fixed-costs-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.cost-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: var(--transition);
}

.cost-item:hover { border-color: rgba(239,68,68,0.2); }

.add-cost-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ── Controle Financeiro ─────────────────────────────────────── */
.finance-year-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.finance-year-label {
  font-size: 1rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
}

.finance-month-tabs {
  overflow-x: auto;
  max-width: 100%;
}

.finance-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .finance-columns { grid-template-columns: 1fr; }
}

.finance-add-form {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr 1fr auto;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  align-items: center;
}

.finance-add-form.no-category {
  grid-template-columns: 2fr 1fr 1fr auto;
}

.finance-category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.finance-category-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 5px 6px 5px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
}

.finance-category-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 50%;
}

.finance-category-remove:hover { background: rgba(239,68,68,0.15); color: #f87171; }

.finance-add-category {
  display: flex;
  gap: 8px;
}

.finance-add-category .field-input { flex: 1; }

.add-cost-form .field-input { margin-bottom: 0; }

.fixed-total {
  margin-top: 12px;
  padding: 12px;
  background: rgba(239,68,68,0.05);
  border: 1px solid rgba(239,68,68,0.15);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  animation: fade-in 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-elevated);
  animation: slide-up 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-body { padding: 20px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ── Info Banner ─────────────────────────────────────────────── */
.info-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  background: rgba(99,102,241,0.06);
  border: 1px solid rgba(99,102,241,0.15);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 12px;
  line-height: 1.4;
}

/* ── Warning Banner (variante âmbar do info-banner, p/ pendências) ─── */
.warning-banner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(245,158,11,0.06);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.warning-banner-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.warning-banner-head strong { color: #f59e0b; }
.warning-banner-table { font-size: 0.8rem; }
.warning-banner-table th { text-align: left; padding: 4px 10px; color: var(--text-muted); font-weight: 500; }
.warning-banner-table td { padding: 4px 10px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-elevated);
  z-index: 9999;
  transform: translateY(20px);
  opacity: 0;
  transition: var(--transition);
}

.toast-visible { transform: translateY(0); opacity: 1; }

/* ── Utility Classes ─────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-xl { font-size: 1.2rem; }
.mt-0 { margin-top: 0; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.py-4 { padding: 16px 0; }
.py-8 { padding: 32px 0; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.ml-auto { margin-left: auto; }
.shrink-0 { flex-shrink: 0; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.hidden { display: none !important; }
.w-full { width: 100%; }

.text-emerald-400 { color: #34d399; }
.text-yellow-400 { color: #fbbf24; }
.text-red-400 { color: #f87171; }
.text-indigo-400 { color: #818cf8; }
.text-amber-400 { color: #fbbf24; }
.text-blue-400 { color: #60a5fa; }
.text-violet-400 { color: #a78bfa; }
.text-pink-400 { color: #f472b6; }
.text-teal-400 { color: #2dd4bf; }
.text-black { color: #0f172a; }
.text-white { color: #ffffff; }
.text-lg { font-size: 1.05rem; }
.bg-emerald-500 { background-color: #10b981; }
.bg-yellow-500 { background-color: #f59e0b; }
.bg-red-500 { background-color: #ef4444; }

code { font-family: var(--font-mono); background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; font-size: 0.8em; }

/* ── Skeleton ────────────────────────────────────────────────── */
.skeleton-pulse {
  animation: skeleton 1.8s ease-in-out infinite;
}

@keyframes skeleton {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Spin animation ──────────────────────────────────────────── */
.spin { animation: spin 0.6s linear infinite; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ── Loading State ───────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  gap: 16px;
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-card-wide { grid-column: 1; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 200px; }

  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .sim-fields { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .app-shell {
    grid-template-columns: 0 1fr;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 200;
    transition: var(--transition-slow);
  }

  .app-shell.sidebar-open .sidebar {
    left: 0;
    box-shadow: var(--shadow-elevated);
  }

  .page-content { padding: 16px; }

  .filter-btn { padding: 5px 8px; font-size: 0.74rem; }

  .kpi-grid { grid-template-columns: 1fr 1fr; }

  .cost-bar-row { grid-template-columns: 1fr; }
}

/* ── Print ───────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar { display: none; }
  .app-shell { display: block; }
  .main-wrapper { overflow: visible; }
  .content-area { overflow: visible; }
}
