/* ==========================================================================
   Sales UI — B24 embedded app (design mockup)
   Light, modern, dependency-free. Single sheet.
   ========================================================================== */

:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f8;
  --border: #e4e9f2;
  --border-strong: #d4dbe8;

  --text: #16202e;
  --text-2: #3d4759;
  --muted: #74809a;
  --faint: #9aa4b8;

  --accent: #2b6cff;
  --accent-600: #1d55d8;
  --accent-700: #1745b3;
  --accent-soft: #e9f0ff;
  --accent-ring: rgba(43, 108, 255, 0.28);

  --success: #12a150;
  --success-soft: #e5f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e2;
  --danger: #e5484d;

  --radius: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.05);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 880px;
  margin: 0 auto;
}

/* ── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-700));
  box-shadow: 0 4px 12px var(--accent-ring);
}

.topbar-titles { min-width: 0; }
.topbar-title {
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub { font-size: 12.5px; color: var(--muted); }

.demo-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
}
.demo-switch-label { font-weight: 600; }
.demo-switch select {
  border: none;
  background: transparent;
  font: inherit;
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

/* ── Content ─────────────────────────────────────────────────────────── */
.content {
  order: 2; /* below the topbar + the (now top-placed) action bar */
  flex: 1 1 auto;
  padding: 20px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.card-head-titles { min-width: 0; }
.card-title {
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.card-subtitle {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.card-body { padding: 18px 20px 20px; }

/* ── Portrait ────────────────────────────────────────────────────────── */
.portrait-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
  color: var(--accent-700);
  background: var(--accent-soft);
  border: 1px solid #d7e2ff;
}
.portrait-name { font-size: 18px; font-weight: 680; letter-spacing: -0.01em; }
.portrait-name-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.meta {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.meta-k {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint);
  font-weight: 600;
}
.meta-v {
  display: block;
  margin-top: 3px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.meta-v.mono { font-family: var(--mono); font-size: 13.5px; font-weight: 550; }

/* ── Summary block (LLM summary of OUR data, above deals) ─────────────── */
.summary-block {
  margin-bottom: 20px;
  padding: 16px 18px;
  border: 1px solid #d7e2ff;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 78%);
  position: relative;
}
.summary-block::before {
  content: "";
  position: absolute;
  left: 0; top: 14px; bottom: 14px;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(var(--accent), var(--accent-700));
}
.summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 680;
  color: var(--accent-700);
  letter-spacing: -0.01em;
}
.summary-meta { font-size: 11.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.summary-text {
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
}
.summary-insights {
  margin-top: 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.insight {
  position: relative;
  padding: 8px 11px 8px 24px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border);
  font-size: 13.5px;
  line-height: 1.45;
}
.insight::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 15px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.insight-text { color: var(--text-2); }
.summary-foot {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--faint);
}

.section { margin-top: 18px; }
.section:first-child { margin-top: 0; }
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}
.count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0;
}

.deal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.deal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.deal:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.deal-main { min-width: 0; }
.deal-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deal-fields { margin-top: 3px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.deal-right { flex: 0 0 auto; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.deal-amount { font-weight: 680; font-size: 14.5px; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.6;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-neutral { background: var(--surface-3); color: var(--muted); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.empty-inline {
  padding: 12px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  font-size: 13.5px;
  background: var(--surface-2);
}

.md-raw {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.md-raw pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Analytics ───────────────────────────────────────────────────────── */
.date-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.date-badge.stale { background: var(--warn-soft); border-color: #f0dcb6; color: var(--warn); }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-700);
  border: 1px solid #d7e2ff;
}
.pill.soft { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

.sources { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.source-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12.5px;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.source-chip:hover { border-color: var(--accent); color: var(--accent-700); }
.source-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Empty / loading states */
.empty-state {
  text-align: center;
  padding: 34px 20px 30px;
}
.empty-illustration {
  width: 62px; height: 62px; margin: 0 auto 14px;
  display: grid; place-items: center;
  font-size: 28px;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.empty-title { font-size: 15.5px; font-weight: 650; }
.empty-sub { margin: 6px auto 0; max-width: 380px; font-size: 13.5px; color: var(--muted); }

.loading-state { padding: 6px 0; }
.loading-status {
  display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 600; color: var(--accent-700);
  margin-bottom: 16px;
}
.spinner {
  width: 16px; height: 16px; flex: 0 0 auto;
  border: 2.2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { border-radius: 7px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton + .skeleton { margin-top: 10px; }
.sk-line { height: 13px; }
.sk-w-40 { width: 40%; } .sk-w-60 { width: 60%; } .sk-w-80 { width: 80%; } .sk-w-100 { width: 100%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ── Rendered markdown (analytics body) ──────────────────────────────── */
.md {
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.62;
}
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; letter-spacing: -0.01em; font-weight: 660; }
.md h1 { font-size: 19px; margin: 22px 0 10px; }
.md h2 { font-size: 16.5px; margin: 20px 0 9px; }
.md h3 { font-size: 14.5px; margin: 16px 0 7px; color: var(--text-2); }
.md p { margin: 10px 0; }
.md ul, .md ol { margin: 10px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--accent); }
.md a { color: var(--accent-700); text-decoration: none; border-bottom: 1px solid var(--accent-ring); }
.md a:hover { border-bottom-color: var(--accent); }
.md strong { font-weight: 660; color: var(--text); }
.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-3);
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font: inherit;
  font-weight: 640;
  cursor: pointer;
  padding: 11px 18px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.05s, color 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn[disabled] { cursor: default; opacity: 0.62; pointer-events: none; }
.btn-ico { flex: 0 0 auto; }

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-600));
  box-shadow: 0 4px 12px var(--accent-ring);
}
.btn.primary:hover { background: linear-gradient(135deg, var(--accent-600), var(--accent-700)); }

.btn.secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover { border-color: var(--accent); color: var(--accent-700); }
.btn.secondary .btn-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
  padding-left: 8px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
}
.btn.secondary:hover .btn-hint { color: var(--accent); border-color: var(--accent-ring); }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn.ghost:hover { color: var(--text-2); border-color: var(--border-strong); background: var(--surface-2); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; font-weight: 600; }

.btn .btn-spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn.secondary .btn-spinner { border-color: var(--accent-ring); border-top-color: var(--accent); }

/* ── Action bar ──────────────────────────────────────────────────────── */
.actionbar {
  /* Placed directly UNDER the topbar (flex order) — the B24 detail-tab frame is
     content-sized (no fixed viewport to pin a bottom bar to), so the actions go
     up top where they are visible the moment the tab opens, no scrolling. */
  order: 1;
  z-index: 15;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.actionbar-inner {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  max-width: 880px;
  margin: 0 auto;
}
.actionbar .btn { flex: 1 1 auto; }
.actionbar .btn.secondary { flex: 0 1 auto; }

/* ── ППР options panel (template + margin), toggled by «Сделать ППР» ──── */
.ppr-panel {
  order: 1; /* sits right under the action bar (both order 1, source after) */
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.ppr-panel-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.ppr-field { display: flex; align-items: center; gap: 8px; }
.ppr-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg label input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg label span {
  display: block;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  user-select: none;
}
.seg label + label span { border-left: 1px solid var(--border); }
.seg label input:checked + span { background: var(--accent); color: #fff; }
.seg label input:focus-visible + span { box-shadow: inset 0 0 0 2px var(--accent-ring); }
.ppr-margin { display: inline-flex; align-items: center; gap: 5px; }
#ppr-margin {
  width: 62px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: right;
  background: var(--surface);
  color: var(--text);
}
.ppr-suffix { font-size: 13px; color: var(--text-2); }
#ppr-submit { margin-left: auto; }

/* ── Toasts ──────────────────────────────────────────────────────────── */
.toast-host {
  /* Anchored to the TOP (just under the topbar + action bar) so it is visible
     right where the buttons are — a bottom anchor sits at the far end of the
     content-sized B24 iframe and never shows on screen when you click a top
     button. */
  position: fixed;
  left: 50%;
  top: 120px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: #101827;
  color: #f2f5fb;
  box-shadow: var(--shadow-pop);
  font-size: 13.5px;
  line-height: 1.45;
  animation: toast-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast.leaving { animation: toast-out 0.2s ease forwards; }
.toast-ico { flex: 0 0 auto; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 6px; font-size: 12px; }
.toast.success .toast-ico { background: rgba(18,161,80,0.22); color: #6fe0a0; }
.toast.warn .toast-ico { background: rgba(183,121,31,0.24); color: #f0c073; }
.toast.info .toast-ico { background: rgba(43,108,255,0.24); color: #93b4ff; }
.toast-body { min-width: 0; }
.toast-title { font-weight: 650; }
.toast-sub { color: #aeb8cc; font-size: 12.5px; margin-top: 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .content { padding: 16px 14px 116px; }
  .card-head, .card-body { padding-left: 16px; padding-right: 16px; }
  .actionbar-inner { padding: 12px 14px; }
  .btn.secondary .btn-hint { display: none; }
  .topbar-sub { display: none; }
}

/* ── LIVE indicator (topbar) ──────────────────────────────────────────── */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--success-soft); color: var(--success);
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(18, 161, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0); }
}

/* ── ADR-0078/0079/0080/0081 portrait enrichments ─────────────────────── */
/* Deal becomes a column: the header row + an optional collapsible detail
   (orders + «Саммари сделки»/«Саммари заказа»). */
.deal { flex-direction: column; align-items: stretch; }
.deal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.deal-detail { margin-top: 2px; }
.deal-detail > summary {
  cursor: pointer; user-select: none; list-style: none;
  font-size: 12px; color: var(--muted); padding: 3px 0;
}
.deal-detail > summary::-webkit-details-marker { display: none; }
.deal-detail > summary::before { content: "▸ "; color: var(--faint); }
.deal-detail[open] > summary::before { content: "▾ "; }
.deal-detail .md {
  font-size: 13px; line-height: 1.55; margin-top: 4px;
  padding: 6px 0 2px 10px; border-left: 2px solid var(--border);
}
.deal-detail .md ul { margin: 4px 0; }
.deal-detail .md p { margin: 4px 0; }

/* Company timeline (ADR-0078). */
.timeline-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  font-size: 13px; color: var(--muted); padding: 7px 0;
  border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
.timeline-item:last-child { border-bottom: none; }

/* Company website link + description «О компании» (ADR-0083). */
.meta-link { color: var(--accent-700); text-decoration: none; overflow-wrap: anywhere; }
.meta-link:hover { text-decoration: underline; }
.notes-block {
  margin: 14px 0 4px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.notes-label {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 5px;
}
.notes-text { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-wrap; }
