:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef3f4;
  --text: #182127;
  --muted: #66737d;
  --line: #d8e0e4;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --danger: #c2410c;
  --good: #16803f;
  --shadow: 0 8px 22px rgba(24, 33, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
}

.topbar p,
.panel-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill,
.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.control-panel,
.strategy-tabs,
.summary-grid,
.workspace,
.table-panel {
  margin-top: 14px;
}

.strategy-tabs {
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.strategy-tab {
  min-width: 112px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.strategy-tab.active {
  border-color: rgba(15, 118, 110, 0.22);
  background: #e7f5f2;
  color: var(--accent);
}

.strategy-tab:hover {
  border-color: rgba(15, 118, 110, 0.35);
}

.control-panel {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
select:hover,
input:hover {
  border-color: #9fb0b8;
}

.reset-control {
  display: flex;
  align-items: end;
}

.reset-control button {
  width: 100%;
  min-height: 38px;
  border-color: #aab8bf;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
}

.metric {
  min-height: 88px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.chart-panel {
  min-width: 0;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.chart-tools {
  display: flex;
  gap: 8px;
}

.chart-wrap {
  position: relative;
  height: 560px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  overflow: hidden;
}

#chartContainer {
  width: 100%;
  height: 100%;
  display: block;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

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

.legend-swatch {
  width: 18px;
  height: 3px;
  border-radius: 3px;
  background: currentColor;
}

.indicator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.indicator-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  overflow: hidden;
}

.indicator-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f7fafb;
}

.indicator-head h3 {
  font-size: 13px;
  line-height: 1.2;
}

.mini-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 11px;
}

.mini-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.indicator-chart {
  width: 100%;
  height: 180px;
}

.table-panel {
  padding: 14px;
}

.table-wrap {
  position: relative;
  overflow: auto;
  max-height: 460px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

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

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3),
th:nth-child(7),
td:nth-child(7),
th:nth-child(8),
td:nth-child(8) {
  text-align: left;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 600;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #eef7f6;
}

tbody tr.selected {
  background: #dff4f0;
  outline: 2px solid rgba(15, 118, 110, 0.2);
}

.profit-positive {
  color: var(--good);
  font-weight: 700;
}

.profit-negative {
  color: var(--danger);
  font-weight: 700;
}

.entry-reason-cell {
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.direction-long {
  color: var(--good);
}

.direction-short {
  color: var(--danger);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.86);
  text-align: center;
}

.hidden {
  display: none;
}

@media (max-width: 1080px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chart-wrap {
    height: 460px;
  }

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

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 20px, 1480px);
    padding-top: 14px;
  }

  .topbar,
  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .control-panel,
  .strategy-tabs,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .strategy-tabs {
    overflow-x: auto;
  }

  .chart-wrap {
    height: 380px;
  }

  .indicator-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .indicator-chart {
    height: 150px;
  }
}
