/* ── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  --navy:      #1A2E5A;
  --navy-light:#243b73;
  --teal:      #0090D4;
  --green:     #16A34A;
  --red:       #DC2626;
  --amber:     #D97706;
  --bg:        #F1F5F9;
  --card:      #FFFFFF;
  --border:    #E2E8F0;
  --text:      #1E293B;
  --text-muted:#64748B;
  --shadow:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
}

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

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: #fff;
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-logo {
  width: 48px;
  height: 48px;
  background: var(--teal);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}
.header-title h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-title .subtitle {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}
.header-tickers {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ticker-badge {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
}
.ticker-badge:hover {
  background: rgba(255,255,255,0.22);
}

/* ── Controls Bar ────────────────────────────────────────────────────────── */
.controls-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.controls-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
#company-selector {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  margin-right: 12px;
}
#company-selector:hover {
  border-color: var(--teal);
}
.mode-buttons {
  display: flex;
  gap: 4px;
}
.mode-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.mode-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}
.mode-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.year-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
}
.year-filters label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}
.year-filters input[type=checkbox] {
  width: 15px;
  height: 15px;
  accent-color: var(--navy);
  cursor: pointer;
}
.year-filters label:has(input:checked) {
  color: var(--navy);
  font-weight: 600;
}
.export-btn {
  margin-left: auto;
  padding: 6px 16px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
}
.export-btn:hover {
  background: var(--navy-light);
  box-shadow: var(--shadow-md);
}

/* ── Main Layout ─────────────────────────────────────────────────────────── */
main {
  padding: 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Loading & Error States ──────────────────────────────────────────────── */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px;
  flex-direction: column;
  gap: 12px;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#dashboard { display: none; }

#error-banner {
  display: none;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
}
#error-banner h3 {
  color: var(--red);
  font-size: 15px;
  margin-bottom: 8px;
}
#error-banner p {
  color: #991B1B;
  font-size: 13px;
  line-height: 1.6;
}
#error-banner code {
  background: #FEE2E2;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

/* ── KPI Cards ───────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--teal);
  border-radius: 12px 12px 0 0;
}
.kpi-card:nth-child(2)::before { background: var(--green); }
.kpi-card:nth-child(3)::before { background: var(--amber); }
.kpi-card:nth-child(4)::before { background: var(--navy); }
.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.kpi-sub    { font-size: 12px; margin-top: 4px; }
.kpi-period { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

/* ── Utility color classes ───────────────────────────────────────────────── */
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral  { color: var(--text-muted); }

/* ── Section Typography ──────────────────────────────────────────────────── */
.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  margin: 24px 0 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}
.section-title:first-of-type { margin-top: 0; }
.section-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}
.chart-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.4;
}
.footnote {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 16px 0 24px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ── Chart Grids ─────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

/* ── Chart Cards ─────────────────────────────────────────────────────────── */
.chart-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.chart-card.full-width { grid-column: 1 / -1; }
.chart-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  flex-shrink: 0;
}
.chart-wrapper {
  position: relative;
  height: 280px;
}
.chart-card.full-width .chart-wrapper { height: 320px; }

/* ── Stock Info Bar ───────────────────────────────────────────────────────── */
.stock-info-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.info-block {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.info-block-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 4px;
}
.info-block-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.info-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #F1F5F9;
}
.info-row:last-child { border-bottom: none; }
.info-label {
  font-size: 12px;
  color: var(--text-muted);
}
.info-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.tables-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.table-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.table-card.full-width { grid-column: 1 / -1; }
.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: #FAFBFC;
  display: flex;
  align-items: center;
  gap: 8px;
}
.table-header .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table thead th {
  padding: 8px 12px;
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  background: #F8FAFC;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table thead th:first-child {
  text-align: left;
  min-width: 160px;
}
table tbody tr:nth-child(even) { background: #F8FAFC; }
table tbody tr:hover           { background: #EFF6FF; }
table tbody td {
  padding: 7px 12px;
  text-align: right;
  border-bottom: 1px solid #F1F5F9;
  white-space: nowrap;
}
table tbody td:first-child {
  text-align: left;
  font-weight: 500;
  color: var(--text);
}
table tbody tr.separator td {
  border-top: 2px solid var(--border);
  font-weight: 700;
  background: #EFF6FF;
  font-size: 12px;
}
table tbody tr.margin-row td {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  header        { padding: 16px; }
  .controls-bar { padding: 10px 16px; flex-direction: column; align-items: flex-start; }
  main          { padding: 16px; }

  .kpi-grid     { grid-template-columns: repeat(2, 1fr); }

  .charts-grid,
  .tables-grid  { grid-template-columns: 1fr; }

  .chart-card.full-width,
  .table-card.full-width { grid-column: 1; }

  .stock-info-bar { grid-template-columns: 1fr; }

  .year-filters {
    padding-left: 0;
    border-left: none;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }
  .export-btn { margin-left: 0; }
}
