:root {
  --bg: #ffffff;
  --surface: #f7f7f8;
  --surface-2: #ececf1;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --muted: #6e6e80;
  --faint: #a1a1aa;
  --primary: #0d0d0d;
  --on-primary: #ffffff;
  --accent: #10a37f;
  --danger: #d93f3f;
  --danger-bg: #fdecec;
  --warn: #b7791f;
  --warn-bg: #fdf4e3;
  --note-bg: #fffbea;
  --bubble-in: #f0f0f2;
  --bubble-out: #0d0d0d;
  --on-bubble-out: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --radius-lg: 20px;

  --s-new: #2f6fed; --s-contacted: #7c5cff; --s-visa_applied: #d4890b; --s-visa_received: #0e9488;
  --s-signed: #10a37f; --s-no_answer: #8e8ea0; --s-not_fit: #d93f3f;

  --chart-a: #10a37f;
  --chart-b: #8e8ea0;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface: #171717;
  --surface-2: #232325;
  --border: #2a2a2d;
  --text: #ececf1;
  --muted: #9b9bab;
  --faint: #5f5f6b;
  --primary: #ececf1;
  --on-primary: #0d0d0d;
  --danger: #f06565;
  --danger-bg: #3a1d1d;
  --warn: #e3a948;
  --warn-bg: #3a2e17;
  --note-bg: #2b2716;
  --bubble-in: #232325;
  --bubble-out: #ececf1;
  --on-bubble-out: #0d0d0d;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.4);
  --s-new: #6b9bff; --s-contacted: #a48cff; --s-visa_applied: #f0b13d; --s-visa_received: #2cc4b6;
  --s-signed: #19c39a; --s-no_answer: #8e8ea0; --s-not_fit: #f06565;
  --chart-a: #19c39a;
  --chart-b: #6b6b78;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { flex-shrink: 0; }

/* ───────── layout ───────── */
#app { min-height: 100vh; }
.main { padding: 0 16px calc(96px + var(--safe-bottom)); max-width: 760px; margin: 0 auto; }
.sidebar { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border: 0; background: none; color: var(--faint);
  font-size: 11px; font-weight: 500; cursor: pointer; position: relative;
}
.tab.active { color: var(--text); }
.tab .badge { position: absolute; top: 0; left: calc(50% + 6px); }
.tab-plus .plus {
  width: 44px; height: 32px; border-radius: 999px; background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
}

@media (min-width: 960px) {
  #app { display: grid; grid-template-columns: 248px 1fr; }
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: 0; height: 100vh; padding: 20px 12px;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .main { padding: 8px 40px 48px; max-width: 1180px; width: 100%; margin: 0; }
  .main.wide { max-width: none; }
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 22px; font-weight: 600; font-size: 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500; cursor: pointer; border: 0; background: none; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.nav-item .badge { margin-left: auto; }
.nav-primary { background: var(--primary); color: var(--on-primary); justify-content: center; margin: 8px 0 14px; }
.nav-primary:hover { background: var(--primary); color: var(--on-primary); opacity: .9; }
.sidebar-foot { margin-top: auto; padding: 12px; display: flex; align-items: center; gap: 10px; font-size: 13px; }

/* ───────── typography & blocks ───────── */
.page-head { padding: 18px 0 14px; display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 600; letter-spacing: -.02em; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.page-head .grow { flex: 1 1 260px; min-width: 0; }
h2.section { font-size: 13px; font-weight: 600; color: var(--muted); margin: 26px 0 10px; text-transform: none; letter-spacing: 0; display: flex; align-items: center; gap: 8px; }
h2.section .link { margin-left: auto; font-weight: 500; color: var(--text); cursor: pointer; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.card { background: var(--surface); border-radius: var(--radius-lg); padding: 16px; }
.card.outline { background: var(--bg); border: 1px solid var(--border); }

/* ───────── stats ───────── */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } .stats.six { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .stats.six { grid-template-columns: repeat(6, 1fr); } }
.stat {
  background: var(--surface); border-radius: var(--radius-lg); padding: 14px 16px 16px;
  border: 0; text-align: left; cursor: pointer; transition: transform .12s ease, background .12s;
}
.stat:active { transform: scale(.98); }
.stat:hover { background: var(--surface-2); }
.stat .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; line-height: 1; }
.stat.alert .value { color: var(--danger); }
.stat.static { cursor: default; }
.stat.static:hover { background: var(--surface); }

/* ───────── buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--primary); color: var(--on-primary); font-weight: 500; white-space: nowrap;
  transition: opacity .12s, transform .12s;
}
.btn:active { transform: scale(.98); }
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); }
.btn.secondary:hover { background: var(--surface-2); opacity: 1; }
.btn.outline { background: transparent; color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.sm { height: 34px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.icon { width: 40px; padding: 0; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px 12px;
  border-radius: var(--radius); background: var(--surface); border: 0; cursor: pointer; font-size: 13px; font-weight: 500;
}
.action:hover { background: var(--surface-2); }
.action.primary { background: var(--primary); color: var(--on-primary); }
.action.primary:hover { opacity: .9; }
.action:disabled { opacity: .35; cursor: default; }

/* ───────── chips ───────── */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
@media (min-width: 960px) { .chips { margin: 0; padding-left: 0; padding-right: 0; flex-wrap: wrap; } }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; height: 34px; padding: 0 14px; border-radius: 999px; border: 0; cursor: pointer;
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--primary); color: var(--on-primary); }
.chip .n { color: var(--faint); font-weight: 500; }
.chip.active .n { color: inherit; opacity: .6; }
.chip-sep { width: 1px; background: var(--border); margin: 6px 4px; flex-shrink: 0; }

.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 600; display: inline-grid; place-items: center; line-height: 1;
}
.badge.neutral { background: var(--surface-2); color: var(--text); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.info { background: color-mix(in srgb, var(--s-new) 14%, transparent); color: var(--s-new); }

/* ───────── list ───────── */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 10px; margin: 0 -10px;
  border-radius: 12px; cursor: pointer; transition: background .1s;
}
.item:hover { background: var(--surface); }
.item.active { background: var(--surface); }
.item + .item { box-shadow: 0 -1px 0 var(--border); }
.item:hover + .item, .item.active + .item { box-shadow: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center; font-weight: 600; font-size: 14px; flex-shrink: 0; position: relative;
}
.avatar .unread { position: absolute; top: -2px; right: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--s-new); box-shadow: 0 0 0 2px var(--bg); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }

/* ───────── search ───────── */
.search { position: relative; margin-bottom: 12px; }
.search input { padding-left: 42px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--faint); }

/* ───────── forms ───────── */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg); outline: none; transition: border-color .12s, box-shadow .12s; font-size: 16px;
}
textarea.input { height: auto; min-height: 88px; padding: 12px 14px; resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.input.big { height: 64px; font-size: 32px; font-weight: 600; letter-spacing: -.02em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select.input { height: 38px; width: auto; font-size: 14px; border-radius: 999px; background-position: calc(100% - 18px) 16px, calc(100% - 13px) 16px; }

.seg { display: flex; background: var(--surface); padding: 3px; border-radius: 12px; gap: 2px; }
.seg button { flex: 1; height: 36px; padding: 0 10px; white-space: nowrap; border: 0; background: transparent; border-radius: 9px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
:root[data-theme="dark"] .seg button.active { background: var(--surface-2); }

/* ───────── lead detail ───────── */
.split { display: block; }
@media (min-width: 960px) {
  .split { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 32px; align-items: start; }
  .split .pane-list { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; padding: 0 10px 40px; margin: 0 -10px; }
  .split .pane-detail { padding-top: 18px; min-width: 0; }
  .split.mobile-detail .pane-list, .split.mobile-list .pane-detail { display: block; }
}
@media (max-width: 959px) {
  .split.mobile-detail .pane-list { display: none; }
  .split.mobile-list .pane-detail { display: none; }
}
.detail-empty { height: 60vh; display: grid; place-items: center; color: var(--faint); }

.lead-head { padding: 14px 0 16px; }
.lead-head h1 { font-size: 26px; margin: 0; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
.lead-head .sub { color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); padding: 12px 0 0; background: none; border: 0; cursor: pointer; font-weight: 500; }
@media (min-width: 960px) { .back.mobile-only { display: none; } }

.stepper { display: flex; gap: 4px; }
.step {
  flex: 1; border: 0; cursor: pointer; background: transparent; padding: 0; text-align: left; color: var(--faint);
  font-size: 12px; font-weight: 500; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (min-width: 960px) { .step { font-size: 13px; } }
.step .bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin-bottom: 7px; transition: background .2s; }
.step.done .bar { background: var(--text); }
.step.done { color: var(--muted); }
.step.current { color: var(--text); font-weight: 600; }
.step.current .bar { background: var(--text); }
.step.signed.done .bar { background: var(--s-signed); }

.banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); }
.banner.danger { background: var(--danger-bg); }
.banner.ok { background: color-mix(in srgb, var(--s-signed) 12%, transparent); }
.banner .body { flex: 1; min-width: 0; }
.banner b { display: block; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

/* composer + timeline */
.composer { background: var(--surface); border-radius: var(--radius-lg); padding: 10px; }
.composer textarea { border: 0; background: transparent; width: 100%; resize: none; outline: none; padding: 6px 8px; min-height: 44px; max-height: 200px; font-size: 15px; }
.composer .bar { display: flex; align-items: center; gap: 6px; }
.composer .seg { background: var(--bg); }
.composer .seg button { height: 30px; padding: 0 12px; font-size: 13px; }
:root[data-theme="dark"] .composer .seg { background: var(--bg); }

.timeline { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.ev-sys { font-size: 12px; color: var(--faint); text-align: center; padding: 2px 0; }
.ev-sys b { font-weight: 500; color: var(--muted); }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.bubble .t { font-size: 11px; opacity: .55; margin-top: 3px; }
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 6px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); color: var(--on-bubble-out); border-bottom-right-radius: 6px; }
.note { background: var(--note-bg); border-radius: 14px; padding: 10px 13px; white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }
.note .t, .mail .t { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; }
.mail { border: 1px solid var(--border); border-radius: 14px; padding: 10px 13px; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; color: var(--muted); max-height: 220px; overflow: auto; }

/* ───────── charts ───────── */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 140px; padding-top: 8px; }
.bars .b { flex: 1; background: var(--chart-a); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; cursor: default; }
.bars .b:hover { opacity: .75; }
.bars .b.zero { background: var(--surface-2); }
.bars-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 6px; }
.hbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 14px; }
.hbar + .hbar { margin-top: 12px; }
.hbar .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 999px; background: var(--text); }
.hbar .v { font-variant-numeric: tabular-nums; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.gbars { display: flex; align-items: flex-end; gap: 14px; height: 150px; }
.gbars .g { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.gbars .pair { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.gbars .pair div { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.gbars .lbl { font-size: 11px; color: var(--faint); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
.scroll-x { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }

/* finance */
.money { font-variant-numeric: tabular-nums; }
.fin-hero { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fin-hero .stat .value { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fin-hero .stat:last-child { grid-column: 1 / -1; }
@media (min-width: 700px) {
  .fin-hero { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fin-hero .stat:last-child { grid-column: auto; }
  .fin-hero .stat .value { font-size: 28px; }
}
.pos { color: var(--accent); }
.neg { color: var(--danger); }
.accounts { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.accounts::-webkit-scrollbar { display: none; }
.account { min-width: 150px; background: var(--surface); border-radius: var(--radius); padding: 12px 14px; flex-shrink: 0; }
.account .n { font-size: 13px; color: var(--muted); }
.account .v { font-weight: 600; font-size: 18px; margin-top: 2px; }
.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch .m { min-width: 128px; text-align: center; font-weight: 500; }
.tx-day { font-size: 12px; color: var(--faint); font-weight: 500; padding: 14px 0 2px; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 6px; }

.fab {
  position: fixed; right: 16px; bottom: calc(80px + var(--safe-bottom)); z-index: 15;
  height: 52px; padding: 0 20px; border-radius: 999px; border: 0; background: var(--primary); color: var(--on-primary);
  font-weight: 600; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow); cursor: pointer;
}
@media (min-width: 960px) { .fab { bottom: 32px; right: 40px; } }

/* ───────── sheet ───────── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg);
  border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + var(--safe-bottom));
  max-height: 92vh; overflow-y: auto; animation: up .22s cubic-bezier(.2,.9,.3,1);
}
.sheet .grip { width: 36px; height: 5px; border-radius: 9px; background: var(--surface-2); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 16px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 480px; transform: translate(-50%, -50%); border-radius: 22px; padding: 24px; animation: pop .18s ease; }
  .sheet .grip { display: none; }
}
@keyframes fade { from { opacity: 0 } }
@keyframes up { from { transform: translateY(100%) } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) } }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--primary); color: var(--on-primary); padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* login */
.login { max-width: 420px; margin: 0 auto; padding: 12vh 0 40px; }
.login h1 { font-size: 30px; letter-spacing: -.02em; margin: 18px 0 6px; font-weight: 600; }

.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 12px; }
@keyframes sk { to { background-position: -200% 0 } }

.help ol { padding-left: 20px; margin: 8px 0 0; }
.help li { margin-bottom: 6px; }

/* ───────── этапы кнопками ───────── */
.next-stage { height: 52px; font-size: 15px; margin-bottom: 10px; }
.stages { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stages .stage:last-child { grid-column: 1 / -1; }
@media (min-width: 1100px) { .stages { grid-template-columns: repeat(5, minmax(0, 1fr)); } .stages .stage:last-child { grid-column: auto; } }
.stage {
  display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 8px 12px; border-radius: 14px;
  border: 0; background: var(--bg); color: var(--text); cursor: pointer;
  font-size: 14px; font-weight: 600; text-align: left; line-height: 1.2; letter-spacing: -.01em;
  box-shadow: 0 0 0 1px var(--border), 0 2px 0 var(--border), 0 4px 10px rgba(0,0,0,.05);
  transition: transform .1s, box-shadow .1s, background .12s;
}
.stage:hover { background: var(--surface); }
.stage:active { transform: translateY(2px); box-shadow: 0 0 0 1px var(--border); }
.stage .num {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 700;
}
.stage .num svg { width: 14px; height: 14px; }
.stage.done { color: var(--muted); font-weight: 500; }
.stage.done .num { background: var(--s-signed); color: #fff; }
.stage.current { background: var(--primary); color: var(--on-primary); box-shadow: 0 2px 0 rgba(0,0,0,.25), 0 6px 14px rgba(0,0,0,.18); }
.stage.current .num { background: var(--on-primary); color: var(--primary); }
.stage.signed.current { background: var(--s-signed); color: #fff; }
.stage.signed.current .num { background: #fff; color: var(--s-signed); }

.next-card .row { align-items: flex-start; }
.next-card .row svg { margin-top: 3px; }
.next-card.overdue { background: var(--danger-bg); }
.grow { flex: 1; min-width: 0; }

/* ───────── админ ───────── */
.sidebar-mode { padding: 8px 0 0; }
.sidebar-mode .seg { background: var(--surface-2); }
.sidebar-mode .seg button { font-size: 13px; height: 32px; }
#admin-bar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--surface); color: var(--text); font-size: 13px; border-bottom: 1px solid var(--border);
}
#admin-bar .who { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#admin-bar.viewing { background: #2f6fed; color: #fff; border-color: #2f6fed; }
#admin-bar button { border: 0; background: var(--primary); color: var(--on-primary); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: 13px; cursor: pointer; flex-shrink: 0; }
#admin-bar.viewing button { background: #fff; color: #2f6fed; }
@media (min-width: 960px) { #admin-bar { padding-left: 264px; } }
.who-opt.active { background: var(--surface); }
.who-opt .check { color: var(--s-signed); }

.boot-msg { min-height: 60vh; display: grid; place-items: center; color: var(--muted); font-size: 15px; }


/* чат лида */
.chat { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; background: var(--bg); }
.chat-log { display: flex; flex-direction: column; gap: 8px; padding: 14px; max-height: min(60vh, 520px); min-height: 120px; overflow-y: auto; background: var(--surface); }
.chat-empty { margin: auto; color: var(--faint); font-size: 14px; }
.chat-foot { padding: 10px; border-top: 1px solid var(--border); }
.chat-composer { background: var(--surface); }
.chat-note { font-size: 13px; color: var(--muted); margin: 4px 4px 10px; line-height: 1.45; }
.chat-foot .composer + .chat-note { margin: 8px 4px 0; }

/* финансы */
.fin-period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fin-period .seg { min-width: 160px; }
.fin-curs { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .fin-curs { grid-template-columns: 1fr 1fr; } }
.fin-cur.dim { opacity: .55; }
.fin-rows { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.fin-rows > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fin-rows b { font-size: 19px; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 1100px) { .fin-rows b { font-size: 22px; } }
.chg { font-size: 12px; color: var(--muted); }
.chg.pos { color: var(--accent); } .chg.neg { color: var(--danger); }
.fin-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-top: 26px; }
.seg-sm button { height: 28px; font-size: 13px; padding: 0 12px; }
.fin-filters .filters select.input { height: 38px; }

/* вкладки карточки лида */
.lead-tabs { position: sticky; top: 0; z-index: 6; margin-top: 16px; box-shadow: 0 0 0 6px var(--bg); }
.lead-tabs button { position: relative; }
.tab-dot { position: absolute; top: 7px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--s-new); }
.tab-pane > h2.section:first-child { margin-top: 18px; }
body:has(#admin-bar) .lead-tabs { top: 45px; }

/* вложения и перевод в чате */
.att-img { display: block; max-width: 240px; max-height: 300px; border-radius: 12px; margin: -2px -4px 6px; cursor: pointer; background: var(--surface-2); }
.att-audio { width: 230px; max-width: 100%; margin-bottom: 4px; }
.att-file { display: inline-flex; gap: 6px; align-items: center; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, currentColor 10%, transparent); cursor: pointer; margin-bottom: 4px; max-width: 100%; }
.att-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: underline; }
.bubble .tr { margin-top: 6px; padding-top: 6px; border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent); font-size: 13.5px; opacity: .85; }
.tr-btn { text-decoration: underline; cursor: pointer; }
.att-preview { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 8px 6px; color: var(--muted); }
.att-preview span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-composer .bar { flex-wrap: wrap; }
.chat-composer .chip { height: 30px; font-size: 13px; }
@media (max-width: 420px) { .hide-xs { display: none; } }
.fin-total { margin-top: 0; }
.fin-rows .faint.small { font-size: 12px; }
.bubble { white-space: normal; }
.bubble .txt, .bubble .tr { white-space: pre-wrap; }
.ch-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.ch-chips .chip { height: 30px; font-size: 13px; }
.bubble .orig { font-size: 12.5px; opacity: .65; margin-top: 4px; white-space: pre-wrap; }
.bubble .orig-btn { display: inline-block; font-size: 12px; opacity: .6; margin-top: 4px; cursor: pointer; text-decoration: underline; }

/* ───────── чат как в Telegram ───────── */
.chat-log { flex: 1; max-height: none; min-height: 0; gap: 4px; padding: 10px 10px 12px; }
.bubble { max-width: 84%; padding: 7px 11px 6px; border-radius: 16px; font-size: 15px; line-height: 1.38; cursor: pointer; transition: background .2s; }
.bubble + .bubble.in, .bubble.out + .bubble.out { margin-top: 0; }
.bubble.in + .bubble.out, .bubble.out + .bubble.in { margin-top: 6px; }
.bubble .t { font-size: 11px; opacity: .55; margin-top: 2px; text-align: right; }
.bubble.flash { box-shadow: 0 0 0 3px var(--s-new); }
.bubble.preview { cursor: default; max-width: 100%; margin-bottom: 12px; }
.quote { border-left: 3px solid var(--s-new); padding: 2px 8px; margin: 2px 0 5px; font-size: 13px; opacity: .9; border-radius: 4px; background: color-mix(in srgb, var(--s-new) 10%, transparent); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.quote b { display: block; font-size: 12px; color: var(--s-new); }
.bubble.out .quote { border-color: currentColor; background: color-mix(in srgb, currentColor 12%, transparent); }
.bubble.out .quote b { color: inherit; }
.day-sep { display: flex; justify-content: center; margin: 8px 0 4px; }
.day-sep span { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--bg); padding: 3px 10px; border-radius: 999px; }
.chat-foot { padding: 8px; }
.cmp { display: flex; flex-direction: column; gap: 6px; }
.cmp-row { display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border-radius: 22px; padding: 4px 4px 4px 6px; }
.cmp-row textarea { flex: 1; border: 0; background: transparent; resize: none; outline: none; padding: 9px 4px; min-height: 40px; max-height: 140px; font-size: 16px; line-height: 1.35; }
.cmp-icon { width: 38px; height: 38px; display: grid; place-items: center; font-size: 19px; cursor: pointer; border-radius: 50%; flex-shrink: 0; }
.cmp-icon:hover { background: var(--surface-2); }
.cmp-send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.cmp-send:disabled { opacity: .4; }
.cmp-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cmp-tools .chip { height: 28px; font-size: 12.5px; padding: 0 10px; }
.reply-bar { display: flex; align-items: center; gap: 6px; }
.reply-bar .quote { flex: 1; margin: 0; }
.chat { display: flex; flex-direction: column; height: 420px; min-height: 320px; }

/* Свайп сообщения влево — ответить (как в Telegram) */
#chat-log .bubble { touch-action: pan-y; position: relative; }
#chat-log .bubble::after { content: "↩"; position: absolute; right: -34px; top: 50%; transform: translateY(-50%) scale(.6);
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 14px;
  background: var(--surface-2, rgba(127,127,127,.18)); color: var(--text); opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none; }
#chat-log .bubble.swipe-ready::after { opacity: 1; transform: translateY(-50%) scale(1); }
#chat-log { overflow-x: hidden; }
@media (max-width: 420px) { .fin-total .fin-rows b { font-size: 17px; } }
