:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #424852;
  --muted: #8b929b;
  --line: #e8e4dc;
  --accent: #9bb5a8;          /* soft sage */
  --accent-ink: #4d6a5d;
  --bar: #cfe1da;             /* soft teal */
  --zebra: #faf9f6;
  --hover: #f0f4f1;
  --shadow: 0 1px 2px rgba(60, 60, 60, .04), 0 6px 18px rgba(60, 60, 60, .05);

  /* pastel category palette */
  --stocks-bg: #dce8f5;  --stocks-ink: #3f5b74;
  --bonds-bg:  #dcefe2;  --bonds-ink:  #3f6b50;
  --etf-bg:    #e8e1f2;  --etf-ink:    #5b4f74;
  --money-bg:  #f5ecd6;  --money-ink:  #7a6536;
  --other-bg:  #ececec;  --other-ink:  #555b61;
  --foreign:   #d8a18f;  /* muted coral */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

main { max-width: 1180px; margin: 0 auto; padding: 32px 24px 64px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 22px;
}

/* --- Toolbar --- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 9px;
  border: 1px solid var(--line);
  background: var(--accent);
  color: #fff;
  font-weight: 600; font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.tool-btn:hover { background: var(--accent-ink); }
.tool-btn:disabled { opacity: .65; cursor: progress; }
.tool-btn .ico { display: block; }
/* spinner shown while a tool action is in flight */
.tool-btn .spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff;
  display: none; animation: spin .6s linear infinite;
}
.tool-btn.loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* URL loader: input + button group */
.url-form { display: flex; align-items: center; gap: 10px; flex: 1 1 360px; }
.url-input {
  flex: 1 1 240px; min-width: 0;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 13px; font-size: 13px; background: #fbfaf7; color: var(--ink);
}
.url-input:focus { outline: none; border-color: var(--accent); }
.url-input::placeholder { color: var(--muted); }

.error { border-color: #e3c2bb; background: #fbf1ee; color: #9a5a4c; }
.hint { color: var(--muted); text-align: center; padding: 40px 0; }

/* --- Tabs --- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; }
.tabs:empty { margin: 0; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-bottom: none;
  background: #efece5; color: var(--muted);
  font-size: 13px; font-weight: 600;
  padding: 9px 12px 9px 14px;
  border-radius: 10px 10px 0 0;
  cursor: pointer; max-width: 280px;
  transition: background .12s ease, color .12s ease;
}
.tab:hover { background: #f3f1ea; color: var(--ink); }
.tab.active {
  background: var(--card); color: var(--accent-ink);
  box-shadow: 0 -2px 0 var(--accent) inset;
}
.tab .tab-ico { display: inline-flex; opacity: .8; }
.tab .tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .tab-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 17px; height: 17px; border-radius: 5px; margin-left: 2px;
  font-size: 15px; line-height: 1; color: var(--muted);
}
.tab .tab-close:hover { background: #e0d6cf; color: #9a5a4c; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* --- Security overview card --- */
.sec-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.sec-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.sec-head .secid { font-weight: 600; color: var(--accent-ink); }
.sec-fullname { color: var(--muted); font-size: 13px; margin-top: 6px; }
.tag-type { background: var(--stocks-bg); color: var(--stocks-ink); margin-left: 4px; }
.sec-price { text-align: right; white-space: nowrap; }
.sec-price .val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sec-price .delta { display: block; font-size: 13px; font-weight: 600; margin-top: 2px; color: var(--muted); }
.sec-price .delta.up { color: #4f8a5b; }
.sec-price .delta.down { color: #b06a57; }

.sec-links { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 4px; }
.src-link {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px; border-radius: 9px; text-decoration: none;
  font-size: 12.5px; font-weight: 600; border: 1px solid var(--line);
  transition: background .12s ease;
}
.src-link .ext { font-size: 11px; }
.src-link.moex { background: #eaf0ea; color: var(--accent-ink); }
.src-link.dh   { background: #d9e6ea; color: #3f6470; }
.src-link.sl   { background: #e6e1cf; color: #6f6531; }
.src-link:hover { filter: brightness(.97); }

.sec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-top: 18px; }
.sec-block { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; background: #fbfaf7; }
.sec-block h3 {
  margin: 0 0 10px; font-size: 12px; font-weight: 700; color: var(--accent-ink);
  text-transform: uppercase; letter-spacing: .4px;
}
.sec-block dl { margin: 0; }
.sec-block dl > div {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 6px 0; border-bottom: 1px solid #f1eee8;
}
.sec-block dl > div:last-child { border-bottom: none; }
.sec-block dt { color: var(--muted); font-size: 13px; }
.sec-block dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* --- Portfolio reconciliation warning --- */
.pf-warning {
  display: flex; align-items: flex-start; gap: 10px;
  margin: 0 0 16px; padding: 12px 16px;
  border: 1px solid #e0b878; border-left: 4px solid #d08a2c;
  border-radius: 10px; background: #fbf1de; color: #8a5a1c;
  font-size: 13px; font-weight: 500; line-height: 1.45;
}
.pf-warning svg { flex: 0 0 auto; margin-top: 1px; color: #d08a2c; }

/* --- Portfolio header --- */
.pf-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.pf-headmain { flex: 1 1 320px; min-width: 0; }
.pf-name {
  display: block; width: 100%; margin: 0 0 2px; padding: 3px 7px 3px 5px;
  font-family: inherit; font-size: 18px; font-weight: 600; line-height: 1.3; color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: 7px;
}
.pf-name:hover { border-color: var(--line); }
.pf-name:focus { outline: none; border-color: var(--accent); background: #fbfaf7; }
.pf-name::placeholder { color: var(--muted); font-weight: 500; }
.pf-comment {
  display: block; width: 100%; margin: 14px 0 0;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px;
  font-family: inherit; font-size: 13px; line-height: 1.45; color: var(--ink);
  background: #fbfaf7; resize: vertical; min-height: 38px;
}
.pf-comment:focus { outline: none; border-color: var(--accent); }
.pf-comment::placeholder { color: var(--muted); }
.meta { color: var(--muted); margin-top: 4px; font-size: 12.5px; }
.meta span { margin-right: 6px; }
.pf-right { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.pf-totals { display: flex; gap: 26px; }
.save-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--accent); background: transparent;
  color: var(--accent-ink); font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.save-btn:hover { background: var(--accent); color: #fff; }
.save-btn .ico { display: block; }

/* add-asset form (trade planning) */
.pf-add { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 4px; }
.pf-add .add-query {
  flex: 0 1 280px; min-width: 0;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; font-size: 13px; background: #fbfaf7; color: var(--ink);
}
.pf-add .add-query:focus { outline: none; border-color: var(--accent); }
.pf-add .add-qty {
  width: 84px;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 10px; font-size: 13px; background: #fbfaf7; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.pf-add .add-qty:focus { outline: none; border-color: var(--accent); }
.add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; background: var(--accent); color: #fff;
  font-weight: 600; font-size: 13px; padding: 9px 16px;
  border-radius: 9px; cursor: pointer; transition: background .12s ease;
}
.add-btn:hover { background: var(--accent-ink); }
.add-btn:disabled { opacity: .65; cursor: progress; }
.add-btn .ico { display: block; }
.pf-msg { font-size: 12.5px; color: var(--muted); }
.pf-msg.err { color: #9a5a4c; }

/* cash form (set the money position: deposit / withdrawal) */
.pf-cash { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.pf-cash .cash-label { font-size: 13px; color: var(--muted); }
.pf-cash .cash-input {
  width: 150px;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 10px; font-size: 13px; background: #fbfaf7; color: var(--ink);
  font-variant-numeric: tabular-nums; text-align: right;
}
.pf-cash .cash-input:focus { outline: none; border-color: var(--accent); }
.pf-cash .cash-ccy { font-size: 13px; color: var(--muted); }
.cash-btn {
  border: 1px solid var(--accent); background: transparent; color: var(--accent-ink);
  font-weight: 600; font-size: 13px; padding: 8px 15px; border-radius: 9px;
  cursor: pointer; transition: background .12s ease, color .12s ease;
}
.cash-btn:hover { background: var(--accent); color: #fff; }
.cash-btn:disabled { opacity: .65; cursor: progress; }

/* correction form (build a correction portfolio against a reference) */
.pf-correction { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 4px; }
.pf-correction .corr-url {
  flex: 1 1 320px; min-width: 0;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; font-size: 13px; background: #fbfaf7; color: var(--ink);
}
.pf-correction .corr-url:focus { outline: none; border-color: var(--accent); }
.corr-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent-ink);
  font-weight: 600; font-size: 13px; padding: 8px 15px; border-radius: 9px;
  cursor: pointer; white-space: nowrap; transition: background .12s ease, color .12s ease;
}
.corr-btn:hover { background: var(--accent); color: #fff; }
.corr-btn:disabled { opacity: .65; cursor: progress; }
.corr-btn .ico { display: block; }

/* per-row quantity controls */
td.row-actions { white-space: nowrap; text-align: right; padding-left: 6px; }
.rb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; margin-left: 4px; padding: 0;
  border: 1px solid var(--line); border-radius: 7px; background: #fff;
  color: var(--accent-ink); font-size: 16px; line-height: 1; cursor: pointer;
  vertical-align: middle; transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.rb:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.rb.trash { color: var(--muted); }
.rb.trash:hover { background: #f6e7e2; color: #9a5a4c; border-color: #e3c2bb; }
.rb.trash svg { display: block; }

/* Pin the actions column to the right edge so +/−/trash stay visible while the
   table scrolls horizontally. Each sticky cell needs an opaque background that
   matches its row, otherwise the scrolled-under content bleeds through. */
.holdings th.nosort,
.holdings td.row-actions,
.holdings tfoot td:last-child {
  position: sticky; right: 0; border-left: 1px solid var(--line);
}
.holdings th.nosort { z-index: 3; }   /* header corner stays above row cells */
.holdings td.row-actions { z-index: 1; background: var(--card); }
.holdings tfoot td:last-child { background: #f7f8f5; }
.holdings tbody tr:nth-child(even) td.row-actions { background: var(--zebra); }
.holdings tbody tr:hover td.row-actions { background: var(--hover); }
.holdings tbody tr.foreign td.row-actions { background: #fcf6f3; }
.holdings tbody tr.foreign:hover td.row-actions { background: #f8efe9; }
.pf-totals .lbl { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.pf-totals .val { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; vertical-align: middle;
}
.tag-correction { background: var(--etf-bg); color: var(--etf-ink); }
.tag-foreign { background: #f6e7e2; color: #9a5a4c; margin-left: 6px; }

/* --- Table tools --- */
.table-tools { display: flex; align-items: center; gap: 16px; margin: 18px 0 10px; }
.filter {
  flex: 0 1 320px;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 12px; font-size: 13px; background: #fbfaf7; color: var(--ink);
}
.filter:focus { outline: none; border-color: var(--accent); }
.legend { color: var(--muted); font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.foreign { background: var(--foreign); }

/* category filter checkboxes */
.cat-filter { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-chk {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px 4px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; cursor: pointer; user-select: none;
  opacity: .5; transition: opacity .12s ease;
}
.cat-chk:has(input:checked) { opacity: 1; }
.cat-chk input { margin: 0; cursor: pointer; accent-color: var(--accent-ink); }

/* --- Holdings table --- */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
table.holdings { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.holdings thead th {
  position: sticky; top: 0;
  background: #f2f4f0; color: var(--accent-ink);
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
  text-align: right; padding: 11px 14px; white-space: nowrap; cursor: pointer;
  border-bottom: 1px solid var(--line); user-select: none;
}
.holdings thead th:nth-child(2),
.holdings thead th:nth-child(3),
.holdings thead th:nth-child(4),
.holdings thead th:nth-child(5) { text-align: left; }
.holdings thead th.sorted-asc::after { content: " ▲"; font-size: 9px; }
.holdings thead th.sorted-desc::after { content: " ▼"; font-size: 9px; }

.holdings tbody td { padding: 10px 14px; border-bottom: 1px solid #f1eee8; text-align: right; }
.holdings tbody tr:nth-child(even) { background: var(--zebra); }
.holdings tbody tr:hover { background: var(--hover); }
.holdings td.name, .holdings td.ticker, .holdings td.isin { text-align: left; }
.holdings td.idx { color: var(--muted); font-size: 12px; }
.holdings td.ticker { font-weight: 600; }
.holdings td.isin { color: var(--muted); font-size: 12.5px; }
.holdings td.num { white-space: nowrap; }
.holdings .note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.moex-link { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid transparent; }
.moex-link:hover { border-bottom-color: var(--accent); }
.moex-link .ext { color: var(--muted); font-size: 11px; margin-left: 4px; vertical-align: super; }

.sources { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; }
.src-chip {
  display: inline-block; padding: 0 6px; height: 16px; line-height: 16px;
  border-radius: 5px; font-size: 10px; font-weight: 700; letter-spacing: .3px;
  text-decoration: none; opacity: .85;
}
.src-chip:hover { opacity: 1; }
.src-chip.sl { background: #e6e1cf; color: #6f6531; }   /* smart-lab — soft sand */
.src-chip.dh { background: #d9e6ea; color: #3f6470; }   /* dohod — soft slate-teal */

.moex-price .delta { display: block; font-size: 11px; margin-top: 1px; color: var(--muted); }
.moex-price .delta.up { color: #4f8a5b; }
.moex-price .delta.down { color: #b06a57; }

.holdings tr.zero td { color: var(--muted); }
.holdings tr.foreign { background: #fcf6f3; }
.holdings tr.foreign:hover { background: #f8efe9; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.cat-stocks { background: var(--stocks-bg); color: var(--stocks-ink); }
.cat-bonds  { background: var(--bonds-bg);  color: var(--bonds-ink); }
.cat-etf    { background: var(--etf-bg);    color: var(--etf-ink); }
.cat-money  { background: var(--money-bg);  color: var(--money-ink); }
.cat-other  { background: var(--other-bg);  color: var(--other-ink); }

/* weight cell with mini bar */
td.weight { position: relative; min-width: 92px; }
td.weight .wbar {
  position: absolute; left: 14px; right: 14px; bottom: 5px; height: 4px;
  border-radius: 3px; background: var(--bar);
  transform: scaleX(calc(var(--w) / 100)); transform-origin: left;
}
td.weight .wnum { position: relative; }

.holdings tfoot td {
  padding: 12px 14px; font-weight: 600; text-align: right;
  border-top: 2px solid var(--line); background: #f7f8f5;
}
.holdings tfoot .foot-label { text-align: right; color: var(--muted); }

/* --- Portfolio "Доходность" button (opens the metrics tab) --- */
.pf-actions { display: flex; align-items: center; gap: 12px; margin: 10px 0 4px; }
.metrics-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent-ink);
  font-weight: 600; font-size: 13px; padding: 8px 15px; border-radius: 9px;
  cursor: pointer; white-space: nowrap; transition: background .12s ease, color .12s ease;
}
.metrics-btn:hover { background: var(--accent); color: #fff; }
.metrics-btn:disabled { opacity: .65; cursor: progress; }
.metrics-btn .ico { display: block; }
.metrics-btn .spinner {
  display: none; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; animation: spin .7s linear infinite;
}
.metrics-btn.loading .spinner { display: block; }

/* --- Metrics tab --- */
.metrics .mx-head { margin-bottom: 6px; }
.mx-title { margin: 0 0 4px; font-size: 19px; color: var(--ink); font-weight: 650; }
.mx-empty { color: var(--muted); margin: 14px 0; }
.mx-section { margin-top: 22px; }
.mx-h3 {
  margin: 0 0 12px; font-size: 13px; font-weight: 650; letter-spacing: .02em;
  text-transform: uppercase; color: var(--muted);
}
.mx-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.mx-metric {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--zebra);
}
.mx-metric.accent { border-color: var(--accent); background: #eef4f0; }
.mx-metric .mx-lbl { font-size: 12.5px; color: var(--muted); }
.mx-metric .mx-val { font-size: 26px; font-weight: 680; color: var(--ink); font-variant-numeric: tabular-nums; }
.mx-metric.accent .mx-val { color: var(--accent-ink); }
.mx-metric .mx-hint { font-size: 11.5px; color: var(--muted); }
.mx-note { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }
.holdings.yields .accent-cell { font-weight: 650; color: var(--accent-ink); }

.mx-glossary { margin: 0; display: grid; gap: 12px; }
.mx-glossary dt { font-weight: 650; color: var(--ink); font-size: 13.5px; }
.mx-glossary dd { margin: 3px 0 0; color: var(--ink); font-size: 13px; line-height: 1.5; opacity: .9; }
