/* Светлая «финтех-промо» тема: перламутровые переливы, хром, красный акцент.
   Палитра данных валидирована для светлой поверхности:
   линия графика #2a78d6, прибыль #006300, убыток #c22f2f */
:root {
  --page: #eef0f5;
  --surface: #ffffff;
  --surface-2: #f4f5f9;
  --ink: #16181f;
  --ink-2: #4c5160;
  --muted: #8a8f9e;
  --grid: #e7e9ef;
  --border: rgba(22, 26, 45, 0.08);
  --series-1: #2a78d6;
  --good: #006300;
  --bad: #c22f2f;
  --accent: #f02d10;
  --accent-grad: linear-gradient(180deg, #ff6a4d 0%, #ea2408 100%);
  --holo: linear-gradient(120deg, #ffd2e6 0%, #d8ecff 30%, #d6f4e4 55%, #e2d9ff 80%, #ffe9d2 100%);
  --chrome: linear-gradient(180deg, #ffffff 0%, #e8eaf0 45%, #d5d8e2 55%, #f2f3f7 100%);
  --shadow: 0 12px 32px rgba(25, 32, 60, 0.08), 0 2px 6px rgba(25, 32, 60, 0.05);
}

* { box-sizing: border-box; margin: 0; }
body {
  background:
    radial-gradient(900px 500px at 8% -5%, rgba(255, 189, 222, 0.30), transparent 60%),
    radial-gradient(900px 520px at 95% 0%, rgba(173, 216, 255, 0.32), transparent 60%),
    radial-gradient(1000px 600px at 50% 110%, rgba(214, 197, 255, 0.28), transparent 60%),
    var(--page);
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px); z-index: 10;
}
.logo { font-size: 20px; font-weight: 800; letter-spacing: .2px; }
.logo span {
  background: linear-gradient(100deg, #ff5a3c 0%, #e0246f 45%, #7d5cff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.tabs { display: flex; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px; }
.tab {
  border: 0; background: none; font: inherit; font-size: 13px; font-weight: 700;
  color: var(--muted); padding: 6px 16px; border-radius: 999px; cursor: pointer;
}
.tab.active {
  background: #fff; color: var(--ink);
  box-shadow: 0 3px 10px rgba(25, 32, 60, 0.10), inset 0 1px 0 rgba(255, 255, 255, .9);
}

.steps { display: flex; gap: 6px; }
@media (max-width: 1150px) { .steps { display: none; } }
.step {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 14px; border-radius: 999px; color: var(--muted); font-size: 13px;
  border: 1px solid transparent;
}
.step i {
  font-style: normal; width: 20px; height: 20px; border-radius: 50%;
  background: var(--chrome); border: 1px solid rgba(22, 26, 45, 0.10);
  color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px;
}
.step.active {
  color: var(--ink); border-color: var(--border); background: #fff;
  box-shadow: 0 4px 14px rgba(25, 32, 60, 0.08);
}
.step.active i { background: var(--accent-grad); border: 0; color: #fff; }
.step.done { color: var(--ink-2); }
.step.done i { background: #e8f5e6; border-color: rgba(0, 99, 0, .25); color: var(--good); }

.layout {
  display: grid; grid-template-columns: minmax(340px, 430px) 1fr;
  gap: 18px; padding: 18px 24px; flex: 1; align-items: start;
  max-width: 1500px; width: 100%; margin: 0 auto;
}
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%);
  border: 1px solid var(--border);
  border-radius: 20px; padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin-bottom: 12px; font-weight: 700; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.hint { color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }

/* ---------- чат ---------- */
.chat-col { display: flex; flex-direction: column; position: sticky; top: 76px; height: calc(100vh - 140px); min-height: 420px; }
.chat-head { display: flex; gap: 10px; align-items: center; padding-bottom: 12px; border-bottom: 1px solid var(--grid); }
.avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--holo);
  border: 1px solid rgba(22, 26, 45, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; color: #2b2545;
}
.chat-title { font-weight: 700; font-size: 14px; }
.chat-sub { font-size: 12px; color: var(--muted); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px 2px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; }
.msg.agent { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 5px; align-self: flex-start; }
.msg.user { background: #1d2130; color: #fff; border-bottom-right-radius: 5px; align-self: flex-end; }
.msg.system { background: none; border: 1px dashed #d4d7e1; color: var(--muted); font-size: 12px; align-self: center; text-align: center; }
.msg.typing { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.tdots { display: inline-flex; gap: 4px; align-items: center; flex-shrink: 0; }
.tdots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); opacity: .3;
  animation: tblink 1.2s ease-in-out infinite;
}
.tdots i:nth-child(2) { animation-delay: .2s; }
.tdots i:nth-child(3) { animation-delay: .4s; }
@keyframes tblink {
  0%, 70%, 100% { opacity: .25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-4px); }
}
.chat-input { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--grid); }
.chat-input input {
  flex: 1; background: #fff; border: 1px solid #d9dce5; color: var(--ink);
  border-radius: 12px; padding: 10px 13px; font-size: 14px; outline: none;
}
.chat-input input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240, 45, 16, 0.10); }
.chat-input button {
  background: var(--accent-grad); border: 0; color: #fff; border-radius: 12px; width: 44px;
  font-size: 15px; cursor: pointer;
  box-shadow: 0 6px 14px rgba(234, 36, 8, 0.30), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.chat-input button:disabled, .chat-input input:disabled { opacity: .45; cursor: default; box-shadow: none; }

/* ---------- панели ---------- */
.panels { display: flex; flex-direction: column; gap: 18px; }

.source-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 1150px) { .source-buttons { grid-template-columns: 1fr; } }
.btn {
  background: #fff; color: var(--ink); border: 1px solid #d9dce5;
  border-radius: 14px; padding: 14px; font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; text-align: left; font-family: inherit;
  box-shadow: 0 2px 8px rgba(25, 32, 60, 0.05), inset 0 1px 0 rgba(255, 255, 255, .9);
  transition: border-color .15s, box-shadow .15s;
}
.btn small { color: var(--muted); font-weight: 400; font-size: 12px; }
.btn:hover { border-color: #b9bdcc; box-shadow: 0 6px 16px rgba(25, 32, 60, 0.10); }
.btn.primary {
  background: var(--accent-grad); color: #fff; border: 0;
  box-shadow: 0 8px 18px rgba(234, 36, 8, 0.30), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.btn.primary small { color: rgba(255, 255, 255, .85); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.wide { align-items: center; text-align: center; }
.btn:disabled { opacity: .5; cursor: default; }

/* данные клиента */
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 14px; min-width: 118px; flex: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}
.tile b { display: block; font-size: 19px; font-weight: 800; margin-top: 2px; }
.tile span { font-size: 11.5px; color: var(--muted); }
.tile .pos { color: var(--good); }
.tile .neg { color: var(--bad); }

.hbar { margin: 6px 0; }
.hbar .lbl { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); margin-bottom: 3px; }
.hbar .track { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 3px; }

/* форма портфеля */
.pf-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.pf-row input {
  background: #fff; border: 1px solid #d9dce5; color: var(--ink);
  border-radius: 12px; padding: 9px 12px; font-size: 14px; outline: none; font-family: inherit;
}
.pf-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(240, 45, 16, 0.10); }
.pf-row .pf-asset { width: 110px; text-transform: uppercase; }
.pf-row .pf-qty { flex: 1; font-variant-numeric: tabular-nums; }
.pf-row .pf-del {
  background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 8px;
}
.pf-row .pf-del:hover { color: var(--bad); }
.pf-row.locked .pf-asset { opacity: .7; pointer-events: none; }

.flags { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.flag {
  font-size: 12.5px; color: var(--ink-2); background: var(--surface-2);
  border-left: 3px solid #e0246f; border-radius: 8px; padding: 6px 10px;
}

/* рынок */
.market-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.mcard {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}
.mcard .sym { font-weight: 800; font-size: 13px; }
.mcard .price { font-size: 17px; font-weight: 800; margin: 2px 0; }
.mcard .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* стратегии */
.strategy-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%);
  border-radius: 20px; padding: 18px; box-shadow: var(--shadow);
}
.strategy-card.selected {
  border: 2px solid transparent;
  background:
    linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%) padding-box,
    linear-gradient(120deg, #ff9ec6, #8ec9ff, #8fe6bb, #b9a9ff) border-box;
}
.sc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.sc-head h3 { font-size: 16px; font-weight: 800; }
.badge {
  font-size: 11.5px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap;
  background: #fff; font-weight: 700;
}
.badge.низкий { color: var(--good); border-color: rgba(0, 99, 0, .35); background: #f0f8ef; }
.badge.средний { color: #9a6b00; border-color: rgba(154, 107, 0, .35); background: #fdf6e7; }
.badge.высокий { color: var(--bad); border-color: rgba(194, 47, 47, .35); background: #fcf0f0; }
.sc-text { font-size: 13.5px; color: var(--ink-2); margin-bottom: 10px; }
.sc-text b { color: var(--ink); }
.rules { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin: 10px 0; font-size: 13px; }
.rules h4 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.rules ul { margin: 0 0 10px 18px; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  background: #fff; border: 1px solid #d9dce5; border-radius: 9px;
  padding: 4px 10px; font-size: 12.5px; color: var(--ink-2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9);
}
.chip b { color: var(--ink); }
.sc-actions { display: flex; gap: 10px; margin-top: 12px; }
details.dlog { margin-top: 12px; }
details.dlog summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.dlog ul { margin: 8px 0 0 18px; font-size: 12.5px; color: var(--ink-2); }

/* бэктест */
.chart-wrap { position: relative; margin: 14px 0 4px; }
.chart-wrap svg { display: block; width: 100%; }
.chart-tip {
  position: absolute; pointer-events: none; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px;
  font-size: 12px; color: var(--ink-2); white-space: nowrap; display: none; z-index: 5;
  box-shadow: 0 6px 18px rgba(25, 32, 60, 0.12);
}
.chart-tip b { color: var(--ink); }
.chart-title { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

table.trades { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 8px; }
table.trades th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
table.trades td { padding: 6px 8px; border-bottom: 1px solid var(--grid); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; max-height: 300px; overflow-y: auto; }

.explain {
  background: var(--surface-2); border-left: 3px solid #7d5cff; border-radius: 10px;
  padding: 12px 14px; font-size: 13.5px; color: var(--ink-2); margin-top: 14px; white-space: pre-wrap;
}

/* дашборд */
.dash {
  display: flex; flex-direction: column; gap: 18px;
  padding: 18px 24px; max-width: 1500px; width: 100%; margin: 0 auto; flex: 1;
}
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1000px) { .summary-grid { grid-template-columns: 1fr; } }
.gauge-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 4px; }
.gauge-wrap .big { font-size: 30px; font-weight: 800; }
.gauge-wrap .sub { font-size: 12.5px; color: var(--muted); }
.str-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 4px;
  border-bottom: 1px solid var(--grid); font-size: 14px;
}
.str-row:last-child { border-bottom: 0; }
.str-row .nm { font-weight: 700; }
.str-row .kind { color: var(--muted); font-size: 12px; margin-left: auto; }
.status-badge {
  font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
}
.status-badge.on { background: #e7f6ea; color: #0b7a2d; }
.status-badge.draft { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); }
.status-badge.err { background: #fcecec; color: var(--bad); }

/* агент-кодер */
.codebox {
  background: #191c26; border-radius: 14px; padding: 4px;
  max-height: 420px; overflow: auto; margin-bottom: 10px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .35);
}
.codebox pre {
  margin: 0; padding: 12px 14px; color: #dfe3f0;
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre; tab-size: 4;
}
.journal {
  background: #191c26; border-radius: 14px; padding: 12px 14px;
  max-height: 340px; overflow-y: auto;
  font: 12px/1.6 ui-monospace, "SF Mono", Menlo, monospace;
}
.jl { display: flex; gap: 10px; }
.jl .t { color: #5c6377; flex-shrink: 0; }
.jl.INFO .m { color: #c7cddd; }
.jl.TRADE .m { color: #6fd18b; font-weight: 600; }
.jl.WARN .m { color: #e8b34c; }
.jl.ERROR .m { color: #ef7a6d; }
.jl.SYS .m { color: #8f96ab; font-style: italic; }
.spec-rules { margin: 6px 0 10px 18px; font-size: 13px; color: var(--ink-2); }
.spec-rules li { margin-bottom: 3px; }
.assume { border-left: 3px solid #c98500; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 14px; border-top: 1px solid var(--border); }

.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--grid);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
  vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
