:root {
  --navy: #1F3A5F;
  --navy-dark: #16304F;
  --gold: #B3824B;
  --ink: #16202C;
  --muted: #71767E;
  --line: #E3E6EA;
  --line-soft: #EEF0F3;
  --bg: #F6F7F9;
  --panel: #FFFFFF;
  --danger: #B4332B;
  --ok: #2F6B52;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(20,28,40,.06), 0 8px 24px rgba(20,28,40,.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
#app { height: 100%; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
.app-loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: #fff; cursor: pointer;
  font-size: 13px; white-space: nowrap; transition: border-color .12s, background .12s;
}
.btn:hover { border-color: #C3C9D1; background: #FBFCFD; }
.btn:active { transform: translateY(.5px); }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); border-color: var(--navy-dark); }
.btn-danger { color: var(--danger); border-color: #EBD4D2; }
.btn-danger:hover { background: #FCF4F3; border-color: #D9A9A4; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 30px; height: 30px; padding: 0; justify-content: center; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #EDEFF2; border-color: transparent; }

/* ---------- каркас ---------- */
.layout { display: grid; grid-template-rows: 58px 1fr; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: #fff; border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.topbar-logo { width: 32px; height: 32px; border-radius: 5px; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font: 600 13px/1 Georgia, serif; letter-spacing: .5px; }
.topbar-title { font-weight: 600; font-size: 14px; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 9px; border-radius: 13px;
  background: #F0F2F5; font-size: 12px; color: var(--muted); }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

.main { display: grid; grid-template-columns: 290px 1fr; min-height: 0; }
.sidebar { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { padding: 16px 16px 10px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-head h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.sec-list { flex: 1; overflow: auto; padding: 0 8px 12px; }
.sec {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius);
  cursor: pointer; border: 1px solid transparent; margin-bottom: 2px;
}
.sec:hover { background: #F5F7F9; }
.sec.active { background: #EEF2F7; border-color: #D7E0EB; }
.sec.dragging { opacity: .4; }
.sec.drop-before { box-shadow: inset 0 2px 0 var(--navy); }
.sec.drop-after { box-shadow: inset 0 -2px 0 var(--navy); }
.sec-grip { color: #BCC3CC; cursor: grab; font-size: 13px; line-height: 1; user-select: none; }
.sec-body { flex: 1; min-width: 0; }
.sec-title { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sec.active .sec-title { color: var(--navy); }
.sec-meta { font-size: 11.5px; color: var(--muted); }
.sec-count { font-size: 12px; color: var(--muted); background: #F0F2F5; border-radius: 10px; padding: 1px 7px; }
.sec-hidden { opacity: .5; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--line-soft); display: grid; gap: 6px; }

.content { overflow: auto; min-height: 0; }
.content-in { padding: 22px 26px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .intro { margin-top: 8px; font-size: 13px; color: #4A525C; max-width: 640px;
  border-left: 3px solid var(--line); padding-left: 10px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.search-inp { height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius); width: 260px; background: #fff; }
.search-inp:focus { outline: none; border-color: var(--navy); }

/* ---------- список материалов ---------- */
.items { display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.item.dragging { opacity: .4; }
.item.drop-before { box-shadow: inset 0 2px 0 var(--navy); }
.item.drop-after { box-shadow: inset 0 -2px 0 var(--navy); }
.item-thumb {
  width: 76px; height: 58px; border-radius: 4px; background: #F4F5F7; border: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.item-thumb img { max-width: 100%; max-height: 100%; display: block; }
.item-thumb.swatch { border-color: rgba(0,0,0,.08); }
.item-thumb .ph { font-size: 10.5px; color: #A8AEB6; text-align: center; padding: 4px; }
.item-main { min-width: 0; }
.item-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.item-desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tags { margin-top: 5px; display: flex; gap: 5px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #EEF1F5; color: #5A626C; }
.badge-kind { background: #E9EFF7; color: var(--navy); }
.badge-off { background: #FBEDEC; color: var(--danger); }
.badge-orient { background: #F3EEE6; color: #8A6A3E; }
.item-actions { display: flex; gap: 5px; align-items: center; }
.item-grip { color: #C4CAD2; cursor: grab; padding: 0 2px; user-select: none; }

.empty-state { background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); padding: 44px; text-align: center; }
.empty-state h3 { font-size: 15px; margin-bottom: 6px; }
.empty-state p { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

/* ---------- модальные окна ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16,22,32,.42); z-index: 100; display: flex;
  align-items: flex-start; justify-content: center; overflow: auto; padding: 34px 16px; }
.modal { background: #fff; border-radius: 8px; box-shadow: var(--shadow); width: 760px; max-width: 100%; }
.modal-lg { width: 940px; }
.modal-sm { width: 460px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 16px; font-weight: 600; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); background: #FAFBFC; border-radius: 0 0 8px 8px; }
.modal-foot .spacer { flex: 1; }
.tabs { display: flex; gap: 2px; padding: 0 18px; border-bottom: 1px solid var(--line); background: #fff; }
.tab { padding: 10px 12px; border: 0; background: none; cursor: pointer; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }

/* ---------- формы ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: #4A525C; margin-bottom: 5px; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: #fff;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(31,58,95,.08); }
.textarea { min-height: 96px; resize: vertical; font-family: inherit; line-height: 1.55; }
.textarea-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; min-height: 230px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { width: 16px; height: 16px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 12px; cursor: pointer; font-size: 12.5px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--navy); color: #fff; }
.seg-preview { display: flex; gap: 10px; align-items: flex-end; margin-top: 8px; }
.seg-preview .box { border: 1px dashed #C9CFD7; border-radius: 3px; background: #F7F8FA; display: flex;
  align-items: center; justify-content: center; font-size: 10px; color: #98A0A9; }

.drop {
  border: 1px dashed #C9CFD7; border-radius: var(--radius); padding: 16px; text-align: center; background: #FAFBFC;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.drop.over { border-color: var(--navy); background: #F1F5FA; color: var(--navy); }
.cover-preview { display: flex; gap: 12px; align-items: center; }
.cover-box { width: 120px; height: 92px; border: 1px solid var(--line); border-radius: 4px; background: #F4F5F7;
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; }
.cover-box img { max-width: 100%; max-height: 100%; }
.filelist { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.filerow { display: grid; grid-template-columns: 1fr 160px auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid var(--line-soft); }
.filerow:last-child { border-bottom: 0; }
.filerow .fname { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filerow .fmeta { font-size: 11.5px; color: var(--muted); }
.color-row { display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; }
.color-chip { width: 56px; height: 56px; border-radius: 5px; border: 1px solid rgba(0,0,0,.1); }
.prose-preview { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: #FCFCFD;
  font-size: 13.5px; line-height: 1.65; max-height: 260px; overflow: auto; }
.prose-preview h3 { font-size: 15px; margin: 12px 0 6px; }
.prose-preview p { margin-bottom: 9px; }
.prose-preview ul { margin: 0 0 10px 18px; }
.markup-help { font-size: 11.5px; color: var(--muted); line-height: 1.7; background: #F7F8FA; padding: 8px 10px; border-radius: 4px; }
.markup-help code { background: #ECEFF3; padding: 1px 4px; border-radius: 3px; font-size: 11px; }

/* ---------- логин ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100%; padding: 20px; }
.login { width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 28px; }
.login h1 { font-size: 18px; margin-bottom: 4px; }
.login p.sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login .error { background: #FCF2F1; color: var(--danger); border: 1px solid #F0D7D4; border-radius: 4px;
  padding: 8px 10px; font-size: 12.5px; margin-bottom: 12px; }
.login .note { margin-top: 14px; font-size: 12px; color: var(--muted); }

/* ---------- экспорт ---------- */
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.export-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.export-card h3 { font-size: 14px; margin-bottom: 6px; }
.export-card p { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; min-height: 60px; }
.stats { display: flex; gap: 20px; padding: 12px 14px; background: #F7F8FA; border-radius: var(--radius); margin-bottom: 16px; }
.stat b { display: block; font-size: 17px; font-weight: 600; }
.stat span { font-size: 11.5px; color: var(--muted); }
.compat { font-size: 12.5px; color: var(--muted); line-height: 1.7; background: #FAFBFC; border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 12px 14px; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 300; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
  box-shadow: var(--shadow); animation: pop .18s ease-out; max-width: 380px; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.onb-step-edit { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: #FCFCFD; }
.onb-step-edit .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.onb-step-edit .head b { flex: 1; font-size: 12px; color: var(--muted); }

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .row, .row-3, .export-grid { grid-template-columns: 1fr; }
}
