/* ─────────────────────────────────────────────────────────────────────────
   Bond Portfolio Tester — terminal/Bloomberg-style dark UI
   Dense rows, monospace digits, single accent (#22c55e), high-info layout.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* surfaces */
  --bg: #07090d;
  --bg-1: #0b0e14;
  --bg-2: #0f131a;
  --bg-3: #141923;
  --bg-hover: #161c27;
  --bg-active: #1a2230;

  /* lines */
  --line: #1a2030;
  --line-2: #242c3d;
  --line-strong: #2e3851;

  /* ink */
  --ink: #d8dde6;
  --ink-mute: #8a93a6;
  --ink-dim: #5b6478;
  --ink-faint: #3d4658;

  /* semantic */
  --pos: #22c55e;
  --pos-dim: #16a34a;
  --pos-bg: rgba(34, 197, 94, 0.08);
  --neg: #ef4444;
  --neg-bg: rgba(239, 68, 68, 0.08);
  --warn: #f0b429;
  --warn-bg: rgba(240, 180, 41, 0.08);
  --info: #5b8def;

  /* fonts */
  --f-ui: "IBM Plex Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* sizes — toggled by [data-density] */
  --row-h: 28px;
  --row-pad-x: 10px;
  --fs-ui: 12px;
  --fs-num: 12px;
  --fs-h: 11px;     /* column headers */
  --fs-micro: 10.5px;
}

[data-density="comfy"] {
  --row-h: 34px;
  --fs-ui: 13px;
  --fs-num: 13px;
  --fs-h: 11.5px;
}

[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-1: #ffffff;
  --bg-2: #f0f2f5;
  --bg-3: #e6e9ee;
  --bg-hover: #eef1f5;
  --bg-active: #e2e6ec;
  --line: #e2e5ec;
  --line-2: #cdd2dc;
  --line-strong: #b8bfcb;
  --ink: #1a1f2c;
  --ink-mute: #555d6e;
  --ink-dim: #818a9c;
  --ink-faint: #b0b7c3;
  --pos: #0f9b46;
  --pos-dim: #0a7f37;
  --pos-bg: rgba(15, 155, 70, 0.10);
  --neg: #d93636;
  --neg-bg: rgba(217, 54, 54, 0.08);
  --warn: #b87900;
  --warn-bg: rgba(184, 121, 0, 0.10);
  --info: #2a6fdb;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-ui);
  font-size: var(--fs-ui);
  font-feature-settings: "ss01", "cv02", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.num  { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-num); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.mute { color: var(--ink-mute); }
.dim  { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }

/* ── App shell ──────────────────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  gap: 16px;
  flex-shrink: 0;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 12px;
}
.topbar .brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}
.topbar .crumb {
  color: var(--ink-mute);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.topbar .spacer { flex: 1; }
.topbar .meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
}
.topbar .meta b { color: var(--ink); font-weight: 500; }
.topbar a, .topbar .navlink {
  color: var(--ink-mute);
  text-decoration: none;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 4px;
}
.topbar a:hover, .topbar .navlink:hover { color: var(--ink); background: var(--bg-hover); }
.topbar .navlink[data-active="1"] { color: var(--ink); background: var(--bg-3); }

/* ── Toolbar — balance/credit/reserve/run ──────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.toolbar .group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-right: 1px solid var(--line);
  height: 32px;
}
.toolbar .group:first-child { padding-left: 0; }
.toolbar .group:last-child { border-right: 0; }
.toolbar .label {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.toolbar input[type="text"],
.toolbar input[type="number"] {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--ink);
  height: 24px;
  padding: 0 8px;
  width: 130px;
  border-radius: 3px;
  font-family: var(--f-mono);
  font-size: 12px;
  outline: none;
  text-align: right;
}
.toolbar input:focus { border-color: var(--pos-dim); background: var(--bg-3); }
.toolbar .suffix {
  font-family: var(--f-mono);
  color: var(--ink-dim);
  font-size: 11px;
  margin-left: -4px;
}
.toolbar .spacer { flex: 1; }

/* Reserve toggle */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle .track {
  width: 30px; height: 16px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  position: relative;
  transition: background 0.15s;
}
.toggle .track::before {
  content: "";
  position: absolute;
  top: 1px; left: 1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ink-mute);
  transition: transform 0.15s, background 0.15s;
}
.toggle[data-on="1"] .track { background: rgba(34, 197, 94, 0.2); border-color: var(--pos-dim); }
.toggle[data-on="1"] .track::before { transform: translateX(14px); background: var(--pos); }

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--ink);
  height: 26px;
  padding: 0 12px;
  font-family: var(--f-ui);
  font-size: 12px;
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.btn:active { background: var(--bg-active); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: var(--pos);
  border-color: var(--pos);
  color: #062611;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.btn.primary:hover { background: #2dd76a; border-color: #2dd76a; }
.btn.primary[disabled] { background: var(--pos-dim); border-color: var(--pos-dim); opacity: 0.7; }

.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-hover); }

.btn.danger:hover { background: var(--neg-bg); border-color: var(--neg); color: var(--neg); }

.btn.sm { height: 22px; padding: 0 8px; font-size: 11px; }
.btn.icon { width: 26px; padding: 0; justify-content: center; }
.btn.icon.sm { width: 22px; }

.kbd {
  font-family: var(--f-mono);
  font-size: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--ink-mute);
}

/* ── Bonds table ───────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  gap: 10px;
}
.section-head h2 {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
}
.section-head .ct {
  font-family: var(--f-mono);
  color: var(--ink-dim);
  font-size: 11px;
}

.tbl-wrap {
  margin: 0 14px 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.tbl-scroll { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-ui);
  table-layout: fixed;
}
.tbl thead th {
  background: var(--bg-2);
  color: var(--ink-mute);
  font-weight: 500;
  font-size: var(--fs-h);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  padding: 6px var(--row-pad-x);
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
}
.tbl thead th.sortable { cursor: pointer; }
.tbl thead th.sortable:hover { color: var(--ink); }
.tbl thead th.num, .tbl tbody td.num { text-align: right; }
.tbl thead th .arr { color: var(--pos); margin-left: 4px; }

.tbl tbody tr { border-bottom: 1px solid var(--line); height: var(--row-h); }
.tbl tbody tr:last-child { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--bg-hover); }
.tbl tbody tr.selected { background: rgba(34, 197, 94, 0.06); }
.tbl tbody tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--pos); }

.tbl tbody td {
  padding: 0 var(--row-pad-x);
  vertical-align: middle;
  white-space: nowrap;
  color: var(--ink);
}
.tbl tbody td.mono, .tbl tbody td.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.tbl tbody td.result-income,
.tbl tbody td.result-trades {
  line-height: 1.15;
}
.result-income span,
.result-trades span {
  display: block;
}
.result-income small,
.result-trades small {
  display: block;
  margin-top: 2px;
  color: var(--ink-dim);
  font-size: 10px;
  white-space: nowrap;
}

.tbl tbody td.sym {
  font-family: var(--f-mono);
  font-weight: 500;
  color: var(--ink);
  position: relative;
}
.tbl tbody td.sym .name {
  font-family: var(--f-ui);
  font-weight: 400;
  font-size: 10.5px;
  color: var(--ink-dim);
  margin-left: 6px;
}

/* Compact inline numeric editor inside rows */
.cell-input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  height: calc(var(--row-h) - 8px);
  padding: 0 6px;
  font-family: var(--f-mono);
  font-size: var(--fs-num);
  font-variant-numeric: tabular-nums;
  border-radius: 2px;
  outline: none;
  text-align: right;
  min-width: 0;
}
.cell-input:hover { background: var(--bg-hover); }
.cell-input:focus { background: var(--bg-3); border-color: var(--pos-dim); }
.cell-input.dirty { color: var(--warn); }
/* hide native number spinners — they crowd dense rows */
.cell-input[type="number"] { -moz-appearance: textfield; }
.cell-input[type="number"]::-webkit-inner-spin-button,
.cell-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.toolbar input[type="number"] { -moz-appearance: textfield; }
.toolbar input[type="number"]::-webkit-inner-spin-button,
.toolbar input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.filter input[type="number"] { -moz-appearance: textfield; }
.filter input[type="number"]::-webkit-inner-spin-button,
.filter input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

select.cell-input {
  text-align: left;
  padding-right: 4px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'><path fill='%238a93a6' d='M0 0h8L4 5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 14px;
}

/* Row actions cell */
.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  align-items: center;
}

/* Add-bond inline row */
.add-row td {
  background: var(--bg-2);
  border-top: 1px solid var(--line-2);
  padding: 8px var(--row-pad-x);
}
.add-row .add-form {
  display: flex;
  align-items: center;
  gap: 8px;
}
.add-row input.tkr {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  color: var(--ink);
  height: 26px;
  padding: 0 10px;
  width: 220px;
  border-radius: 3px;
  font-family: var(--f-mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  outline: none;
}
.add-row input.tkr:focus { border-color: var(--pos-dim); }
.add-row input.tkr.err { border-color: var(--neg); background: var(--neg-bg); }
.add-row .err-msg { font-size: 11px; color: var(--neg); margin-left: 4px; }
.add-row .warn-msg { font-size: 11px; color: var(--warn); margin-left: 4px; }
.tiny-loader {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(6, 38, 17, 0.25);
  border-top-color: #062611;
  display: inline-block;
  animation: spin 0.75s linear infinite;
}
.moex-load {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  min-width: 260px;
  color: var(--warn);
  font-size: 11px;
  margin-left: 4px;
}
.moex-load-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.moex-load-text:before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 8px rgba(240, 180, 41, 0.75);
  animation: pulse 0.9s ease-in-out infinite;
}
.moex-bar {
  position: relative;
  display: block;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
}
.moex-bar > i {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 38%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--warn), transparent);
  animation: scan 1.15s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: .45; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }
@keyframes scan { 0% { left: -42%; } 100% { left: 104%; } }

/* Status badge */
.badge {
  display: inline-block;
  font-family: var(--f-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 2px;
  border: 1px solid var(--line-2);
  background: var(--bg-3);
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}
.badge.pos { background: var(--pos-bg); border-color: var(--pos-dim); color: var(--pos); }
.badge.neg { background: var(--neg-bg); border-color: var(--neg); color: var(--neg); }
.badge.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.badge.info { background: rgba(91, 141, 239, 0.1); border-color: var(--info); color: var(--info); }

/* ── Optimizer accordion ───────────────────────────────────────────────── */

.opt-row td {
  padding: 0;
  background: var(--bg);
  border-top: 1px solid var(--pos-dim);
  border-bottom: 1px solid var(--pos-dim);
}
.opt-panel {
  padding: 10px 14px 14px;
  background: linear-gradient(180deg, rgba(34,197,94,0.04), transparent 40%);
}
.opt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  gap: 12px;
}
.opt-head .title {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
}
.opt-head .title b { color: var(--pos); font-family: var(--f-mono); margin-left: 6px; }

.filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding-bottom: 8px;
}
.filter {
  display: inline-flex;
  align-items: center;
  height: 24px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 3px;
  font-size: 11px;
  overflow: hidden;
}
.filter .lbl {
  color: var(--ink-mute);
  padding: 0 6px 0 8px;
  border-right: 1px solid var(--line);
  letter-spacing: 0.04em;
  font-size: 10.5px;
}
.filter input, .filter select {
  background: transparent;
  border: 0;
  color: var(--ink);
  height: 22px;
  padding: 0 6px;
  font-family: var(--f-mono);
  font-size: 11px;
  width: 70px;
  outline: none;
}
.filter select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'><path fill='%238a93a6' d='M0 0h8L4 5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 16px;
  width: auto;
  min-width: 60px;
  appearance: none;
}
.filter .sep { color: var(--ink-faint); padding: 0 2px; }

.opt-loading {
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(34, 197, 94, 0.06), rgba(8, 12, 18, 0.35)),
    var(--bg-1);
  padding: 14px 16px;
  min-height: 126px;
}
.opt-loading-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink);
}
.opt-loading-top b {
  font-weight: 500;
  flex: 1;
}
.opt-loading-top span:last-child {
  color: var(--pos);
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 10px rgba(240, 180, 41, 0.75);
  animation: pulse 0.9s ease-in-out infinite;
}
.opt-loading-bar {
  position: relative;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  margin: 12px 0 10px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
}
.opt-loading-bar > i {
  display: block;
  height: 100%;
  min-width: 24px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pos-dim), var(--pos), #b6f7c8);
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.28);
  transition: width .25s linear;
}
.opt-loading-log {
  display: grid;
  gap: 4px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
}
.opt-loading-log .line {
  display: flex;
  gap: 8px;
  line-height: 1.25;
}
.opt-loading-log .line span {
  color: var(--ink-faint);
  width: 18px;
}
.opt-loading-log .line em {
  font-style: normal;
  color: var(--ink-mute);
}

/* Pagination */
.pager {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
}
.pager .pg {
  width: 22px; height: 22px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--ink);
  border-radius: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pager .pg:hover { background: var(--bg-hover); }
.pager .pg[disabled] { opacity: 0.3; cursor: not-allowed; }
.pager .info { padding: 0 8px; }

/* Optimizer table — compact, scrollable */
.opt-table-wrap {
  border: 1px solid var(--line-2);
  border-radius: 3px;
  overflow: auto;
  max-height: 360px;
}
.opt-table-wrap table.tbl thead th { background: var(--bg-3); }
.opt-table-wrap table.tbl tbody tr { height: 26px; }
.opt-table-wrap table.tbl tbody td { padding: 0 8px; }

/* ── Results panel ─────────────────────────────────────────────────────── */

.results {
  margin: 0 14px 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.results .res-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.results .res-head .ttl {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
}
.results .res-head .ttl b { color: var(--ink); margin-right: 8px; }
.results .res-head .ts { font-family: var(--f-mono); font-size: 11px; color: var(--ink-dim); }

.res-hero {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
}
.res-hero .cell {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}
.res-hero .cell:last-child { border-right: 0; }
.res-hero .k {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 4px;
}
.res-hero .v {
  font-family: var(--f-mono);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.res-hero .sub {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
  margin-top: 2px;
}

.res-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.res-col {
  border-right: 1px solid var(--line);
  padding: 6px 0;
}
.res-col:last-child { border-right: 0; }
.res-col .col-ttl {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: 6px 14px 4px;
  border-bottom: 1px dashed var(--line);
}
.res-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 4px 14px;
  font-size: 12px;
  min-height: 24px;
}
.res-line .k { color: var(--ink-mute); }
.res-line .v {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-size: var(--fs-num);
}
.res-line.major { background: var(--bg-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.res-line.major .k { color: var(--ink); font-weight: 500; }
.res-line.major .v { font-size: 13px; font-weight: 600; }

.res-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}

/* ── Status bar / progress ─────────────────────────────────────────────── */

.statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 24px;
  padding: 0 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-dim);
  flex-shrink: 0;
}
.statusbar .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-dim);
}
.statusbar.running .dot { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.statusbar.done .dot { background: var(--pos); }
.statusbar.error .dot { background: var(--neg); }
.statusbar .spacer { flex: 1; }

@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.3 } }

/* Run overlay */
.run-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 13, 0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.run-overlay .panel {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 24px 28px;
  min-width: 420px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}
.run-overlay h3 {
  margin: 0 0 14px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  font-weight: 600;
}
.run-overlay .pbar {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
.run-overlay .pbar > i {
  display: block;
  height: 100%;
  background: var(--pos);
  transition: width 0.2s linear;
}
.run-overlay .log {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink-mute);
  height: 120px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.run-overlay .log .line {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}
.run-overlay .log .ts { color: var(--ink-faint); }
.run-overlay .log .ok { color: var(--pos); }
.run-overlay .log .info { color: var(--ink); }
.run-overlay .log .err { color: var(--neg); }

/* ── Report pages ──────────────────────────────────────────────────────── */

.report-shell {
  padding: 0 14px 24px;
}
.report-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 14px 10px;
  gap: 14px;
}
.report-head h1 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.01em;
}
.report-head .desc {
  color: var(--ink-mute);
  font-size: 12px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 0 14px 14px;
}
.kpi {
  background: var(--bg-1);
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 4px;
}
.kpi .k {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.kpi .v {
  font-family: var(--f-mono);
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  margin-top: 2px;
}

/* trades sub-tabs */
.subtabs {
  display: flex;
  gap: 2px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.subtab {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--ink-mute);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--f-ui);
  background: transparent;
  border-left: 0; border-right: 0; border-top: 0;
}
.subtab:hover { color: var(--ink); }
.subtab[data-active="1"] {
  color: var(--ink);
  border-bottom-color: var(--pos);
}
.subtab .ct {
  font-family: var(--f-mono);
  color: var(--ink-dim);
  font-size: 11px;
  margin-left: 6px;
}

/* misc */
.icon-svg {
  width: 14px; height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-svg.sm { width: 12px; height: 12px; }

.hidden { display: none !important; }


/* ─────────────────────────────────────────────────────────────────────────
   MOBILE (≤ 720px) — card layouts, stacked toolbar, full-screen sheets.
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root {
    --row-h: 32px;
    --row-pad-x: 12px;
    --fs-ui: 14px;
    --fs-num: 14px;
  }

  /* topbar */
  .topbar { height: auto; padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar .meta { display: none; }
  .topbar .crumb { display: none; }
  .topbar .brand { font-size: 13px; flex: 0 1 auto; white-space: nowrap; }
  .topbar .navlink { padding: 4px 8px; font-size: 12px; }

  /* toolbar — stack into cards */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 12px;
  }
  .toolbar .group {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 4px 0 10px;
    height: auto;
    justify-content: space-between;
    gap: 10px;
  }
  .toolbar .group:last-child { border-bottom: 0; padding-bottom: 0; }
  .toolbar .group:first-child { padding-left: 0; padding-top: 0; }
  .toolbar input[type="text"], .toolbar input[type="number"] {
    width: auto;
    flex: 1;
    height: 36px;
    font-size: 15px;
  }
  .toolbar .label { font-size: 11px; flex-shrink: 0; }
  .toolbar .spacer { display: none; }
  .toolbar .btn.primary {
    width: 100%;
    height: 44px;
    font-size: 14px;
    justify-content: center;
  }
  .toolbar .group:has(.btn.primary) { flex-direction: column; }
  .toolbar .group:has(.btn.primary) > span { align-self: flex-end; }

  /* section heads */
  .section-head { padding: 12px 12px 6px; }
  .section-head h2 { font-size: 10.5px; }

  /* bonds table → cards */
  .tbl-wrap { margin: 0 12px 12px; }
  .tbl-scroll { overflow-x: visible; }

  .bond-cards { display: flex; flex-direction: column; gap: 8px; padding: 10px; }
  .bond-card {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
  }
  .bond-card.selected {
    border-color: var(--pos-dim);
    box-shadow: 0 0 0 1px var(--pos-dim);
  }
  .bond-card .sym-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--line);
    margin-bottom: 10px;
  }
  .bond-card .sym-line .sym {
    font-family: var(--f-mono);
    font-size: 14px;
    font-weight: 500;
  }
  .bond-card .sym-line .name {
    color: var(--ink-dim);
    font-size: 12px;
    margin-left: 6px;
  }
  .bond-card .params {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 12px;
  }
  .bond-card .param {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 32px;
  }
  .bond-card .param .lbl {
    color: var(--ink-dim);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  .bond-card .param .cell-input {
    width: 80px;
    height: 30px;
    font-size: 13px;
    background: var(--bg-1);
    border: 1px solid var(--line-2);
  }
  .bond-card .param select.cell-input { width: 80px; }
  .bond-card .actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
  }
  .bond-card .actions .btn { flex: 1; height: 34px; font-size: 13px; justify-content: center; }
  .bond-card .actions .btn.icon { flex: 0 0 40px; }
  .bond-card .res-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 0 0;
    margin-top: 6px;
    border-top: 1px dashed var(--line);
    font-size: 12px;
  }
  .bond-card .res-strip > span { min-width: 0; }
  .bond-card .res-strip .k { color: var(--ink-dim); font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; }
  .bond-card .res-strip .v { font-family: var(--f-mono); font-weight: 600; }

  /* add-bond row on mobile */
  .add-bond-mobile {
    margin: 0 12px 14px;
    padding: 14px;
    border: 1px dashed var(--line-2);
    border-radius: 6px;
    background: var(--bg-1);
  }
  .add-bond-mobile .row {
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .add-bond-mobile input {
    flex: 1;
    height: 38px;
    background: var(--bg-2);
    border: 1px solid var(--line-2);
    color: var(--ink);
    padding: 0 10px;
    border-radius: 4px;
    font-family: var(--f-mono);
    font-size: 14px;
    outline: none;
  }
  .add-bond-mobile input:focus { border-color: var(--pos-dim); }
  .add-bond-mobile input.err { border-color: var(--neg); }
  .add-bond-mobile .btn { height: 38px; }
  .add-bond-mobile .err-msg, .add-bond-mobile .warn-msg { margin-top: 6px; font-size: 12px; display: block; }
  .add-bond-mobile .err-msg { color: var(--neg); }
  .add-bond-mobile .warn-msg { color: var(--warn); }
  .add-bond-mobile .moex-load {
    display: flex;
    min-width: 0;
    width: 100%;
    margin: 8px 0 0;
    font-size: 12px;
  }
  .mobile-load-card {
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    background:
      linear-gradient(180deg, rgba(34, 197, 94, 0.06), rgba(8, 12, 18, 0.35)),
      var(--bg-2);
  }
  .mobile-load-head {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    font-family: var(--f-mono);
    font-size: 12px;
  }
  .mobile-load-head b {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-load-head span:last-child { color: var(--pos); }
  .mobile-load-bar {
    position: relative;
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    margin-top: 10px;
    background: var(--bg-3);
    border: 1px solid var(--line-2);
  }
  .mobile-load-bar > i {
    position: absolute;
    top: -1px;
    bottom: -1px;
    width: 40%;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, var(--pos), transparent);
    animation: scan 1.05s ease-in-out infinite;
  }
  .mobile-load-bar.fixed > i {
    position: static;
    display: block;
    height: 100%;
    min-width: 22px;
    background: linear-gradient(90deg, var(--pos-dim), var(--pos), #b6f7c8);
    animation: none;
    transition: width .25s linear;
  }
  .mobile-load-note {
    margin-top: 8px;
    color: var(--ink-dim);
    font-size: 11px;
    line-height: 1.35;
  }
  .mobile-opt-loading {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
  }
  .mobile-opt-loading .mobile-load-card { margin-top: 0; }
  .mobile-load-log {
    display: grid;
    gap: 5px;
    margin-top: 10px;
    font-family: var(--f-mono);
    font-size: 11px;
    color: var(--ink-mute);
  }
  .mobile-load-log .line {
    display: flex;
    gap: 8px;
    line-height: 1.3;
  }
  .mobile-load-log .line span {
    width: 18px;
    color: var(--ink-faint);
  }
  .mobile-load-log .line em { font-style: normal; }

  /* optimizer sheet — full screen */
  .opt-sheet {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 90;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .opt-sheet .sheet-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--line);
  }
  .opt-sheet .sheet-head .ttl { flex: 1; font-size: 14px; font-weight: 500; }
  .opt-sheet .sheet-head .ttl small { display: block; color: var(--ink-dim); font-size: 11px; font-weight: 400; font-family: var(--f-mono); margin-top: 2px; }
  .opt-sheet .sheet-head .close {
    appearance: none; background: var(--bg-2); border: 1px solid var(--line-2);
    color: var(--ink); width: 36px; height: 36px; border-radius: 4px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .opt-sheet .filters {
    padding: 10px 12px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
  .opt-sheet .filters .filter { flex-shrink: 0; }
  .opt-sheet .opt-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px 80px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .opt-card {
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
  }
  .opt-card .opt-hero {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--line);
  }
  .opt-card .opt-hero .net {
    font-family: var(--f-mono);
    font-size: 18px;
    font-weight: 600;
    color: var(--pos);
  }
  .opt-card .opt-hero .acc {
    font-family: var(--f-mono);
    font-size: 13px;
    color: var(--ink-mute);
  }
  .opt-card .opt-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px 10px;
    padding: 10px 0 8px;
    font-size: 12px;
  }
  .opt-card .opt-stats .s .k {
    color: var(--ink-dim);
    font-size: 10.5px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    display: block;
  }
  .opt-card .opt-stats .s .v {
    font-family: var(--f-mono);
    font-size: 13px;
  }
  .opt-card .opt-params {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
  }
  .opt-card .opt-params .chip {
    background: var(--bg-2);
    border: 1px solid var(--line);
    color: var(--ink-mute);
    font-family: var(--f-mono);
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 3px;
  }
  .opt-card .opt-params .chip b { color: var(--ink); font-weight: 500; margin-left: 4px; }
  .opt-card .apply-btn {
    margin-top: 10px;
    width: 100%;
    height: 38px;
    justify-content: center;
  }
  .opt-sheet .pager {
    position: sticky;
    bottom: 0;
    background: var(--bg-1);
    padding: 10px 12px;
    border-top: 1px solid var(--line);
    justify-content: center;
  }
  .opt-sheet .pager .pg { width: 38px; height: 38px; }

  /* results panel */
  .results { margin: 0 12px 14px; }
  .results .res-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 12px;
  }
  .results .res-head .ttl { font-size: 11px; }
  .results .res-head .ttl span {
    display: block;
    margin-top: 4px;
    text-transform: none !important;
    letter-spacing: 0 !important;
  }
  .res-hero { grid-template-columns: repeat(2, 1fr); }
  .res-hero .cell { padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .res-hero .cell:nth-child(2n) { border-right: 0; }
  .res-hero .cell:nth-last-child(-n+2) { border-bottom: 0; }
  .res-hero .v { font-size: 17px; }
  .res-grid { grid-template-columns: 1fr; }
  .res-col { border-right: 0; border-bottom: 1px solid var(--line); }
  .res-col:last-child { border-bottom: 0; }
  .res-actions { flex-direction: column; align-items: stretch; padding: 12px; }
  .res-actions .btn { height: 40px; justify-content: center; }
  .res-actions span { font-size: 11px; text-align: center; margin-top: 4px; }

  /* status bar */
  .statusbar { font-size: 10.5px; padding: 0 12px; gap: 8px; }
  .statusbar .spacer + span { display: none; }
  .statusbar > span:nth-of-type(5),
  .statusbar > span:nth-of-type(6),
  .statusbar > span:nth-of-type(7) { display: none; }

  /* run overlay */
  .run-overlay .panel { min-width: 0; width: calc(100vw - 24px); padding: 18px 16px; }
  .run-overlay .log { height: 90px; font-size: 10.5px; }

  /* reports */
  .report-head { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 12px 8px; }
  .report-head h1 { font-size: 17px; }
  .report-head .btn { width: 100%; height: 36px; justify-content: center; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0 12px 14px; }
  .kpi { padding: 10px; }
  .kpi .v { font-size: 14px; }
  .kpi .v.pos, .kpi .v.neg { font-size: 14px; }

  /* generic table → card list on reports */
  .report-table-mobile { padding: 0 12px 14px; display: flex; flex-direction: column; gap: 6px; }
  .report-card {
    background: var(--bg-1);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
  }
  .report-card .row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    font-size: 12.5px;
  }
  .report-card .row .k { color: var(--ink-dim); }
  .report-card .row .v { font-family: var(--f-mono); }
  .report-card .row.head {
    padding-bottom: 7px;
    margin-bottom: 5px;
    border-bottom: 1px dashed var(--line);
  }
  .report-card .row.head .k { color: var(--ink); font-weight: 500; font-size: 13px; }
  .report-card .row.major { background: var(--bg-2); margin: 6px -12px -10px; padding: 8px 12px; border-bottom-left-radius: 6px; border-bottom-right-radius: 6px; }
  .report-card .row.major .k, .report-card .row.major .v { font-weight: 600; font-size: 13.5px; }

  /* subtabs */
  .subtabs { padding: 0 12px; flex-wrap: wrap; }
  .subtab { padding: 8px 10px; font-size: 13px; }
  .subtab .ct { font-size: 10.5px; }
  .subtabs .filters { width: 100%; padding: 8px 0 !important; gap: 8px; }
  .subtabs .filter { flex: 1; }
  .subtabs .filter input { width: 100% !important; }

  /* tweaks panel narrower */
  .twk-panel { width: calc(100vw - 16px); right: 8px !important; bottom: 8px !important; }
}

/* very narrow (≤ 360px) */
@media (max-width: 360px) {
  .res-hero { grid-template-columns: 1fr; }
  .res-hero .cell { border-right: 0; }
  .res-hero .cell:nth-child(2n) { border-right: 0; }
  .kpi-row { grid-template-columns: 1fr; }
  .bond-card .params { grid-template-columns: 1fr; }
}
