* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #10131a; --panel: #181d27; --panel2: #1f2532; --line: #2a3244;
  --text: #e8ecf4; --dim: #93a0b8; --accent: #ffc927; --accent-dark: #23305e;
  --ok: #3ecf8e; --err: #ff6b6b;
}
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); padding: 40px; border-radius: 14px; width: 340px; text-align: center; }
.login-card h1 { font-size: 30px; letter-spacing: 1px; }
.login-card h1 span, .side-head h1 span { color: var(--accent); }
.login-card p { color: var(--dim); margin: 8px 0 24px; }
.login-card input { width: 100%; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 15px; }
.login-card button { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 8px; background: var(--accent); color: #1a1a1a; font-weight: 700; font-size: 15px; cursor: pointer; }
.login-error { color: var(--err); margin-top: 12px; min-height: 18px; }

/* ---------- app layout ---------- */
#app { display: flex; height: 100vh; }
#sidebar { width: 280px; min-width: 280px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.side-head h1 { font-size: 20px; }
.side-head button { background: none; border: 1px solid var(--line); color: var(--dim); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
#btn-account { padding: 5px 8px; }
#btn-account:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- publish ---------- */
#pub-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
#pub-modal.hidden { display: none; }
.pub-target { font-size: 12px; line-height: 1.6; border-radius: 8px; padding: 11px 13px; margin-bottom: 14px; background: var(--panel2); border-left: 3px solid var(--accent); color: var(--dim); }
.pub-target b { color: var(--text); }
.pub-target code { color: var(--accent); }
#pub-mark { background: var(--accent); color: #1a1a1a; font-weight: 700; border: 0; }
#pub-mark:disabled { opacity: .4; cursor: default; }

/* ---------- find & replace ---------- */
.fr-open { margin: 12px 12px 0; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12.5px; font-weight: 600; }
.fr-open:hover { border-color: var(--accent); color: var(--accent); }
#fr-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
#fr-modal.hidden { display: none; }
.fr-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 560px; max-width: 100%; max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.fr-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.fr-head h3 { font-size: 16px; }
.fr-body { padding: 16px 20px; overflow-y: auto; }
.fr-fld { display: block; margin-bottom: 12px; }
.fr-fld > span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 5px; }
.fr-fld input { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 13px; font-family: ui-monospace, Menlo, monospace; }
.fr-fld input:focus { outline: none; border-color: var(--accent); }
.fr-hint { font-size: 11.5px; color: var(--dim); line-height: 1.55; background: var(--panel2); border-radius: 8px; padding: 10px 12px; }
.fr-hint b { color: var(--text); }
#fr-result { margin-top: 12px; }
.fr-sum { font-size: 13px; margin-bottom: 8px; }
.fr-sum.ok { color: var(--ok); } .fr-sum.err { color: var(--err); } .fr-sum.warn { color: var(--accent); }
.fr-pages { max-height: 200px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.fr-page { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; font-size: 12px; border-bottom: 1px solid var(--line); }
.fr-page:last-child { border-bottom: 0; }
.fr-page .fp-path { color: var(--dim); word-break: break-all; }
.fr-page .fp-count { color: var(--accent); flex: none; }
.fr-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.fr-foot button { padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
#fr-apply { background: var(--err); color: #fff; font-weight: 700; border: 0; }
#fr-apply:disabled { opacity: .4; cursor: default; }

/* ---------- account modal ---------- */
#account-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
#account-modal.hidden { display: none; }
.acct-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 440px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.acct-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.acct-head h3 { font-size: 16px; }
.acct-body { padding: 8px 20px 16px; overflow-y: auto; }
.acct-sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.acct-sec:last-child { border-bottom: 0; }
.acct-sec h4 { font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.acct-admin-tag { font-size: 10px; font-weight: 700; color: var(--accent); background: var(--accent-dark); padding: 2px 7px; border-radius: 10px; }
.acct-sec input { width: 100%; padding: 9px 11px; margin-bottom: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 13px; }
.acct-sec input:focus { outline: none; border-color: var(--accent); }
.acct-btn { padding: 9px 16px; border-radius: 8px; border: 0; background: var(--accent); color: #1a1a1a; font-weight: 700; cursor: pointer; font-size: 13px; }
.acct-status { font-size: 12px; min-height: 16px; margin-top: 8px; }
.acct-status.ok { color: var(--ok); }
.acct-status.err { color: var(--err); }
.acct-adduser { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; }
.acct-adduser input { flex: 1; margin-bottom: 0; }
.acct-adduser .acct-btn { flex: none; white-space: nowrap; }
#acct-users { margin-bottom: 10px; }
.acct-user-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; font-size: 13px; }
.acct-user-row .au-name { display: flex; align-items: center; gap: 8px; }
.acct-user-row .au-del { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--err); cursor: pointer; font-size: 12px; }
.acct-user-row .au-del:hover { border-color: var(--err); }
.acct-user-row .au-del:disabled { opacity: .35; cursor: default; }
.acct-foot { display: flex; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.acct-foot button { padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
.side-user { display: flex; align-items: center; gap: 8px; }
#who { font-size: 12px; color: var(--accent); background: var(--panel2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 20px; }
.login-card input + input { margin-top: 10px; }
#page-search { margin: 12px; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); }
#page-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.page-item { display: flex; align-items: flex-start; gap: 4px; padding: 9px 8px 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.page-item:hover { background: var(--panel2); }
.page-item.active { background: var(--accent-dark); }
.page-item .pi-main { flex: 1; min-width: 0; cursor: pointer; }
.page-item .pi-title { font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.page-item .pi-path { font-size: 11px; color: var(--dim); margin-top: 2px; word-break: break-all; }
.page-item .pi-clone { flex: none; width: 24px; height: 24px; border: 0; background: none; color: var(--dim); border-radius: 6px; cursor: pointer; font-size: 14px; line-height: 1; opacity: 0; transition: opacity .12s; }
.page-item:hover .pi-clone { opacity: 1; }
.page-item .pi-clone:hover { background: var(--line); color: var(--accent); }

/* ---------- clone modal ---------- */
#clone-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
#clone-modal.hidden { display: none; }
.clone-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: 420px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.clone-card h3 { font-size: 16px; margin-bottom: 6px; }
.clone-src { font-size: 12.5px; color: var(--dim); margin-bottom: 16px; }
.clone-src b { color: var(--text); }
.clone-fld { display: block; font-size: 12px; color: var(--dim); margin-bottom: 10px; }
.clone-fld input { width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 14px; }
.clone-fld input:focus { outline: none; border-color: var(--accent); }
.clone-preview { font-size: 12px; color: var(--dim); background: var(--panel2); border-radius: 8px; padding: 9px 12px; }
.clone-preview code { color: var(--accent); word-break: break-all; }
#clone-status { font-size: 12px; min-height: 16px; margin-top: 10px; }
#clone-status.err { color: var(--err); }
#clone-status.ok { color: var(--ok); }
.clone-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.clone-foot button { padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
#clone-go { background: var(--accent); color: #1a1a1a; font-weight: 700; border: 0; }
.loading { color: var(--dim); padding: 16px; }

/* ---------- sidebar tabs + panes ---------- */
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tab { flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 11px 8px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--dim); cursor: pointer; font-size: 12.5px; font-weight: 600; }
.side-tab:hover { color: var(--text); }
.side-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.side-tab .st-ico { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.side-pane { flex: 1; min-height: 0; display: none; flex-direction: column; }
.side-pane.active { display: flex; }
#pages-panel #page-search { margin: 12px; }
.regions-bar { padding: 12px; border-bottom: 1px solid var(--line); }
.regions-row { display: flex; gap: 8px; margin-bottom: 8px; }
.region-btn { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12.5px; font-weight: 600; }
.region-btn:hover { border-color: var(--accent); }
.region-btn.missing { opacity: .5; }
.region-sync { display: flex; align-items: flex-start; gap: 7px; font-size: 11px; color: var(--dim); line-height: 1.45; cursor: pointer; }
.region-sync input { margin-top: 1px; flex: none; }
.region-sync b { color: var(--accent); font-weight: 700; }
.add-hint { font-size: 11.5px; color: var(--dim); line-height: 1.5; padding: 12px 14px; border-bottom: 1px solid var(--line); }

/* ---------- widget / block palette ---------- */
#blocks-list { flex: 1; overflow-y: auto; padding: 12px; }
.blocks-cat { font-size: 12px; font-weight: 700; color: var(--text); margin: 4px 2px 10px; display: flex; align-items: center; gap: 7px; }
.blocks-cat::before { content: "▾"; color: var(--dim); font-size: 10px; }
.blocks-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.block-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 18px 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); cursor: pointer; transition: border-color .12s, transform .06s; }
.block-card:hover { border-color: var(--accent); }
.block-card:active { transform: scale(.97); }
.block-card .bc-icon { display: flex; align-items: center; justify-content: center; height: 26px; }
.block-card .bc-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.block-card .bc-label { font-size: 12.5px; color: var(--text); }
.tpl-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.tpl-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; color: var(--text); cursor: pointer; text-align: left; transition: border-color .12s, transform .06s; }
.tpl-card:hover { border-color: var(--accent); }
.tpl-card:active { transform: scale(.99); }
.tpl-card .tc-icon { flex: none; display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 8px; background: var(--accent-dark); }
.tpl-card .tc-icon svg { width: 20px; height: 20px; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tpl-card .tc-text { display: flex; flex-direction: column; min-width: 0; }
.tpl-card .tc-name { font-size: 13px; font-weight: 600; }
.tpl-card .tc-desc { font-size: 11px; color: var(--dim); margin-top: 1px; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tb-left { min-width: 0; flex: 1; display: flex; align-items: center; gap: 10px; }
#btn-menu { display: none; flex: none; width: 34px; height: 32px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 15px; }
#btn-menu:hover { border-color: var(--accent); }
#nav-backdrop { display: none; }
#tb-title { font-size: 14px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.tb-center { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: center; }
.tb-center .fmt, .tb-center .fmt2 { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.tb-center .fmt:hover, .tb-center .fmt2:hover { border-color: var(--accent); }
.tb-center .fmt2.on { border-color: var(--accent); background: var(--accent-dark); }
.tb-center .fmt2 svg { width: 16px; height: 16px; }
.tb-center .fmt2 svg line, .tb-center .fmt2 svg circle { stroke: currentColor; }
.tb-center .fmt2 svg line { stroke-width: 1.5; stroke-linecap: round; }
.tb-center .fmt2 svg circle { fill: currentColor; stroke: none; }
.tb-center .fmt2 svg .num { font-size: 5.5px; fill: currentColor; font-family: inherit; }
.tb-center .fmt2 svg.stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#fmt-block { height: 32px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12px; padding: 0 6px; }
#fmt-block:hover { border-color: var(--accent); }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 3px; }
.tb-right { display: flex; align-items: center; gap: 8px; }
.tb-right button { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
.tb-right button:disabled { opacity: .4; cursor: default; }
#btn-save { background: var(--accent); color: #1a1a1a; font-weight: 700; border: 0; }
#btn-save.dirty { box-shadow: 0 0 0 3px rgba(255, 201, 39, .3); }
#save-status { font-size: 12px; color: var(--dim); }
#save-status.ok { color: var(--ok); }
#save-status.err { color: var(--err); }

#lock-banner { display: flex; align-items: center; gap: 8px; padding: 9px 14px; background: rgba(255,107,107,.12); border-bottom: 1px solid var(--err); font-size: 12.5px; color: var(--text); }
#lock-banner.hidden { display: none; }
#draft-banner { display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: var(--accent-dark); border-bottom: 1px solid var(--accent); font-size: 12.5px; color: var(--text); }
#draft-banner.hidden { display: none; }
#draft-banner span { flex: 1; }
#draft-banner button { padding: 6px 14px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12px; }
#draft-restore { background: var(--accent); color: #1a1a1a; font-weight: 700; border: 0; }
#draft-banner button:hover { border-color: var(--accent); }

#canvas { flex: 1; position: relative; background: #0b0d12; }
#frame { width: 100%; height: 100%; border: 0; background: #fff; }
#welcome { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--dim); text-align: center; padding: 24px; }
#welcome h2 { color: var(--text); }

/* ---------- style panel ---------- */
#style-panel { position: fixed; right: 16px; top: 70px; width: 300px; max-height: calc(100vh - 100px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; z-index: 55; box-shadow: 0 12px 40px rgba(0,0,0,.5); display: flex; flex-direction: column; }
#style-panel.hidden { display: none; }
.sp-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sp-head h3 { font-size: 15px; }
.sp-sel { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.sp-sel #sp-parent { flex: none; width: 26px; height: 24px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font-size: 11px; }
.sp-sel #sp-parent:hover { border-color: var(--accent); }
.sp-sel #sp-target { font-size: 11.5px; color: var(--accent); font-family: ui-monospace, Menlo, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-body { padding: 12px 14px 14px; overflow-y: auto; }
.sp-sec { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.sp-h { font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.sp-row { display: flex; gap: 8px; }
.sp-f { flex: 1; display: block; font-size: 11px; color: var(--dim); margin-bottom: 8px; min-width: 0; }
.sp-f > span { display: block; margin-bottom: 3px; }
.sp-f input[type=text], .sp-f select { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; }
.sp-f input:focus, .sp-f select:focus { outline: none; border-color: var(--accent); }
.sp-color { display: flex; flex-direction: column; }
.sp-color input[type=color] { width: 100%; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); cursor: pointer; }
.sp-color .sp-x { position: absolute; margin-left: 999px; }
.sp-f .sp-x { align-self: flex-end; margin-top: 4px; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 11px; }
.sp-f .sp-x:hover { color: var(--err); }
.sp-btn { width: 100%; margin-top: 6px; padding: 7px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12px; }
.sp-btn:hover { border-color: var(--accent); }
.sp-check { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--dim); margin-top: 8px; cursor: pointer; }
.sp-check input { flex: none; }
.sp-btn.danger { color: var(--err); margin-top: 4px; }
.sp-btn.danger:hover { border-color: var(--err); }
.sp-up { margin-top: 8px; font-size: 12px; padding: 8px; }
#sp-bg-preview { width: 100%; height: 70px; object-fit: cover; border-radius: 7px; background: #0b0d12; margin-bottom: 8px; }
#sp-bg-preview.hidden { display: none; }
#sp-bg-url { width: 100%; margin-top: 8px; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 11.5px; }
#sp-bg-grid { margin-top: 8px; }
#sp-status { font-size: 11.5px; min-height: 15px; margin-top: 6px; }
#sp-status.ok { color: var(--ok); } #sp-status.err { color: var(--err); }

/* ---------- image panel ---------- */
#img-panel { position: fixed; right: 16px; top: 70px; width: 300px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; z-index: 50; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
#img-panel.hidden, #link-pop.hidden, #versions-modal.hidden, #seo-modal.hidden { display: none; }
#img-panel h3 { font-size: 15px; margin-bottom: 10px; }
#img-preview { width: 100%; max-height: 140px; object-fit: contain; background: #0b0d12; border-radius: 8px; margin-bottom: 10px; }
.up-btn { display: block; text-align: center; background: var(--accent); color: #1a1a1a; font-weight: 700; border-radius: 8px; padding: 10px; cursor: pointer; font-size: 13px; }
.up-btn input { display: none; }
#img-panel .or { text-align: center; color: var(--dim); font-size: 11px; margin: 8px 0; }
#img-panel input[type=text] { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; }
#img-apply-url { width: 100%; margin-top: 6px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
.media-lib { margin-top: 8px; }
.media-toggle { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 12px; text-align: left; }
.media-toggle:hover { border-color: var(--accent); }
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; max-height: 220px; overflow-y: auto; }
.media-grid.hidden { display: none; }
.media-grid .m-thumb { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: pointer; background: #0b0d12; padding: 0; }
.media-grid .m-thumb:hover { border-color: var(--accent); }
.media-grid .m-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .m-empty { grid-column: 1 / -1; color: var(--dim); font-size: 12px; padding: 10px 4px; }
#img-panel .fld { display: block; font-size: 12px; color: var(--dim); margin-top: 10px; }
#img-panel .fld input { margin-top: 4px; }
#img-panel .row { display: flex; gap: 8px; margin-top: 12px; }
#img-panel .row button { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
#img-status { font-size: 12px; margin-top: 8px; min-height: 16px; }
#img-status.err { color: var(--err); }
#img-status.ok { color: var(--ok); }
.img-size { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.img-size .is-head { font-size: 12px; color: var(--text); font-weight: 600; margin-bottom: 8px; }
.img-size .is-row { display: flex; gap: 6px; }
.img-size .is-fld { flex: 1; display: block; font-size: 11px; color: var(--dim); }
.img-size .is-fld input, .img-size .is-fld select { width: 100%; margin-top: 3px; padding: 6px 7px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; }
.img-size .is-check { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--dim); margin-top: 10px; cursor: pointer; }
.img-size .is-check input { width: auto; }
.img-size .is-align { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.img-size .is-align span { font-size: 11.5px; color: var(--dim); margin-right: 2px; }
.img-size .ib { flex: 1; padding: 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
.img-size .ib:hover { border-color: var(--accent); }
.img-size .ib.on { border-color: var(--accent); background: var(--accent-dark); }

/* ---------- link popover ---------- */
#link-pop { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; gap: 8px; align-items: center; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
#link-pop label { font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 6px; }
#link-pop input { width: 320px; padding: 7px 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; }
#link-pop button { padding: 7px 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
#link-pop select { max-width: 170px; padding: 7px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; cursor: pointer; }
#link-pop select:hover { border-color: var(--accent); }
#link-apply { background: var(--accent); color: #1a1a1a; border: 0; font-weight: 700; }

/* ---------- versions modal ---------- */
#versions-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; }
.vm-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 640px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column; }
.vm-compare { display: flex; align-items: center; gap: 8px; padding-bottom: 12px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.vm-compare select { flex: 1; min-width: 0; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 12px; cursor: pointer; }
.vm-compare select:hover { border-color: var(--accent); }
.vm-arrow { color: var(--dim); font-size: 13px; }
#cmp-run { padding: 7px 14px; border-radius: 7px; border: 0; background: var(--accent); color: #1a1a1a; font-weight: 700; cursor: pointer; font-size: 12px; white-space: nowrap; }
#vm-diff { flex: none; max-height: 46vh; overflow: auto; background: #0b0d12; border: 1px solid var(--line); border-radius: 8px; padding: 8px 0; margin-bottom: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; line-height: 1.55; }
#vm-diff.hidden { display: none; }
.d-sum { color: var(--dim); padding: 4px 12px 8px; font-family: -apple-system, sans-serif; font-size: 12px; }
.d-sum b.add { color: var(--ok); } .d-sum b.del { color: var(--err); }
.d-hunk { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 4px; }
.d-row { display: flex; gap: 8px; padding: 0 12px; white-space: pre-wrap; word-break: break-word; }
.d-row .d-ln { flex: none; width: 42px; text-align: right; color: #4a5568; user-select: none; }
.d-row.add { background: rgba(62,207,142,.10); color: #9ff0c8; }
.d-row.del { background: rgba(255,107,107,.10); color: #ffb3b3; }
.d-row.ctx { color: var(--dim); }
.d-none { color: var(--dim); padding: 12px; font-family: -apple-system, sans-serif; }
.vm-card h3 { margin-bottom: 12px; }
#versions-list { flex: 1; overflow-y: auto; }
.v-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 13px; }
.v-row button { padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
.v-row button:hover { border-color: var(--accent); }
#versions-close { margin-top: 12px; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; }
.v-empty { color: var(--dim); padding: 12px 4px; }

/* ---------- SEO modal ---------- */
#seo-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
.seo-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 560px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.seo-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.seo-head h3 { font-size: 16px; }
.seo-x { background: none; border: 0; color: var(--dim); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.seo-x:hover { color: var(--text); background: var(--panel2); }
.seo-body { padding: 16px 20px; overflow-y: auto; }
.seo-fld { display: block; margin-bottom: 14px; }
.seo-fld > span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 5px; }
.seo-fld > span em { font-style: normal; float: right; font-size: 11px; color: var(--dim); }
.seo-fld > span em.ok { color: var(--ok); }
.seo-fld > span em.warn { color: var(--accent); }
.seo-fld input, .seo-fld textarea { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 13px; font-family: inherit; resize: vertical; }
.seo-fld input:focus, .seo-fld textarea:focus { outline: none; border-color: var(--accent); }
.seo-two { display: flex; gap: 12px; }
.seo-two .seo-fld { flex: 1; }
.seo-group { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; background: var(--panel2); }
.seo-group summary { cursor: pointer; font-size: 13px; color: var(--text); font-weight: 600; padding: 2px 0; user-select: none; }
.seo-group[open] summary { margin-bottom: 10px; }
.seo-group .seo-fld:last-child { margin-bottom: 4px; }
.seo-hint { font-size: 11.5px; color: var(--dim); line-height: 1.5; background: var(--panel2); border-radius: 8px; padding: 10px 12px; }
.seo-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.seo-spacer { flex: 1; }
.seo-foot button { padding: 9px 18px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font-size: 13px; }
.seo-foot .seo-ghost { font-size: 12px; color: var(--dim); padding: 9px 12px; }
.seo-foot .seo-ghost:hover { color: var(--text); border-color: var(--accent); }
#seo-apply { background: var(--accent); color: #1a1a1a; font-weight: 700; border: 0; }

/* ---------- tablet / mobile ---------- */
@media (max-width: 900px) {
  /* left palette becomes an off-canvas drawer */
  #btn-menu { display: inline-flex; align-items: center; justify-content: center; }
  #sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 80; width: 290px; min-width: 290px;
             transform: translateX(-100%); transition: transform .22s ease; }
  #app.nav-open #sidebar { transform: translateX(0); box-shadow: 0 0 50px rgba(0,0,0,.65); }
  #app.nav-open #nav-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 75; }
  #main { width: 100%; min-width: 0; }

  /* toolbar wraps onto its own rows */
  #toolbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .tb-left { flex: 1 1 auto; order: 1; }
  .tb-right { order: 2; flex: 0 0 auto; gap: 6px; }
  .tb-right button { padding: 8px 11px; font-size: 12px; }
  .tb-center { order: 3; flex: 1 1 100%; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
  #save-status { flex: 1 1 100%; order: 4; }

  /* side panels become bottom sheets */
  #style-panel, #img-panel { top: auto; right: 8px; left: 8px; bottom: 8px; width: auto;
                             max-height: 62vh; border-radius: 14px; }
  #img-panel { overflow-y: auto; }

  /* popovers + modals get room to breathe */
  #link-pop { left: 8px !important; right: 8px; transform: none !important; flex-wrap: wrap; }
  #link-pop input { width: 100%; }
  #link-pop select { max-width: none; flex: 1; }
  .vm-card, .seo-card, .fr-card, .acct-card, .clone-card { width: 100%; max-height: 88vh; }
  .blocks-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  #sidebar { width: 86vw; min-width: 86vw; }
  .side-head h1 { font-size: 17px; }
  .tb-right button { padding: 7px 9px; font-size: 11.5px; }
  #style-panel, #img-panel { max-height: 70vh; }
  .vm-compare { flex-wrap: wrap; }
  .vm-compare select { flex: 1 1 100%; }
  .seo-two { flex-direction: column; }
}
