/* === INTEIA Design System — Lenia Eleitoral DF === */

:root {
  --bg: #07090d;
  --panel: #101723;
  --panel-2: #162234;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f5e6c8;
  --muted: #c5b286;
  --amber: #d69e2e;
  --gold: #f6e05e;
  --navy: #0f172a;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

[data-theme="light"] {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --line: rgba(0, 0, 0, 0.1);
  --text: #0f172a;
  --muted: #475569;
  --navy: #e2e8f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(214, 158, 46, 0.12), transparent 28%),
    linear-gradient(180deg, var(--bg), color-mix(in srgb, var(--bg) 90%, #0d121b) 52%, var(--bg));
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

[data-theme="light"] body {
  background: var(--bg);
}

/* === Layout Shell === */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 56px 1fr;
}

/* === Sidebar === */

.sidebar {
  padding: 16px 8px;
  border-right: 1px solid var(--line);
  background: rgba(8, 11, 16, 0.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

[data-theme="light"] .sidebar {
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
}

.logo-box {
  width: 36px;
  height: 36px;
  background: var(--amber);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #0f172a;
  letter-spacing: -0.02em;
}

.logo-name {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text);
  margin-top: 12px;
}

.logo-name .highlight {
  color: var(--gold);
}

.brand-sub {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  margin-top: 8px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* === Main Panel === */

.main-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* === Content Grid === */

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  flex: 1;
}

.canvas-card,
.control-panel {
  background: linear-gradient(180deg, rgba(18, 25, 38, 0.92), rgba(8, 13, 20, 0.94));
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

[data-theme="light"] .canvas-card,
[data-theme="light"] .control-panel {
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* === Stats Bar === */

.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

[data-theme="light"] .stat-chip {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.stat-label {
  color: var(--muted);
}

.stat-chip strong {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

[data-theme="light"] .stat-chip strong {
  color: #92400e;
}

/* === Config Panel === */

.config-panel {
  padding: 18px;
  margin-bottom: 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(18, 25, 38, 0.92), rgba(8, 13, 20, 0.94));
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .config-panel {
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.config-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.config-label {
  flex: 1;
  min-width: 200px;
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 0;
}

.config-label select,
.config-label input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

[data-theme="light"] .config-label select,
[data-theme="light"] .config-label input[type="number"] {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #0f172a;
}

.config-small {
  min-width: 120px;
  flex: 0.5;
}

.budget-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.budget-group input[type="range"] {
  flex: 1;
}

.budget-value {
  font-weight: 600;
  color: var(--gold);
  font-size: 14px;
  white-space: nowrap;
  min-width: 120px;
  text-align: right;
}

[data-theme="light"] .budget-value {
  color: #92400e;
}

.config-advanced {
  margin-top: 8px;
  margin-bottom: 8px;
}

.config-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0;
}

.config-advanced summary:hover {
  color: var(--text);
}

.config-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* === Constraint rows === */

.constraint-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}

.constraint-row select,
.constraint-row input {
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}

.constraint-row select {
  min-width: 120px;
}

.constraint-row input {
  width: 100px;
}

[data-theme="light"] .constraint-row select,
[data-theme="light"] .constraint-row input {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #0f172a;
}

/* === Content Grid GA === */

.content-grid-ga {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 18px;
  margin-bottom: 18px;
}

.right-column {
  display: grid;
  gap: 14px;
  align-content: start;
}

/* === Map Card === */

.canvas-card {
  position: relative;
  background: linear-gradient(180deg, rgba(18, 25, 38, 0.92), rgba(8, 13, 20, 0.94));
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

[data-theme="light"] .canvas-card {
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.map-header {
  padding: 14px 18px 0;
}

.map-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.map-area {
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.ra-tooltip {
  position: absolute;
  bottom: 18px;
  left: 18px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: rgba(3, 6, 10, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(14px);
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
  pointer-events: none;
}

.ra-tooltip strong {
  color: var(--gold);
}

/* === Table === */

.table-section {
  margin-bottom: 18px;
}

.table-scroll {
  overflow-x: auto;
}

.ra-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ra-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line);
}

.ra-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.ra-table td.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.ra-table tr.top-ra td {
  background: rgba(214, 158, 46, 0.06);
}

.ra-table tr:hover td {
  background: rgba(255, 255, 255, 0.04);
}

.ra-name-small {
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
}

[data-theme="light"] .ra-table td {
  border-bottom-color: #f1f5f9;
}

[data-theme="light"] .ra-table tr.top-ra td {
  background: #fffbeb;
}

[data-theme="light"] .ra-table tr:hover td {
  background: #f8fafc;
}

/* === Saved strategies === */

.saved-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 120ms ease;
}

.saved-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.saved-item strong {
  color: var(--gold);
  font-size: 13px;
}

.saved-time {
  color: var(--muted);
  font-size: 11px;
}

/* === Control Panel === */

.control-panel {
  padding: 18px;
  display: grid;
  gap: 14px;
  align-content: start;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.panel-section {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

[data-theme="light"] .panel-section {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.panel-section h2 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}

.panel-highlight {
  background:
    radial-gradient(circle at top left, rgba(214, 158, 46, 0.18), transparent 55%),
    rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .panel-highlight {
  background:
    radial-gradient(circle at top left, rgba(214, 158, 46, 0.12), transparent 55%),
    #fffbeb;
}

.insight-headline {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  line-height: 1.4;
}

[data-theme="light"] .insight-headline {
  color: #92400e;
}

/* === Buttons === */

.button-row,
.button-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  border: 1px solid rgba(214, 158, 46, 0.35);
  background: rgba(214, 158, 46, 0.08);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: background 120ms ease, border-color 120ms ease;
}

button:hover {
  background: rgba(214, 158, 46, 0.16);
  border-color: rgba(214, 158, 46, 0.55);
}

button.primary {
  background: linear-gradient(180deg, rgba(214, 158, 46, 0.28), rgba(214, 158, 46, 0.12));
}

button.ghost {
  background: transparent;
}

[data-theme="light"] button {
  border-color: rgba(214, 158, 46, 0.45);
  color: #0f172a;
}

/* === Sliders === */

label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  margin-bottom: 8px;
}

.slider-help {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
}

/* === Metrics === */

.metric-list {
  display: grid;
  gap: 6px;
}

.metric-list div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.metric-list strong {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

[data-theme="light"] .metric-list strong {
  color: #92400e;
}

/* === Chart === */

.chart-container {
  position: relative;
  height: 160px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* === Region Insights === */

.region-insights {
  display: grid;
  gap: 8px;
}

.region-insight-item,
.region-insight-empty {
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .region-insight-item,
[data-theme="light"] .region-insight-empty {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.region-insight-item strong {
  display: block;
  color: var(--gold);
  margin-bottom: 4px;
  font-size: 13px;
}

[data-theme="light"] .region-insight-item strong {
  color: #92400e;
}

.region-insight-item span,
.region-insight-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

/* === Legend === */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  flex-shrink: 0;
}

.swatch.low { background: #3d2b0a; }
.swatch.mid { background: #c19552; }
.swatch.high { background: #ffe159; }

[data-theme="light"] .swatch.low { background: #fef3c7; }
[data-theme="light"] .swatch.mid { background: #f59e0b; }
[data-theme="light"] .swatch.high { background: #d97706; }

.panel-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

/* === Channel Toggles === */

.config-section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 8px 0 6px;
}

.channel-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.channel-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  cursor: pointer;
  transition: all 150ms ease;
  margin-bottom: 0;
}

.channel-toggle:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

.channel-toggle.active {
  border-color: rgba(214, 158, 46, 0.4);
  background: rgba(214, 158, 46, 0.08);
}

.channel-toggle input[type="checkbox"] {
  display: none;
}

.channel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.4;
  transition: opacity 150ms;
}

.channel-toggle.active .channel-dot {
  opacity: 1;
}

[data-theme="light"] .channel-toggle {
  border-color: #e2e8f0;
  background: #f8fafc;
}

[data-theme="light"] .channel-toggle.active {
  border-color: rgba(214, 158, 46, 0.5);
  background: #fffbeb;
}

/* === Footer === */

.footer {
  margin-top: 24px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.footer-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--amber);
  border-radius: 4px;
  font-weight: 700;
  font-size: 10px;
  color: #0f172a;
}

.footer-info {
  text-align: right;
  line-height: 1.5;
}

/* === Responsive === */

@media (max-width: 1100px) {
  .content-grid,
  .content-grid-ga {
    grid-template-columns: 1fr;
  }
  .canvas-card {
    min-height: 350px;
  }
  .control-panel {
    max-height: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .main-panel {
    padding: 14px;
  }
  .topbar {
    flex-direction: column;
  }
  .config-row {
    flex-direction: column;
  }
  .stats-bar {
    flex-wrap: wrap;
  }
  .footer {
    flex-direction: column;
    text-align: center;
  }
  .footer-info {
    text-align: center;
  }
}

/* === Evolution Progress Bar === */

.evolution-progress {
  position: relative;
  width: 200px;
  height: 24px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(214, 158, 46, 0.3);
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.evolution-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(214, 158, 46, 0.4), rgba(246, 224, 94, 0.7));
  border-radius: 12px;
  transition: width 150ms ease;
  box-shadow: 0 0 12px rgba(214, 158, 46, 0.3);
}

.evolution-counter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* === Map Animations === */

.ra-path {
  cursor: pointer;
  transition: fill 300ms ease, stroke 200ms ease, stroke-width 200ms ease;
}

.evolving .ra-path {
  transition: fill 120ms ease;
}

.ra-label {
  transition: fill 300ms ease;
}

/* Pulse ao completar evolucao */
@keyframes pulse-glow {
  0% { filter: none; }
  50% { filter: drop-shadow(0 0 8px rgba(214, 158, 46, 0.6)); }
  100% { filter: none; }
}

.pulse-complete {
  animation: pulse-glow 750ms ease 2;
}

/* Shake no select quando nao selecionou candidato */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake {
  animation: shake 500ms ease;
}

/* Glow sutil no mapa durante evolucao */
.evolving .canvas-card {
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38), 0 0 30px rgba(214, 158, 46, 0.08);
}

/* Status pulsante durante evolucao */
@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.evolving #status-text {
  animation: status-pulse 1.2s ease infinite;
}

/* Top-3 RAs na tabela com destaque dourado */
.ra-table tr.top-ra td:first-child {
  color: var(--gold);
  font-weight: 700;
}

/* === Print === */

@media print {
  @page { size: A4 landscape; margin: 5mm; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  html, body { background: #fff !important; font-size: 7pt !important; line-height: 1.1 !important; }

  .no-print,
  .sidebar,
  .canvas-overlay,
  .cursor-card,
  .region-chip { display: none !important; }

  .app-shell { grid-template-columns: 1fr !important; }

  .main-panel { padding: 2mm !important; }

  .topbar { margin-bottom: 2mm !important; }
  .topbar h1 { font-size: 14pt !important; margin: 0 !important; }
  .topbar p { font-size: 8pt !important; margin: 1mm 0 !important; }

  .content-grid {
    display: grid !important;
    grid-template-columns: 1.4fr 1fr !important;
    gap: 3mm !important;
  }

  .canvas-card { min-height: 80mm !important; border-radius: 2mm !important; }
  .control-panel { max-height: none !important; padding: 2mm !important; gap: 2mm !important; border-radius: 2mm !important; }

  .panel-section { padding: 2mm !important; border-radius: 1mm !important; }
  .panel-section h2 { font-size: 8pt !important; margin-bottom: 1mm !important; }

  .insight-headline { font-size: 9pt !important; }
  .metric-list div { font-size: 7pt !important; }
  .metric-list strong { font-size: 7pt !important; }
  .panel-hint { font-size: 6pt !important; margin-top: 1mm !important; }
  .legend li { font-size: 6pt !important; }

  .chart-container { height: 22mm !important; }

  .region-insight-item { padding: 1mm 2mm !important; }
  .region-insight-item strong { font-size: 7pt !important; }
  .region-insight-item span { font-size: 6pt !important; }

  .footer { padding: 1mm 2mm !important; margin-top: 2mm !important; font-size: 5pt !important; }
}
