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

:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --border: #e7e5e4;
  --text: #1c1917;
  --text-muted: #78716c;
  --crude:        #2563eb;
  --w95:          #059669;
  --w100:         #7c3aed;
  --wdiesel:      #0891b2;
  --retail95:     #dc2626;
  --retail-diesel:#d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.header-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 1.2rem; }
.logo-text { font-weight: 600; font-size: 1rem; letter-spacing: -0.02em; }
.last-update { font-size: 0.75rem; color: var(--text-muted); }

/* Main */
.main {
  max-width: 1280px; margin: 0 auto;
  padding: 32px 24px; flex: 1;
  display: flex; flex-direction: column; gap: 32px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.03em; margin: 6px 0 2px; }
.kpi-sub { font-size: 0.72rem; color: var(--text-muted); }

#kpi-crude        .kpi-value { color: var(--crude); }
#kpi-w95          .kpi-value { color: var(--w95); }
#kpi-w100         .kpi-value { color: var(--w100); }
#kpi-wdiesel      .kpi-value { color: var(--wdiesel); }
#kpi-retail95     .kpi-value { color: var(--retail95); }
#kpi-retail-diesel .kpi-value { color: var(--retail-diesel); }

/* Chart */
.chart-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.chart-header {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: 16px; margin-bottom: 24px;
}
.chart-title { font-size: 1rem; font-weight: 600; }
.chart-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; }
.range-buttons { display: flex; gap: 4px; }
.range-btn {
  padding: 4px 14px; font-size: 0.8rem; font-weight: 500;
  border: 1px solid var(--border); background: transparent;
  border-radius: 4px; cursor: pointer; color: var(--text-muted);
  transition: all 0.15s;
}
.range-btn:hover { border-color: #a8a29e; color: var(--text); }
.range-btn.active { background: var(--text); color: #fff; border-color: var(--text); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; }
.legend-item { font-size: 0.72rem; display: flex; align-items: center; gap: 5px; color: var(--text-muted); }
.legend-item::before { content: ''; width: 12px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend-item.crude::before         { background: var(--crude); }
.legend-item.w95::before           { background: var(--w95); }
.legend-item.w100::before          { background: var(--w100); }
.legend-item.wdiesel::before       { background: var(--wdiesel); }
.legend-item.retail95::before      { background: var(--retail95); }
.legend-item.retail-diesel::before { background: var(--retail-diesel); }

.chart-wrapper { position: relative; height: 360px; }
canvas#priceChart { width: 100% !important; height: 100% !important; }

.chart-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.9); border-radius: var(--radius);
}
.chart-overlay.hidden { display: none; }
.overlay-msg { font-size: 0.875rem; color: var(--text-muted); text-align: center; padding: 0 24px; }

/* Tables */
.tables-section {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px;
}
.table-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.table-title { font-size: 0.875rem; font-weight: 600; margin-bottom: 16px; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.data-table th {
  text-align: left; font-weight: 500; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 0 8px 8px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 7px 8px; border-bottom: 1px solid var(--bg); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* Footer */
.footer {
  border-top: 1px solid var(--border); background: var(--surface);
  padding: 16px 24px; font-size: 0.75rem; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.footer a { color: var(--text-muted); text-decoration: none; }
.footer a:hover { color: var(--text); }

/* Responsive */
@media (max-width: 768px) {
  .main { padding: 20px 16px; gap: 20px; }
  .header-inner { padding: 0 16px; }
  .chart-header { flex-direction: column; }
  .kpi-value { font-size: 1.35rem; }
  .chart-wrapper { height: 280px; }
  .legend { gap: 8px; }
}
