/* ============================================================
   Spasich — design system
   Ультра-минимализм, урбанизм. Палитра выведена из логотипа.
   ============================================================ */

:root {
  /* core ink / navy */
  --ink:        #1B2244;
  --ink-2:      #2A3358;
  --ink-soft:   #4A5374;

  /* violet accent (from document gradient) */
  --violet:     #6C5CE7;
  --violet-600: #5949C9;
  --violet-300: #A99CF5;
  --violet-050: #F1EEFC;
  --periwinkle: #A9B6FF;
  --grad: linear-gradient(135deg, #8E7CF8 0%, #6C5CE7 100%);

  /* neutrals */
  --bg:        #F7F8FB;
  --surface:   #FFFFFF;
  --surface-2: #FBFBFE;
  --line:      #EAECF3;
  --line-2:    #E0E3EE;
  --muted:     #767E99;
  --muted-2:   #9AA1B8;

  /* semantic */
  --ok:    #2BB673;
  --warn:  #E0A33B;
  --risk:  #E0584B;

  --radius:    14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(27,34,68,.05), 0 1px 3px rgba(27,34,68,.04);
  --shadow:    0 4px 18px rgba(27,34,68,.07), 0 1px 4px rgba(27,34,68,.05);
  --shadow-lg: 0 20px 50px rgba(27,34,68,.16);

  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Manrope', var(--sans);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
svg.ic { width: 16px; height: 16px; flex-shrink: 0; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--violet-300); color: #fff; }

/* scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #D9DCE8; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #C3C8DA; background-clip: padding-box; }

/* ============================== layout ============================== */
#app { display: grid; grid-template-columns: 252px 1fr; height: 100vh; height: 100dvh; overflow: hidden; max-width: 100vw; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 22px 16px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.brand__mark { width: 38px; height: 38px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.1; }
.brand__name { font-family: var(--display); font-weight: 800; font-size: 19px; letter-spacing: -.02em; color: var(--ink); }
.brand__sub { font-size: 11px; color: var(--muted-2); font-weight: 500; letter-spacing: .01em; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav__item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s; text-align: left;
}
.nav__item .ic { width: 19px; height: 19px; stroke: currentColor; stroke-width: 1.9; fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.nav__item:hover { background: var(--surface-2); color: var(--ink); }
.nav__item.is-active { background: var(--violet-050); color: var(--violet-600); }
.nav__item.is-active .ic { opacity: 1; }

.sidebar__foot { margin-top: auto; padding-top: 14px; }
.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); flex-shrink: 0; }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(43,182,115,.15); }
.status.err .dot { background: var(--risk); box-shadow: 0 0 0 3px rgba(224,88,75,.15); }

.main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }

/* ============================== generic UI ============================== */
.view { flex: 1; overflow-y: auto; min-height: 0; }
.view-head { padding: 26px 36px 0; }
.view-head h1 { font-family: var(--display); font-size: 24px; font-weight: 800; letter-spacing: -.025em; color: var(--ink); }
.view-head p { color: var(--muted); margin-top: 4px; font-size: 13.5px; }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 15px; border-radius: var(--radius-sm); font-weight: 600; font-size: 13.5px; transition: all .15s; border: 1px solid transparent; white-space: nowrap; }
.btn .ic { width: 16px; height: 16px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.btn--primary { background: var(--violet); color: #fff; box-shadow: 0 2px 8px rgba(108,92,231,.25); }
.btn--primary:hover { background: var(--violet-600); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(108,92,231,.32); }
.btn--ghost { background: var(--surface); border-color: var(--line-2); color: var(--ink-soft); }
.btn--ghost:hover { border-color: var(--violet-300); color: var(--violet-600); background: var(--surface-2); }
.btn--subtle { color: var(--muted); padding: 7px 10px; }
.btn--subtle:hover { color: var(--ink); background: var(--surface-2); }
.btn--danger { color: var(--risk); }
.btn--danger:hover { background: #FDECEA; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 100px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); }
.chip--violet { background: var(--violet-050); border-color: transparent; color: var(--violet-600); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.input, .textarea, select.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--surface); transition: border .15s, box-shadow .15s; outline: none;
}
.input:focus, .textarea:focus, select.input:focus { border-color: var(--violet-300); box-shadow: 0 0 0 3px rgba(108,92,231,.12); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty svg { width: 46px; height: 46px; stroke: var(--line-2); stroke-width: 1.5; fill: none; margin-bottom: 14px; }
.empty h3 { color: var(--ink-soft); font-weight: 600; margin-bottom: 4px; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--violet-300); border-top-color: var(--violet); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================== CREATE / chat view ============================== */
.create { display: grid; grid-template-rows: 1fr auto; height: 100%; }
.chat-scroll { overflow-y: auto; padding: 30px 0 18px; }
.chat-wrap { max-width: 760px; margin: 0 auto; padding: 0 28px; display: flex; flex-direction: column; gap: 22px; }

.hero { text-align: center; padding: 40px 0 10px; }
.hero__mark { width: 56px; height: 56px; margin: 0 auto 16px; display: block; }
.hero h1 { font-family: var(--display); font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.hero p { color: var(--muted); margin-top: 8px; font-size: 15px; }
.suggest { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 28px; text-align: left; }
.suggest__card { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); transition: all .15s; }
.suggest__card:hover { border-color: var(--violet-300); transform: translateY(-2px); box-shadow: var(--shadow); }
.suggest__card b { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.suggest__card span { font-size: 12.5px; color: var(--muted); }

.msg { display: flex; gap: 12px; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg__av { width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.msg__av--me { background: var(--ink); color: #fff; }
.msg__av--ai { background: var(--violet-050); }
.msg__av--ai img { width: 20px; height: 20px; }
.msg__body { padding-top: 3px; min-width: 0; flex: 1; }
.msg__body p { margin-bottom: 8px; }
.msg__body p:last-child { margin-bottom: 0; }
.msg--me .msg__body { color: var(--ink); font-weight: 500; }

/* pipeline progress */
.pipeline { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pipeline__head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13.5px; }
.pipeline__steps { padding: 6px 8px; }
.pstep { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-sm); font-size: 13px; color: var(--muted); }
.pstep__ic { width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--line-2); }
.pstep.running { color: var(--ink); }
.pstep.running .pstep__ic { border-color: transparent; }
.pstep.done { color: var(--ink-soft); }
.pstep.done .pstep__ic { background: var(--ok); border-color: var(--ok); }
.pstep__check { width: 11px; height: 11px; stroke: #fff; stroke-width: 3; fill: none; }
.pstep__label b { font-weight: 600; color: var(--ink); }
.pstep__sub { font-size: 11.5px; color: var(--muted-2); }
.pstep__mini-spin { width: 14px; height: 14px; border: 2px solid var(--violet-300); border-top-color: var(--violet); border-radius: 50%; animation: spin .7s linear infinite; }

/* result card */
.result-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.result-card__top { padding: 16px 18px; display: flex; align-items: flex-start; gap: 14px; border-bottom: 1px solid var(--line); }
.result-card__fmt { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 11px; color: #fff; flex-shrink: 0; letter-spacing: .02em; }
.fmt-docx { background: var(--grad); }
.fmt-xlsx { background: linear-gradient(135deg,#36b37e,#1f9d65); }
.result-card__meta { flex: 1; min-width: 0; }
.result-card__meta h3 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.result-card__meta .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.scorebar { display: flex; gap: 14px; flex-wrap: wrap; padding: 12px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.score { display: flex; flex-direction: column; gap: 3px; }
.score__l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); font-weight: 600; }
.score__v { font-size: 16px; font-weight: 700; font-family: var(--display); }
.result-card__actions { padding: 13px 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.warnings { padding: 12px 18px; border-top: 1px solid var(--line); background: #FFFBF2; font-size: 12.5px; color: #8A6D2B; }
.warnings b { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; color: var(--warn); }
.warnings ul { margin-left: 18px; }

/* composer */
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 14px 28px 18px; }
.composer__inner { max-width: 760px; margin: 0 auto; }
.composer__box { border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface); transition: border .15s, box-shadow .15s; padding: 6px 6px 6px 6px; }
.composer__box:focus-within { border-color: var(--violet-300); box-shadow: 0 0 0 3px rgba(108,92,231,.1); }
.composer textarea { width: 100%; border: none; outline: none; resize: none; padding: 9px 10px; max-height: 200px; background: transparent; line-height: 1.5; }
.composer__bar { display: flex; align-items: center; gap: 8px; padding: 4px 6px 2px; }
.composer__bar .spacer { flex: 1; }
.composer__hint { text-align: center; font-size: 11px; color: var(--muted-2); margin-top: 8px; }
.mode-toggle { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 100px; padding: 3px; }
.mode-toggle button { padding: 5px 12px; border-radius: 100px; font-size: 12.5px; font-weight: 600; color: var(--muted); transition: all .15s; }
.mode-toggle button.on { background: var(--surface); color: var(--violet-600); box-shadow: var(--shadow-sm); }

.crm-attach { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.crm-attach .chip button { display: grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; color: var(--muted); }
.crm-attach .chip button:hover { background: var(--line-2); color: var(--ink); }

/* ============================== LIBRARY ============================== */
.lib { display: grid; grid-template-columns: 230px 1fr; height: 100%; }
.lib__folders { border-right: 1px solid var(--line); padding: 20px 14px; overflow-y: auto; }
.lib__folders h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; padding: 0 8px 10px; display: flex; justify-content: space-between; align-items: center; }
.folder { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: 13.5px; font-weight: 500; transition: all .15s; cursor: pointer; }
.folder .ic { width: 17px; height: 17px; stroke: currentColor; stroke-width: 1.8; fill: none; opacity: .8; }
.folder:hover { background: var(--surface-2); }
.folder.on { background: var(--violet-050); color: var(--violet-600); }
.folder__count { margin-left: auto; font-size: 11px; color: var(--muted-2); }
.folder .del { opacity: 0; margin-left: auto; }
.folder:hover .del { opacity: 1; }

.lib__main { overflow-y: auto; padding: 22px 28px; }
.lib__toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.lib__toolbar .search { flex: 1; max-width: 360px; position: relative; }
.lib__toolbar .search input { padding-left: 34px; }
.lib__toolbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: var(--muted-2); stroke-width: 2; fill: none; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.doc-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 16px; transition: all .15s; cursor: pointer; position: relative; }
.doc-card:hover { border-color: var(--violet-300); box-shadow: var(--shadow); transform: translateY(-2px); }
.doc-card__fmt { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 9.5px; font-weight: 800; color: #fff; margin-bottom: 12px; }
.doc-card h4 { font-size: 13.5px; font-weight: 600; line-height: 1.35; margin-bottom: 6px; min-height: 36px; }
.doc-card .meta { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.verdict-pill { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 100px; }
.v-ready { background: #E7F7EF; color: var(--ok); }
.v-needs_fixes { background: #FBF2E2; color: var(--warn); }
.v-risky { background: #FDECEA; color: var(--risk); }
.doc-card__menu { position: absolute; top: 12px; right: 12px; opacity: 0; }
.doc-card:hover .doc-card__menu { opacity: 1; }

/* ============================== CRM ============================== */
.crm { padding: 22px 28px; overflow-y: auto; }
.crm__toolbar { display: flex; align-items: center; gap: 12px; margin: 16px 0 18px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.cc { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 18px; transition: all .15s; }
.cc:hover { box-shadow: var(--shadow); border-color: var(--line-2); }
.cc__top { display: flex; align-items: center; gap: 11px; margin-bottom: 13px; }
.cc__ava { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.cc__ava--company { background: var(--violet-050); color: var(--violet-600); }
.cc__ava--person { background: #EAF6F0; color: var(--ok); }
.cc__ava--ip { background: #FBF2E2; color: var(--warn); }
.cc__name { font-weight: 700; font-size: 14.5px; }
.cc__type { font-size: 11.5px; color: var(--muted); }
.cc__rows { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; }
.cc__row { display: flex; gap: 8px; }
.cc__row .k { color: var(--muted-2); min-width: 92px; flex-shrink: 0; }
.cc__row .v { color: var(--ink-soft); font-weight: 500; }
.cc__foot { display: flex; gap: 6px; margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--line); }

/* ============================== EDITOR ============================== */
.editor { display: grid; grid-template-columns: 1fr 320px; height: 100%; }
.editor__main { display: flex; flex-direction: column; overflow: hidden; }
.editor__bar { display: flex; align-items: center; gap: 10px; padding: 13px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.editor__bar .title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor__bar input.title { border: 1px solid transparent; padding: 5px 8px; border-radius: 8px; }
.editor__bar input.title:hover { border-color: var(--line); }
.editor__bar input.title:focus { border-color: var(--violet-300); background: var(--surface); }
.editor__canvas { flex: 1; overflow-y: auto; padding: 34px; background: var(--bg); }
.editor__sidebar { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 20px; }
.editor__sidebar h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted-2); font-weight: 700; margin-bottom: 12px; }
.editor__sidebar h3:not(:first-child) { margin-top: 26px; }

/* document page (paper) */
.paper { max-width: 800px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 56px 64px; min-height: 60vh; }
.paper.doc-view { font-family: 'Times New Roman', Georgia, serif; font-size: 15px; line-height: 1.6; color: #16203a; }
.paper.doc-view h1 { font-size: 19px; text-align: center; font-weight: 700; margin: 6px 0 18px; font-family: inherit; letter-spacing: 0; }
.paper.doc-view h2 { font-size: 16px; font-weight: 700; margin: 18px 0 8px; }
.paper.doc-view h3 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.paper.doc-view p { margin: 0 0 9px; text-align: justify; }
.paper.doc-view p.b { font-weight: 700; }
.paper.doc-view ul, .paper.doc-view ol { margin: 0 0 9px 26px; }
.paper.doc-view li { margin-bottom: 4px; }
.paper.doc-view .sigs { margin-top: 26px; }
.paper.doc-view .spacer { height: 16px; }
.doc-table { border-collapse: collapse; width: 100%; margin: 8px 0 14px; font-size: 13.5px; }
.doc-table th, .doc-table td { border: 1px solid #c8cddc; padding: 7px 10px; text-align: left; vertical-align: top; }
.doc-table th { background: #eef0fb; font-weight: 600; }
.doc-table.sheet { font-family: var(--sans); }
mark.ph { background: #FFF3C4; color: #8A6D2B; padding: 0 2px; border-radius: 3px; font-style: normal; box-decoration-break: clone; }

/* editable blocks */
.eb { position: relative; border-radius: 8px; transition: background .12s; }
.eb:hover { background: rgba(108,92,231,.045); }
.eb__tools { position: absolute; right: -2px; top: 2px; display: none; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px; box-shadow: var(--shadow-sm); z-index: 5; }
.eb:hover .eb__tools { display: flex; }
.eb__tools button { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); }
.eb__tools button:hover { background: var(--violet-050); color: var(--violet-600); }
.eb__tools svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2; fill: none; }
[contenteditable="true"] { outline: none; }
[contenteditable="true"]:focus { background: rgba(108,92,231,.06); border-radius: 4px; }

/* review panel */
.rv-score { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.rv-score:last-child { border: none; }
.rv-bar { width: 90px; height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.rv-bar i { display: block; height: 100%; border-radius: 6px; background: var(--violet); }
.rv-issue { padding: 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; font-size: 12.5px; }
.rv-issue__top { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.sev { font-size: 9.5px; font-weight: 700; padding: 1px 6px; border-radius: 100px; text-transform: uppercase; }
.sev-high { background: #FDECEA; color: var(--risk); }
.sev-medium { background: #FBF2E2; color: var(--warn); }
.sev-low { background: var(--surface-2); color: var(--muted); }
.rv-issue .prob { color: var(--ink); font-weight: 500; }
.rv-issue .fix { color: var(--muted); margin-top: 3px; }

/* ============================== VIEWER ============================== */
.viewer { padding: 22px 28px; overflow-y: auto; height: 100%; }
.dropzone { border: 2px dashed var(--line-2); border-radius: var(--radius-lg); padding: 50px; text-align: center; color: var(--muted); transition: all .15s; background: var(--surface); cursor: pointer; }
.dropzone.drag { border-color: var(--violet); background: var(--violet-050); }
.dropzone svg { width: 44px; height: 44px; stroke: var(--violet-300); stroke-width: 1.5; fill: none; margin-bottom: 14px; }
.dropzone b { color: var(--ink); }
.file-preview { margin-top: 22px; }
.file-preview__bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; border-bottom: none; }
.file-preview .paper { border-radius: 0 0 var(--radius) var(--radius); margin: 0; max-width: none; }
#pdfFrame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }

/* ============================== modal ============================== */
.modal-bg { position: fixed; inset: 0; background: rgba(20,26,52,.4); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 100; animation: fade .15s; padding: 20px; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 88vh; overflow: hidden; display: flex; flex-direction: column; animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } }
.modal--wide { max-width: 720px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal__head h2 { font-family: var(--display); font-size: 18px; font-weight: 700; }
.modal__body { padding: 22px; overflow-y: auto; }
.modal__foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal__x { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--muted); }
.modal__x:hover { background: var(--surface-2); color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* toast */
#toast-host { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 100px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); animation: rise .2s ease; display: flex; align-items: center; gap: 8px; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--risk); }

@media (max-width: 1080px) {
  .editor { grid-template-columns: 1fr; grid-auto-rows: min-content; overflow-y: auto; }
  .editor__main { overflow: visible; }
  .editor__canvas { overflow: visible; }
  .editor__sidebar { border-left: none; border-top: 1px solid var(--line); max-height: none; }
}
@media print {
  .sidebar, .editor__bar, .editor__sidebar, .composer, #toast-host { display: none !important; }
  .editor__canvas { padding: 0; background: #fff; }
  .paper { box-shadow: none; border: none; max-width: none; padding: 0; }
}

/* ============================================================
   v2 components
   ============================================================ */

/* generic icon button */
.iconbtn { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); transition: all .14s; flex-shrink: 0; }
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn .ic { width: 16px; height: 16px; }
.iconbtn.busy { pointer-events: none; }

/* ── login ── */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 10; overflow: hidden; }
.login__bg { position: absolute; inset: 0; z-index: 0; background:
   radial-gradient(60% 50% at 80% 10%, rgba(108,92,231,.10), transparent 60%),
   radial-gradient(50% 50% at 10% 90%, rgba(142,124,248,.10), transparent 60%); }
.login__card { position: relative; z-index: 1; width: 380px; max-width: 92vw; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-lg); padding: 38px 34px; text-align: center; }
.login__mark { width: 56px; height: 56px; margin-bottom: 14px; }
.login__title { font-family: var(--display); font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.login__sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; margin-bottom: 26px; }
.login__form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login__btn { justify-content: center; padding: 11px; margin-top: 4px; }
.login__err { color: var(--risk); font-size: 12.5px; min-height: 16px; text-align: center; }
.login__hint { color: var(--muted-2); font-size: 11.5px; margin-top: 18px; }

/* ── userchip ── */
.userchip { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: var(--radius-sm); margin-top: 8px; transition: background .14s; text-align: left; }
.userchip:hover { background: var(--surface-2); }
.userchip__ava { width: 32px; height: 32px; border-radius: 9px; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.userchip__info { flex: 1; min-width: 0; }
.userchip__name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip__role { font-size: 11px; color: var(--muted-2); }
.userchip .ic { width: 16px; height: 16px; color: var(--muted-2); }

/* ── settings ── */
.settings__section { margin-bottom: 22px; }
.settings__h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; margin-bottom: 12px; }
.settings__row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 4px 0; }
.settings__rowlabel { font-size: 13.5px; font-weight: 500; }
.settings__rowhint { font-size: 12px; color: var(--muted); margin-top: 1px; }
.settings__logout { width: 100%; justify-content: center; color: var(--risk); border-color: var(--line); }
.settings__logout:hover { background: #FDECEA; border-color: transparent; }

.toggle { width: 42px; height: 24px; border-radius: 100px; background: var(--line-2); position: relative; transition: background .18s; flex-shrink: 0; }
.toggle.on { background: var(--violet); }
.toggle__knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle.on .toggle__knob { left: 21px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg__btn { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.seg__btn .ic { width: 15px; height: 15px; }
.seg__btn.on { background: var(--surface); color: var(--violet-600); box-shadow: var(--shadow-sm); }

.swatches { display: flex; gap: 8px; }
.swatch { width: 26px; height: 26px; border-radius: 8px; border: 2px solid transparent; transition: transform .12s; }
.swatch:hover { transform: scale(1.1); }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

/* ── create shell: rail + chat ── */
.create-shell { flex: 1; display: grid; grid-template-columns: 274px 1fr; min-height: 0; min-width: 0; }
.rail { border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; overflow: hidden; background: var(--surface); }
.rail__new { justify-content: center; margin-bottom: 14px; }
.rail__projects { margin-bottom: 8px; }
.rail__head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; }
.rail__proj { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: var(--radius-sm); color: var(--ink-soft); font-size: 13px; font-weight: 500; cursor: pointer; transition: background .14s; }
.rail__proj:hover { background: var(--surface-2); }
.rail__proj.on { background: var(--violet-050); color: var(--violet-600); }
.rail__proj .ic { width: 16px; height: 16px; opacity: .8; }
.dotcolor { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; margin: 0 3px; }
.rail__projedit { width: 22px; height: 22px; opacity: 0; }
.rail__proj:hover .rail__projedit { opacity: 1; }
.rail__chats { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 4px; }
.rail__chat { display: flex; align-items: center; gap: 9px; padding: 9px; border-radius: var(--radius-sm); cursor: pointer; transition: background .14s; }
.rail__chat:hover { background: var(--surface-2); }
.rail__chat.on { background: var(--violet-050); }
.rail__chat > .ic { width: 16px; height: 16px; color: var(--muted-2); flex-shrink: 0; }
.rail__chat.on > .ic { color: var(--violet-600); }
.rail__chatmeta { flex: 1; min-width: 0; }
.rail__chattitle { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail__chat.on .rail__chattitle { color: var(--violet-600); }
.rail__chatdate { font-size: 11px; color: var(--muted-2); }
.rail__chatmenu { width: 24px; height: 24px; opacity: 0; }
.rail__chat:hover .rail__chatmenu { opacity: 1; }
.rail__empty { color: var(--muted-2); font-size: 12.5px; text-align: center; padding: 20px; }

.chatarea { display: grid; grid-template-rows: 1fr auto; min-height: 0; min-width: 0; }
.chatarea .chat-scroll { overflow-y: auto; padding: 30px 0 18px; }

/* ── composer additions ── */
.composer__inputrow { display: flex; align-items: flex-start; gap: 4px; }
.composer__inputrow textarea { flex: 1; }
.composer__wand { margin-top: 6px; color: var(--violet); }
.composer__wand:hover { background: var(--violet-050); }
.composer__wand.busy { opacity: 1; }
.composer__send { padding: 9px 13px; }
.composer__send .ic { margin: 0; }
.composer .iconbtn .ic { width: 17px; height: 17px; }
.composer .iconbtn.rec { color: #fff; background: var(--risk); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(224,88,75,.4); } 50% { box-shadow: 0 0 0 5px rgba(224,88,75,0); } }

.attach-files { display: none; flex-wrap: wrap; gap: 7px; padding: 8px 8px 4px; }
.attach-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; font-size: 12px; max-width: 220px; }
.attach-chip .ic { width: 14px; height: 14px; color: var(--violet); flex-shrink: 0; }
.attach-chip__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.attach-chip__size { color: var(--muted-2); font-size: 11px; flex-shrink: 0; }
.attach-chip button { display: grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; color: var(--muted); flex-shrink: 0; }
.attach-chip button:hover { background: var(--line-2); color: var(--ink); }
.attach-chip button .ic { width: 11px; height: 11px; color: inherit; }
.attach-chip--ro { background: transparent; }
.msg__attach { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.msg { position: relative; }
.msg__body { position: relative; }
.msg__body code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; font-family: ui-monospace, monospace; }
.msg__body h4 { font-size: 14px; font-weight: 700; margin: 8px 0 4px; }
.msg__body ul { margin: 4px 0 8px 20px; }
.msg__body li { margin-bottom: 3px; }
.msg__copy { position: absolute; top: -2px; right: 0; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 7px; color: var(--muted-2); opacity: 0; transition: all .14s; }
.msg:hover .msg__copy { opacity: 1; }
.msg__copy:hover { background: var(--surface-2); color: var(--ink); }
.msg__copy .ic { width: 14px; height: 14px; }

/* ── quality ring + score chips (redesigned) ── */
.qualring { --p: 0; width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: conic-gradient(var(--violet) calc(var(--p) * 1%), var(--line) 0); position: relative; }
.qualring::before { content: ''; position: absolute; inset: 5px; background: var(--surface); border-radius: 50%; }
.qualring span { position: relative; font-family: var(--display); font-weight: 800; font-size: 16px; color: var(--ink); }
.scorebar { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.scorechip { display: flex; align-items: center; gap: 8px; padding: 7px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 100px; }
.scorechip__dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.scorechip__txt { display: flex; align-items: baseline; gap: 6px; }
.scorechip__l { font-size: 12px; color: var(--muted); }
.scorechip__v { font-size: 13px; font-weight: 700; font-family: var(--display); }

/* ── tags ── */
.tagfilter { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 18px; }
.tagchip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: 100px; font-size: 12.5px; font-weight: 500; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line-2); transition: all .14s; }
.tagchip .ic { width: 12px; height: 12px; opacity: .7; }
.tagchip:hover { border-color: var(--violet-300); color: var(--violet-600); }
.tagchip.on { background: var(--violet); color: #fff; border-color: transparent; }
.tagchip.on .ic { opacity: 1; }
.minitag { display: inline-block; padding: 2px 8px; border-radius: 100px; font-size: 10.5px; font-weight: 600; background: var(--violet-050); color: var(--violet-600); }
.doc-card__tags, .cc__tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0; }
.tagedit { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 4px; }

/* ── fill fields ── */
.fillfields { display: flex; flex-direction: column; gap: 9px; }
.fillfield { display: flex; flex-direction: column; gap: 3px; }
.fillfield label { font-size: 11px; color: var(--muted); font-weight: 500; }
.input--sm { padding: 7px 10px; font-size: 13px; }

/* ── file preview (viewer) ── */
.file-preview__paper { border-radius: 0 0 var(--radius) var(--radius); margin: 0; max-width: none; }

/* ============================================================
   dark theme
   ============================================================ */
[data-theme="dark"] {
  --ink: #ECEEF6; --ink-2: #C7CCDD; --ink-soft: #AAB1C7;
  --violet: #8B7CF8; --violet-600: #9D8DF7; --violet-300: #5B4BC9; --violet-050: #25264A;
  --bg: #0F1320; --surface: #161B2B; --surface-2: #1C2233;
  --line: #262C40; --line-2: #313850; --muted: #8A92AC; --muted-2: #69728E;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 4px 18px rgba(0,0,0,.35); --shadow-lg: 0 20px 50px rgba(0,0,0,.5);
}
[data-theme="dark"] .paper { background: var(--surface); border-color: var(--line); }
[data-theme="dark"] .paper.doc-view { color: var(--ink-2); }
[data-theme="dark"] .doc-table th { background: var(--surface-2); }
[data-theme="dark"] .doc-table th, [data-theme="dark"] .doc-table td { border-color: var(--line-2); }
[data-theme="dark"] mark.ph { background: #4A3C12; color: #F0D58A; }
[data-theme="dark"] .msg__av--me { background: var(--violet-300); }
[data-theme="dark"] .warnings { background: #2A2410; color: #D7B86A; }
[data-theme="dark"] .v-ready { background: #16301F; } [data-theme="dark"] .v-needs_fixes { background: #2E2710; } [data-theme="dark"] .v-risky { background: #311714; }
[data-theme="dark"] .cc__ava--company { background: var(--violet-050); } [data-theme="dark"] .cc__ava--person { background: #14301F; } [data-theme="dark"] .cc__ava--ip { background: #2E2710; }
[data-theme="dark"] .sev-high { background: #311714; } [data-theme="dark"] .sev-medium { background: #2E2710; }
[data-theme="dark"] .settings__logout:hover { background: #311714; }
[data-theme="dark"] .login__btn, [data-theme="dark"] .btn--primary { color: #fff; }

/* ============================================================
   Нативная мобильная оболочка + динамика
   ============================================================ */
:root { --tabbar-h: 60px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); }
.main { display: flex; flex-direction: column; }
.main__view { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.main__view > * { flex: 1; min-height: 0; }

/* нативные мелочи */
html { -webkit-text-size-adjust: 100%; }
* { -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior-y: none; }
.chat-scroll, .lib__main, .crm, .viewer, .editor__canvas, .editor__sidebar, .rail__chats, .modal__body { -webkit-overflow-scrolling: touch; }

/* top bar (mobile) */
.topbar { display: none; align-items: center; gap: 10px; padding: calc(9px + var(--sat)) 12px 9px; background: var(--surface); border-bottom: 1px solid var(--line); flex: 0 0 auto; position: relative; z-index: 20; }
.topbar__left { min-width: 38px; display: flex; }
.topbar__brand { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center; }
.topbar__brand img { width: 26px; height: 26px; }
.topbar__brand span { font-family: var(--display); font-weight: 800; font-size: 16px; letter-spacing: -.02em; }
.topbar__avatar { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(108,92,231,.35); transition: transform .15s; }
.topbar__avatar:active { transform: scale(.9); }

/* bottom tab bar (mobile) */
.tabbar { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding-bottom: var(--sab);
  background: var(--surface);
  border-top: 1px solid var(--line); box-shadow: 0 -2px 14px rgba(27,34,68,.05); }
.tabbar__item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px 7px; color: var(--muted-2); position: relative; transition: color .18s, transform .12s; }
.tabbar__item .ic { width: 22px; height: 22px; transition: transform .22s cubic-bezier(.3,1.4,.5,1); }
.tabbar__item span { font-size: 10.5px; font-weight: 600; letter-spacing: .01em; }
.tabbar__item:active { transform: scale(.9); }
.tabbar__item.is-active { color: var(--violet-600); }
.tabbar__item.is-active .ic { transform: translateY(-2px) scale(1.08); }
.tabbar__item.is-active::before { content: ''; position: absolute; top: 0; width: 26px; height: 3px; border-radius: 0 0 4px 4px; background: var(--violet); animation: tabPop .25s ease; }
@keyframes tabPop { from { transform: scaleX(0); opacity: 0; } }

.drawer-overlay { display: none; position: fixed; inset: 0; background: rgba(20,26,52,.45); backdrop-filter: blur(2px); z-index: 40; }
.drawer-overlay.show { display: block; animation: fade .15s; }

/* плавная смена экранов */
.view-enter { animation: viewIn .28s cubic-bezier(.2,.8,.2,1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px) scale(.995); } to { opacity: 1; transform: none; } }

/* ── интерактивность (везде) ── */
.btn { transition: all .15s, transform .08s; }
.btn:active { transform: scale(.96); }
.btn--primary:active { transform: scale(.96); }
.iconbtn:active { transform: scale(.88); }
.nav__item:active { transform: scale(.97); }
.suggest__card:active, .doc-card:active, .cc:active, .rail__chat:active, .tagchip:active, .scorechip:active { transform: scale(.98); }
.result-card { animation: rise .3s ease; }
.toggle, .swatch, .seg__btn { transition: all .18s; }
@media (prefers-reduced-motion: reduce) { *, *::before { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ============================================================
   @media: телефон/планшет
   ============================================================ */
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .topbar { display: flex; }
  .tabbar { display: none; }
  /* навигация — левое выезжающее меню (как в ChatGPT) */
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(84vw, 300px); z-index: 60;
    transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.85,.25,1); box-shadow: var(--shadow-lg);
    padding-top: calc(20px + var(--sat)); padding-bottom: calc(16px + var(--sab)); }
  .sidebar.is-open { transform: translateX(0); }

  /* create: рейл — выезжающий ящик слева */
  .create-shell { grid-template-columns: 1fr; }
  .create-shell .rail { position: fixed; top: 0; left: 0; bottom: 0; width: min(86vw, 320px); z-index: 50;
    transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow-lg);
    padding-top: calc(16px + var(--sat)); }
  .create-shell.rail-open .rail { transform: translateX(0); }
  .chat-wrap { padding: 0 16px; }
  .chatarea .chat-scroll { padding-top: 22px; }
  .composer { padding: 12px 14px 16px; }
  .hero { padding: 20px 0 6px; }
  .hero h1 { font-size: 23px; }
  .hero p { font-size: 14px; }
  .suggest { grid-template-columns: 1fr; }

  /* library: папки — выезжающий ящик */
  .lib { grid-template-columns: 1fr; }
  .lib__folders { position: fixed; top: 0; left: 0; bottom: 0; width: min(82vw, 300px); z-index: 50;
    transform: translateX(-100%); transition: transform .26s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow-lg);
    padding-top: calc(20px + var(--sat)); }
  .lib.folders-open .lib__folders { transform: translateX(0); }
  .lib__main { padding: 18px 16px; }

  .crm, .viewer { padding: 18px 16px; }

  /* editor */
  .editor__bar { flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  .editor__bar .title { flex: 1 1 100%; order: -1; font-size: 16px; }
  .editor__canvas { padding: 14px; }
  .paper { padding: 26px 20px; border-radius: 10px; }

  /* generic */
  .view-head { padding: 16px 16px 0; }
  .view-head h1 { font-size: 21px; }
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; width: 100%; border-radius: 22px 22px 0 0; max-height: 92vh; padding-bottom: var(--sab); animation: sheetUp .3s cubic-bezier(.2,.85,.25,1); }
  @keyframes sheetUp { from { transform: translateY(100%); } }
  .form-grid { grid-template-columns: 1fr; }
  .doc-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-grid { grid-template-columns: 1fr; }
  .scorebar { gap: 6px; padding: 12px; overflow-x: auto; }
  .result-card__actions { gap: 6px; }
  .result-card__actions .btn { flex: 1 1 auto; justify-content: center; }
  .composer__bar { flex-wrap: wrap; }
  .input, .textarea, select.input { font-size: 16px; }  /* iOS не зумит при фокусе */
}

@media (max-width: 460px) {
  .doc-grid { grid-template-columns: 1fr; }
  .topbar__brand span { font-size: 15px; }
  .composer__hint { display: none; }
  .paper { padding: 22px 15px; }
}

/* standalone (добавлено на рабочий стол) — топ-бар учитывает статус-бар */
@media (display-mode: standalone) {
  .login { padding-top: var(--sat); }
}

/* ── composer на мобилке: тоггл отдельной строкой, иконки + отправка ниже ── */
@media (max-width: 860px) {
  .composer__box { padding: 8px; }
  .composer__inputrow textarea { padding: 8px 6px; }
  .composer__bar { flex-wrap: wrap; row-gap: 10px; column-gap: 6px; align-items: center; padding: 2px 2px 0; }
  .composer__bar .mode-toggle { order: -1; flex: 1 1 100%; }
  .composer__bar .mode-toggle button { flex: 1; text-align: center; padding: 8px 10px; }
  .composer .iconbtn { width: 40px; height: 40px; }
  .composer .iconbtn .ic { width: 19px; height: 19px; }
  .composer__bar .crm-attach { flex: 1 1 100%; order: 2; }       /* чипы контрагентов — своей строкой */
  .composer__bar .crm-attach:empty { display: none; }
  .composer__send { margin-left: auto; padding: 10px 18px; }
  .composer__send .ic { width: 18px; height: 18px; }
}

/* ============================================================
   Фиксы переполнения по горизонтали на мобилке
   ============================================================ */
@media (max-width: 860px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  #app, .main, .main__view { max-width: 100vw; overflow-x: hidden; }
  .main__view > * { max-width: 100%; }

  /* CRM: тулбар в столбик, фильтр типов — горизонтальная лента */
  .crm__toolbar { flex-wrap: wrap; gap: 10px; margin: 14px 0 16px; }
  .crm__toolbar > .btn--primary { flex: 1 1 100%; justify-content: center; }
  .crm__toolbar .search { flex: 1 1 100%; max-width: none; }
  .crm__toolbar .mode-toggle { flex: 1 1 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; justify-content: flex-start; scrollbar-width: none; }
  .crm__toolbar .mode-toggle::-webkit-scrollbar { display: none; }
  .crm__toolbar .mode-toggle button { white-space: nowrap; flex: 0 0 auto; }

  /* Библиотека: поиск на всю ширину */
  .lib__toolbar { margin-bottom: 14px; }
  .lib__toolbar .search { flex: 1 1 100%; max-width: none; }

  /* фильтры тегов — лента с прокруткой, без переноса-каши */
  .tagfilter { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .tagfilter::-webkit-scrollbar { display: none; }
  .tagfilter .tagchip { flex: 0 0 auto; }

  /* широкие таблицы в документе не растягивают страницу */
  .paper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .doc-table { min-width: 0; }

  /* карточки/сетки не вылезают */
  .doc-grid, .card-grid { width: 100%; }
  .result-card, .pipeline, .msg { max-width: 100%; }
  .msg__body { min-width: 0; word-break: break-word; overflow-wrap: anywhere; }

  /* модалки: контент не шире экрана */
  .modal, .modal__body, .form-grid { max-width: 100%; }
  .modal__body { overflow-x: hidden; }

  /* редактор: бар не уезжает */
  .editor__bar { max-width: 100%; }
  .editor__bar .btn { flex: 0 0 auto; }
}

/* ============================================================
   v3: токены, бейджи, редактор-бар, админ
   ============================================================ */
.topbar__leftgrp { display: flex; align-items: center; gap: 4px; }

.nav__item { position: relative; }
.nav__badge { margin-left: auto; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--risk); color: #fff; font-size: 10.5px; font-weight: 800; display: grid; place-items: center; }

.gauge { height: 7px; background: var(--line); border-radius: 6px; overflow: hidden; }
.gauge i { display: block; height: 100%; border-radius: 6px; transition: width .5s ease; }
.tokmeter { padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.tokmeter__row { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.tokmeter__row .ic { width: 14px; height: 14px; color: var(--violet); }
.tokmeter__row b { font-weight: 700; }

/* editor bar */
.editor__bar { display: flex; align-items: center; gap: 10px; }
.editor__barrow { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.editor__back { width: 34px; height: 34px; flex-shrink: 0; }
.editor__baract { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* admin */
.admin { padding: 22px 28px; overflow-y: auto; }
.admin__stats { display: flex; gap: 12px; margin: 14px 0 8px; }
.admin__stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; min-width: 92px; }
.admin__stat.is-warn { border-color: var(--warn); background: #FFFBF2; }
.admin__statn { font-family: var(--display); font-size: 24px; font-weight: 800; }
.admin__statl { font-size: 12px; color: var(--muted); }
.admin__h { display: flex; align-items: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); font-weight: 700; margin: 24px 0 12px; }
.admin__h .ic { width: 15px; height: 15px; }
.admin__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.admin__chk { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--ink-soft); cursor: pointer; }
.ac-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 16px; transition: box-shadow .15s; }
.ac-card:hover { box-shadow: var(--shadow); }
.ac-card.is-pending { border-color: var(--warn); box-shadow: 0 0 0 3px rgba(224,163,59,.1); }
.ac-card__top { display: flex; align-items: center; gap: 11px; }
.ac-card__ava { width: 40px; height: 40px; border-radius: 11px; background: var(--violet-050); color: var(--violet-600); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.ac-card__name { font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 7px; }
.ac-card__you { font-size: 10px; font-weight: 700; background: var(--violet-050); color: var(--violet-600); padding: 1px 6px; border-radius: 100px; }
.ac-card__user { font-size: 12px; color: var(--muted); }
.ac-badge { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 100px; }
.ac-badge--pending { background: #FBF2E2; color: var(--warn); }
.ac-badge--active { background: #E7F7EF; color: var(--ok); }
.ac-badge--blocked { background: #FDECEA; color: var(--risk); }
.ac-card__meta { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-size: 12px; }
.ac-role { font-weight: 600; color: var(--ink-soft); }
.ac-card__tok { margin-bottom: 14px; }
.ac-card__tokrow { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.ac-card__tokval { font-weight: 600; color: var(--ink-soft); }
.ac-card__act { display: flex; flex-wrap: wrap; gap: 6px; }

/* auth modal */
.auth { text-align: center; padding: 6px 4px 2px; }
.auth__mark { width: 48px; height: 48px; margin-bottom: 12px; }
.auth__title { font-family: var(--display); font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.auth__sub { color: var(--muted); font-size: 13.5px; margin-top: 4px; margin-bottom: 18px; }
.auth__tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 100px; padding: 3px; margin-bottom: 18px; }
.auth__tabs button { padding: 7px 18px; border-radius: 100px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth__tabs button.on { background: var(--surface); color: var(--violet-600); box-shadow: var(--shadow-sm); }
.auth .login__form { text-align: left; }
.auth--ok { padding: 14px 4px; }
.auth__okic { width: 56px; height: 56px; border-radius: 50%; background: #E7F7EF; color: var(--ok); display: grid; place-items: center; margin: 0 auto 14px; }
.auth__okic .ic { width: 28px; height: 28px; stroke-width: 2.5; }

/* ============================================================
   Лендинг (главная для незалогиненных)
   ============================================================ */
.landing { position: fixed; inset: 0; overflow-y: auto; overflow-x: hidden; background: var(--bg);
  z-index: 5; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }

.lp-head { position: sticky; top: 0; z-index: 20; background: rgba(247,248,251,.8); backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line); }
.lp-head__in { max-width: 1140px; margin: 0 auto; padding: 13px 24px; display: flex; align-items: center; gap: 18px; }
.lp-logo { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.lp-logo img { width: 30px; height: 30px; }
.lp-logo span { font-family: var(--display); font-weight: 800; font-size: 19px; letter-spacing: -.02em; color: var(--ink); }
.lp-nav { display: flex; gap: 22px; margin-left: 20px; flex: 1; }
.lp-nav a { color: var(--ink-soft); text-decoration: none; font-size: 14px; font-weight: 500; transition: color .15s; }
.lp-nav a:hover { color: var(--violet-600); }
.lp-head__cta { display: flex; gap: 8px; }

/* hero */
.lp-hero { position: relative; max-width: 1140px; margin: 0 auto; padding: 70px 24px 50px; overflow: hidden; }
.lp-hero__in { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr 1fr; gap: 50px; align-items: center; }
.lp-orb { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .5; z-index: 1; pointer-events: none; animation: float 16s ease-in-out infinite; }
.lp-orb--1 { width: 360px; height: 360px; background: #8E7CF8; top: -60px; right: 10%; }
.lp-orb--2 { width: 300px; height: 300px; background: #A9B6FF; bottom: -40px; left: 0; animation-delay: -5s; }
.lp-orb--3 { width: 220px; height: 220px; background: #6C5CE7; top: 40%; right: 35%; opacity: .25; animation-delay: -9s; }
.lp-orb--4 { width: 420px; height: 420px; background: #8E7CF8; top: -120px; left: 30%; opacity: .25; }
@keyframes float { 0%,100% { transform: translate(0,0) scale(1); } 33% { transform: translate(20px,-26px) scale(1.06); } 66% { transform: translate(-18px,16px) scale(.96); } }

.lp-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: 100px; background: var(--surface); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--ink-soft); box-shadow: var(--shadow-sm); }
.lp-badge__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(43,182,115,.18); }
.lp-h1 { font-family: var(--display); font-size: 46px; line-height: 1.05; font-weight: 800; letter-spacing: -.035em; margin: 18px 0 16px; color: var(--ink); }
.lp-sub { font-size: 17px; line-height: 1.55; color: var(--muted); max-width: 520px; }
.lp-hero__btns { display: flex; gap: 10px; margin: 26px 0 22px; flex-wrap: wrap; }
.lp-cta { padding: 13px 22px; font-size: 15px; }
.lp-trust { display: flex; gap: 18px; flex-wrap: wrap; }
.lp-trust__i { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.lp-trust__i .ic { width: 16px; height: 16px; color: var(--ok); }

/* hero demo window */
.lp-demo { position: relative; }
.lp-demo__win { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden; transform: perspective(1200px) rotateY(-6deg) rotateX(2deg); transition: transform .4s; }
.lp-demo:hover .lp-demo__win { transform: perspective(1200px) rotateY(0) rotateX(0); }
.lp-demo__bar { display: flex; align-items: center; gap: 6px; padding: 11px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.d-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line-2); }
.lp-demo__title { margin-left: 8px; font-size: 12px; font-weight: 700; color: var(--muted); font-family: var(--display); }
.lp-demo__body { padding: 18px; min-height: 320px; }
.lp-demo__prompt { display: inline-flex; align-items: center; max-width: 100%; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 14px 14px 14px 4px; font-size: 13.5px; line-height: 1.4; min-height: 40px; }
.lp-demo__caret { display: inline-block; width: 2px; height: 15px; background: var(--violet-300); margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.lp-demo__steps { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.lp-dstep { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--muted-2); transition: color .3s; }
.lp-dstep__ic { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-2); flex-shrink: 0; transition: all .3s; position: relative; }
.lp-dstep.run { color: var(--ink); }
.lp-dstep.run .lp-dstep__ic { border-color: var(--violet); border-top-color: transparent; animation: spin .7s linear infinite; }
.lp-dstep.done { color: var(--ink-soft); }
.lp-dstep.done .lp-dstep__ic { background: var(--ok); border-color: var(--ok); }
.lp-dstep.done .lp-dstep__ic::after { content: ''; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.lp-demo__doc { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 16px; opacity: 0; transform: translateY(14px); transition: opacity .5s, transform .5s; position: relative; }
.lp-demo__doc.show { opacity: 1; transform: none; }
.lp-demo__doctitle { font-family: 'Times New Roman', serif; font-weight: 700; text-align: center; font-size: 14px; margin-bottom: 12px; }
.lp-dline { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--line-2), var(--line)); width: var(--w); margin: 7px 0; opacity: 0; transform: translateX(-8px); transition: opacity .4s, transform .4s, background .3s, box-shadow .3s; }
.lp-dline.show { opacity: 1; transform: none; }
.lp-dline.is-mark.edit { background: linear-gradient(90deg, #FFE9A8, #FFD980); box-shadow: 0 0 0 4px rgba(224,163,59,.12); }
.lp-demo__chip { position: absolute; right: 14px; bottom: 14px; display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 100px; background: var(--violet); color: #fff; font-size: 11.5px; font-weight: 600; box-shadow: 0 6px 18px rgba(108,92,231,.4); opacity: 0; transform: scale(.8) translateY(8px); transition: all .35s cubic-bezier(.3,1.5,.5,1); }
.lp-demo__chip .ic { width: 13px; height: 13px; }
.lp-demo__chip.show { opacity: 1; transform: none; }

/* sections */
.lp-sec { max-width: 1140px; margin: 0 auto; padding: 64px 24px; }
.lp-sec--tight { padding: 40px 24px; }
.lp-sec__head { text-align: center; max-width: 640px; margin: 0 auto 40px; }
.lp-h2 { font-family: var(--display); font-size: 34px; font-weight: 800; letter-spacing: -.03em; color: var(--ink); }
.lp-lead { color: var(--muted); font-size: 16px; margin-top: 10px; line-height: 1.5; }
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .6s ease, transform .6s cubic-bezier(.2,.8,.2,1); }
.reveal.in { opacity: 1; transform: none; }

.lp-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.lp-step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; transition: transform .2s, box-shadow .2s; }
.lp-step:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.lp-step__n { width: 34px; height: 34px; border-radius: 10px; background: var(--grad); color: #fff; display: grid; place-items: center; font-family: var(--display); font-weight: 800; margin-bottom: 14px; }
.lp-step h3 { font-size: 15.5px; font-weight: 700; margin-bottom: 6px; }
.lp-step p { font-size: 13.5px; color: var(--muted); line-height: 1.5; }

.lp-feats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.lp-feat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; transition: transform .2s, box-shadow .2s, border-color .2s; }
.lp-feat:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--violet-300); }
.lp-feat__ic { width: 46px; height: 46px; border-radius: 13px; background: var(--violet-050); color: var(--violet-600); display: grid; place-items: center; margin-bottom: 16px; }
.lp-feat__ic .ic { width: 22px; height: 22px; }
.lp-feat h3 { font-size: 16px; font-weight: 700; margin-bottom: 7px; }
.lp-feat p { font-size: 13.5px; color: var(--muted); line-height: 1.55; }

.lp-tags { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 760px; margin: 0 auto; }
.lp-tag { padding: 9px 16px; border-radius: 100px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 500; color: var(--ink-soft); transition: all .15s; }
.lp-tag:hover { border-color: var(--violet-300); color: var(--violet-600); transform: translateY(-2px); }

.lp-cta-band { position: relative; max-width: 1000px; margin: 30px auto 60px; padding: 56px 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
.lp-cta-band__in { position: relative; z-index: 2; }
.lp-cta-band .lp-lead { max-width: 520px; margin: 12px auto 24px; }

.lp-foot { border-top: 1px solid var(--line); background: var(--surface); }
.lp-foot__in { max-width: 1140px; margin: 0 auto; padding: 26px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.lp-foot__note { font-size: 12.5px; color: var(--muted); flex: 1; min-width: 200px; }
.lp-foot__copy { font-size: 12.5px; color: var(--muted-2); }

@media (max-width: 900px) {
  .lp-hero__in { grid-template-columns: 1fr; gap: 36px; }
  .lp-demo { max-width: 460px; }
  .lp-demo__win { transform: none; }
  .lp-steps { grid-template-columns: repeat(2, 1fr); }
  .lp-feats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .lp-nav { display: none; }
  .lp-head__in { padding: 11px 16px; }
  .lp-hero { padding: 40px 16px 30px; }
  .lp-h1 { font-size: 33px; }
  .lp-sub { font-size: 15.5px; }
  .lp-sec { padding: 46px 16px; }
  .lp-h2 { font-size: 26px; }
  .lp-steps, .lp-feats { grid-template-columns: 1fr; }
  .lp-hero__btns .btn { flex: 1 1 100%; justify-content: center; }
}
