/* NEPSE Flow V2 — same theme as v1, plus heatmap / sparkline / streak styles. */

: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;
}

.beta {
  display: inline-block;
  vertical-align: middle;
  margin-left: 8px;
  padding: 2px 8px;
  border: 1px solid rgba(224, 163, 58, 0.5);
  border-radius: 999px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.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;
  flex-wrap: wrap;
}

.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: 150px;
  max-width: 100%;
}

select:focus,
input: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;
}

button.secondary {
  appearance: none;
  border: 1px solid var(--border);
  background: #0b1323;
  color: var(--accent-2);
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

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

.view {
  margin-top: 12px;
}

.view-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 6px 2px 10px;
}

.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;
}

.legend-scale {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-top: 4px;
}

.legend-bar {
  width: 120px;
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: linear-gradient(90deg, rgba(225, 91, 100, 0.85), rgba(111, 155, 216, 0.15), rgba(47, 191, 113, 0.85));
}

.legend-inline {
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin: 0 4px 0 8px;
  vertical-align: baseline;
}

.dot.buy {
  background: var(--green);
}

.dot.sell {
  background: var(--red);
}

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

.chart-wrap.short {
  height: 340px;
}

.chart-wrap.tall {
  height: 520px;
}

canvas {
  max-width: 100%;
}

/* ------------------------------------------------------------------ */
/* Heatmap                                                             */
/* ------------------------------------------------------------------ */
.heatmap-scroll {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid rgba(34, 48, 77, 0.7);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: 200px repeat(var(--hm-cols, 15), minmax(52px, 1fr));
  gap: 2px;
  padding: 8px;
  min-width: max-content;
}

.hm-corner {
  font-size: 10.5px;
  color: var(--muted);
  align-self: end;
  padding: 4px 6px;
  position: sticky;
  left: 0;
  background: #101a2f;
  z-index: 3;
}

.hm-row-head {
  font-size: 12px;
  color: var(--text);
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: sticky;
  left: 0;
  background: #101a2f;
  z-index: 2;
  border-right: 1px solid rgba(34, 48, 77, 0.7);
  font-variant-numeric: tabular-nums;
}

.hm-col-head {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  color: var(--text);
  padding: 6px 2px;
  height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
  background: #101a2f;
  z-index: 2;
}

.hm-cell {
  appearance: none;
  border: 0;
  height: 26px;
  padding: 0;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: rgba(231, 237, 248, 0.92);
  cursor: pointer;
  border-radius: 3px;
  overflow: hidden;
}

.hm-cell:hover {
  outline: 2px solid rgba(122, 167, 255, 0.8);
  outline-offset: -2px;
}

.hm-cell.empty {
  background: rgba(11, 19, 35, 0.5);
  cursor: default;
  box-shadow: inset 0 0 0 1px rgba(34, 48, 77, 0.35);
}

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

.table-wrap.short {
  max-height: 320px;
}

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 {
  color: var(--text);
}

thead th.sortable::after {
  content: '↕';
  margin-left: 5px;
  opacity: 0.45;
}

thead th.sortable.asc::after {
  content: '↑';
  opacity: 1;
  color: var(--accent-2);
}

thead th.sortable.desc::after {
  content: '↓';
  opacity: 1;
  color: var(--accent-2);
}

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);
}

/* ------------------------------------------------------------------ */
/* Streaks                                                             */
/* ------------------------------------------------------------------ */
.streak-strip {
  display: inline-flex;
  gap: 2px;
  vertical-align: middle;
}

.streak-day {
  width: 9px;
  height: 16px;
  border-radius: 2px;
  background: rgba(11, 19, 35, 0.85);
  box-shadow: inset 0 0 0 1px rgba(34, 48, 77, 0.45);
}

.streak-day.pos {
  background: var(--green);
  box-shadow: none;
}

.streak-day.neg {
  background: var(--red);
  box-shadow: none;
}

/* ------------------------------------------------------------------ */
/* Sparklines                                                          */
/* ------------------------------------------------------------------ */
.spark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.spark-card {
  border: 1px solid rgba(34, 48, 77, 0.7);
  border-radius: 10px;
  background: rgba(11, 19, 35, 0.65);
  padding: 9px 11px;
  min-width: 0;
}

.spark-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.spark-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 600;
}

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

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

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

.spark-svg {
  display: block;
  width: 100%;
  max-width: 190px;
}

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;
    padding: 8px 8px;
    font-size: 13px;
  }

  .controls {
    width: 100%;
  }

  .control {
    flex: 1 1 45%;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

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

  .chart-wrap.short,
  .chart-wrap.tall {
    height: 360px;
  }

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

  .heatmap-grid {
    grid-template-columns: 150px repeat(var(--hm-cols, 15), minmax(44px, 1fr));
  }

  .hm-cell {
    font-size: 0;
  }
}
