:root {
  --surface-1:      #fcfcfb;
  --surface-2:      #ffffff;
  --page:           #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --good:           #0ca30c;
  --good-text:      #006300;
  --warning:        #fab219;
  --serious:        #ec835a;
  --critical:       #d03b3b;

  --s-tech:   #2a78d6; /* blue */
  --s-health: #1baf7a; /* aqua */
  --s-fin:    #eda100; /* yellow */
  --s-ind:    #008300; /* green */
  --s-cdisc:  #4a3aa7; /* violet */
  --s-energy: #e34948; /* red */
  --s-comm:   #e87ba4; /* magenta */
  --s-mat:    #eb6834; /* orange */
  --s-other:  #a6a49c; /* gray */

  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec;
  --seq-400: #3987e5; --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:      #1a1a19;
    --surface-2:      #212120;
    --page:           #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --good:           #0ca30c;
    --good-text:      #0ca30c;
    --warning:        #fab219;
    --serious:        #ec835a;
    --critical:       #d03b3b;

    --s-tech:   #3987e5;
    --s-health: #199e70;
    --s-fin:    #c98500;
    --s-ind:    #008300;
    --s-cdisc:  #9085e9;
    --s-energy: #e66767;
    --s-comm:   #d55181;
    --s-mat:    #d95926;
    --s-other:  #66655f;

    --seq-100: #10233c; --seq-200: #133560; --seq-300: #184f95;
    --seq-400: #1c5cab; --seq-500: #256abf; --seq-600: #3987e5; --seq-700: #6da7ec;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--s-tech); }

.app { max-width: 1440px; margin: 0 auto; padding: 16px 20px 48px; }

/* ---------- Header ---------- */
header.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 4px 0 16px;
  flex-wrap: wrap;
}
header.top h1 { font-size: 19px; margin: 0; font-weight: 700; }
header.top .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.search-wrap { position: relative; flex: 1; max-width: 420px; min-width: 220px; }
.search-wrap input {
  width: 100%; padding: 9px 12px 9px 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  outline: none;
}
.search-wrap input:focus { border-color: var(--s-tech); }
.search-wrap::before {
  content: "🔍"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: 0.6;
}

/* ---------- Template chips ---------- */
.templates { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover { background: var(--surface-1); }
.chip.active { background: var(--s-tech); border-color: var(--s-tech); color: #fff; }
.template-desc {
  color: var(--text-secondary); font-size: 12.5px; margin: 2px 0 16px; min-height: 16px;
}

/* ---------- Filter bar ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 14px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 600; }
.filter-group .row { display: flex; gap: 6px; align-items: center; }
.filter-group input[type=number] {
  width: 76px; padding: 5px 7px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
}
.filter-group select {
  padding: 5px 7px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary);
}
.mcgroup-chips { display: flex; gap: 4px; flex-wrap: wrap; max-width: 260px; }
.mc-chip {
  border: 1px solid var(--border); background: var(--surface-1); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer; color: var(--text-secondary);
}
.mc-chip.active { background: var(--s-tech); border-color: var(--s-tech); color: #fff; }
.check-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.reset-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12.5px; align-self: center;
}
.reset-btn:hover { background: var(--surface-1); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.kpi .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi .value.small { font-size: 18px; }

/* ---------- Panels / cards ---------- */
.card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.card h2 { font-size: 14px; margin: 0 0 2px; font-weight: 700; }
.card .card-sub { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

/* ---------- Chart axis controls ---------- */
.axis-controls { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.axis-controls .filter-group select { min-width: 150px; }

/* ---------- Chart (SVG) ---------- */
.chart-wrap { position: relative; width: 100%; }
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
.axis path, .axis line { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 11px; }
.axis-title { fill: var(--text-secondary); font-size: 11.5px; font-weight: 600; }
.mark-dot { stroke: var(--surface-2); stroke-width: 2; cursor: pointer; }
.direct-label { fill: var(--text-secondary); font-size: 10.5px; font-weight: 600; pointer-events: none; }
.bar-rect { cursor: pointer; }
.bar-label { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.bar-cat-label { fill: var(--text-primary); font-size: 11.5px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.tooltip {
  position: fixed; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.5; z-index: 1000;
  max-width: 260px; box-shadow: 0 4px 16px rgba(0,0,0,0.25); display: none;
}
.tooltip b { display: block; font-size: 12.5px; margin-bottom: 2px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; opacity: 0.9; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; }
table.data-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.data-table th {
  text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.02em; white-space: nowrap; cursor: pointer; position: sticky; top: 0;
  background: var(--surface-2);
}
table.data-table th:first-child, table.data-table th:nth-child(2), table.data-table th:nth-child(3) { text-align: left; }
table.data-table th.sorted { color: var(--s-tech); }
table.data-table th .arrow { font-size: 9px; margin-left: 2px; }
table.data-table td {
  text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--gridline);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
table.data-table td:first-child, table.data-table td:nth-child(2), table.data-table td:nth-child(3) { text-align: left; font-variant-numeric: normal; }
table.data-table tbody tr { cursor: pointer; }
table.data-table tbody tr:hover { background: var(--surface-1); }
.sym { font-weight: 700; }
.cname { color: var(--text-secondary); font-size: 11.5px; }
.pos { color: var(--good-text); }
.neg { color: var(--critical); }
.score-pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 11.5px;
  color: #fff;
}

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; font-size: 12.5px; color: var(--text-secondary); }
.pagination .controls { display: flex; gap: 6px; align-items: center; }
.pagination button {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

/* ---------- Detail drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 900; display: none;
}
.overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(480px, 100%);
  background: var(--surface-1); border-left: 1px solid var(--border); z-index: 901;
  transform: translateX(100%); transition: transform 0.18s ease; overflow-y: auto;
  padding: 20px;
}
.drawer.open { transform: translateX(0); }
.drawer .close-btn {
  position: absolute; top: 16px; right: 16px; border: none; background: var(--surface-2);
  border-radius: 999px; width: 30px; height: 30px; cursor: pointer; font-size: 15px;
  color: var(--text-secondary);
}
.drawer h2 { margin: 0 0 2px; font-size: 20px; }
.drawer .drawer-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 4px; }
.drawer .price-row { font-size: 26px; font-weight: 700; margin: 10px 0 2px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 10px 0 18px; }
.stat-grid .g-title { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); font-weight: 700; margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.stat { display: flex; justify-content: space-between; font-size: 12.5px; }
.stat .k { color: var(--text-secondary); }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }

.factor-row { margin-bottom: 8px; }
.factor-row .fr-top { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 3px; color: var(--text-secondary); }
.factor-track { height: 8px; border-radius: 4px; background: var(--seq-100); overflow: hidden; }
.factor-fill { height: 100%; background: var(--seq-500); border-radius: 4px; }

footer.appfoot { text-align: center; color: var(--text-muted); font-size: 11.5px; margin-top: 24px; }

@media (max-width: 720px) {
  .stat-grid { grid-template-columns: 1fr; }
  header.top { flex-direction: column; align-items: stretch; }
  .search-wrap { max-width: none; }
}
