/* Романос — стили. Светлая и тёмная тема через CSS-переменные. */
:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f7f8fb;
  --text: #172b4d;
  --muted: #6b778c;
  --border: #e1e5ee;
  --accent: #2f6bff;
  --accent-2: #1f55e0;
  --accent-weak: #e8efff;
  --sidebar: #141d33;
  --sidebar-2: #1c2745;
  --sidebar-text: #b9c4dc;
  --col-bg: #f0f2f6;
  --card: #ffffff;
  --danger: #e5484d;
  --danger-weak: #fdecec;
  --green: #1f9d55;
  --green-weak: #e6f6ec;
  --amber: #d97706;
  --amber-weak: #fff4e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 12px;
  --in-bubble: #ffffff;
  --out-bubble: #dbe7ff;
  --chat-bg: #e9edf3;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0d1220;
  --panel: #161d2e;
  --panel-2: #1b2336;
  --text: #e5e9f2;
  --muted: #8e9ab3;
  --border: #263049;
  --accent: #4c82ff;
  --accent-2: #6b97ff;
  --accent-weak: #1d2a4d;
  --sidebar: #0a0f1c;
  --sidebar-2: #151d33;
  --sidebar-text: #a9b4cc;
  --col-bg: #111827;
  --card: #1c2539;
  --danger-weak: #3a1d22;
  --green-weak: #15301f;
  --amber-weak: #33270f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  --in-bubble: #1f2940;
  --out-bubble: #23407a;
  --chat-bg: #0f1525;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
code { background: var(--panel-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; font-size: 12px; word-break: break-all; }
.i { flex-shrink: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row.end { justify-content: flex-end; }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; text-decoration: none !important; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.xs { width: 24px; height: 24px; }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.attn { color: var(--amber); animation: pulse 1.6s infinite; }
.icon-btn.light { color: rgba(255, 255, 255, .85); }
.icon-btn.light:hover { background: rgba(255, 255, 255, .18); color: #fff; }
@keyframes pulse { 50% { transform: scale(1.12); } }

.input {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
select.input { padding-right: 6px; cursor: pointer; }
.fld { display: block; margin: 10px 0; }
.fld > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.file { display: block; margin: 10px 0; max-width: 100%; }

.switch { display: flex; align-items: center; gap: 10px; margin: 10px 0; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch span { position: relative; width: 38px; height: 22px; border-radius: 11px; background: var(--border); transition: background .2s; flex-shrink: 0; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.new { background: var(--green-weak); color: var(--green); }
.pill.st-online { background: var(--green-weak); color: var(--green); }
.pill.st-connecting { background: var(--amber-weak); color: var(--amber); }
.pill.st-error { background: var(--danger-weak); color: var(--danger); }

/* ---------- Каркас ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 14px 10px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; text-decoration: none !important; }
.brand b { display: block; font-size: 17px; letter-spacing: .2px; }
.brand small { display: block; font-size: 11px; color: var(--sidebar-text); opacity: .8; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6 60%, #ec4899); color: #fff; font-weight: 800; font-size: 19px;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .45);
}
.logo.sm { width: 30px; height: 30px; font-size: 16px; border-radius: 8px; }
.logo.big { width: 64px; height: 64px; font-size: 34px; border-radius: 18px; margin: 0 auto 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-text); text-decoration: none !important; font-weight: 500; position: relative;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(47, 107, 255, .35); }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.nav-badge.warn { background: var(--amber); }
.side-foot { margin-top: auto; padding-top: 18px; }
.side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; opacity: .6; padding: 0 12px 6px; }
.side-ch { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 8px; color: var(--sidebar-text); text-decoration: none !important; }
.side-ch:hover { background: var(--sidebar-2); }
.side-ch span { flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5b6478; }
.dot.online { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.dot.connecting { background: #f59e0b; }
.dot.error { background: #ef4444; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; height: 58px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tb-brand { display: none; }
.tb-title { font-size: 18px; font-weight: 700; margin-right: 12px; white-space: nowrap; }
.tb-settings { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 520px; }
.search { width: 100%; height: 38px; border-radius: 10px; border: 1px solid transparent; background: var(--panel-2); color: var(--text); font: inherit; padding: 0 12px 0 36px; outline: none; }
.search:focus { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-weak); }
.search-ic { position: absolute; left: 11px; top: 11px; color: var(--muted); }
.search-results { position: absolute; top: 44px; left: 0; right: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 50; max-height: 70vh; overflow-y: auto; padding: 6px; }
.sr-head { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 8px 10px 4px; }
.sr-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.sr-row:hover { background: var(--panel-2); }
.sr-row small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.sr-empty { padding: 14px; color: var(--muted); text-align: center; }
.offline { display: inline-flex; align-items: center; gap: 4px; color: var(--danger); font-size: 12px; font-weight: 600; }
.view { flex: 1; min-height: 0; overflow: auto; }
.view-inbox, .view-deals, .view-board { overflow: hidden; display: flex; flex-direction: column; }
.tabbar { display: none; }

.page { padding: 24px; max-width: 1280px; margin: 0 auto; }
.page.wide { max-width: none; }
.page-head { display: flex; align-items: center; margin-bottom: 16px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); padding: 28px 12px; text-align: center; }
.empty p { margin: 0; }

/* ---------- Аватары и иконки каналов ---------- */
.ava {
  position: relative; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, hsl(var(--h), 70%, 58%), hsl(calc(var(--h) + 40), 70%, 48%));
}
.ava-ch { position: absolute; right: -3px; bottom: -3px; border-radius: 50%; box-shadow: 0 0 0 2px var(--panel); display: flex; }
.ch-ic { display: inline-grid; place-items: center; border-radius: 50%; background: var(--ch); color: #fff; flex-shrink: 0; vertical-align: middle; }
.ch-ic b { font-weight: 800; line-height: 1; }
.qual { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; font-size: 11px; font-weight: 800; color: #fff; background: var(--q); flex-shrink: 0; }

/* ---------- Главная ---------- */
.hello { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.hello h2 { font-size: 26px; }
.hello p { margin: 4px 0 0; }
.hello p::first-letter { text-transform: uppercase; }
.banner { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-weak); border: 1px solid transparent; margin-bottom: 14px; flex-wrap: wrap; }
.banner > .i { color: var(--accent); }
.banner > div:not(.banner-actions) { flex: 1; min-width: 220px; }
.banner.info { background: var(--amber-weak); }
.banner.info > .i { color: var(--amber); }
.banner-actions { display: flex; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--border); color: var(--text); text-decoration: none !important; transition: transform .15s; }
.kpi:hover { transform: translateY(-2px); }
.kpi.red { border-top-color: var(--danger); }
.kpi.red .kpi-value { color: var(--danger); }
.kpi.amber { border-top-color: var(--amber); }
.kpi.green { border-top-color: var(--green); }
.kpi.blue { border-top-color: var(--accent); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; margin: 4px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.panel-head a { font-size: 13px; }
.row-link { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 8px; color: var(--text); text-decoration: none !important; cursor: pointer; }
.row-link:hover { background: var(--panel-2); }
.fbar { margin: 10px 0; }
.fbar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; gap: 8px; }
.fbar-track { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.fbar-track div { height: 100%; border-radius: 4px; min-width: 4px; transition: width .3s; }

.wait { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--amber); white-space: nowrap; }
.wait.over { color: var(--danger); }
.wait.tiny { font-size: 11px; }
.due { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.due.late { background: var(--danger); color: #fff; }
.due.today { background: var(--amber); color: #fff; }
.due.done { background: var(--green); color: #fff; }

/* ---------- Единый чат ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr auto; flex: 1; min-height: 0; }
.conv-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); min-height: 0; }
.pane-head { padding: 12px 12px 6px; }
.chips { display: flex; gap: 6px; padding: 4px 12px 10px; overflow-x: auto; flex-shrink: 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.conv-list { flex: 1; overflow-y: auto; }
/* Папки чатов (вкладки как в Telegram) */
.ftabs { display: flex; gap: 2px; padding: 8px 8px 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.ftabs::-webkit-scrollbar { display: none; }
.ftab { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ftab:hover { color: var(--text); }
.ftab.on { color: var(--accent); border-bottom-color: var(--accent); }
.ftab.add { font-size: 18px; padding: 4px 10px; }
.ftab-n { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; display: grid; place-items: center; }
.ftab:not(.on) .ftab-n { background: var(--muted); }
.kind { font-size: 13px; flex-shrink: 0; }
.fold-tag { font-size: 10px; padding: 1px 6px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.badge.grey { background: var(--muted); }
.muted-conv .conv-name { color: var(--muted); }
.msg-author { font-size: 12px; font-weight: 700; margin-bottom: 2px; }
.fold-select { width: auto; max-width: 150px; height: 30px; font-size: 13px; padding: 0 4px; }
.center { text-align: center; padding: 8px; }
.nowrap { white-space: nowrap; }
.wide-card { grid-column: 1 / -1; }
.conv { display: flex; gap: 12px; padding: 10px 12px; cursor: pointer; border-left: 3px solid transparent; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-weak); border-left-color: var(--accent); }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: center; gap: 6px; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.conv-bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.conv-text { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv.unread .conv-text { color: var(--text); font-weight: 500; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.conv .wait { margin-top: 3px; }

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 380px; }
.chat-empty h3 { color: var(--text); margin: 12px 0 6px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-head .back { display: none; }
.chat-title { cursor: pointer; }
.chat-title b, .chat-title small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-warn { display: flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--amber-weak); color: var(--amber); font-size: 13px; font-weight: 500; flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 4px; }
.msgs.compact { padding: 10px 0; max-height: 52vh; }
.day { text-align: center; margin: 10px 0 6px; }
.day span { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 10px; background: var(--panel); color: var(--muted); box-shadow: var(--shadow); }
.msg { display: flex; flex-direction: column; max-width: 72%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 7px 10px 6px; border-radius: 14px; background: var(--in-bubble); box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in .bubble { border-bottom-left-radius: 4px; }
.msg.out .bubble { background: var(--out-bubble); border-bottom-right-radius: 4px; }
.msg.err .bubble { outline: 1px solid var(--danger); }
.meta { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.msg-err { font-size: 12px; color: var(--danger); margin-top: 3px; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--border); flex-shrink: 0; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 18px; padding: 8px 14px; font: inherit; background: var(--panel-2); color: var(--text); outline: none; max-height: 160px; line-height: 1.4; min-height: 38px; }
.composer textarea:focus { border-color: var(--accent); background: var(--panel); }
.send-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.send-btn:hover { background: var(--accent-2); }
.popover { position: absolute; z-index: 30; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; }
.templates { left: 12px; right: 12px; bottom: 64px; max-height: 50%; overflow-y: auto; }
.tpl { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.tpl:hover { background: var(--panel-2); }
.templates a { display: block; padding: 6px 10px; }

.client-pane { width: 320px; border-left: 1px solid var(--border); background: var(--panel); overflow-y: auto; }
.cp { padding: 16px; }
.cp-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.cp-head b { font-size: 16px; }
.cp-empty { padding: 32px 18px; text-align: center; color: var(--muted); }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg-btn { flex: 1; min-width: 80px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; padding: 0 6px; }
.seg-btn:hover { border-color: var(--q); }
.seg-btn.on { background: var(--q); border-color: var(--q); color: #fff; }
.mini-task { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; background: var(--panel-2); margin-bottom: 5px; cursor: pointer; font-size: 13px; }
.mini-task:hover { background: var(--accent-weak); }

/* ---------- Канбан (сделки и доски) ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; flex-wrap: wrap; flex-shrink: 0; }
.toolbar .input { width: auto; min-width: 150px; }
.toolbar input.input { min-width: 220px; }
.deals { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.kanban { display: flex; gap: 12px; align-items: flex-start; padding: 4px 16px 16px; overflow-x: auto; flex: 1; min-height: 0; }
.col { width: 284px; flex-shrink: 0; background: var(--col-bg); border-radius: var(--radius); display: flex; flex-direction: column; max-height: 100%; position: relative; }
.col-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px 12px; }
.col-head.stage { display: block; border-top: 4px solid var(--c); border-radius: var(--radius) var(--radius) 0 0; }
.col-title-row { display: flex; align-items: center; gap: 6px; }
.col-title { font-weight: 700; flex: 1; }
.col-count { font-size: 12px; color: var(--muted); background: var(--panel); border-radius: 10px; padding: 1px 8px; font-weight: 600; }
.col-sum { font-size: 13px; color: var(--muted); margin-top: 2px; font-weight: 600; }
.col-title-input { flex: 1; min-width: 0; border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; font-weight: 700; padding: 4px 6px; border-radius: 6px; outline: none; }
.col-title-input:focus { background: var(--panel); border-color: var(--accent); }
.col-body { padding: 4px 8px; overflow-y: auto; min-height: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.kcard {
  background: var(--card); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); cursor: pointer;
  border: 1px solid transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.kcard:hover { border-color: var(--accent); }
.kcard.archived { opacity: .55; }
.kcard-title { overflow-wrap: anywhere; }
.labels { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.lbl { display: inline-block; min-width: 40px; height: 18px; line-height: 18px; padding: 0 8px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #172b4d; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.badges:empty { display: none; }
.badges span { display: inline-flex; align-items: center; gap: 3px; }
.badges .ok { color: var(--green); }
.client-chip { background: var(--accent-weak); color: var(--accent); padding: 1px 6px; border-radius: 4px; }
.add-card, .add-list { display: flex; align-items: center; gap: 6px; margin: 4px 8px 8px; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; cursor: pointer; text-align: left; }
.add-card:hover, .add-list:hover { background: rgba(127, 127, 127, .14); color: var(--text); }
.add-col { background: rgba(255, 255, 255, .22); }
.add-list { margin: 0; width: 100%; color: inherit; font-weight: 600; padding: 12px; }
.add-form { padding: 4px 8px 8px; }
.add-form .row { margin-top: 6px; }
.list-menu { top: 44px; right: 8px; display: flex; flex-direction: column; min-width: 200px; }
.list-menu button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; text-align: left; border-radius: 8px; cursor: pointer; }
.list-menu button:hover { background: var(--panel-2); }
.list-menu .danger { color: var(--danger); }

.deal .deal-top { display: flex; align-items: center; gap: 6px; }
.deal-meta { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.money { font-weight: 700; }
.chs { display: flex; gap: 3px; }
.deal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }

/* Перетаскивание */
.drag-ghost { position: fixed; top: 0; left: 0; z-index: 1000; pointer-events: none; box-shadow: var(--shadow-lg); opacity: .95; border-color: var(--accent) !important; }
.drag-src { display: none !important; }
.drag-ph { border-radius: 10px; background: rgba(47, 107, 255, .12); border: 2px dashed var(--accent); flex-shrink: 0; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none !important; }

/* Доска в стиле Trello */
.board { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--board); background-image: linear-gradient(180deg, rgba(0, 0, 0, .12), rgba(0, 0, 0, .28)); }
.board-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; color: #fff; flex-shrink: 0; background: rgba(0, 0, 0, .18); }
.board-title { background: transparent; border: 1px solid transparent; color: #fff; font: inherit; font-size: 18px; font-weight: 700; padding: 4px 8px; border-radius: 6px; min-width: 0; width: min(420px, 60vw); outline: none; }
.board-title:hover { background: rgba(255, 255, 255, .15); }
.board-title:focus { background: var(--panel); color: var(--text); }
.board-opt { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.board-opt:hover { background: rgba(255, 255, 255, .15); }
.board-opt.color input { width: 26px; height: 26px; border: 0; padding: 0; background: none; cursor: pointer; }
.board .kanban { padding-top: 12px; }
.board .add-col { color: #fff; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.board-tile { position: relative; display: flex; flex-direction: column; justify-content: space-between; height: 112px; padding: 14px; border-radius: var(--radius); border: 0; background: var(--bg, #0c66e4); background: linear-gradient(135deg, var(--bg), color-mix(in srgb, var(--bg) 65%, #000)); color: #fff; text-decoration: none !important; font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow); transition: transform .15s; }
.board-tile:hover { transform: translateY(-2px); }
.board-tile b { font-size: 16px; }
.board-tile small { opacity: .85; }
.board-tile.new { background: var(--panel); color: var(--muted); border: 2px dashed var(--border); align-items: center; justify-content: center; gap: 6px; box-shadow: none; }
.board-tile.new:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Таблица клиентов ---------- */
.count-line { margin: 0 0 8px; }
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover, .tbl th.sorted { color: var(--text); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; }
.cell-client { display: flex; align-items: center; gap: 10px; }
.stage-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 12px; background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--c); white-space: nowrap; }
.stage-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }

/* ---------- Модальные окна ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(9, 14, 28, .55); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; padding: 18px 20px 20px; animation: rise .18s; }
.modal.wide { max-width: 900px; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.title-input { flex: 1; min-width: 0; font: inherit; font-size: 20px; font-weight: 700; border: 1px solid transparent; background: transparent; color: var(--text); border-radius: 8px; padding: 4px 8px; resize: none; outline: none; overflow: hidden; }
.title-input:hover { background: var(--panel-2); }
.title-input:focus { border-color: var(--accent); background: var(--panel); }
.in-list { padding: 0 8px 8px; }
.inline-select { font: inherit; color: var(--accent); background: transparent; border: 0; cursor: pointer; text-decoration: underline; padding: 0; }
.client-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 8px 10px; }
.modal-grid { display: grid; grid-template-columns: 1fr 230px; gap: 22px; }
.modal-grid.client { grid-template-columns: 290px 1fr; }
.modal h4 { font-size: 13px; display: flex; align-items: center; gap: 6px; margin: 16px 0 8px; color: var(--text); }
.modal-side h4:first-child, .modal-main h4:first-child { margin-top: 6px; }
.label-pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lbl.big { height: 30px; line-height: 30px; min-width: 56px; border: 0; cursor: pointer; opacity: .45; font: inherit; font-size: 12px; font-weight: 700; color: #172b4d; padding: 0 10px; border-radius: 6px; }
.lbl.big.on { opacity: 1; box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.progress { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-bottom: 8px; }
.progress div { height: 100%; background: var(--green); transition: width .3s; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.check-item:hover { background: var(--panel-2); }
.check-item label { flex: 1; display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check-item input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--green); }
.check-item.done span { text-decoration: line-through; color: var(--muted); }
.comments { margin-top: 10px; }
.comment { padding: 8px 10px; background: var(--panel-2); border-radius: 10px; margin-bottom: 8px; }
.comment-head { display: flex; align-items: center; gap: 6px; }
.comment-head .icon-btn { margin-left: auto; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.attach { display: block; font-size: 13px; padding: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none !important; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent); border-bottom-color: var(--accent); }
.tabs.sm .tab { padding: 8px 12px; }
.conv-links { display: flex; flex-wrap: wrap; gap: 6px; }
.timeline { margin-top: 12px; }
.tl-item { display: flex; gap: 10px; padding: 6px 0; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 5px; flex-shrink: 0; box-shadow: 0 0 0 3px var(--accent-weak); }
.tl-item.note .tl-dot { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-weak); }
.tl-item.lead .tl-dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-weak); }
.board-preview { height: 80px; border-radius: 10px; background: linear-gradient(135deg, var(--bg), color-mix(in srgb, var(--bg) 60%, #000)); margin: 8px 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 36px; height: 28px; border-radius: 6px; border: 0; cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }

/* ---------- Настройки ---------- */
.settings { max-width: 1100px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.integ-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.integ-head h3 { margin: 0; }
.integ details { margin: 8px 0; background: var(--panel-2); border-radius: 10px; padding: 8px 12px; }
.integ summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.integ ol, .panel ol { padding-left: 20px; margin: 8px 0; }
.integ li, .panel li { margin: 4px 0; }
.err-box { display: flex; gap: 6px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--danger-weak); color: var(--danger); font-size: 13px; margin: 6px 0; overflow-wrap: anywhere; }
.stage-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.stage-row input[type="color"] { width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--panel); cursor: pointer; flex-shrink: 0; }
.stage-row select.input { width: 120px; flex-shrink: 0; }
.import-log { margin-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.import-log .err { color: var(--danger); }
.addr { margin: 6px 0; font-size: 15px; }
.addr code { font-size: 14px; padding: 4px 8px; }

/* ---------- Тосты ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; background: var(--panel); color: var(--text); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-lg); border-left: 4px solid var(--accent); cursor: pointer; animation: slide .25s; transition: opacity .4s, transform .4s; }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--amber); }
.toast.out { opacity: 0; transform: translateX(30px); }
.toast-text { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

/* ---------- Вход ---------- */
.login { height: 100vh; height: 100dvh; overflow-y: auto; display: grid; place-items: safe center; padding: 20px; background: radial-gradient(circle at 20% 10%, rgba(99, 102, 241, .25), transparent 50%), radial-gradient(circle at 80% 90%, rgba(236, 72, 153, .18), transparent 50%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow-lg); text-align: center; }
.login-card h1 { font-size: 26px; margin-bottom: 6px; }
.login-card .fld { text-align: left; }
.err-text { color: var(--danger); min-height: 20px; font-size: 13px; margin: 4px 0; font-weight: 600; }
.forgot { display: block; margin: 14px auto 0; font-size: 14px; }
.recover-steps { text-align: left; background: var(--panel-2); border-radius: 10px; padding: 4px 14px; margin: 12px 0; font-size: 14px; }
.ok-text:empty { display: none; }
.ok-text { color: var(--green); font-size: 13px; margin: 4px 0 10px; font-weight: 600; }

/* Поле пароля с «глазком» */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 42px; }
.pw-eye { position: absolute; right: 2px; top: 0; width: 38px; height: 36px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; }
.pw-eye:hover { color: var(--text); }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-weak); }
.pw-panel { max-width: 460px; }

/* Тряска при неверном пароле */
.shake { animation: shake .5s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-10px); }
  40%, 60% { transform: translateX(10px); }
}
/* ---------- Адаптив ---------- */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .client-pane { display: none; }
  .inbox { grid-template-columns: 320px 1fr; }
}
@media (max-width: 1000px) {
  .grid2 { grid-template-columns: 1fr; }
  .hide-md { display: none; }
  .modal-grid, .modal-grid.client { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .layout.chat-open .main { padding-bottom: 0; }
  .layout.chat-open .tabbar { display: none; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--panel);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); height: calc(60px + env(safe-area-inset-bottom));
  }
  .tabbar .nav-item { flex: 1; flex-direction: column; gap: 2px; padding: 8px 0 6px; border-radius: 0; font-size: 11px; color: var(--muted); justify-content: center; }
  .tabbar .nav-item.active { background: none; color: var(--accent); box-shadow: none; }
  .tabbar .nav-badge { position: absolute; top: 4px; left: 50%; margin-left: 6px; }
  .topbar { padding: 0 10px; gap: 4px; height: 54px; }
  .tb-brand { display: block; }
  .tb-title { display: none; }
  .tb-settings { display: inline-flex; }
  .search-wrap { max-width: none; }
  .search::placeholder { font-size: 13px; }
  .page { padding: 14px; }
  .hello h2 { font-size: 21px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi-value { font-size: 21px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-chat .conv-pane { display: none; }
  .inbox:not(.has-chat) .chat-pane { display: none; }
  .chat-head { padding: 6px 8px; }
  .chat-head .back { display: inline-flex; }
  .msgs { padding: 10px; }
  .msg { max-width: 86%; }
  .hide-sm { display: none; }
  .toolbar { padding: 10px; }
  .toolbar .input, .toolbar input.input { min-width: 0; flex: 1 1 140px; }
  .kanban { padding: 4px 10px 12px; scroll-snap-type: x mandatory; }
  .col { width: 84vw; max-width: 320px; scroll-snap-align: center; }
  .modal-back { padding: 0; align-items: stretch; }
  .modal, .modal.wide { max-width: none; border-radius: 0; min-height: 100%; padding: 14px; }
  .board-head { padding: 8px 10px; }
  .board-title { font-size: 16px; }
  #toasts { right: 10px; left: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); max-width: none; }
  .tbl td, .tbl th { padding: 8px; }
  .settings-grid { grid-template-columns: 1fr; }
  .stage-row { flex-wrap: wrap; }
  .stage-row .input.grow { flex: 1 1 140px; }
}
