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

/* === Canvas === */

.canvas-card {
  position: relative;
  min-height: 72vh;
}

#lenia-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #06070a;
  opacity: 1;
  filter: none;
}

.territory-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.territory-mask {
  fill: rgba(3, 6, 10, 0.82);
}

[data-theme="light"] .territory-mask {
  fill: rgba(200, 210, 220, 0.6);
}

.territory-borders path {
  fill: rgba(214, 158, 46, 0.06);
  stroke: rgba(255, 235, 170, 0.38);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
  transition: fill 120ms ease, stroke 120ms ease;
  cursor: pointer;
}

.territory-borders path:hover,
.territory-borders path.is-active {
  fill: rgba(246, 224, 94, 0.16);
  stroke: rgba(255, 240, 180, 0.82);
}

/* === Canvas Overlays === */

.canvas-overlay {
  position: absolute;
  left: 18px;
  bottom: 16px;
  z-index: 4;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(3, 6, 10, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  font-size: 12px;
}

.cursor-card {
  position: absolute;
  left: 18px;
  top: 18px;
  z-index: 4;
  max-width: 320px;
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  background: rgba(3, 6, 10, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

.cursor-card strong { color: var(--gold); }
.cursor-card span { color: var(--muted); font-size: 13px; line-height: 1.4; }

.region-chip {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 4;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(3, 6, 10, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--gold);
  font-size: 13px;
  line-height: 1.35;
}

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

/* === 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 {
    grid-template-columns: 1fr;
  }
  .canvas-card {
    min-height: 58vh;
  }
  .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;
  }
  .cursor-card,
  .region-chip {
    position: static;
    margin: 12px;
  }
  .canvas-overlay {
    left: 12px;
    bottom: 12px;
  }
  .footer {
    flex-direction: column;
    text-align: center;
  }
  .footer-info {
    text-align: center;
  }
}

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