/* Верстак — интерфейс */
:root {
  --bg: #16181d;
  --bg2: #1c1f26;
  --bg3: #232731;
  --bg4: #2b303c;
  --line: #2e3340;
  --text: #d7dae0;
  --dim: #8a91a0;
  --faint: #5d6474;
  --accent: #e8a33d;
  --accent2: #f2b75b;
  --danger: #e5534b;
  --ok: #57ab5a;
  --sel: #3a4a6b;
  --mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', Consolas, 'DejaVu Sans Mono', 'Liberation Mono', monospace;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, sans-serif;
  --code-size: 14px;
  --code-lh: 21px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--ui); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--accent2); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); background: var(--bg3); border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg4); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1408; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.ibtn {
  width: 26px; height: 26px; display: inline-grid; place-items: center; border: 0; background: none;
  border-radius: 5px; color: var(--dim); cursor: pointer; padding: 0;
}
.ibtn:hover { background: var(--bg4); color: var(--text); }
.ibtn.on { color: var(--accent); }
.ibtn svg, .btn svg { width: 16px; height: 16px; }
input.field, select.field, textarea.field {
  width: 100%; height: 32px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; outline: none;
}
textarea.field { height: auto; padding: 8px 10px; resize: vertical; }
input.field:focus, select.field:focus, textarea.field:focus { border-color: var(--accent); }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- вход ---------- */
.login { height: 100%; display: grid; place-items: center; background:
  radial-gradient(1200px 600px at 20% 0%, #2a2216 0%, transparent 60%), var(--bg); }
.login form { width: 340px; padding: 28px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 22px; display: flex; align-items: center; gap: 10px; }
.login p { margin: 0; color: var(--dim); }
.login label { display: grid; gap: 4px; color: var(--dim); font-size: 12px; }
.login .err { color: var(--danger); min-height: 18px; }
.logo { width: 30px; height: 30px; color: var(--accent); }
.login code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }

/* ---------- каркас ---------- */
.app { height: 100%; display: grid; grid-template-rows: 40px 1fr 24px; }
.top {
  display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; margin-right: 6px; }
.brand .logo { width: 22px; height: 22px; }
.top .grow { flex: 1; }
.top .proj-select { width: auto; min-width: 180px; max-width: 320px; height: 28px; flex: none; }
.people { display: flex; align-items: center; gap: 4px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px;
  color: #111; border: 2px solid var(--bg2); position: relative; cursor: default;
}
.avatar.agent { border-radius: 8px; font-size: 13px; }
.avatar.me::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg2); }
.main { display: grid; grid-template-columns: var(--side, 260px) 4px 1fr var(--panel, 0px); min-height: 0; }
.main.panel-open { --panel: 340px; }

/* ---------- дерево ---------- */
.side { display: flex; flex-direction: column; min-height: 0; background: var(--bg2); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; gap: 2px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); }
.side-head .title { flex: 1; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree { flex: 1; overflow: auto; padding: 4px 0 40px; user-select: none; }
.tree.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.node {
  display: flex; align-items: center; gap: 4px; height: 24px; padding-right: 8px; cursor: pointer; white-space: nowrap;
  color: var(--text); position: relative;
}
.node:hover { background: var(--bg3); }
.node.active { background: var(--sel); }
.node.dropzone { background: #3b3220; }
.node .chev { width: 14px; height: 14px; color: var(--faint); flex: none; transition: transform .1s; }
.node.open .chev { transform: rotate(90deg); }
.node .ficon { width: 16px; height: 16px; flex: none; color: var(--dim); }
.node.dir > .ficon { color: var(--accent); }
.node .name { overflow: hidden; text-overflow: ellipsis; }
.node .dots { margin-left: auto; display: flex; gap: 3px; }
.node .dots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.tree-empty { padding: 20px 14px; color: var(--dim); line-height: 1.6; }
.splitter { cursor: col-resize; background: transparent; }
.splitter:hover { background: var(--accent); opacity: .5; }

/* ---------- центр ---------- */
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; align-items: stretch; height: 36px; background: var(--bg2); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 0 6px 0 12px; border-right: 1px solid var(--line);
  cursor: pointer; color: var(--dim); white-space: nowrap; position: relative; max-width: 240px;
}
.tab .tname { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { color: var(--text); background: var(--bg3); }
.tab.active { color: var(--text); background: var(--bg); }
.tab.active::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--accent); }
.tab .x { width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; opacity: .6; }
.tab .x:hover { background: var(--bg4); opacity: 1; }
.tab .x svg { width: 12px; height: 12px; }
.tab .pend { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.tab .tdots { display: flex; gap: 2px; }
.tab .tdots i { width: 6px; height: 6px; border-radius: 50%; display: block; }
.toolbar { display: flex; align-items: center; gap: 4px; padding: 0 8px; height: 34px; border-bottom: 1px solid var(--line); background: var(--bg); }
.crumbs { flex: 1; color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs b { color: var(--text); font-weight: 500; }
.views { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.welcome { height: 100%; display: grid; place-items: center; color: var(--dim); text-align: center; padding: 20px; }
.welcome .logo { width: 64px; height: 64px; opacity: .25; margin-bottom: 12px; }
.welcome h2 { color: var(--text); font-weight: 600; margin: 0 0 8px; }
.welcome kbd, .hint kbd { font-family: var(--mono); font-size: 11px; background: var(--bg3); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; color: var(--text); }
.welcome .keys { display: grid; grid-template-columns: auto auto; gap: 6px 14px; margin-top: 18px; text-align: left; font-size: 12px; }
.binary { height: 100%; display: grid; place-items: center; text-align: center; color: var(--dim); padding: 20px; overflow: auto; }
.binary img { max-width: 90%; max-height: 70vh; background: repeating-conic-gradient(#2a2e38 0 25%, #20232b 0 50%) 0 0/16px 16px; border-radius: 6px; margin-bottom: 14px; }

/* ---------- редактор ---------- */
.ed { position: absolute; inset: 0; background: var(--bg); }
.ed-scroll { position: absolute; inset: 0; overflow: auto; }
.ed-inner { display: flex; min-width: 100%; width: max-content; min-height: 100%; }
.ed-gutter {
  position: sticky; left: 0; z-index: 3; margin: 0; padding: 8px 12px 50vh 14px; min-width: 52px; text-align: right;
  font: var(--code-size)/var(--code-lh) var(--mono); color: var(--faint); background: var(--bg); border-right: 1px solid var(--line);
  user-select: none;
}
.ed-code { position: relative; flex: 1; }
.ed-hl, .ed-ta {
  margin: 0; padding: 8px 40px 50vh 14px; font: var(--code-size)/var(--code-lh) var(--mono); tab-size: 4;
  white-space: pre; word-wrap: normal; overflow-wrap: normal; letter-spacing: 0; font-variant-ligatures: none;
}
.ed-hl { color: var(--text); pointer-events: none; min-height: 100%; }
.ed-ta {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: transparent; caret-color: var(--accent2); z-index: 2;
}
.ed-ta::selection { background: rgba(90, 120, 190, .45); color: transparent; }
.ed-curline { position: absolute; left: 0; right: 0; top: 0; background: rgba(255,255,255,.035); pointer-events: none; }
.ed-remote { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.rsel { position: absolute; border-radius: 2px; }
.rcur { position: absolute; width: 2px; background: var(--c); margin-left: -1px; }
.rcur span {
  position: absolute; left: 0; top: -15px; background: var(--c); color: #111; font: 600 10px/14px var(--ui);
  padding: 0 5px; border-radius: 3px 3px 3px 0; white-space: nowrap; opacity: .95;
}
.rcur:hover span, .rcur.fresh span { opacity: 1; }

/* подсветка */
.t-kw { color: #f08d49; }
.t-str, .t-val { color: #a5d6a7; }
.t-com { color: #6b7385; font-style: italic; }
.t-num { color: #e6c07b; }
.t-lit { color: #d895c9; }
.t-fn { color: #7cb7ff; }
.t-type { color: #67d3c4; }
.t-tag { color: #f07178; }
.t-attr { color: #e6c07b; }
.t-punc { color: #8a91a0; }
.t-prop { color: #7cb7ff; }
.t-sel { color: #f2b75b; }
.t-ann { color: #c792ea; }
.t-var { color: #ff9e80; }
.t-pre { color: #c792ea; }
.t-bold { font-weight: 700; color: #fff; }

/* ---------- правая панель ---------- */
.panel { background: var(--bg2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
.ptab { padding: 4px 10px; border-radius: 5px; cursor: pointer; color: var(--dim); border: 0; background: none; }
.ptab.on { background: var(--bg4); color: var(--text); }
.panel-body { flex: 1; overflow: auto; padding: 8px; }
.ver { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: grid; gap: 2px; border: 1px solid transparent; }
.ver:hover { background: var(--bg3); }
.ver.sel { border-color: var(--accent); background: var(--bg3); }
.ver .row { display: flex; align-items: center; gap: 6px; }
.ver .who { font-weight: 600; }
.ver .when { color: var(--dim); font-size: 12px; margin-left: auto; }
.ver .cm { color: var(--accent2); font-size: 12px; }
.ver .path { color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.panel-empty { color: var(--dim); padding: 16px 8px; line-height: 1.6; }
.group-title { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; padding: 10px 10px 4px; }

/* ---------- строка состояния ---------- */
.status { display: flex; align-items: center; gap: 16px; padding: 0 12px; background: var(--bg2); border-top: 1px solid var(--line); font-size: 12px; color: var(--dim); }
.status .grow { flex: 1; }
.conn { display: flex; align-items: center; gap: 6px; }
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.conn.off i { background: var(--danger); }
.conn.wait i { background: var(--accent); }

/* ---------- окна ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 6, 10, .6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; width: min(440px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal.wide { width: min(1100px, 100%); height: 86vh; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px; overflow: auto; display: grid; gap: 12px; align-content: start; }
.modal-body label { display: grid; gap: 4px; color: var(--dim); font-size: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal .err { color: var(--danger); }

/* сравнение версий */
.diff { flex: 1; overflow: auto; font: 13px/20px var(--mono); padding: 0 0 20px; background: var(--bg); }
.diff .dl { display: flex; white-space: pre; }
.diff .dl .n { width: 52px; flex: none; text-align: right; padding-right: 8px; color: var(--faint); user-select: none; }
.diff .dl .s { width: 18px; flex: none; text-align: center; color: var(--faint); user-select: none; }
.diff .add { background: rgba(87, 171, 90, .14); }
.diff .add .s { color: var(--ok); }
.diff .del { background: rgba(229, 83, 75, .14); }
.diff .del .s { color: var(--danger); }
.diff .gap { color: var(--faint); background: var(--bg2); padding: 2px 0 2px 70px; font-family: var(--ui); font-size: 12px; cursor: default; }
.diff-stats { color: var(--dim); font-size: 12px; }
.diff-stats .p { color: var(--ok); } .diff-stats .m { color: var(--danger); }

/* меню */
.menu { position: fixed; z-index: 60; min-width: 190px; background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 6px 10px; border: 0; background: none; border-radius: 5px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--bg4); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .kb { margin-left: auto; color: var(--faint); font-size: 11px; }

/* уведомления */
.toasts { position: fixed; right: 16px; bottom: 36px; display: grid; gap: 8px; z-index: 70; }
.toast { background: var(--bg3); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: tin .15s ease-out; }
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

.trash-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 6px; }
.trash-item:hover { background: var(--bg3); }
.trash-item .info { flex: 1; min-width: 0; }
.trash-item .info div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-item .info div:last-child { color: var(--dim); font-size: 12px; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #353b48; border-radius: 6px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #444b5a; }
::-webkit-scrollbar-corner { background: transparent; }

@media (max-width: 760px) {
  .main { grid-template-columns: 0 0 1fr 0; }
  .main.side-open { grid-template-columns: 82vw 0 1fr 0; }
  .main.panel-open { --panel: 0px; }
  .brand span { display: none; }
  .top .proj-select { min-width: 0; max-width: 40vw; }
}
