:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #66707c;
  --line: #dce1e6;
  --blue: #2563eb;
  --green: #127f4f;
  --red: #b42318;
  --amber: #8a5a00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.gateOpen {
  overflow: hidden;
}

.shell {
  width: min(1600px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 36px;
}

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

h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #b8c1cc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(120px, 165px)) repeat(3, minmax(120px, auto));
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}

.check {
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.tableWrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef2f6;
  color: #4b5563;
  font-size: 12px;
  font-weight: 700;
}

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

tbody tr:hover {
  background: #f8fafc;
}

.edgeRow td:first-child {
  cursor: pointer;
}

.groupRow {
  background: #f4f7fb;
  cursor: pointer;
}

.groupRow:hover {
  background: #edf3fa;
}

.groupRow td {
  border-bottom-color: #ccd6e0;
}

.groupToggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--blue);
  font-weight: 800;
  line-height: 1;
}

.groupName {
  font-weight: 800;
}

.groupChild td:first-child {
  padding-left: 28px;
}

.groupChild .market {
  max-width: 620px;
}

.market {
  display: grid;
  gap: 3px;
  min-width: 330px;
  max-width: 560px;
}

.marketTitle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.market a {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.market a:hover {
  color: var(--blue);
}

.market .pmLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel);
  line-height: 1;
  text-decoration: none;
}

.market .pmLink:hover {
  border-color: #b8c1cc;
  background: #f8fafc;
}

.market .pmLink img {
  width: 14px;
  height: 14px;
  display: block;
}

.sub {
  color: var(--muted);
  font-size: 12px;
}

.coverageWarn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #f0c36a;
  background: #fff7df;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.gapBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 124px;
  height: 30px;
  border-radius: 6px;
  padding: 0 10px;
  font-weight: 800;
  font-size: 13px;
}

.gapBadge.pos {
  background: #e8f6ef;
  border: 1px solid #b8e2ca;
  color: var(--green);
}

.gapBadge.neg {
  background: #fff0ee;
  border: 1px solid #f4c2bc;
  color: var(--red);
}

.priceCell {
  display: inline-grid;
  grid-template-columns: 1fr;
  gap: 2px;
  min-width: 82px;
  text-align: left;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.priceCell span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.priceCell b {
  color: var(--muted);
  font-size: 11px;
}

.pos {
  color: var(--green);
  font-weight: 700;
}

.neg {
  color: var(--red);
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.empty {
  height: 180px;
  color: var(--muted);
  text-align: center !important;
  vertical-align: middle;
}

.historyRow td {
  padding: 0;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: normal;
}

.historyRow:hover {
  background: #fbfcfd;
}

.historyPanel {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.chartHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.chartHeader h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0;
}

.chartHeader p {
  margin-top: 4px;
  font-size: 12px;
}

.chartStats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 14px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.chartStats span {
  display: inline-flex;
  gap: 6px;
}

.chartStats b {
  color: var(--muted);
  font-size: 11px;
}

.gapChart {
  width: 100%;
  height: 220px;
  display: block;
}

.chartGrid {
  stroke: #cfd7df;
  stroke-width: 1;
}

.zeroLine {
  stroke: #9aa5b1;
  stroke-dasharray: 4 4;
  stroke-width: 1;
}

.gapLine {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.posLine {
  stroke: var(--green);
}

.negLine {
  stroke: var(--red);
}

.gapPoint {
  fill: var(--panel);
  stroke: var(--blue);
  stroke-width: 2;
}

.axisLabel {
  fill: var(--muted);
  font-size: 11px;
}

.endLabel {
  text-anchor: end;
}

.chartState {
  min-height: 80px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.chartState.small {
  min-height: 0;
  place-items: start;
  font-size: 12px;
}

.tableFooter {
  display: flex;
  justify-content: center;
  padding: 14px 0 0;
}

#showMore {
  min-width: 140px;
}

#showMore[hidden] {
  display: none;
}

.followGate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 42, 0.48);
  backdrop-filter: blur(5px);
}

.followGate[hidden] {
  display: none;
}

.followDialog {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(23, 32, 42, 0.22);
}

.followDialog h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.followDialog p {
  margin: 0;
}

.followLinks {
  display: grid;
  gap: 10px;
}

.followLink {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.followLink:hover {
  border-color: #b8c1cc;
}

.followLink.visited {
  border-color: #b8e2ca;
  background: #eefaf4;
}

.followLink b {
  color: var(--blue);
  font-size: 12px;
}

#confirmFollow {
  width: 100%;
  background: var(--text);
  color: var(--panel);
  border-color: var(--text);
}

#confirmFollow:disabled {
  background: #d7dde4;
  color: #6b7280;
  border-color: #d7dde4;
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 20px, 1600px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 22px;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }
}
