@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');
:root { --r: #E60000; --rd: #C40000; --ink: #10151D; --tx: #3A4350; --mu: #6B7480; --ln: #E4E8EE; --soft: #F4F6F9; --bg: #EEF1F5; --ok: #1F9D55; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: 'Manrope', Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; overflow: hidden; display: flex; flex-direction: column; }
button, input, select, textarea { font-family: inherit; font-size: 14px; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid rgba(230,0,0,.45); outline-offset: 1px; }
.muted { color: var(--mu); }

/* ---- верхня панель ---- */
.top { min-height: 60px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: #fff; border-bottom: 1px solid var(--ln); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.brand .logo { flex: none; width: 34px; height: 34px; border-radius: 10px; background: var(--r); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.brand b { display: block; font-size: 15px; line-height: 1.1; white-space: nowrap; }
.brand small { color: var(--mu); font-size: 11.5px; white-space: nowrap; }
.top-mid { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; }
.pg-name { flex: 1 1 200px; width: 0; min-width: 120px; max-width: 260px; padding: 8px 12px; border: 1px solid var(--ln); border-radius: 10px; background: var(--soft); font-weight: 700; text-overflow: ellipsis; }
.pg-name:focus { background: #fff; outline: 2px solid rgba(230,0,0,.25); border-color: var(--r); }
#presetSel { flex: 0 1 200px; min-width: 100px; padding: 8px 10px; border: 1px solid var(--ln); border-radius: 10px; background: #fff; }
#presetSel[hidden] { display: none; }
.save-info { color: var(--ok); font-size: 12px; font-weight: 700; opacity: 0; transition: opacity .4s; white-space: nowrap; }
.save-info.on { opacity: 1; transition: opacity .1s; }
.btn { border: 1px solid transparent; border-radius: 10px; padding: 9px 14px; font-weight: 700; background: var(--soft); color: var(--ink); white-space: nowrap; }
.btn:hover:not(:disabled) { background: #e7ebf1; }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--r); color: #fff; }
.btn.primary:hover { background: var(--rd); }
.btn.ghost { background: #fff; border-color: var(--ln); }
.btn.ghost:hover { border-color: #c9d0da; background: #fff; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn.danger { color: var(--r); }
#helpBtn .ico { display: none; }
.ibtn { width: 34px; height: 34px; flex: none; border: 1px solid var(--ln); border-radius: 9px; background: #fff; font-size: 16px; line-height: 1; }
.ibtn:hover:not(:disabled) { border-color: #c9d0da; background: var(--soft); }
.ibtn:disabled { opacity: .35; }
.seg { display: inline-flex; border: 1px solid var(--ln); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: #fff; padding: 8px 12px; font-weight: 700; color: var(--mu); }
.seg button.on { background: var(--ink); color: #fff; }

/* ---- каркас ---- */
.app { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px minmax(0, 1fr) 360px; }
.left, .right { background: #fff; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.left { border-right: 1px solid var(--ln); }
.right { border-left: 1px solid var(--ln); }
.tabs { display: flex; border-bottom: 1px solid var(--ln); flex: none; }
.tabs button { flex: 1; border: 0; background: #fff; padding: 12px 8px; font-weight: 700; color: var(--mu); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--r); }
.tabs i { font-style: normal; background: var(--soft); border-radius: 20px; padding: 1px 7px; font-size: 11.5px; margin-left: 4px; }
.tabpane { display: none; flex: 1; min-height: 0; overflow: auto; }
.tabpane.on { display: flex; flex-direction: column; }
#tabLib { padding: 12px; gap: 10px; }
#libSearch { width: 100%; flex: none; padding: 9px 12px; border: 1px solid var(--ln); border-radius: 10px; background: var(--soft); }
.lib-hint { flex: none; color: var(--mu); font-size: 11.5px; line-height: 1.4; margin: -2px 2px 0; }
.lib-group { margin-top: 6px; }
.lib-group h4 { margin: 12px 2px 8px; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--mu); }
.lib-item { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 10px; margin-bottom: 6px; border: 1px solid var(--ln); background: #fff; border-radius: 12px; }
.lib-item:hover { border-color: var(--r); background: #fff7f7; }
.lib-ic { flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--soft); color: var(--r); display: flex; align-items: center; justify-content: center; }
.lib-ic svg { width: 19px; height: 19px; }
.lib-tx { min-width: 0; }
.lib-item b { display: block; font-size: 13.5px; }
.lib-item span { display: block; color: var(--mu); font-size: 11.5px; line-height: 1.3; }

/* ---- структура ---- */
#struct { padding: 10px; display: flex; flex-direction: column; gap: 6px; }
#struct > p { margin: 6px 4px; }
.s-item { position: relative; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--ln); border-radius: 11px; background: #fff; cursor: pointer; }
.s-item:hover { border-color: #c9d0da; }
.s-item.sel { border-color: var(--r); background: #fff7f7; }
.s-item.over-top { box-shadow: 0 -3px 0 var(--r); }
.s-item.over-bottom { box-shadow: 0 3px 0 var(--r); }
.s-item .n { flex: none; color: var(--mu); font-weight: 800; font-size: 12px; min-width: 16px; text-align: right; }
.s-item .nm { flex: 1; min-width: 0; }
.s-item .nm b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-item .nm small { display: block; color: var(--mu); font-size: 11.5px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-item .nm small:empty { display: none; }
.s-item .acts { display: none; position: absolute; right: 6px; top: 50%; transform: translateY(-50%); gap: 1px; padding: 2px; background: #fff; border: 1px solid var(--ln); border-radius: 9px; box-shadow: 0 2px 10px rgba(16,21,29,.12); }
.s-item:hover .acts, .s-item:focus-within .acts { display: flex; }
.s-item .acts button { border: 0; background: transparent; padding: 3px 6px; border-radius: 6px; color: var(--mu); font-size: 14px; }
.s-item .acts button:hover:not(:disabled) { background: var(--soft); color: var(--ink); }
.s-item .acts button:disabled { opacity: .3; }
.s-item .grab { flex: none; cursor: grab; color: #aab2bf; font-size: 15px; }
.s-item:active .grab { cursor: grabbing; }

/* ---- превʼю ---- */
.center { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #dfe4eb; }
.frame-wrap { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 14px; }
#preview { width: 100%; height: 100%; border: 0; background: #fff; border-radius: 12px; box-shadow: 0 6px 30px rgba(16,21,29,.12); transition: width .2s; }
.frame-wrap.mob #preview { width: 390px; max-width: 100%; }
.empty { position: absolute; inset: 14px; display: none; align-items: center; justify-content: center; text-align: center; color: var(--mu); pointer-events: none; }
.empty.show { display: flex; }
.empty-in { max-width: 460px; padding: 0 20px; }
.empty b { font-size: 18px; color: var(--ink); }
.empty p { margin: 8px 0 14px; line-height: 1.5; }
.empty p.small { font-size: 12px; margin: 16px 0 0; }
.empty .quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; pointer-events: auto; }
.empty .quick .btn:hover { border-color: var(--r); color: var(--r); }

/* ---- редактор блоку ---- */
#editor { padding: 14px; }
.ed-empty { padding-top: 6px; }
.ed-empty b { font-size: 15px; }
.ed-empty p { margin: 8px 0; line-height: 1.5; }
.ed-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.ed-head h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; }
.ed-n { color: var(--mu); font-size: 11.5px; white-space: nowrap; }
.ed-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.ed-bar .btn { padding: 6px 9px; }
.fld { margin-bottom: 13px; }
.fld > label { display: block; font-weight: 700; font-size: 12.5px; margin-bottom: 5px; }
.fld .hint { color: var(--mu); font-size: 11.5px; margin-top: 4px; line-height: 1.4; }
.fld input[type=text], .fld input[type=url], .fld input[type=number], .fld select, .fld textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--ln); border-radius: 9px; background: #fff; }
.fld textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: 2px solid rgba(230,0,0,.25); border-color: var(--r); }
.fld.chk label { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.fld.chk input { flex: none; width: 16px; height: 16px; accent-color: var(--r); }
.row-url { display: flex; gap: 6px; }
.row-url input { flex: 1; min-width: 0; }
.icon-btn { display: flex; align-items: center; gap: 8px; }
.icon-btn .lib-ic { width: 28px; height: 28px; }
.rtool { display: flex; gap: 4px; margin-bottom: 4px; }
.rtool button { border: 1px solid var(--ln); background: #fff; border-radius: 7px; padding: 3px 9px; font-weight: 800; font-size: 12px; }
.rtool button:hover { border-color: #c9d0da; background: var(--soft); }
.imgf { display: flex; gap: 8px; align-items: stretch; }
.imgf .th { flex: none; width: 54px; height: 54px; border-radius: 9px; background: var(--soft) center/cover no-repeat; border: 1px solid var(--ln); }
.imgf .col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.imgf .row { display: flex; gap: 5px; }
.imgf .row button { flex: 1; padding-left: 6px; padding-right: 6px; }
.lst { border: 1px solid var(--ln); border-radius: 12px; background: var(--soft); padding: 8px; }
.lst-item { background: #fff; border: 1px solid var(--ln); border-radius: 10px; margin-bottom: 7px; }
.lst-item[open] { border-color: #cfd5de; }
.lst-item > summary { list-style: none; display: flex; align-items: center; gap: 2px; padding: 7px 6px 7px 10px; cursor: pointer; font-weight: 700; font-size: 13px; }
.lst-item > summary::-webkit-details-marker { display: none; }
.lst-item > summary::before { content: '▸'; flex: none; margin-right: 6px; color: var(--mu); font-size: 11px; transition: transform .15s; }
.lst-item[open] > summary::before { transform: rotate(90deg); }
.lst-item > summary .tt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lst-item > summary button { flex: none; border: 0; background: transparent; color: var(--mu); padding: 2px 5px; border-radius: 6px; }
.lst-item > summary button:hover:not(:disabled) { background: var(--soft); color: var(--ink); }
.lst-item > summary button:disabled { opacity: .3; }
.lst-body { padding: 8px 10px 2px; border-top: 1px solid var(--ln); }
.lst-add { width: 100%; }
.lst-empty, .lst-max { margin: 4px 2px 6px; }
.sub-note { color: var(--mu); font-size: 11.5px; margin: 2px 0 10px; line-height: 1.4; }

/* ---- код ---- */
#rCode { padding: 0; }
.code-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--ln); flex: none; }
.code-bar span { flex: 1; min-width: 0; color: var(--mu); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#codeArea { flex: 1; width: 100%; border: 0; padding: 12px; font: 11.5px/1.45 Consolas, 'Courier New', monospace; resize: none; background: #0f141b; color: #cfe3ff; white-space: pre; overflow: auto; tab-size: 2; }

/* ---- модальні вікна й повідомлення ---- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(16,21,29,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 16px; width: 760px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--ln); font-size: 16px; }
.modal-body { padding: 16px 18px; overflow: auto; flex: 1; min-height: 0; }
.modal-body label { display: block; font-weight: 700; font-size: 12.5px; margin: 0 0 5px; }
.modal-body .chk-row { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; font-weight: 600; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--ln); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.modal-foot:empty { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-grid > p { grid-column: 1 / -1; }
.photo-grid button { border: 2px solid transparent; border-radius: 10px; padding: 0; background: var(--soft); overflow: hidden; text-align: left; }
.photo-grid button:hover { border-color: var(--r); }
.photo-grid .im { aspect-ratio: 4/3; background: center/cover no-repeat; }
.photo-grid span { display: block; padding: 5px 7px; font-size: 11.5px; font-weight: 600; line-height: 1.25; }
.pg-list button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--ln); background: #fff; padding: 9px 4px; }
.pg-list button:hover, .pg-list button:focus-visible { background: var(--soft); }
.pg-list small { display: block; color: var(--mu); font-size: 11.5px; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.icon-grid button { border: 1px solid var(--ln); border-radius: 10px; background: #fff; padding: 10px 4px 6px; color: var(--ink); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }
.icon-grid button:hover { border-color: var(--r); color: var(--r); }
.icon-grid button.cur { border-color: var(--r); background: #fff7f7; color: var(--r); }
.icon-grid svg { width: 26px; height: 26px; display: block; margin: 0 auto 4px; }
.search { width: 100%; padding: 9px 12px; border: 1px solid var(--ln); border-radius: 10px; margin-bottom: 12px; background: var(--soft); }
.search:focus { background: #fff; outline: 2px solid rgba(230,0,0,.25); border-color: var(--r); }
.chk-list { margin: 0; padding: 0; list-style: none; }
.chk-list li { padding: 8px 10px; border-radius: 9px; background: #fff6e8; margin-bottom: 6px; font-size: 13px; }
.chk-list li.go { cursor: pointer; }
.chk-list li.go:hover { background: #ffedd1; }
.chk-ok { padding: 12px; border-radius: 10px; background: #e9f8ef; color: #17633a; font-weight: 700; }
.help ol { padding-left: 20px; line-height: 1.7; }
.help p { line-height: 1.55; }
.help code { background: var(--soft); padding: 1px 6px; border-radius: 5px; }
.proj-save { display: flex; gap: 8px; }
.proj-save .search { flex: 1; min-width: 0; }
.proj-save .btn { margin-bottom: 12px; flex: none; }
.proj-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--ln); }
.proj-row .pn { flex: 1; min-width: 0; }
.proj-row .pn b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-row .pn small { color: var(--mu); font-size: 11.5px; }
.proj-imp { margin-top: 14px; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 80vw; line-height: 1.4; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- вузькі вікна ---- */
@media (max-width: 1280px) {
  .brand { min-width: 0; }
  .brand small { display: none; }
}
@media (max-width: 1100px) {
  .app { grid-template-columns: 240px minmax(0, 1fr) 310px; }
  .brand-tx { display: none; }
  .top { gap: 10px; padding: 0 12px; }
  .save-info { display: none; }
  #helpBtn .lbl { display: none; }
  #helpBtn .ico { display: inline; }
  #helpBtn { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 1000px) {
  .app { grid-template-columns: 210px minmax(0, 1fr) 290px; }
  .top { flex-wrap: wrap; row-gap: 6px; padding: 8px 10px; }
  .top-mid { flex: 1 1 260px; }
  .pg-name { max-width: none; }
  .lib-item span { display: none; }
  .lib-item { padding: 7px 8px; }
  .lib-ic { width: 30px; height: 30px; }
  .tabs button { padding: 10px 4px; }
}
