:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface2: #f9f7f4;
  --border: #e2ddd6;
  --border2: #ccc8c0;
  --accent: #b5601a;
  --accent-light: #fdf0e6;
  --accent2: #2a6e5c;
  --accent2-light: #e8f4f0;
  --accent3: #8b4444;
  --blue: #2a4a8b;
  --blue-light: #eef1fa;
  --text: #1a1612;
  --text-muted: #7a7068;
  --text-dim: #b5afa6;
  --shadow: 0 1px 4px rgba(0,0,0,0.07), 0 4px 16px rgba(0,0,0,0.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* HEADER */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 20px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 16px; }
.logo-mark {
  width: 40px; height: 40px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  flex-shrink: 0;
}
.header-left h1 {
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}
.header-left p {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-top: 2px;
}
.header-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* YEAR SWITCHER */
.year-tabs {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.year-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.18s;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: 0.5px;
}
.year-tab:hover { color: var(--text); background: var(--border); }
.year-tab.active { background: var(--accent); color: white; }

.search-wrap { position: relative; }
.search-wrap input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px 8px 34px;
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  width: 200px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.search-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-dim); }
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

/* STATS */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 20px 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.stat .num {
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  color: var(--accent);
  line-height: 1;
}
.stat .lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
  font-family: 'IBM Plex Mono', monospace;
}
.stat.highlight { border-color: var(--accent); background: var(--accent-light); }
.stat.highlight .num { color: var(--accent); }

/* MAIN */
.main { padding: 20px 32px; }

/* TABS */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}
.tab {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.18s;
  font-family: 'IBM Plex Mono', monospace;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* TABLE */
.table-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 10px;
}
.table-wrap {
  overflow-x: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 860px; }
thead th {
  background: var(--surface2);
  padding: 10px 14px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: 'IBM Plex Mono', monospace;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--accent); }
thead th.sorted-asc::after { content: ' ↑'; color: var(--accent); }
thead th.sorted-desc::after { content: ' ↓'; color: var(--accent); }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; cursor: pointer; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 14px; vertical-align: middle; white-space: nowrap; }
.col-num { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--text-dim); width: 36px; text-align: center; }
.col-name { font-weight: 500; }
.col-muted { color: var(--text-muted); font-size: 12px; }
.col-date { font-family: 'IBM Plex Mono', monospace; font-size: 11px; color: var(--text-muted); }

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  font-family: 'IBM Plex Mono', monospace;
  white-space: nowrap;
}
.badge-green { background: var(--accent2-light); color: var(--accent2); }
.badge-orange { background: var(--accent-light); color: var(--accent); }
.badge-red { background: #fceaea; color: var(--accent3); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-gray { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-yellow { background: #fef9e7; color: #8a6d00; }

/* YEAR BADGE IN TABLE */
.year-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* RETURNING HIGHLIGHT */
.returning-star { color: var(--accent); margin-right: 3px; }

/* DETAIL OVERLAY */
.detail-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26,22,18,0.5);
  z-index: 200;
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
}
.detail-overlay.open { display: flex; }
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(660px, 95vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.detail-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--surface2);
  border-radius: 14px 14px 0 0;
}
.detail-header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 26px;
  color: var(--text);
  line-height: 1.1;
}
.detail-header .d-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
  font-family: 'IBM Plex Mono', monospace;
}
.close-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 500;
  transition: all 0.15s;
  flex-shrink: 0;
}
.close-btn:hover { background: var(--border); color: var(--text); }
.detail-body { padding: 24px 32px; }
.detail-section-title {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
  margin: 20px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.detail-section-title:first-child { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-field label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
}
.detail-field .val {
  font-size: 13px;
  color: var(--text);
  margin-top: 2px;
  word-break: break-word;
  white-space: normal;
  font-weight: 500;
}
.detail-field .val.empty { color: var(--text-dim); font-weight: 400; }
.notes-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.65;
  white-space: normal;
  word-break: break-word;
}

/* CHARTS */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.chart-card.wide { grid-column: 1 / -1; }
.chart-title {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 18px;
  font-weight: 600;
}
.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 130px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 22px;
  background: var(--surface2);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
  display: flex; align-items: center; padding-left: 8px;
}
.bar-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  min-width: 22px;
  text-align: right;
}

/* TREND LINE */
.trend-chart { position: relative; }
.trend-svg { width: 100%; overflow: visible; }

/* TIMELINE */
.timeline-intern { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.tl-name { min-width: 140px; font-size: 12px; color: var(--text-muted); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track { flex: 1; height: 26px; background: var(--surface2); border-radius: 5px; position: relative; border: 1px solid var(--border); }
.tl-bar { position: absolute; height: 100%; border-radius: 4px; opacity: 0.85; display: flex; align-items: center; padding: 0 8px; }
.tl-bar-label { font-size: 10px; color: white; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tl-end { min-width: 70px; font-family: 'IBM Plex Mono', monospace; font-size: 10px; color: var(--text-dim); }

/* YOY TABLE */
.yoy-table { width: 100%; border-collapse: collapse; }
.yoy-table th, .yoy-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.yoy-table th { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; background: var(--surface2); }
.yoy-table td { font-size: 13px; }
.yoy-table tr:last-child td { border-bottom: none; }
.delta-up { color: var(--accent2); font-family: 'IBM Plex Mono', monospace; font-size: 11px; }
.delta-down { color: var(--accent3); font-family: 'IBM Plex Mono', monospace; font-size: 11px; }
.delta-same { color: var(--text-dim); font-family: 'IBM Plex Mono', monospace; font-size: 11px; }

/* RETURNING BANNER */
.returning-banner {
  background: var(--accent-light);
  border: 1px solid #f0d0b0;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.returning-banner .rb-icon { font-size: 20px; }
.returning-banner .rb-text { flex: 1; }
.returning-banner .rb-text strong { color: var(--accent); }
.returning-banner .rb-text p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* EMPTY */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); font-family: 'IBM Plex Mono', monospace; font-size: 13px; }

/* LEGEND DOTS */
.leg { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.leg-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.leg-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

@media (max-width: 700px) {
  header { padding: 14px 16px; flex-direction: column; align-items: flex-start; }
  .stats { padding: 12px 16px; }
  .main { padding: 12px 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-header, .detail-body { padding: 18px; }
}
