:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #16181d;
  --ink-2: #5b6270;
  --line: #e4e7ec;
  --accent: #1f4fd8;
  --accent-ink: #ffffff;
  --green: #0e8f5a;
  --red: #d23b3b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
  --mono: "Cascadia Code", Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 26px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #1f4fd8, #6d8bff);
  color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .02em;
}
.brand h1 { font-size: 19px; }
.brand p { margin: 1px 0 0; font-size: 12.5px; color: var(--ink-2); }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.pill {
  font-size: 12.5px; color: var(--ink-2); background: var(--bg);
  border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px;
}

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 400px 1fr;
  gap: 20px; padding: 20px 26px; max-width: 1660px; margin: 0 auto;
  align-items: start;
}
@media (max-width: 1080px) { .layout { grid-template-columns: 1fr; } }
.panel.config { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 86px; }

/* ---------- cards & forms ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2); margin-bottom: 12px; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); flex: 1; min-width: 90px; }
input, select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfbfc; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9c8f5; border-color: var(--accent); }
.chk { flex-direction: row; align-items: center; gap: 7px; font-size: 13px; color: var(--ink); min-width: 0; }
.chk input { width: auto; }
.weekdays { align-items: center; gap: 8px; }
.wd-label { font-size: 12.5px; color: var(--ink-2); }

/* ---------- legs ---------- */
.leg {
  display: grid; grid-template-columns: 74px 64px 1fr 74px 60px 66px 66px 30px;
  gap: 6px; align-items: end; padding: 9px 10px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: #fafbfe;
}
.leg label { font-size: 10.5px; min-width: 0; }
.leg .del { border: none; background: none; color: var(--red); font-size: 16px; cursor: pointer; padding: 6px 2px; }
.leg.sell { border-left: 4px solid var(--red); }
.leg.buy  { border-left: 4px solid var(--green); }

/* ---------- buttons ---------- */
button { font: inherit; cursor: pointer; border-radius: 10px; }
.primary {
  background: var(--accent); color: var(--accent-ink); border: none;
  padding: 11px 22px; font-weight: 650; box-shadow: var(--shadow);
  transition: transform .08s ease, filter .15s ease;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .55; cursor: wait; }
.ghost {
  background: var(--surface); border: 1px solid var(--line);
  padding: 9px 14px; color: var(--ink);
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost.small { padding: 6px 11px; font-size: 12.5px; }
.run-row { display: flex; gap: 10px; align-items: center; }
.run-row select { flex: 1; }
.status { min-height: 18px; font-size: 12.5px; color: var(--ink-2); margin: 4px 2px; }
.status.err { color: var(--red); }

/* ---------- stats ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; box-shadow: var(--shadow);
}
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.stat .v { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 3px; }
.stat .v.pos { color: var(--green); }
.stat .v.neg { color: var(--red); }

/* ---------- charts ---------- */
.charts { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
.chart-card { flex: 1 1 100%; }
.chart-card.half { flex: 1 1 calc(50% - 7px); min-width: 320px; }
.chart-card canvas { max-height: 260px; }

/* ---------- table ---------- */
.table-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.table-wrap { max-height: 480px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child, th:nth-child(4), td:nth-child(4), th:nth-child(7), td:nth-child(7) { text-align: left; }
thead th {
  position: sticky; top: 0; background: #f8f9fb; color: var(--ink-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--line);
}
tbody tr { border-bottom: 1px solid #f0f1f4; }
tbody tr:hover { background: #f7f9ff; }
td.pos { color: var(--green); font-weight: 600; }
td.neg { color: var(--red); font-weight: 600; }
td.mono { font-family: var(--mono); font-size: 12px; }
tr.skip td { color: var(--ink-2); font-style: italic; }

/* ---------- empty state ---------- */
.empty-state {
  display: grid; place-items: center; min-height: 420px; text-align: center;
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-2);
}
.empty-state h2 { color: var(--ink); margin-bottom: 8px; }

/* ---------- modal ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px; width: min(480px, 92vw);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog h2 { font-size: 17px; margin-bottom: 8px; }
dialog label { margin: 10px 0; }
.muted { color: var(--ink-2); font-size: 12.5px; white-space: pre-wrap; }
