:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --card: #1a212b;
  --line: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3fb950;
  --accent2: #2f81f7;
  --danger: #f85149;
  --radius: 14px;
}
* { box-sizing: border-box; }
/* Our own display rules (.modal{display:grid}, .login-wrap{display:grid}) would
   otherwise override the UA stylesheet, so [hidden] elements stayed visible and
   the "Добавить в портфель" modal covered the login form. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1 { font-size: 1.25rem; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.error { color: var(--danger); min-height: 1.2em; font-size: .88rem; margin: 6px 0 0; }
.grow { flex: 1 1 240px; }
.wrap { flex-wrap: wrap; }

/* ── login ── */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 1.35rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 0; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  background: #0e141b;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent2); border-color: transparent; }
button { font: inherit; cursor: pointer; border-radius: 10px; padding: 11px 14px; border: 1px solid transparent; }
button.primary { background: var(--accent2); color: #fff; margin-top: 12px; }
button.primary:disabled { opacity: .55; }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); margin-top: 12px; }
button.small { padding: 6px 10px; font-size: .82rem; margin: 0; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; }
.gap { gap: 10px; }

/* ── layout ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: rgba(13,17,23,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; }
.tabs { display: flex; gap: 6px; padding: 10px 14px 0; }
.tab {
  flex: 1; background: var(--bg2); border: 1px solid var(--line); color: var(--muted);
  padding: 10px 8px; font-size: .95rem;
}
.tab.active { color: #fff; border-color: var(--accent2); background: #17233a; }
main { max-width: 1080px; margin: 0 auto; padding: 14px 14px 90px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; margin-right: 6px; }
.dot.ok { background: var(--accent); }
.dot.bad { background: #d29922; }
.disclaimer { text-align: center; color: var(--muted); font-size: .78rem; padding: 8px 14px 22px; }

/* ── quotes ── */
.segmented { display: flex; gap: 4px; background: var(--bg2); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg { background: transparent; color: var(--muted); padding: 8px 10px; font-size: .85rem; border-radius: 8px; }
.seg.active { background: #17233a; color: #fff; }
.summary { margin-top: 12px; }
.summary-text { margin: 8px 0 0; white-space: pre-wrap; }
.badge { font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.instrument { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.inst-name { font-weight: 600; }
.inst-sub { color: var(--muted); font-size: .8rem; }
.inst-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; font-size: .82rem; }
.inst-stats span b { font-weight: 600; }
.pos { color: var(--accent); }
.neg { color: var(--danger); }
.add-btn { background: #17233a; border: 1px solid var(--accent2); color: #fff; width: 40px; height: 40px; font-size: 1.2rem; padding: 0; }
.pos-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.pf-total { font-weight: 600; }
.strategy { white-space: pre-wrap; color: var(--muted); font-size: .88rem; margin: 6px 0 0; }
.warn { border-color: #d29922; background: #241f10; }

/* ── chat ── */
.chat-panel { display: none; flex-direction: column; }
.chat-panel.active { display: flex; }
.messages { flex: 1; display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.msg { max-width: 88%; padding: 10px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #1f3b8a; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.msg .meta { display: block; font-size: .7rem; color: var(--muted); margin-top: 6px; }
.msg.error-bubble { border-color: var(--danger); color: #ffd7d5; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; margin: 0; max-height: 140px; }
.chat-input button { margin: 0; }
.chat-tools { margin-top: 8px; }
.proposal { border-color: var(--accent2); margin-bottom: 10px; }
.proposal pre { white-space: pre-wrap; font: inherit; margin: 8px 0 0; }

/* ── modal / toast ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: end center; z-index: 50; padding: 0; }
.modal-card { width: 100%; max-width: 460px; border-radius: var(--radius) var(--radius) 0 0; padding: 18px; }
.total-line { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--accent2); padding: 10px 16px;
  border-radius: 12px; z-index: 80; max-width: 90vw;
}

@media (min-width: 720px) {
  .modal { place-items: center; }
  .modal-card { border-radius: var(--radius); }
  .login-card { padding: 22px; }
}
