/* CRM «Союз». Цвета — из brand/souz/tokens.css, приёмы — как в сайте Гида (brand/gid). */
@font-face{font-family:'Onest';font-style:normal;font-weight:300 900;font-display:swap;src:url('fonts/Onest-normal-cyrillic.woff2') format('woff2');unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116}
@font-face{font-family:'Onest';font-style:normal;font-weight:300 900;font-display:swap;src:url('fonts/Onest-normal-latin.woff2') format('woff2');unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}

:root{
  --red:#B01A0C; --red-deep:#8A1409; --red-100:#F6D9D5; --red-50:#FBEFED;
  --ink:#14110F; --ink-700:#2E2926; --ink-500:#5F5650; --ink-300:#B9B0A8;
  --ivory:#F6F0E8; --ivory-200:#EDE3D6; --line-c:#E6DFD8; --blue:#1F3FD1;

  --bg:var(--ivory);
  --surface:#fff;
  --tile:var(--ivory-200);
  --tile-hover:#E4D8C9;
  --line:var(--line-c);
  --text:var(--ink);
  --text2:var(--ink-500);
  --text3:#8C847D;
  --head:var(--ink);
  --head-text:#fff;
  --action:var(--ink);
  --action-text:#fff;
  --nav:#fff;
  --pad-on:var(--red);
  --late-bg:var(--red-50);
  --late-text:var(--red);
  --focus:var(--blue);
  --shadow-card:0 1px 2px rgba(20,17,15,.06),0 4px 12px rgba(20,17,15,.04);
  --shadow-lift:0 18px 40px rgba(20,17,15,.22);
  --scrim:rgba(20,17,15,.38);

  --font:'Onest',-apple-system,BlinkMacSystemFont,'Segoe UI',system-ui,sans-serif;
  --r-card:14px; --r-pill:999px;
  --h-btn:46px; --h-btn-sm:38px; --h-head:56px; --h-nav:62px;
  --safe-b:max(env(safe-area-inset-bottom,0px),var(--tg-safe-area-inset-bottom,0px));
  --safe-t:max(env(safe-area-inset-top,0px),var(--tg-content-safe-area-inset-top,0px));
  color-scheme:light;
}
:root[data-theme="dark"]{
  --bg:#14110F;
  --surface:var(--ink-700);
  --tile:rgba(246,240,232,.08);
  --tile-hover:rgba(246,240,232,.13);
  --line:rgba(246,240,232,.12);
  --text:var(--ivory);
  --text2:var(--ink-300);
  --text3:#8C847D;
  --head:#0D0B0A;
  --head-text:var(--ivory);
  --action:var(--ivory);
  --action-text:var(--ink);
  --nav:#1C1815;
  --late-bg:rgba(176,26,12,.28);
  --late-text:var(--red-100);
  --focus:#8EA2FF;
  --shadow-card:0 1px 2px rgba(0,0,0,.3);
  --shadow-lift:0 18px 40px rgba(0,0,0,.55);
  --scrim:rgba(0,0,0,.55);
  color-scheme:dark;
}

*{box-sizing:border-box;margin:0;padding:0;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{font-family:var(--font);font-size:15px;line-height:1.45;color:var(--text);background:var(--bg);-webkit-font-smoothing:antialiased;overscroll-behavior:none}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;border:0;background:none}
a{color:inherit}
svg{display:block;flex:none}
.num{font-variant-numeric:tabular-nums}
.muted{color:var(--text2)}
.small{font-size:13px}
.grow{flex:1;min-width:0}
.row{display:flex;align-items:center;gap:8px}
.ellipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
:focus-visible{outline:2px solid var(--focus);outline-offset:2px}

/* ---------- загрузка ---------- */
.boot{height:100vh;display:grid;place-items:center}
.spin{width:28px;height:28px;border-radius:50%;border:3px solid var(--tile);border-top-color:var(--text);animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* ---------- каркас ---------- */
.shell{height:var(--tg-viewport-stable-height,100dvh);display:flex;flex-direction:column;overflow:hidden}
.head{flex:none;height:calc(var(--h-head) + var(--safe-t));padding:var(--safe-t) 12px 0 14px;background:var(--head);color:var(--head-text);display:flex;align-items:center;gap:10px}
.brand{display:flex;align-items:center;gap:9px;min-width:0}
.brand .mark{width:22px;height:22px}
.brand b{font-weight:700;letter-spacing:.06em;font-size:16px}
.brand small{font-weight:500;font-size:13px;opacity:.6;letter-spacing:.02em}
.head .sp{flex:1}
.head .hbtn{width:40px;height:40px;border-radius:12px;display:grid;place-items:center;color:var(--head-text)}
.head .hbtn:hover{background:rgba(255,255,255,.08)}
.ava{width:32px;height:32px;border-radius:50%;background:var(--ivory-200);color:var(--ink);display:grid;place-items:center;font-weight:700;font-size:14px;flex:none}
.topnav{display:none}
.app-main{flex:1;min-height:0;display:flex;flex-direction:column;position:relative}
.page{flex:1;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch}
.page-in{padding:14px 14px 28px;max-width:760px;margin:0 auto}

.nav{flex:none;height:calc(var(--h-nav) + var(--safe-b));padding-bottom:var(--safe-b);background:var(--nav);border-top:1px solid var(--line);display:flex}
.nav button{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font-size:11px;font-weight:600;color:var(--text2)}
.nav .pad{width:48px;height:30px;border-radius:11px;display:grid;place-items:center}
.nav .on{color:var(--text)}
.nav .on .pad{background:var(--pad-on);color:#fff}

@media (min-width:900px){
  .nav{display:none}
  .topnav{display:flex;gap:4px;margin-left:18px}
  .topnav button{height:36px;padding:0 14px;border-radius:var(--r-pill);color:var(--head-text);opacity:.72;font-weight:600;font-size:14px;display:flex;align-items:center;gap:7px}
  .topnav button:hover{opacity:1;background:rgba(255,255,255,.07)}
  .topnav .on{opacity:1;background:rgba(255,255,255,.12)}
  .topnav .on .dot{width:6px;height:6px;border-radius:50%;background:var(--red)}
}

/* ---------- кнопки ---------- */
.btn{text-decoration:none;height:var(--h-btn);padding:0 20px;border-radius:var(--r-pill);font-weight:600;font-size:15px;display:inline-flex;align-items:center;justify-content:center;gap:7px;white-space:nowrap;transition:transform .12s var(--ease,ease),background .15s}
.btn:active{transform:scale(.97)}
.btn.sm{height:var(--h-btn-sm);padding:0 15px;font-size:14px}
.btn.main{background:var(--action);color:var(--action-text)}
.btn.soft{background:var(--tile);color:var(--text)}
.btn.soft:hover{background:var(--tile-hover)}
.btn.ghost{color:var(--text2)}
.btn.danger{background:var(--late-bg);color:var(--late-text)}
.btn.wide{width:100%}
.btn[disabled]{opacity:.45;pointer-events:none}
.ibtn{width:40px;height:40px;border-radius:12px;display:grid;place-items:center;color:var(--text)}
.ibtn:hover{background:var(--tile)}

/* ---------- сегменты (воронки) ---------- */
.seg{display:flex;gap:2px;background:var(--tile);border-radius:var(--r-pill);padding:3px;overflow-x:auto;scrollbar-width:none}
.seg::-webkit-scrollbar{display:none}
.seg button{flex:1 0 auto;height:34px;padding:0 14px;border-radius:var(--r-pill);font-weight:600;font-size:13.5px;color:var(--text2);white-space:nowrap}
.seg .on{background:var(--action);color:var(--action-text)}

/* ---------- доска ---------- */
.dealbar{flex:none;padding:12px 14px 0}
.totals{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:12px 0 10px}
.totals b{font-size:15px;display:block}
.totals small{color:var(--text2);font-size:13px}
.board{flex:1;min-height:0;display:flex;gap:10px;padding:0 14px 12px;overflow-x:auto;overflow-y:hidden;scroll-snap-type:x mandatory;scroll-padding:0 14px;overscroll-behavior-x:contain}
.board.dragging{scroll-snap-type:none}
.col{flex:0 0 min(84vw,300px);display:flex;flex-direction:column;min-height:0;scroll-snap-align:start}
.col-h{flex:none;display:flex;align-items:center;gap:8px;padding:2px 2px 8px}
.col-h i{width:10px;height:10px;border-radius:50%;flex:none}
.col-h b{font-size:14px;font-weight:650;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.col-h .cnt{font-size:12px;font-weight:600;background:var(--tile);border-radius:var(--r-pill);padding:1px 7px;color:var(--text2)}
.col-h .sum{margin-left:auto;font-size:12.5px;color:var(--text2);white-space:nowrap}
.col-list{flex:1;min-height:60px;overflow-y:auto;padding:0 1px 30px;border-radius:12px;scrollbar-width:thin}
.col-list.target{background:var(--tile)}
.col-empty{border:1.5px dashed var(--line);border-radius:12px;padding:14px;text-align:center;color:var(--text3);font-size:13px}
@media (min-width:900px){.col{flex-basis:280px}.board{scroll-snap-type:none}}

.card{background:var(--surface);border-radius:var(--r-card);padding:12px 12px 11px;margin-bottom:8px;box-shadow:var(--shadow-card);cursor:pointer;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;touch-action:pan-x pan-y;transition:transform .15s,box-shadow .15s,opacity .15s}
.card:hover{box-shadow:var(--shadow-card),0 0 0 1px var(--line)}
.card .t{font-weight:600;font-size:15px;line-height:1.25;word-break:break-word}
.card .c{color:var(--text2);font-size:13px;margin-top:3px}
.card .f{display:flex;align-items:center;justify-content:space-between;margin-top:9px;gap:8px}
.card .b{font-weight:650;font-size:14px}
.card .b.none{color:var(--text3);font-weight:500;font-size:13px}
.card .tags{display:flex;gap:4px;flex-wrap:wrap;margin-top:6px}
.tag{font-size:11.5px;font-weight:600;padding:1px 7px;border-radius:6px;background:var(--tile);color:var(--text2)}
.card.ghosted{opacity:.25}
.card.lift{position:fixed;z-index:60;pointer-events:none;box-shadow:var(--shadow-lift);transform:rotate(1.5deg) scale(1.03);transition:none;margin:0}
.drop-line{height:4px;border-radius:2px;background:var(--red);margin:-2px 4px 6px}
.chip{font-size:12px;font-weight:550;padding:3px 8px;border-radius:var(--r-pill);background:var(--tile);color:var(--text2);white-space:nowrap;display:inline-flex;align-items:center;gap:4px}
.chip.late{background:var(--late-bg);color:var(--late-text)}
.chip.today{background:var(--action);color:var(--action-text)}

/* ---------- листы (карточка сделки и формы) ---------- */
.scrim{position:fixed;inset:0;background:var(--scrim);z-index:40;animation:fade .18s}
@keyframes fade{from{opacity:0}}
.sheet{position:fixed;z-index:41;inset:0;background:var(--bg);display:flex;flex-direction:column;animation:up .22s cubic-bezier(.2,.7,.2,1)}
@keyframes up{from{transform:translateY(24px);opacity:.4}}
@media (min-width:900px){
  .sheet{left:auto;width:560px;box-shadow:-20px 0 60px rgba(20,17,15,.18);animation:side .22s cubic-bezier(.2,.7,.2,1)}
  .sheet.small{top:10vh;bottom:auto;right:50%;transform:translateX(50%);width:480px;max-height:80vh;border-radius:20px;animation:none}
  @keyframes side{from{transform:translateX(30px);opacity:.4}}
}
.sh-head{flex:none;display:flex;align-items:center;gap:6px;padding:calc(8px + var(--safe-t)) 8px 8px;border-bottom:1px solid var(--line);background:var(--bg)}
.sh-head h2{font-size:17px;font-weight:700;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;padding-left:4px}
.sh-body{flex:1;min-height:0;overflow-y:auto;padding:14px 14px 24px}
.sh-foot{flex:none;padding:10px 14px calc(10px + var(--safe-b));border-top:1px solid var(--line);background:var(--bg)}

.title-edit{width:100%;font-size:20px;font-weight:700;line-height:1.25;border:0;background:transparent;padding:4px 0;border-radius:8px;resize:none}
.title-edit:focus{outline:none;background:var(--tile);padding:4px 8px}
.stagepick{display:inline-flex;align-items:center;gap:8px;height:34px;padding:0 12px 0 10px;border-radius:var(--r-pill);background:var(--tile);font-weight:600;font-size:13.5px;margin:6px 0 12px;max-width:100%}
.stagepick i{width:10px;height:10px;border-radius:50%;flex:none}

.fields{background:var(--surface);border-radius:var(--r-card);box-shadow:var(--shadow-card);padding:2px 12px;margin-bottom:12px}
.field{display:flex;align-items:center;gap:10px;min-height:46px;border-bottom:1px solid var(--line)}
.field:last-child{border-bottom:0}
.field>span{width:118px;flex:none;color:var(--text2);font-size:13.5px}
.field input,.field select{flex:1;min-width:0;height:44px;border:0;background:transparent;font-size:15px;text-align:left}
.field select{appearance:none;-webkit-appearance:none;cursor:pointer}
.field input:focus,.field select:focus{outline:none}
.field .saved{font-size:12px;color:var(--text3)}

.box{background:var(--surface);border-radius:var(--r-card);box-shadow:var(--shadow-card);padding:12px;margin-bottom:12px}
.box-h{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:6px}
.box-h b{font-size:13px;color:var(--text2);font-weight:600;text-transform:uppercase;letter-spacing:.06em}
.contact-name{font-weight:650;font-size:16px}
.links{display:flex;gap:8px;flex-wrap:wrap;margin-top:8px}

.label{display:block;font-size:13px;color:var(--text2);font-weight:550;margin:12px 0 5px}
.input,.select,.area{width:100%;height:44px;border:1px solid var(--line);border-radius:12px;background:var(--surface);padding:0 12px;font-size:15px}
.area{height:auto;min-height:44px;padding:10px 12px;resize:none;line-height:1.4}
.input:focus,.select:focus,.area:focus{outline:2px solid var(--focus);outline-offset:-1px;border-color:transparent}
.hint{font-size:12.5px;color:var(--text3);margin-top:4px}
.err{font-size:13px;color:var(--late-text);background:var(--late-bg);border-radius:10px;padding:8px 10px;margin-top:10px}

/* ---------- история ---------- */
.tl{display:flex;flex-direction:column;gap:8px}
.tl-day{align-self:center;font-size:12px;font-weight:600;color:var(--text2);background:var(--tile);border-radius:var(--r-pill);padding:2px 10px;margin:6px 0 2px}
.ev{font-size:12.5px;color:var(--text2);padding:0 4px;line-height:1.35}
.ev time{color:var(--text3);margin-right:6px}
.note{background:var(--surface);border-radius:var(--r-card);box-shadow:var(--shadow-card);padding:10px 12px}
.note .meta{font-size:12px;color:var(--text3);display:flex;gap:6px;align-items:center;margin-bottom:3px}
.note .txt{white-space:pre-wrap;word-break:break-word;font-size:15px}
.note.imported .meta{color:var(--text2)}
.task{display:flex;gap:10px;align-items:flex-start;background:var(--surface);border-radius:var(--r-card);box-shadow:var(--shadow-card);padding:10px 12px}
.task .chk{width:22px;height:22px;border-radius:50%;border:2px solid var(--text3);flex:none;display:grid;place-items:center;margin-top:1px}
.task.done .chk{background:var(--text2);border-color:var(--text2);color:var(--bg)}
.task.done .txt{text-decoration:line-through;color:var(--text2)}
.task .meta{font-size:12px;color:var(--text3);margin-top:2px}
.task.late .when{color:var(--late-text);font-weight:600}
.composer .tabs{display:flex;gap:6px;margin-bottom:8px}
.composer .row2{display:flex;gap:8px;align-items:flex-end}
.composer .area{max-height:160px}
.quick{display:flex;gap:6px;overflow-x:auto;scrollbar-width:none;margin-bottom:8px}
.quick::-webkit-scrollbar{display:none}
.pill{height:32px;padding:0 12px;border-radius:var(--r-pill);background:var(--tile);font-size:13px;font-weight:600;white-space:nowrap;flex:none;color:var(--text)}
.pill.on{background:var(--action);color:var(--action-text)}

/* ---------- списки ---------- */
.search{position:relative;margin-bottom:12px}
.search input{width:100%;height:44px;border:1px solid var(--line);border-radius:14px;background:var(--surface);padding:0 12px 0 40px;font-size:15px}
.search input:focus{outline:2px solid var(--focus);outline-offset:-1px;border-color:transparent}
.search svg{position:absolute;left:12px;top:12px;color:var(--text3)}
.list{background:var(--surface);border-radius:var(--r-card);box-shadow:var(--shadow-card);overflow:hidden}
.li{display:flex;align-items:center;gap:12px;padding:11px 12px;border-bottom:1px solid var(--line);cursor:pointer;width:100%;text-align:left}
.li:last-child{border-bottom:0}
.li:hover{background:var(--tile)}
.li .main-t{font-weight:600;font-size:15px}
.li .sub{font-size:13px;color:var(--text2)}
.li .end{margin-left:auto;display:flex;align-items:center;gap:6px;color:var(--text2);font-size:13px;flex:none}
.round{width:36px;height:36px;border-radius:50%;background:var(--tile);display:grid;place-items:center;color:var(--text);flex:none}
.h1{font-size:22px;font-weight:750;letter-spacing:-.02em;margin:4px 0 12px}
.h3{font-size:13px;font-weight:600;color:var(--text2);text-transform:uppercase;letter-spacing:.06em;margin:20px 2px 8px}
.empty{color:var(--text2);text-align:center;padding:30px 10px;font-size:14px}

/* ---------- итоги ---------- */
.kpi{background:var(--head);color:var(--head-text);border-radius:18px;padding:16px 16px 18px;margin-bottom:12px}
.kpi small{opacity:.7;font-size:13px}
.kpi b{display:block;font-size:30px;font-weight:750;letter-spacing:-.02em;line-height:1.1;margin-top:4px}
.kpi span{opacity:.75;font-size:14px}
.bar{height:6px;border-radius:3px;background:var(--tile);margin-top:6px;overflow:hidden}
.bar i{display:block;height:100%;background:var(--red);border-radius:3px}
.statrow{padding:10px 12px;border-bottom:1px solid var(--line)}
.statrow:last-child{border-bottom:0}
.statrow .row{justify-content:space-between}

/* ---------- настройки ---------- */
.swatches{display:flex;gap:8px;flex-wrap:wrap}
.swatch{width:30px;height:30px;border-radius:50%;border:3px solid transparent}
.swatch.on{border-color:var(--text)}
.stage-row{display:flex;align-items:center;gap:8px;padding:8px 10px;border-bottom:1px solid var(--line)}
.stage-row:last-child{border-bottom:0}
.stage-row i{width:12px;height:12px;border-radius:50%;flex:none}
.toggle{width:44px;height:26px;border-radius:13px;background:var(--tile);position:relative;flex:none;transition:background .15s}
.toggle::after{content:'';position:absolute;left:3px;top:3px;width:20px;height:20px;border-radius:50%;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.25);transition:transform .15s}
.toggle.on{background:var(--red)}
.toggle.on::after{transform:translateX(18px)}

/* ---------- вход ---------- */
.login{min-height:100vh;display:grid;place-items:center;padding:24px 16px;background:var(--bg)}
.login-card{width:100%;max-width:420px;background:var(--surface);border-radius:24px;box-shadow:var(--shadow-card);padding:28px 24px;text-align:center}
.login-card .mark{width:44px;height:44px;margin:0 auto 14px}
.login-card h1{font-size:22px;font-weight:750;letter-spacing:-.02em}
.login-card p{color:var(--text2);margin-top:8px;font-size:14.5px}
.qr{width:220px;height:220px;margin:20px auto 8px;padding:14px;background:#fff;border-radius:16px;border:1px solid var(--line-c)}
.qr svg{width:100%;height:100%}
.steps{text-align:left;margin:16px 0 0;padding:0;list-style:none;counter-reset:s}
.steps li{counter-increment:s;display:flex;gap:10px;margin:8px 0;font-size:14.5px}
.steps li::before{content:counter(s);width:22px;height:22px;border-radius:50%;background:var(--tile);display:grid;place-items:center;font-size:12px;font-weight:700;flex:none}

/* ---------- всплывашки ---------- */
.toast{position:fixed;left:50%;bottom:calc(var(--h-nav) + var(--safe-b) + 14px);transform:translateX(-50%);z-index:80;background:var(--action);color:var(--action-text);padding:10px 16px;border-radius:14px;font-size:14px;font-weight:550;box-shadow:var(--shadow-lift);max-width:calc(100vw - 32px);display:flex;gap:12px;align-items:center;animation:up .2s}
.toast button{font-weight:700;text-decoration:underline;color:inherit}
@media (min-width:900px){.toast{bottom:24px}}
.menu{position:fixed;z-index:61;background:var(--surface);border-radius:14px;box-shadow:var(--shadow-lift);padding:6px;min-width:200px}
.menu button{display:flex;width:100%;align-items:center;gap:10px;height:42px;padding:0 12px;border-radius:10px;font-size:15px;text-align:left}
.menu button:hover{background:var(--tile)}
.menu .danger{color:var(--late-text)}
