:root {
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border-hairline: rgba(11,11,11,0.10);

  --series-1: #2a78d6; /* blue */
  --series-2: #1baf7a; /* aqua */
  --series-3: #eda100; /* yellow */
  --series-4: #008300; /* green */
  --series-5: #4a3aa7; /* violet */
  --series-6: #e34948; /* red */
  --series-7: #e87ba4; /* magenta */
  --series-8: #eb6834; /* orange */

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --seq-100: #cde2fb;
  --seq-400: #3987e5;
  --seq-700: #0d366b;

  --radius-card: 12px;
  --radius-control: 8px;
}

[data-theme="dark"] {
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border-hairline: rgba(255,255,255,0.10);

  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-4: #008300;
  --series-5: #9085e9;
  --series-6: #e66767;
  --series-7: #d55181;
  --series-8: #d95926;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}

body {
  min-height: 100vh;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 18px 0 14px;
  position: sticky;
  top: 0;
  background: var(--page-plane);
  z-index: 20;
  border-bottom: 1px solid var(--border-hairline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
}
.brand-mark { color: var(--series-1); font-size: 15px; }

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { background: var(--border-hairline); color: var(--text-primary); }
.tab-btn.is-active { background: var(--series-1); color: #fff; }

.theme-toggle {
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-primary);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--gridline); }

/* ---------- Panels ---------- */
.panel { display: none; padding-top: 20px; }
.panel.is-active { display: block; }

/* ---------- Filter row ---------- */
.filter-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 20px;
}
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}
.filter-field select, select, input, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-primary);
}
.filter-field select { min-width: 180px; }

/* ---------- Stat tiles ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
@media (max-width: 720px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 600; color: var(--text-primary); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-card);
  padding: 20px;
  margin-bottom: 20px;
}
.card-head { margin-bottom: 14px; }
.card-head h2 { margin: 0 0 4px; font-size: 16px; }
.card-sub { margin: 0; font-size: 13px; color: var(--text-secondary); }
.card-foot { margin-top: 8px; }

.link-btn {
  border: none;
  background: none;
  color: var(--series-1);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Charts ---------- */
.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; overflow: visible; }

.bar-mark { transition: opacity 0.1s ease; cursor: pointer; }
.bar-mark:hover, .bar-mark.is-hovered { opacity: 0.82; }

.chart-label { font-size: 12px; fill: var(--text-secondary); }
.chart-value-label { font-size: 12px; fill: var(--text-primary); font-weight: 600; }
.chart-axis-label { font-size: 11px; fill: var(--text-muted); }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1; }

.rank-list { display: flex; flex-direction: column; gap: 4px; }
.rank-row {
  display: grid;
  grid-template-columns: 140px 1fr 56px;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}
.rank-row-mini { min-height: 24px; }
.rank-label {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-track { position: relative; height: 20px; }
.rank-row-mini .rank-track { height: 14px; }
.rank-grid-line {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 1px;
  background: var(--gridline);
}
.rank-grid-line.is-baseline { background: var(--baseline); }
.rank-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 20px;
  border-radius: 0 4px 4px 0;
  min-width: 2px;
}
.rank-bar-mini { height: 14px; }
.rank-value {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  text-align: right;
  color: var(--text-primary);
  font-weight: 600;
}
.rank-axis { margin-top: 6px; }
.rank-axis .rank-track { height: 16px; }

.skill-groups {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 6px;
}
.skill-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.skill-group-bars { display: flex; flex-direction: column; gap: 4px; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-hairline);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-primary);
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  pointer-events: none;
  max-width: 240px;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; gap: 12px; }
.tooltip .tt-key { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .tt-swatch { width: 8px; height: 2px; display: inline-block; }
.tooltip .tt-val { font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-hairline);
  white-space: nowrap;
}
tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
tbody tr:hover { background: var(--page-plane); }
td.num, th.num { font-variant-numeric: tabular-nums; }

.table-view { margin-top: 14px; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.pill-easy { background: rgba(27,175,122,0.16); color: #0b6b47; }
.pill-medium { background: rgba(237,161,0,0.18); color: #7a5400; }
.pill-hard { background: rgba(227,73,72,0.16); color: #a12726; }
[data-theme="dark"] .pill-easy { color: #4fe0ab; }
[data-theme="dark"] .pill-medium { color: #f0c04d; }
[data-theme="dark"] .pill-hard { color: #f19a99; }

.result-pass { color: var(--status-good); font-weight: 600; }
.result-fail { color: var(--status-critical); font-weight: 600; }

.icon-btn {
  border: 1px solid var(--border-hairline);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}
.icon-btn:hover { background: var(--status-critical); color: #fff; border-color: var(--status-critical); }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 16px;
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-secondary); }
.field-wide { grid-column: 1 / -1; }
.field textarea { resize: vertical; font-family: inherit; }
.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-checkbox input { width: auto; }

.field-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  border: none;
  border-radius: var(--radius-control);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--series-1); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.form-msg { font-size: 13px; color: var(--text-secondary); }
.form-msg.is-error { color: var(--status-critical); }
.form-msg.is-success { color: var(--status-good); }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 12px 0; }
