:root {
  color-scheme: dark;
  --bg: #0a0f1c;
  --bg-2: #0e1526;
  --panel: #111a2e;
  --panel-2: #0d1526;
  --border: #22304d;
  --text: #e7edf8;
  --muted: #91a0b8;
  --accent: #5b8def;
  --accent-2: #7aa7ff;
  --green: #2fbf71;
  --red: #e15b64;
  --amber: #e0a33a;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(91, 141, 239, 0.16), transparent 65%),
    radial-gradient(700px 400px at 100% 0%, rgba(47, 191, 113, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

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

a:hover {
  text-decoration: underline;
}

.site-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 30px 24px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 760px;
}

.status {
  flex: 0 0 auto;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(17, 26, 46, 0.8);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.status.ready {
  color: #b7e4c7;
  border-color: rgba(47, 191, 113, 0.35);
}

.status.busy {
  color: var(--accent-2);
  border-color: rgba(91, 141, 239, 0.45);
}

.status.warn {
  color: #ffd79a;
  border-color: rgba(224, 163, 58, 0.45);
}

.status.error {
  color: #ffc2c7;
  border-color: rgba(225, 91, 100, 0.45);
}

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 24px 40px;
}

.panel {
  background: linear-gradient(180deg, rgba(17, 26, 46, 0.95), rgba(13, 21, 38, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
}

.toolbar {
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 7px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: #1b2a49;
  color: var(--text);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

select,
input[type="search"] {
  appearance: none;
  background: #0b1323;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  min-height: 36px;
}

select {
  min-width: 170px;
  max-width: 100%;
}

#flowMode {
  min-width: 220px;
}

input[type="search"]:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(91, 141, 239, 0.75);
  outline-offset: 1px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: #0b1323;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.segmented button.active {
  background: #1b2a49;
  color: var(--text);
}

button.primary {
  appearance: none;
  border: 1px solid rgba(91, 141, 239, 0.55);
  background: linear-gradient(180deg, #4b7fe0, #3f6fc9);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

button.primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.selector-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 4px 10px;
  flex-wrap: wrap;
}

.selector-row label {
  color: var(--muted);
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.selector-row select {
  min-width: 320px;
  max-width: 100%;
}

.meta {
  color: var(--muted);
  font-size: 12.5px;
}

.chart-card,
.table-card {
  padding: 16px;
  margin-top: 8px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.card-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 3px 0 0;
}

.hint.warn {
  color: #ffd79a;
}

.chart-wrap {
  position: relative;
  height: 430px;
  margin: 8px 0 12px;
}

canvas {
  max-width: 100%;
}

.series-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(34, 48, 77, 0.7);
  padding-top: 12px;
}

.series-tools input {
  min-width: 240px;
  flex: 0 1 320px;
}

.series-list {
  margin-top: 10px;
  max-height: 240px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 4px 16px;
  padding-right: 4px;
}

.series-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 3px 0;
  font-size: 13px;
}

.series-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.series-item input[type="checkbox"] {
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.series-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.series-tag {
  flex: 0 0 auto;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
  opacity: 0.9;
}

.series-tag.accum {
  color: var(--green);
}

.series-tag.dist {
  color: var(--red);
}

.series-tag.flat {
  color: var(--muted);
}

.series-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  flex: 0 0 auto;
}

.series-value.pos {
  color: var(--green);
}

.series-value.neg {
  color: var(--red);
}

.table-card {
  margin-top: 18px;
}

.table-wrap {
  max-height: 440px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(34, 48, 77, 0.7);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #101a2f;
  color: var(--muted);
  text-align: right;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th:first-child {
  text-align: left;
}

thead th.sortable {
  cursor: pointer;
  user-select: none;
}

thead th.sortable:hover,
thead th[aria-sort] {
  color: var(--text);
}

thead th.sortable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sort-arrow {
  color: var(--accent-2);
  font-size: 10px;
}

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(34, 48, 77, 0.45);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tbody td:first-child {
  text-align: left;
  white-space: normal;
}

tbody tr:hover {
  background: rgba(91, 141, 239, 0.06);
}

td.pos {
  color: var(--green);
}

td.neg {
  color: var(--red);
}

tfoot td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  background: #101a2f;
}

tfoot td:first-child {
  text-align: left;
}

footer {
  max-width: 1240px;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: 12.5px;
}

footer p {
  margin: 6px 0;
}

.link-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

@media (max-width: 720px) {
  .site-header {
    flex-direction: column;
    padding-top: 22px;
  }

  .status {
    white-space: normal;
  }

  .toolbar {
    align-items: stretch;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .controls {
    width: 100%;
  }

  .control {
    flex: 1 1 45%;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .selector-row select {
    min-width: 0;
    width: 100%;
  }

  .chart-wrap {
    height: 360px;
  }

  .card-head {
    flex-direction: column;
    gap: 4px;
  }

  tbody td:first-child,
  thead th:first-child {
    min-width: 180px;
  }

  .series-list {
    grid-template-columns: 1fr;
  }
}
