/* Альфа Инсайт — три зоны: узкая красная панель сервисов, лента инсайтов, аналитика события.
   Цвета — рабочие токены прототипа, не значения из официального брендбука. */
:root {
  --bg: #f5f5f6;
  --panel: #ffffff;
  --ink: #121316;
  --muted: #676b73;
  --line: #e4e5e8;
  --red: #ef3124;
  --red-ink: #ffffff;
  --red-soft: #fdeceb;
  --red-text: #c4231a;
  --green: #17784a;
  --green-soft: #e8f5ee;
  --amber: #8a5d00;
  --amber-soft: #fff3d6;
  --bank: #2d3c99;
  --bank-soft: #edf0ff;
  --chip: #eff0f2;
  --shadow: 0 1px 2px rgba(18, 19, 22, .06), 0 4px 16px rgba(18, 19, 22, .05);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101114; --panel: #1a1c20; --ink: #eef0f3; --muted: #9ba1ab; --line: #2b2e35;
    --red-soft: #3a1b19; --red-text: #ff8d85; --green: #7fd1a3; --green-soft: #14301f;
    --amber: #ffd27a; --amber-soft: #382c10; --bank: #a9b4ff; --bank-soft: #1e2447; --chip: #24272d;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101114; --panel: #1a1c20; --ink: #eef0f3; --muted: #9ba1ab; --line: #2b2e35;
  --red-soft: #3a1b19; --red-text: #ff8d85; --green: #7fd1a3; --green-soft: #14301f;
  --amber: #ffd27a; --amber-soft: #382c10; --bank: #a9b4ff; --bank-soft: #1e2447; --chip: #24272d;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 64px minmax(0, 1fr); min-height: 100vh; }
.app.with-detail { grid-template-columns: 64px minmax(0, 1fr) minmax(400px, 560px); }
.app.rail-open { grid-template-columns: 232px minmax(0, 1fr); }
.app.rail-open.with-detail { grid-template-columns: 232px minmax(0, 1fr) minmax(400px, 520px); }

/* ---------- панель сервисов ---------- */
.rail { background: var(--red); color: var(--red-ink); display: flex; flex-direction: column; gap: 4px; padding: 12px 8px;
  position: sticky; top: 0; height: 100vh; overflow: hidden; z-index: 6; }
.rail button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 12px;
  border-radius: 10px; cursor: pointer; white-space: nowrap; color: var(--red-ink); }
.rail button:hover, .rail button.active { background: rgba(255, 255, 255, .16); }
.rail button:focus-visible { outline: 2px solid #fff; }
.rail svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail-logo { margin-bottom: 12px; font-weight: 700; }
.logo-mark { width: 24px; height: 24px; flex: none; display: grid; place-items: center; font-size: 12px; letter-spacing: -.02em;
  background: #fff; color: var(--red); border-radius: 7px; font-weight: 800; margin-left: -2px; }
.rail-label { opacity: 0; transition: opacity .15s; font-size: 14px; }
.app.rail-open .rail-label { opacity: 1; }

/* ---------- лента ---------- */
.main { padding: 24px max(16px, 2.2vw) 48px; min-width: 0; }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
h1 { font-size: 26px; line-height: 1.2; margin: 6px 0 4px; letter-spacing: -.01em; text-wrap: balance; }
.company-btn { all: unset; cursor: pointer; border-bottom: 2px solid var(--red); }
.company-btn:focus-visible { outline: 2px solid var(--red); }
.sub { color: var(--muted); font-size: 14px; }
.top-badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.badge.demo { background: var(--amber-soft); color: var(--amber); cursor: help; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.seg { display: flex; gap: 4px; background: var(--chip); padding: 4px; border-radius: 12px; flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 500; }
.seg-btn.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.filters-right { display: flex; gap: 8px; flex-wrap: wrap; }
select, input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; max-width: 100%; }
.feed-meta { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }

.feed { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; cursor: pointer;
  display: grid; gap: 6px; transition: border-color .12s, box-shadow .12s; }
.card:hover { box-shadow: var(--shadow); }
.card.selected { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pill.risk { background: var(--red-soft); color: var(--red-text); }
.pill.opportunity { background: var(--green-soft); color: var(--green); }
.pill.uncertain { background: var(--amber-soft); color: var(--amber); }
.sig { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sig b { font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.sig-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--chip); overflow: hidden; }
.sig-bar span { display: block; height: 100%; background: var(--ink); border-radius: 3px; }
.card.high .sig-bar span { background: var(--red); }
.card h3 { margin: 2px 0 0; font-size: 17px; line-height: 1.35; text-wrap: balance; }
.orig { font-size: 13px; color: var(--muted); }
.meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.meta .dot::before { content: "·"; margin-right: 6px; }
.tag-demo { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--amber-soft); color: var(--amber); }
.empty { color: var(--muted); padding: 40px 12px; text-align: center; }

/* ---------- аналитика события ---------- */
.detail { background: var(--panel); border-left: 1px solid var(--line); padding: 24px 24px 32px; position: sticky; top: 0; height: 100vh; overflow-y: auto; min-width: 0; }
.detail-close { float: right; border: 0; background: var(--chip); width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 16px; line-height: 1; }
.d-eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); }
.d-eyebrow .pill { margin-right: 6px; }
.detail h2 { font-size: 22px; line-height: 1.25; margin: 10px 0 16px; text-wrap: balance; letter-spacing: -.01em; }
.insight { background: var(--red-soft); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 22px; }
.insight .label { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--red-text); }
.insight p.big { font-size: 19px; font-weight: 700; line-height: 1.35; margin: 6px 0 8px; }
.insight p.basis { font-size: 13px; color: var(--muted); margin: 0; }
.section { margin: 0 0 22px; }
.section h4 { font-size: 16px; margin: 0 0 8px; }
.section p { margin: 0; }
.section ul { margin: 0; padding-left: 18px; }
.section li { margin: 4px 0; }
.ro { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ro-box { border-radius: 12px; padding: 12px 14px; }
.ro-box.opp { background: var(--green-soft); }
.ro-box.risk { background: var(--red-soft); }
.ro-box h5 { margin: 0 0 6px; font-size: 13px; }
.ro-box.opp h5 { color: var(--green); }
.ro-box.risk h5 { color: var(--red-text); }
.ro-box ul { padding-left: 16px; font-size: 14px; }
.ro-box .none { font-size: 14px; color: var(--muted); }
.horizon { font-size: 12px; color: var(--muted); white-space: nowrap; }
.bank-box { background: var(--bank-soft); border-radius: 12px; padding: 12px 14px; }
.bank-box .label { font-size: 12px; font-weight: 700; color: var(--bank); }
.ref { font-size: 11px; font-weight: 700; color: var(--bank); background: var(--bank-soft); border-radius: 5px; padding: 0 5px; margin-left: 4px; cursor: pointer; border: 0; vertical-align: 1px; }
.warn { font-size: 12px; color: var(--amber); margin-left: 4px; }
.basis-note { font-size: 12px; color: var(--muted); }
.src { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; font-size: 14px; }
.src-kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.src-title { font-weight: 600; margin: 2px 0; }
.src a { color: var(--bank); }
.quote { font-size: 13px; border-left: 3px solid var(--line); padding: 2px 10px; margin: 6px 0 0; color: var(--ink); }
.quote.flash { border-left-color: var(--red); background: var(--red-soft); }
details.more { border-top: 1px solid var(--line); padding: 10px 0; }
details.more summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.more[open] summary { margin-bottom: 8px; }
.comp-row { display: grid; grid-template-columns: 150px 1fr 40px; gap: 8px; align-items: center; font-size: 12px; margin: 4px 0; }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ink); }
.trace { padding-left: 18px; font-size: 13px; margin: 0; }
.trace li { margin: 3px 0; }
.table-wrap { overflow-x: auto; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 13px; }
table.cmp td, table.cmp th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.cmp tr.current td { font-weight: 600; }

.chat-box { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 16px; }
.chat-box h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 16px; }
.chat-box h4::before { content: ""; width: 10px; height: 10px; border: 2px solid var(--red); border-radius: 50%; }
.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.msg { padding: 9px 12px; border-radius: 12px; font-size: 14px; max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--panel); }
.msg.bot { background: var(--chip); }
.msg .basis-note { display: block; margin-top: 4px; }
.ask-form { display: flex; gap: 6px; }
.ask-form input { flex: 1; min-width: 0; border-radius: 12px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.suggest button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; }

.btn { background: var(--red); color: var(--red-ink); border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: .6; cursor: wait; }

/* ---------- профиль (личный кабинет) ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .32); z-index: 20; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(420px, 100vw); background: var(--panel); z-index: 21; overflow-y: auto;
  padding: 24px max(20px, env(safe-area-inset-left, 0px)) 32px 24px; box-shadow: 0 0 40px rgba(0, 0, 0, .2); }
.drawer h2 { margin: 6px 0 4px; font-size: 22px; line-height: 1.25; }
.drawer dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; margin: 16px 0; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; }
.drawer h4 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.drawer ul { margin: 0; padding-left: 18px; font-size: 14px; }
.drawer li { margin: 3px 0; }

/* ---------- диалоги ---------- */
.dlg { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); }
.dlg::backdrop { background: rgba(0, 0, 0, .4); }
.dlg-body { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.dlg h2 { margin: 0; font-size: 21px; line-height: 1.25; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.company-list:focus { outline: none; }
.company-list { display: grid; gap: 8px; max-height: 50vh; overflow-y: auto; }
.company-opt { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.company-opt:has(input:checked) { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.company-opt input { margin-top: 4px; accent-color: var(--red); }
.company-opt b { display: block; font-size: 14px; }
.company-opt span { font-size: 13px; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: calc(100vw - 32px); }

/* ---------- планшет и телефон: анализ раскрывается под карточкой ---------- */
@media (max-width: 1100px) {
  .app, .app.with-detail, .app.rail-open, .app.rail-open.with-detail { grid-template-columns: 64px minmax(0, 1fr); }
  .detail { position: static; height: auto; border: 1px solid var(--red); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); margin-top: -12px; padding: 20px 18px; }
  .card.selected { border-radius: var(--radius) var(--radius) 0 0; }
  .app.rail-open .rail { position: fixed; left: 0; width: 232px; }
}
@media (max-width: 640px) {
  .app, .app.with-detail { display: block; padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .rail { position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; flex-direction: row; justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .rail-logo, .rail .rail-label { display: none; }
  .rail button { height: 44px; padding: 0 10px; }
  .main { padding: 18px max(16px, env(safe-area-inset-left, 0px)) 24px max(16px, env(safe-area-inset-right, 0px)); }
  h1 { font-size: 22px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters > * { min-width: 0; max-width: 100%; }
  .seg { flex-wrap: nowrap; overflow-x: auto; }
  .filters-right select { min-width: 0; }
  .seg-btn { white-space: nowrap; }
  .filters-right select { flex: 1; }
  .ro { grid-template-columns: 1fr; }
  .detail h2 { font-size: 19px; }
  .comp-row { grid-template-columns: 110px 1fr 36px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
