:root {
  --color-good: #0cce6b;
  --color-good-bg: rgba(12, 206, 107, 0.1);
  --color-medium: #ffa400;
  --color-medium-bg: rgba(255, 164, 0, 0.1);
  --color-bad: #ff4e42;
  --color-bad-bg: rgba(255, 78, 66, 0.1);

  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-accent: #4f46e5;
  --color-accent-light: #eef2ff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-border: #334155;
    --color-accent: #818cf8;
    --color-accent-light: #1e1b4b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.2);
  }
}

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

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

/* ============ HEADER ============ */
header {
  background: linear-gradient(135deg, var(--color-accent), #7c3aed);
  margin: 0 -1.25rem;
  padding: 1.75rem 1.25rem 1.25rem;
  color: #fff;
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  background: rgba(255,255,255,0.2);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  backdrop-filter: blur(4px);
}

/* ============ VIEW TABS (top nav) ============ */
#view-tabs {
  display: flex;
  gap: 0;
  margin: 1.25rem 0 1rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.view-tab {
  flex: 1;
  padding: 0.7rem 1rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.view-tab:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.view-tab.active {
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.view-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color-accent);
  border-radius: 3px 3px 0 0;
}

/* ============ VIEWS ============ */
.view { display: none; }
.view.active { display: block; }

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  justify-content: space-between;
}

.toolbar-left {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ============ PILL BUTTONS ============ */
.pill-group {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pill {
  padding: 0.45rem 1rem;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.pill:hover {
  color: var(--color-text);
  background: var(--color-bg);
}

.pill.active {
  background: var(--color-accent);
  color: #fff;
}

/* ============ CARDS ============ */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.card-header h2,
.card-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* ============ TABLES ============ */
.table-wrapper {
  overflow-x: auto;
}

.detail-table-wrapper {
  max-height: 520px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th {
  text-align: left;
  padding: 0.6rem 1rem;
  border-bottom: 2px solid var(--color-border);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}

td {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Summary table row interaction */
#summary-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

#summary-table tbody tr:hover {
  background: var(--color-accent-light);
}

.go-detail-btn {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: background 0.15s;
}

.go-detail-btn:hover {
  background: var(--color-accent-light);
}

/* Status colors */
.status-good { color: var(--color-good); font-weight: 600; }
.status-medium { color: var(--color-medium); font-weight: 600; }
.status-bad { color: var(--color-bad); font-weight: 600; }

/* Detail data table coloring */
#detail-data-table td.cell-good { background: var(--color-good-bg); }
#detail-data-table td.cell-medium { background: var(--color-medium-bg); }
#detail-data-table td.cell-bad { background: var(--color-bad-bg); }

/* Overview metric column banding */
.col-cls { background: rgba(99, 102, 241, 0.05); }
.col-lcp { background: rgba(245, 158, 11, 0.05); }
.col-inp { background: rgba(16, 185, 129, 0.05); }
#summary-table th.col-cls,
#summary-table th.col-lcp,
#summary-table th.col-inp { font-size: 0.8rem; color: var(--color-text-secondary); }

/* Trend arrows in detail table */
.arrow-up   { color: var(--color-good);   font-size: 0.75rem; margin-left: 0.25rem; }
.arrow-down { color: var(--color-bad);    font-size: 0.75rem; margin-left: 0.25rem; }

/* ============ ORIGIN SELECT ============ */
#origin-select {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.85rem;
  min-width: 280px;
  box-shadow: var(--shadow);
}

/* ============ DETAIL LAYOUT ============ */
.detail-origin-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--color-accent);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

#stacked-container {
  padding: 0 1rem 1rem;
  position: relative;
  min-height: 480px;
}

#trend-container {
  padding: 0 1rem 1rem;
  position: relative;
  min-height: 280px;
}

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

/* ============ LOADING ============ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--color-text-secondary);
}

/* ============ FOOTER ============ */
footer {
  padding: 1.5rem 0;
  text-align: center;
  color: var(--color-text-secondary);
  font-size: 0.78rem;
}

footer a {
  color: var(--color-accent);
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }
