:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #d9dee5;
  --border-strong: #b9c1cc;
  --text: #171a1f;
  --muted: #667085;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0a8f54;
  --green-soft: #e8f7ef;
  --red: #d43f4d;
  --red-soft: #fcecef;
  --amber: #b76e00;
  --shadow: 0 12px 34px rgba(22, 29, 37, 0.12);
  --radius: 6px;
  --filter-width: 328px;
  --detail-width: 420px;
  --resizer-width: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: white;
  background: #111827;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand h1,
.brand p,
.panel-heading h2,
.panel-heading p,
.summary-heading h2,
.table-toolbar h2,
.detail-heading h2,
.empty-state h3,
.empty-state p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.05;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns:
    minmax(260px, var(--filter-width))
    var(--resizer-width)
    minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.filter-panel {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  overflow-y: auto;
  padding: 20px 18px 28px;
  background: var(--surface);
}

.pane-resizer {
  position: relative;
  z-index: 5;
  min-width: var(--resizer-width);
  cursor: col-resize;
  outline: none;
  touch-action: none;
  user-select: none;
}

.pane-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
  transition: width 0.15s ease, background 0.15s ease;
}

.pane-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 42px;
  border-radius: 2px;
  background: var(--border-strong);
  box-shadow: 0 0 0 3px var(--bg);
  transform: translate(-50%, -50%);
  transition: background 0.15s ease, height 0.15s ease;
}

.pane-resizer:hover::before,
.pane-resizer:focus-visible::before,
.pane-resizer.dragging::before {
  width: 3px;
  background: var(--blue);
}

.pane-resizer:hover::after,
.pane-resizer:focus-visible::after,
.pane-resizer.dragging::after {
  height: 54px;
  background: var(--blue);
}

.workspace-resizer {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
}

body.resizing-panes {
  cursor: col-resize;
  user-select: none;
}

.panel-heading,
.summary-heading,
.table-toolbar,
.detail-heading,
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading {
  margin-bottom: 22px;
}

.panel-heading h2 {
  font-size: 17px;
}

.panel-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.control-section {
  margin-bottom: 20px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.control {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  outline: none;
}

.control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.control.compact {
  width: 170px;
  height: 34px;
  font-size: 12px;
}

.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-grid label span,
.sort-control span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.conditions {
  display: grid;
  gap: 8px;
  margin-bottom: 9px;
}

.condition-row {
  padding: 10px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.condition-top,
.condition-bottom {
  display: grid;
  gap: 7px;
}

.condition-top {
  grid-template-columns: 1fr 34px;
  margin-bottom: 7px;
}

.condition-bottom {
  grid-template-columns: minmax(0, 1fr) 72px 82px;
}

.condition-row .control {
  height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: #475467;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.icon-button:hover {
  color: var(--text);
  background: #eef1f4;
}

.icon-button.bordered {
  border: 1px solid var(--border);
  background: var(--surface);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.text-button {
  padding: 0;
  color: var(--blue);
  background: transparent;
  border: 0;
  font-size: 12px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  font-weight: 700;
}

.primary-button {
  color: white;
  background: var(--blue);
  border: 1px solid var(--blue);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  color: #344054;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
}

.primary-button svg,
.secondary-button svg {
  width: 17px;
  height: 17px;
}

.full-width {
  width: 100%;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.preset-grid button {
  min-height: 38px;
  padding: 7px 8px;
  color: #344054;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  text-align: left;
}

.preset-grid button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.saved-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.save-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 7px;
}

.saved-filters {
  display: grid;
  gap: 6px;
  margin-top: 9px;
}

.saved-filter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.saved-filter > button:first-child {
  min-width: 0;
  padding: 7px 9px;
  overflow: hidden;
  color: #344054;
  background: transparent;
  border: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-filter .icon-button {
  width: 28px;
  height: 28px;
}

.cloud-filter-label {
  margin-top: 14px;
}

.cloud-filter {
  grid-template-columns: minmax(0, 1fr) 30px;
}

.cloud-filter > i {
  width: 15px;
  height: 15px;
  color: var(--primary);
}

.saved-filter-status {
  padding: 5px 1px;
  color: var(--muted);
  font-size: 12px;
}

.coverage-section {
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
}

.coverage-section summary {
  cursor: pointer;
  color: #344054;
  font-weight: 700;
}

.coverage-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.coverage-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.coverage-source {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 5px;
  color: #475467;
  background: #eef1f4;
  border-radius: 3px;
  font-size: 10px;
}

.main-content {
  min-width: 0;
  padding: 24px;
}

.summary-band {
  margin-bottom: 18px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.summary-heading h2 {
  margin-top: 4px;
  font-size: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-actions,
.detail-actions {
  display: flex;
  gap: 7px;
}

.probability-strip {
  height: 9px;
  display: flex;
  margin-top: 20px;
  overflow: hidden;
  background: #e5e7eb;
  border-radius: 3px;
}

.prob-up {
  width: 50%;
  background: var(--green);
}

.prob-down {
  width: 50%;
  background: var(--red);
}

.probability-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 7px;
  font-size: 12px;
  font-weight: 700;
}

#up-label {
  color: var(--green);
}

#down-label {
  color: var(--red);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 9px;
  margin-top: 18px;
}

.metric {
  min-height: 74px;
  padding: 11px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 18px;
  line-height: 1;
}

.positive {
  color: var(--green) !important;
}

.negative {
  color: var(--red) !important;
}

.neutral {
  color: var(--text) !important;
}

.results-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.results-layout.with-detail {
  grid-template-columns:
    minmax(360px, 1fr)
    var(--resizer-width)
    minmax(320px, var(--detail-width));
}

.detail-resizer {
  display: none;
}

.results-layout.with-detail .detail-resizer {
  position: sticky;
  top: 92px;
  display: block;
  height: calc(100vh - 116px);
}

.results-section,
.detail-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-toolbar {
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.table-toolbar h2 {
  display: inline;
  margin-right: 8px;
  font-size: 16px;
}

.table-toolbar > div > span {
  color: var(--muted);
  font-size: 12px;
}

.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sort-control span {
  margin: 0;
}

.table-wrap {
  max-height: calc(100vh - 315px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 42px;
  padding: 8px 10px;
  color: #475467;
  background: #f1f4f7;
  border-bottom: 1px solid var(--border-strong);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
}

th:first-child {
  z-index: 3;
  background: #f1f4f7;
}

td:first-child {
  background: var(--surface);
}

td {
  height: 48px;
  padding: 8px 10px;
  border-bottom: 1px solid #e8ebef;
  text-align: right;
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover td,
tbody tr.selected td {
  background: #f0f6ff;
}

.triplet {
  display: inline-flex;
  gap: 5px;
  color: var(--muted);
}

.triplet b {
  color: #344054;
  font-weight: 600;
}

.time-note {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.detail-panel {
  position: sticky;
  top: 92px;
  height: calc(100vh - 116px);
  overflow-y: auto;
}

.detail-heading {
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.detail-heading h2 {
  margin-top: 3px;
  font-size: 16px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.detail-stat {
  min-width: 0;
  padding: 10px;
  background: var(--surface);
}

.detail-stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.detail-stat strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-readout {
  display: grid;
  grid-template-columns: 0.9fr 1.15fr repeat(4, 1fr) 1.35fr;
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.chart-readout span {
  min-width: 0;
  padding: 7px 9px;
  background: #fbfcfd;
}

.chart-readout small {
  display: block;
  color: var(--muted);
  font-size: 9px;
}

.chart-readout strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: #344054;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-readout.up strong:not(#readout-time):not(#readout-session) {
  color: var(--green);
}

.chart-readout.down strong:not(#readout-time):not(#readout-session) {
  color: var(--red);
}

.chart-sessions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  padding: 6px;
  background: #eef1f4;
  border-bottom: 1px solid var(--border);
}

.chart-session-tab {
  min-width: 0;
  min-height: 28px;
  padding: 4px 6px;
  overflow: hidden;
  color: var(--muted);
  background: #fff;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-session-tab:hover {
  color: var(--text);
  background: #f7f9fb;
}

.chart-session-tab.active {
  color: #155eef;
  background: #eef4ff;
  border-color: #84adff;
}

.chart {
  position: relative;
  width: 100%;
  height: 330px;
}

.chart-session-overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.chart-session-boundary {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(71, 84, 103, 0.72);
}

.chart-session-axis-label {
  position: absolute;
  bottom: 24px;
  max-width: 54px;
  padding: 2px 5px;
  overflow: hidden;
  color: #344054;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d0d5dd;
  border-radius: 3px;
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  line-height: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
}

.chart-session-axis-label.night {
  color: #475467;
  border-color: #98a2b3;
}

.chart-session-axis-label.pre {
  color: #b54708;
  border-color: #fdb022;
}

.chart-session-axis-label.regular {
  color: #067647;
  border-color: #32d583;
}

.chart-session-axis-label.after {
  color: #175cd3;
  border-color: #84adff;
}

.chart-message {
  min-height: 280px;
  display: grid;
  place-items: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 9px 14px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
}

.legend-candle {
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-right: 4px;
}

.legend-candle.up {
  background: var(--green);
}

.legend-candle.down {
  background: var(--red);
}

.legend-line {
  width: 12px;
  height: 0;
  display: inline-block;
  margin: 0 4px 3px 0;
  border-top: 1px dashed currentColor;
}

.legend-line.previous-close {
  color: #667085;
}

.condition-snapshot {
  padding: 14px;
}

.condition-snapshot h3 {
  margin: 0 0 10px;
  font-size: 13px;
}

.snapshot-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, 60px);
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-align: right;
}

.snapshot-row:first-of-type {
  color: var(--muted);
}

.snapshot-row span:first-child {
  text-align: left;
}

.empty-state {
  min-height: 320px;
  display: grid;
  place-items: center;
  align-content: center;
  margin-top: 18px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.empty-state svg {
  width: 30px;
  height: 30px;
  margin-bottom: 12px;
}

.empty-state h3 {
  color: var(--text);
  font-size: 16px;
}

.empty-state p {
  margin-top: 6px;
  font-size: 12px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(244, 246, 248, 0.88);
}

.loading-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #d7dce2;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 120;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  color: white;
  background: #111827;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.mobile-only {
  display: none;
}

@media (max-width: 1180px) {
  .results-layout.with-detail {
    grid-template-columns: minmax(0, 1fr);
  }

  .results-layout.with-detail .detail-resizer {
    display: none;
  }

  .detail-panel {
    position: relative;
    top: auto;
    height: auto;
    margin-top: 18px;
  }
}

@media (max-width: 820px) {
  .mobile-only {
    display: inline-grid;
  }

  .topbar {
    height: 62px;
    padding: 0 14px;
  }

  .status-dot {
    display: none;
  }

  .workspace {
    display: block;
  }

  .workspace-resizer,
  .desktop-only {
    display: none !important;
  }

  .filter-panel {
    position: fixed;
    inset: 0 10% 0 0;
    z-index: 60;
    height: 100vh;
    padding-top: 16px;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .filter-panel.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 12px;
  }

  .summary-band {
    padding: 14px;
  }

  .summary-heading h2 {
    max-width: 250px;
    font-size: 15px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    min-height: 66px;
  }

  .metric strong {
    font-size: 16px;
  }

  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .sort-control {
    width: 100%;
    justify-content: space-between;
  }

  .table-wrap {
    max-height: 520px;
  }

  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-readout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout-volume {
    grid-column: span 3;
  }

  .chart {
    height: 300px;
  }
}
