/* Decision Studio — светлая дизайн-система */
:root {
  --bg: #f6f7fb;
  --bg-canvas: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --surface-3: #f2f4f8;
  --border: #e4e7ef;
  --border-strong: #ced3e0;
  --text: #1b1f2a;
  --text-dim: #6b7280;
  --text-faint: #9aa1ae;
  --accent: #4f6ef7;
  --accent-soft: #eaeefe;
  --accent-ink: #2f49c4;
  --danger: #e0575b;
  --danger-soft: #fdeded;
  --ok: #2fa06a;
  --warn: #e2a33a;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-1: 0 1px 2px rgba(20, 25, 45, .05), 0 2px 8px rgba(20, 25, 45, .05);
  --shadow-2: 0 4px 14px rgba(20, 25, 45, .09), 0 12px 32px rgba(20, 25, 45, .08);
  --shadow-drag: 0 12px 28px rgba(20, 25, 45, .18), 0 2px 6px rgba(20, 25, 45, .1);
  --sidebar-w: 268px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  /* пастельная палитра карточек */
  --c-yellow: #fff3c4; --c-mint: #d8f5e3; --c-sky: #dbeafe; --c-lilac: #e7e0fb;
  --c-peach: #ffe3d3; --c-rose: #fde1ea; --c-sand: #f1ece2; --c-gray: #eef0f5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.01em; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d9dde7; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #c3c9d6; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transition: margin-left .22s ease;
}
.app.sidebar-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.sidebar__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px 18px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 680; letter-spacing: -.02em; }
.brand__mark { font-size: 19px; }
.brand__name { font-size: 15px; }
.sidebar__section { padding: 6px 12px 10px; }
.sidebar__label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); padding: 6px 6px 8px; font-weight: 600; }
.project-list { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar__foot { padding: 12px; border-top: 1px solid var(--border); }
.sidebar__hint { font-size: 11px; color: var(--text-faint); padding: 8px 6px 2px; }

.project-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; border: 1px solid transparent; user-select: none; position: relative;
}
.project-item:hover { background: var(--surface-3); }
.project-item.active { background: var(--accent-soft); border-color: #d8dffd; }
.project-item.active .project-item__name { color: var(--accent-ink); font-weight: 600; }
.project-item__dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px; background: var(--accent); }
.project-item__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item__count { font-size: 11px; color: var(--text-faint); background: var(--surface-3); border-radius: 20px; padding: 1px 7px; }
.project-item.active .project-item__count { background: #fff; }
.project-item.drag-ghost { opacity: .4; }
.project-item.drop-before::before, .project-item.drop-after::after {
  content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--accent); border-radius: 2px;
}
.project-item.drop-before::before { top: -2px; }
.project-item.drop-after::after { bottom: -2px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: rgba(255,255,255,.86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); z-index: 20;
}
.topbar__menu { display: none; }
.app.sidebar-hidden .topbar__menu { display: inline-flex; }
.topbar__titles { min-width: 0; flex: 1; }
.topbar__title { font-size: 17px; outline: none; border-radius: 6px; padding: 1px 4px; margin-left: -4px; }
.topbar__title[contenteditable="true"]:focus { background: var(--accent-soft); }
.topbar__sub { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

.viewport { flex: 1; position: relative; overflow: hidden; background: var(--bg-canvas);
  background-image: radial-gradient(circle, #d7dbe6 1px, transparent 1px); background-size: 22px 22px;
  cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; }
.viewport.panning { cursor: grabbing; }
.canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; width: 100%; height: 100%; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-size: 13.5px; font-weight: 520;
  transition: background .12s, border-color .12s, transform .08s, box-shadow .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 3px rgba(79,110,247,.35); }
.btn--primary:hover { background: #4361ea; }
.btn--ghost { border-color: transparent; background: transparent; justify-content: flex-start; }
.btn--ghost:hover { background: var(--surface-3); }
.btn--block { width: 100%; }
.btn--sm { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
.btn--danger { color: var(--danger); border-color: #f1cccd; background: var(--danger-soft); }
.btn--danger:hover { background: #fbdedf; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.icon-btn {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 1px solid transparent; background: transparent; cursor: pointer;
  color: var(--text-dim); font-size: 15px; line-height: 1; transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.zoom { display: flex; align-items: center; gap: 1px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; padding: 1px; }
.zoom__level { min-width: 48px; border: 0; background: transparent; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-2); padding: 5px; display: flex; flex-direction: column;
}
.menu button {
  text-align: left; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px;
  cursor: pointer; font-size: 13.5px;
}
.menu button:hover { background: var(--surface-3); }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger-soft); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 2px; }

/* ---------- inputs ---------- */
.input, .textarea, .select {
  width: 100%; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field__label { font-size: 12.5px; color: var(--text-dim); font-weight: 560; }
.field__hint { font-size: 12px; color: var(--text-faint); }

/* ---------- cards on canvas ---------- */
.card {
  position: absolute; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1); display: flex; flex-direction: column;
  overflow: hidden; transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow-2); }
.card.dragging { box-shadow: var(--shadow-drag); transition: none; cursor: grabbing; z-index: 999 !important; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-2); }
.card__head {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px 9px 12px;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.card__icon { font-size: 15px; }
.card__title { flex: 1; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card__tools { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.card:hover .card__tools { opacity: 1; }
.card__body { flex: 1; overflow: hidden; padding: 11px 13px; font-size: 13px; color: var(--text-dim); }
.card__resize { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none; }
.card__resize::after { content: ""; position: absolute; right: 4px; bottom: 4px; width: 7px; height: 7px; border-right: 2px solid var(--border-strong); border-bottom: 2px solid var(--border-strong); border-radius: 0 0 2px 0; }
.card--note .card__head { background: transparent; border-bottom-color: rgba(0,0,0,.06); }
.card--note .card__body { color: var(--text); white-space: pre-wrap; overflow-y: auto; cursor: text; }
.card--note .note-edit { width: 100%; height: 100%; border: 0; background: transparent; outline: none; resize: none; font: inherit; color: inherit; padding: 0; }
.card__preview { display: flex; flex-direction: column; gap: 7px; height: 100%; overflow: hidden; }
.card__stat { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.card__stat b { font-weight: 600; color: var(--text); }
.card__bar { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; display: flex; }
.card__bar i { display: block; height: 100%; }
.card__chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--surface-3); color: var(--text-dim); white-space: nowrap; }
.chip--accent { background: var(--accent-soft); color: var(--accent-ink); }
.card__empty { color: var(--text-faint); font-size: 12.5px; font-style: italic; }
.card__open { margin-top: auto; }

/* ---------- empty state ---------- */
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.empty-state__inner { text-align: center; max-width: 420px; pointer-events: auto; padding: 32px; }
.empty-state__icon { font-size: 40px; margin-bottom: 10px; }
.empty-state h2 { font-size: 19px; margin-bottom: 8px; }
.empty-state p { color: var(--text-dim); margin: 0 0 18px; }
.empty-state__actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- overlay / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(23, 27, 40, .34);
  display: flex; align-items: center; justify-content: center; padding: 28px;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0 } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  width: min(520px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden;
  animation: pop .18s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6 } }
.modal--wide { width: min(1080px, 100%); }
.modal--full { width: 100%; height: 100%; max-width: 1480px; }
.modal__head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal__title { font-size: 16px; flex: 1; }
.modal__sub { font-size: 12.5px; color: var(--text-dim); font-weight: 400; margin-top: 2px; }
.modal__body { padding: 20px; overflow: auto; flex: 1; min-height: 0; }
.modal--full .modal__body { padding: 0; display: flex; }
.modal--full .modal__body > .tool { flex: 1; min-width: 0; height: 100%; }
.modal__foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1f2433; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow-2); animation: toast-in .2s ease; max-width: 60vw;
}
.toast--err { background: var(--danger); }
.toast--ok { background: #1d7a52; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0 } }

/* ---------- tool picker ---------- */
.picker__search { margin-bottom: 14px; }
.picker__group-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); font-weight: 650; margin: 18px 0 10px; }
.picker__group-title:first-child { margin-top: 0; }
.picker__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 10px; }
.picker__item {
  text-align: left; padding: 12px 13px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .08s;
  display: flex; gap: 10px; align-items: flex-start;
}
.picker__item:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.picker__item:active { transform: translateY(1px); }
.picker__icon { font-size: 19px; line-height: 1.2; }
.picker__name { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.picker__desc { font-size: 12px; color: var(--text-dim); line-height: 1.45; }

/* ---------- планшет и телефон ---------- */
@media (max-width: 860px) {
  .app { --sidebar-w: min(78vw, 300px); }

  /* сайдбар выезжает поверх полотна и гасит фон */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 90;
    box-shadow: var(--shadow-2); transition: transform .22s ease;
  }
  .app.sidebar-hidden .sidebar { margin-left: 0; transform: translateX(-100%); }
  .app:not(.sidebar-hidden)::after {
    content: ""; position: fixed; inset: 0; background: rgba(23, 27, 40, .34); z-index: 80;
  }
  .topbar__menu { display: inline-flex; }
  .app.sidebar-hidden .topbar__menu { display: inline-flex; }

  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar__title { font-size: 15.5px; }
  .topbar__sub { font-size: 11.5px; }
  .topbar__actions { gap: 4px; }
  /* на узком экране оставляем только самое нужное */
  .topbar__actions .zoom,
  .topbar__actions #btn-add-note { display: none; }
  .sync { display: none; }
  .sync--offline { display: inline-block; font-size: 11px; padding: 3px 8px; }

  .icon-btn { width: 36px; height: 36px; }
  .btn { padding: 8px 12px; }

  /* окна методов занимают экран целиком */
  .overlay { padding: 0; }
  .modal, .modal--wide, .modal--full { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .modal__head { padding: 12px 14px; }
  .modal__title { font-size: 15px; }
  .modal__body { padding: 14px; }
  .modal__foot { padding: 12px 14px; }
  .picker__grid { grid-template-columns: 1fr; }

  .menu { min-width: 200px; }
  .toasts { bottom: 12px; }
  .toast { max-width: 88vw; }
}

@media (max-width: 560px) {
  .topbar__actions #btn-undo, .topbar__actions #btn-redo { display: none; }
  .empty-state__inner { padding: 20px; }
  .empty-state__actions { flex-direction: column; }
  .empty-state__actions .btn { width: 100%; }
}

/* на устройствах без мыши прячем то, что открывается по наведению */
@media (hover: none) {
  .card__tools { opacity: 1; }
  .item__del, .tree-acts, .dnode__acts { opacity: 1; }
}
}


/* ---------- связи между карточками ---------- */
.link-layer { position: absolute; left: 0; top: 0; width: 12000px; height: 9000px; pointer-events: none; overflow: visible; }
.link-line { fill: none; stroke: #b9c0cf; stroke-width: 2; }
.link-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.link-hit:hover + .link-line, .link-layer g:hover > .link-line { stroke: #4f6ef7; }
.link-label { font: 11.5px var(--font); fill: var(--text-dim); }
.link-label-bg { fill: #fff; stroke: var(--border); }
.app.linking .card { cursor: crosshair; }
.app.linking .card:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.linking-banner {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%); z-index: 150;
  background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 20px;
  font-size: 13px; box-shadow: var(--shadow-2); display: flex; align-items: center; gap: 12px;
}
.linking-banner button { background: rgba(255,255,255,.22); border: 0; color: #fff; border-radius: 12px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.icon-btn[disabled] { opacity: .32; pointer-events: none; }
.picker__item--on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px #e4e9ff; }

/* ---------- индикатор синхронизации ---------- */
.sync {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-faint);
  border-radius: 20px; padding: 4px 11px; font-size: 12px; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.sync:hover { background: var(--surface-3); }
.sync--pending { border-color: #f0d9a8; background: #fdf6e6; color: #8a6413; }
.sync--offline { border-color: #f1cccd; background: var(--danger-soft); color: #a8393d; font-weight: 560; }
@media (max-width: 1100px) { .sync { display: none; } }
.card__body--flush { padding: 0; }
.card__body--flush .card__preview { height: 100%; gap: 0; }
.card__body--flush .card__open { margin: 0; position: absolute; right: 10px; bottom: 10px; opacity: 0; transition: opacity .12s; }
.card:hover .card__body--flush .card__open { opacity: 1; }

/* ---------- справка по методу ---------- */
.help-btn { border-color: var(--border-strong); background: var(--surface); white-space: nowrap; }
.help { max-width: 680px; }
.help__summary { font-size: 14.5px; line-height: 1.65; margin: 0 0 4px; }
.help__block { margin-top: 18px; }
.help__title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin-bottom: 8px; }
.help__list { margin: 0; padding-left: 20px; line-height: 1.6; }
.help__list li { margin: 5px 0; }
.help__list--warn li::marker { color: var(--danger); }
.help p { line-height: 1.65; margin: 6px 0; }

.picker__item { position: relative; padding-right: 34px; }
.picker__help {
  position: absolute; right: 8px; top: 8px; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-faint); font-size: 12px; font-weight: 700;
}
.picker__help:hover { background: var(--accent); color: #fff; }

@media (max-width: 860px) {
  .help-btn { font-size: 12px; padding: 5px 9px; }
  .help-btn .label-long { display: none; }
}

/* ---------- вход и профиль ---------- */
.auth-screen {
  position: fixed; inset: 0; z-index: 300; display: grid; place-items: center;
  background: linear-gradient(160deg, #eef1fb, #f7f8fb 60%); padding: 20px;
}
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2); padding: 28px;
}
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 680; letter-spacing: -.02em; color: var(--text-dim); }
.auth-title { font-size: 21px; margin: 14px 0 6px; }
.auth-hint { color: var(--text-dim); font-size: 13px; margin: 0 0 8px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-dim); }
.auth-error { background: var(--danger-soft); color: #a8393d; border-radius: 9px; padding: 8px 11px; font-size: 13px; }
.auth-switch { margin-top: 14px; text-align: center; }
.link-btn { background: none; border: 0; color: var(--accent-ink); cursor: pointer; font-size: 13px; text-decoration: underline; }

.profile { display: flex; align-items: center; }
.profile-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 3px 10px 3px 3px;
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface); cursor: pointer; font-size: 13px;
}
.profile-btn:hover { background: var(--surface-3); }
.profile-avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 650;
}
.profile-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.admin { display: flex; flex-direction: column; gap: 14px; }
.admin-toggle { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; }
.admin-toggle input { margin-top: 3px; }
.admin-invites { display: flex; flex-direction: column; gap: 6px; }
.admin-invite { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.admin-invite code { background: var(--surface-3); padding: 2px 8px; border-radius: 6px; font-family: var(--mono); }

@media (max-width: 860px) {
  .profile-name { display: none; }
  .auth-card { padding: 20px; border-radius: var(--radius); }
}
