:root {
  --bg: #f4efe6;
  --panel: #fffaf2;
  --ink: #1e2328;
  --muted: #66707a;
  --line: #d6c8b2;
  --primary: #245f4a;
  --danger: #9f2f22;
  --warn: #8f6500;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #e7dfcf, var(--bg));
  color: var(--ink);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 26px;
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
}

.badge {
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid var(--line);
}

.badge.running {
  background: #d8f2e6;
  color: #13573f;
}

.badge.stopping {
  background: #fff2d6;
  color: #7b5200;
}

.badge.stopped {
  background: #f6ded9;
  color: #7a2419;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 10px;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn.warning {
  background: var(--warn);
  color: #fff;
  border-color: var(--warn);
}

input[type="number"],
input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}

select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  background: #fff;
}

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

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

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

.card strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.panel h3 {
  margin: 10px 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.panel h4 {
  margin: 10px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.equity-chart {
  width: 100%;
  height: 240px;
}

.hidden {
  display: none !important;
}

.tabbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tab-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 700;
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.retrain-cards {
  margin-bottom: 8px;
}

.retrain-path {
  margin: 4px 0 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace;
  overflow-wrap: anywhere;
}

.retrain-tag-logs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 8px;
}

.retrain-tag-log-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-width: 0;
}

.retrain-tag-log-head {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #f7f2e9;
  font-size: 12px;
  font-weight: 700;
}

.retrain-tag-log-box {
  max-height: 180px;
  overflow: auto;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #0f1720;
  color: #d6e0ea;
  border-radius: 0 0 10px 10px;
}

.config-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
}

.config-toolbar input[type="search"] {
  min-width: 260px;
  flex: 1 1 320px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 10px;
  align-items: start;
}

.cfg-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  min-width: 0;
}

.cfg-group-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #f8f1e5;
}

.cfg-group-title {
  margin: 0;
  font-size: 13px;
  color: #30404e;
}

.cfg-group-count {
  font-size: 12px;
  color: var(--muted);
}

.cfg-group-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 380px;
  overflow: auto;
}

.cfg-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: center;
  gap: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  min-width: 0;
}

.cfg-key {
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  color: #30404e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace;
}

.cfg-item input[type="number"],
.cfg-item input[type="text"] {
  width: 100%;
  min-width: 0;
}

.cfg-item input[type="checkbox"] {
  justify-self: end;
  width: 18px;
  height: 18px;
}

.cfg-empty {
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.table-wrap {
  overflow: auto;
  max-height: 260px;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #f7f2e9;
}

.logs {
  background: #0f1720;
  color: #d6e0ea;
  border-radius: 8px;
  min-height: 180px;
  max-height: 280px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 8px;
}

.log-line {
  margin: 0 0 2px;
}

.pnl-pos {
  color: #146c43;
  font-weight: 700;
}

.pnl-neg {
  color: #b42318;
  font-weight: 700;
}

.reason-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  background: #f2ede5;
  color: #4f5a65;
}

.reason-none {
  background: #f2ede5;
  color: #5f6770;
}

.reason-llm-low-confidence {
  background: #fff3d6;
  border-color: #f0cb80;
  color: #7b5a00;
}

.reason-llm-edge-filter {
  background: #ffefcc;
  border-color: #efc97a;
  color: #744f00;
}

.reason-llm-direction-conflict {
  background: #f8deda;
  border-color: #dfaaa1;
  color: #812b20;
}

.reason-llm-template-unavailable {
  background: #dce9f9;
  border-color: #adc5e6;
  color: #2b4b74;
}

.reason-llm-failed {
  background: #f6d6d2;
  border-color: #d9a09a;
  color: #7d2219;
}

.reason-edge {
  background: #efe9d7;
  border-color: #d9cba5;
  color: #625126;
}

.reason-risk {
  background: #fbe9d7;
  border-color: #e6bf95;
  color: #7a4a18;
}

.reason-entry {
  background: #e9f1fb;
  border-color: #c1d4ee;
  color: #2f4e70;
}

.reason-position-open {
  background: #e5ecef;
  border-color: #c3d1d8;
  color: #41545f;
}

.reason-cap {
  background: #f5e1db;
  border-color: #debbb0;
  color: #6b3f33;
}

.reason-stop {
  background: #f7dcd5;
  border-color: #d9a89a;
  color: #7b2b20;
}

.reason-target {
  background: #dff2e7;
  border-color: #b5ddc7;
  color: #1f5b3f;
}

.reason-resolved {
  background: #d9ece3;
  border-color: #b2d6c6;
  color: #245141;
}

.reason-neutral {
  background: #e9edf0;
  border-color: #ccd6dd;
  color: #4a5865;
}

@media (max-width: 920px) {
  .config-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .cfg-item {
    grid-template-columns: 1fr;
  }

  .cfg-item input[type="checkbox"] {
    justify-self: start;
  }
}
