:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --surface: #fffaf1;
  --surface-2: #f8f1e4;
  --line: #ded3c2;
  --ink: #202832;
  --muted: #677382;
  --red: #d84c3f;
  --green: #2e8b57;
  --blue: #2367d8;
  --orange: #dd8a25;
  --violet: #7552db;
  --gray: #82796d;
  --shadow: 0 18px 45px rgba(69, 51, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 20px;
  border-right: 1px solid var(--line);
  background: #eee7dc;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
}

.brand p,
.control-panel p,
.panel-heading p,
.metric-card small,
.metric-card span {
  margin: 0;
  color: var(--muted);
}

.brand p {
  margin-top: 4px;
  font-size: 13px;
}

.control-panel {
  margin-top: 22px;
}

.control-panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #4d5864;
}

.tool-button {
  height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.select-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

select,
.search-input,
input[type="date"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffaf1;
  color: var(--ink);
  padding: 0 12px;
}

.date-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.date-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.zoom-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.mini-button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf1;
  color: var(--ink);
  cursor: pointer;
}

.mini-button:hover {
  border-color: #cbbba3;
  background: #fff;
}

.mini-button.accent {
  border-color: #2367d8;
  background: #2367d8;
  color: #fff;
  font-weight: 600;
}

.mini-button.accent:hover {
  background: #1a52b3;
  border-color: #1a52b3;
}

.level-filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.level-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 250, 241, 0.65);
  color: #303b46;
  font-size: 13px;
}

.level-chip input {
  width: 15px;
  height: 15px;
  accent-color: var(--orange);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: #303b46;
}

.check-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--blue);
}

.note-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.55);
}

.note-panel p + p {
  margin-top: 10px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar,
.panel-heading,
.toolbar,
.legend {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--orange);
  font-weight: 700;
}

.topbar h2 {
  margin: 0;
  font-size: 30px;
}

.toolbar {
  gap: 10px;
}

.tool-button {
  min-width: 104px;
  padding: 0 14px;
  background: var(--ink);
  color: #fff;
}

.tool-button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card,
.chart-panel,
.detail-panel,
.inspector-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 98px;
  padding: 16px;
}

.metric-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 28px;
  line-height: 1.05;
}

.chart-panel {
  padding: 18px;
  margin-bottom: 16px;
}

.panel-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.panel-heading.compact {
  padding: 16px 16px 0;
}

.panel-heading h3 {
  margin: 0 0 3px;
  font-size: 20px;
}

.legend {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #43505d;
  font-size: 13px;
}

.legend-swatch {
  width: 20px;
  height: 4px;
  border-radius: 99px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.actual-line {
  background: var(--blue);
}

.structure-dot {
  background: var(--orange);
}

.forecast-mark {
  background: repeating-linear-gradient(90deg, var(--blue) 0 6px, transparent 6px 11px);
  border: 1px solid rgba(35, 103, 216, 0.22);
}

.chart-wrap {
  position: relative;
  height: 360px;
  border: 1px solid #eadfce;
  border-radius: 8px;
  background: #f7f1e7;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.chart-wrap.grabbing {
  cursor: grabbing;
}

.chart-wrap.grab {
  cursor: grab;
}

.zoom-indicator {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(32, 40, 50, 0.7);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 0.25s;
}

.zoom-indicator button {
  pointer-events: all;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.zoom-indicator button:hover {
  background: rgba(255, 255, 255, 0.32);
}

.chart-overlay-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 42px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s;
}

.chart-overlay-edge.left {
  left: 0;
  background: linear-gradient(90deg, rgba(247, 241, 231, 0.92), transparent);
}

.chart-overlay-edge.right {
  right: 0;
  background: linear-gradient(270deg, rgba(247, 241, 231, 0.92), transparent);
}

.chart-overlay-edge.visible {
  opacity: 1;
}

#marketChart {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.chart-wrap.grabbing #marketChart {
  cursor: grabbing;
}

.chart-tooltip {
  position: absolute;
  z-index: 4;
  width: 286px;
  padding: 12px;
  border: 1px solid rgba(32, 40, 50, 0.14);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.98);
  box-shadow: 0 16px 36px rgba(69, 51, 31, 0.18);
  color: var(--ink);
  pointer-events: none;
}

.tooltip-title {
  margin-bottom: 8px;
  font-weight: 800;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid #eadfce;
  font-size: 12px;
}

.tooltip-row span {
  color: var(--muted);
}

.tooltip-row b {
  max-width: 190px;
  text-align: right;
}

.chart-tooltip p {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid #eadfce;
  color: #4e5a65;
  font-size: 12px;
  line-height: 1.55;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}

.detail-panel {
  min-width: 0;
  overflow: hidden;
}

.search-input {
  max-width: 260px;
}

.table-wrap {
  max-height: 520px;
  overflow: auto;
  padding: 12px 16px 16px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
}

th,
td {
  padding: 11px 9px;
  border-bottom: 1px solid #eadfce;
  white-space: nowrap;
}

.energy-cell {
  color: #4e5a65;
  font-size: 12px;
}

tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #f3eadb;
}

.empty-row {
  height: 72px;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-width: 46px;
  justify-content: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.up {
  background: #fde5df;
  color: #a7372d;
}

.badge.super-up {
  background: #f8cfc7;
  color: #872018;
}

.badge.mild-up {
  background: #f8e8c8;
  color: #8a5515;
}

.badge.down {
  background: #daf0e2;
  color: #1f6d46;
}

.badge.super-down {
  background: #c9e9d5;
  color: #114d31;
}

.badge.mild-down {
  background: #e3f1df;
  color: #3f714a;
}

.badge.flat {
  background: #e9e2d7;
  color: #62594d;
}

.badge.match {
  background: #e0ebff;
  color: #2258b8;
}

.badge.miss {
  background: #f6dcd6;
  color: #a7372d;
}

.badge.avoid {
  background: #d7eee0;
  color: #17633d;
}

.badge.missed {
  background: #fae0d6;
  color: #b14a28;
}

.badge.neutral {
  background: #e3e9f2;
  color: #365475;
}

.badge.empty {
  background: #ebe6dc;
  color: #6f685f;
}

.inspector {
  display: grid;
  gap: 16px;
  align-content: start;
}

.inspector-card {
  padding: 18px;
}

.section-kicker {
  color: var(--orange);
  font-size: 12px;
  font-weight: 800;
}

.inspector-card h3 {
  margin: 6px 0 8px;
  font-size: 22px;
}

.selected-day p {
  min-height: 44px;
  margin: 0;
  color: var(--muted);
}

.score-meter {
  height: 10px;
  margin: 18px 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #e5f2e9, #ede6dc, #fbe2dd);
  overflow: hidden;
}

#scoreFill {
  height: 100%;
  width: 50%;
  background: var(--orange);
}

.energy-breakdown {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.energy-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 88px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.energy-row strong {
  color: var(--ink);
  font-size: 12px;
  text-align: right;
}

.energy-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe3d6;
}

.energy-track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(32, 40, 50, 0.24);
}

.energy-track b {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 2px;
  border-radius: 999px;
}

dl {
  display: grid;
  gap: 12px;
  margin: 0;
}

dl div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid #eadfce;
  padding-top: 12px;
}

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

dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

.selected-day dd {
  max-width: 210px;
  white-space: normal;
}

.rule-list {
  display: grid;
  gap: 12px;
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}

.rule-list li {
  display: grid;
  gap: 3px;
  padding: 10px 0;
  border-top: 1px solid #eadfce;
}

.rule-list span {
  color: var(--muted);
}

@media (max-width: 1180px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .brand {
    grid-column: 1 / -1;
  }

  .metrics-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }
}
