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

:root {
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --border:    #dde1e9;
  --text:      #1a1f2e;
  --muted:     #6b7280;
  --accent:    #2563eb;
  --danger:    #dc2626;
  --success:   #16a34a;
  --warn:      #d97706;
  --radius:    8px;
  --shadow:    0 1px 4px rgba(0,0,0,0.08);
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: 48px;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

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

/* ── KPI Row ── */
.kpi-row {
  display: flex;
  gap: 16px;
  padding: 24px 32px 0;
  flex-wrap: wrap;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  flex: 1;
  min-width: 160px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Charts Grid ── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 24px 32px;
}

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

.chart-card.wide {
  grid-column: 1 / -1;  /* span full width */
}

.chart-card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text);
}

.chart-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.chart-card canvas {
  max-height: 280px;
}

/* ── Insights Section ── */
.insights-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 32px 24px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.insights-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
}

#insights-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#insights-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
}

#insights-list li::before {
  content: "•";
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

/* ── AI Section ── */
.ai-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 32px 24px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.ai-header h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.ai-header p {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 14px;
}

/* API key row */
.api-key-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.api-key-row label {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

#api-key-input {
  flex: 1;
  min-width: 220px;
  max-width: 400px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  font-family: monospace;
  outline: none;
  background: #f8fafc;
}

#api-key-input:focus {
  border-color: var(--accent);
  background: #fff;
}

.get-key-link {
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
}

.get-key-link:hover { text-decoration: underline; }

#ai-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

#ai-btn:hover { background: #1d4ed8; }
#ai-btn:disabled { background: #93c5fd; cursor: not-allowed; }

.ai-output {
  margin-top: 16px;
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.9rem;
  line-height: 1.7;
}

.ai-output.hidden { display: none; }

/* ── Footer ── */
footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 16px 32px 0;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card.wide { grid-column: 1; }
  .kpi-row { padding: 16px; }
  .charts-grid, .insights-section, .ai-section { padding: 16px; margin: 0 12px 16px; }
  .charts-grid { padding: 16px 12px; }
}
