:root {
  --paper: #f6f1e6;
  --panel: #fbf8f1;
  --card: #ffffff;
  --ink: #2b241b;
  --muted: #7a6f60;
  --line: #e4dccb;
  --line-strong: #cfc3ab;
  --gold: #7e5d1f;
  --gold-soft: #f0e6cf;
  --sel: #e9dcbc;
  --accent: #8a5a1c;
  --danger: #a3372b;
  --ok: #3f7a3a;
  --warn: #b0731c;
  --radius: 6px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 6px; }
.end { justify-content: flex-end; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--card); color: var(--ink); cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1.2;
}
.btn:hover { border-color: var(--gold); }
.btn:disabled { opacity: .45; cursor: default; border-color: var(--line); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.primary:hover { background: #6a4d18; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--gold-soft); border-color: var(--gold-soft); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 9px; }
.badge { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 9px; font-size: 11px; background: var(--gold-soft); }
.badge.warn { background: #f6e1bf; color: #7a4a0c; }

/* ---------- каркас ---------- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 600; font-size: 15px; letter-spacing: .02em; }
.mark { color: var(--gold); font-family: Georgia, "Times New Roman", serif; letter-spacing: .12em; margin-right: 4px; }
.top-status { flex: 1; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 4px; }

.layout { flex: 1; display: grid; grid-template-columns: 300px 1fr 330px; min-height: 0; }
.pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.pane.center { background: var(--paper); }
.pane.left { border-right: 1px solid var(--line); }
.pane.right { border-left: 1px solid var(--line); position: relative; }
.pane-head { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.search, .asm-name, select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--card);
}
.search:focus, .asm-name:focus, select:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
.target-folder { font-size: 12px; color: var(--muted); }
.target-folder b { color: var(--ink); font-weight: 600; }

/* ---------- дерево ---------- */
.tree { flex: 1; overflow: auto; padding: 6px 4px 20px; }
.node { user-select: none; }
.n-row {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px; cursor: pointer;
  border: 1px solid transparent; min-height: 28px;
}
.n-row:hover { background: var(--gold-soft); }
.n-row.active { background: var(--sel); }
.n-row.target { border-color: var(--gold); }
.n-row.drop { background: #e6d6ad; border-color: var(--gold); }
.n-caret { width: 14px; color: var(--muted); font-size: 10px; text-align: center; flex: none; }
.n-icon { width: 16px; flex: none; text-align: center; color: var(--gold); }
.n-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.n-meta { color: var(--muted); font-size: 11px; flex: none; }
.n-more { visibility: hidden; padding: 0 5px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; }
.n-row:hover .n-more { visibility: visible; }
.n-children { padding-left: 14px; }
.st { font-size: 11px; flex: none; }
.st.err { color: var(--danger); }
.st.warn { color: var(--warn); }
.st.busy { color: var(--muted); }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--line-strong); border-top-color: var(--gold); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -1px; }
@keyframes sp { to { transform: rotate(360deg); } }
.tree-empty { padding: 20px 12px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.upload-progress { padding: 10px 12px; border-top: 1px solid var(--line); background: var(--card); }
.up-text { font-size: 12px; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--gold); transition: width .2s; }

/* ---------- центр ---------- */
.empty { margin: auto; text-align: center; max-width: 360px; line-height: 1.5; }
.doc-view, .page-view { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.doc-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px 8px; flex-wrap: wrap; }
.doc-title { flex: 1; min-width: 200px; }
.doc-title h2 { margin: 0 0 3px; font-size: 17px; font-weight: 600; word-break: break-word; }
.fonts-line { margin: 0 18px; padding: 7px 10px; border-radius: var(--radius); font-size: 12.5px; line-height: 1.45; }
.fonts-line.ok { background: #e9f1e4; color: #2f5d2b; }
.fonts-line.bad { background: #f8e6d6; color: #7a3d0c; }
.fonts-line.info { background: var(--gold-soft); }
.fonts-line:empty { display: none; }
.zoom-row { display: flex; align-items: center; gap: 8px; padding: 8px 18px 0; }
.zoom-row input { width: 140px; accent-color: var(--gold); }
.pages {
  --tw: 200px;
  flex: 1; overflow: auto; padding: 12px 18px 40px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tw), 1fr)); gap: 16px; align-content: start;
}
.page {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 6px 6px 4px;
  cursor: grab; transition: border-color .1s, box-shadow .1s;
}
.page:hover { border-color: var(--line-strong); box-shadow: 0 2px 8px rgba(60, 40, 10, .08); }
.page.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.page img { display: block; width: 100%; aspect-ratio: 8.5 / 11; object-fit: contain; background: #fafafa; pointer-events: none; }
.page .pn { text-align: center; font-size: 12px; color: var(--muted); padding-top: 4px; }
.page .in-asm { position: absolute; top: 10px; right: 10px; background: var(--gold); color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 8px; }
.page-state { margin: 40px auto; text-align: center; color: var(--muted); line-height: 1.6; }
.page-state.err { color: var(--danger); max-width: 520px; white-space: pre-wrap; }

.pv-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.pv-bar > span { flex: 1; text-align: center; font-size: 13px; }
.pv-scroll { flex: 1; overflow: auto; padding: 20px; text-align: center; }
.pv-scroll img { max-width: min(100%, 1000px); box-shadow: 0 3px 18px rgba(60, 40, 10, .15); background: #fff; }

/* ---------- сборка ---------- */
.asm-name { font-weight: 600; }
.asm-info { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.dirty { color: var(--warn); }
.save-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.small-actions { flex-wrap: wrap; }
.asm-list {
  flex: 1; overflow: auto; padding: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start;
}
.asm-list.drag-over { background: #f3ead6; }
.ai {
  position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 5px 5px 3px; cursor: grab;
}
.ai img { display: block; width: 100%; aspect-ratio: 8.5 / 11; object-fit: contain; background: #fafafa; pointer-events: none; }
.ai .num { position: absolute; top: 8px; left: 8px; background: rgba(43, 36, 27, .78); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 8px; }
.ai .cap { font-size: 10.5px; color: var(--muted); padding-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.ai .x { position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .92); color: var(--danger); cursor: pointer; display: none; line-height: 18px; padding: 0; }
.ai:hover .x { display: block; }
.ai.sortable-selected, .ai.sel { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.ai.broken { border-color: var(--danger); }
.ai.broken img { opacity: .3; }
.ai.sortable-ghost { opacity: .35; }
.ins-mark { grid-column: span 1; border: 2px dashed var(--gold); border-radius: 4px; min-height: 60px; background: #f6edd8; }
.asm-drop-hint { position: absolute; left: 12px; right: 12px; bottom: 12px; text-align: center; padding: 18px 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--muted); font-size: 12.5px; pointer-events: none; background: var(--panel); }

/* ---------- меню, тост, диалог ---------- */
.menu { position: fixed; z-index: 50; min-width: 200px; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 6px 22px rgba(40, 30, 10, .16); padding: 4px; }
.menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; border-radius: 4px; cursor: pointer; }
.menu button:hover { background: var(--gold-soft); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 16px; border-radius: var(--radius); font-size: 13px; max-width: 70vw; }
.toast.err { background: var(--danger); }
dialog { border: 1px solid var(--line-strong); border-radius: 8px; padding: 0; background: var(--panel); color: var(--ink); width: min(620px, 92vw); }
dialog::backdrop { background: rgba(40, 30, 10, .25); }
.dlg { padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; max-height: 80vh; overflow: auto; }
.dlg h3 { margin: 0; }
.dlg h4 { margin: 8px 0 0; font-size: 13px; }
.font-row { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.font-row b { font-weight: 600; }
.font-row .grow { flex: 1; color: var(--muted); font-size: 12px; }

/* ---------- вход ---------- */
.login { display: grid; place-items: center; }
.login-card { display: flex; flex-direction: column; gap: 10px; width: 300px; padding: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.login-card input { padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: #fff; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

@media (max-width: 1100px) { .layout { grid-template-columns: 250px 1fr 290px; } }
