:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2456d6;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --danger: #c23434;
  --ok: #1f8a4c;
  --warn: #b26b00;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; background: #fff; }

/* ---------- top bar */
.topbar { display: flex; align-items: center; gap: 24px; background: #151a24; color: #fff; padding: 0 24px; height: 54px; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: #c9cfdb; text-decoration: none; padding: 8px 12px; border-radius: 6px; }
.topbar nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.topbar nav a.active { color: #fff; background: rgba(255, 255, 255, .14); }
.topbar .user { color: #9aa3b5; font-size: 13px; }
.topbar .user a { color: #c9cfdb; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.actions { display: flex; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } .topbar { gap: 10px; padding: 0 12px; } .topbar .user { display: none; } }

/* ---------- buttons & forms */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 6px; padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #f1f3f6; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1c47b5; }
.btn.danger { color: var(--danger); border-color: #f0c9c9; }
.btn.danger:hover { background: #fdf0f0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, .05); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.attention { background: #fff4e0; border-color: #f3c97a; color: #7a4a00; }
.icon-btn { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea.code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12.5px; line-height: 1.45; white-space: pre; tab-size: 4; }
label { display: block; font-weight: 500; font-size: 14px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row-actions { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
details > summary { cursor: pointer; color: var(--accent); margin: 6px 0; }

/* ---------- tables, badges */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.table tr.bad td { background: #fdf0f0; }
.table td.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent); padding: 1px 7px; border-radius: 10px; margin-left: 6px; vertical-align: 1px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 10px; font-weight: 500; }
.pill.ok { background: #e6f4ec; color: var(--ok); }
.pill.warn { background: #fff4e0; color: var(--warn); }
.alert { padding: 10px 14px; border-radius: 6px; margin: 0 0 14px; font-size: 14px; }
.alert.error { background: #fdf0f0; color: #8f1f1f; border: 1px solid #f0c9c9; }
.alert.warn { background: #fff8e8; color: #7a4a00; border: 1px solid #f3dca8; }
.empty { text-align: center; padding: 30px 0 10px; }

/* ---------- auth pages */
body.auth { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: #fff; width: 100%; max-width: 380px; padding: 32px; border-radius: 12px; box-shadow: 0 10px 30px rgba(16, 24, 40, .1); }
.auth-card h1 { margin-bottom: 0; }
.auth-card label { margin-top: 14px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 22px; padding: 11px; }

/* ---------- toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: 560px; transition: opacity .4s, transform .4s; }
.toast.ok { background: #17663a; }
.toast.error { background: #a32626; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- modals */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); display: flex; flex-direction: column; max-height: 88vh; }
.modal.wide { max-width: 880px; }
.modal.full { max-width: 1240px; height: 86vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; overflow: auto; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal-body > p:first-child { margin-top: 0; }
ul.help { padding-left: 20px; margin: 0; }
ul.help li { margin-bottom: 10px; }

/* ---------- media */
.media-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.media-bar .search { max-width: 280px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.media-picker .media-grid { max-height: 52vh; overflow: auto; padding: 2px; }
.media-item { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px; cursor: pointer; text-align: left; font: inherit; }
.media-item:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.media-item.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.media-item { position: relative; }
.media-item.picked { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); background: var(--accent-soft); }
.media-item .pick-no { position: absolute; top: 2px; right: 2px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.media-item .thumb { aspect-ratio: 4 / 3; background: #f0f2f5 repeating-conic-gradient(#e8ebef 0 25%, #f6f7f9 0 50%) 0 0 / 16px 16px; display: flex; align-items: center; justify-content: center; border-radius: 4px; overflow: hidden; }
.media-item .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-item .name { font-size: 11.5px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-icon { font-weight: 700; color: var(--muted); font-size: 13px; }
.media-drop { display: none; }
.dragging { outline: 3px dashed var(--accent); outline-offset: 4px; }
.dragging .media-drop { display: block; position: absolute; }
.media-preview { max-width: 100%; max-height: 55vh; display: block; margin: 0 auto; }
.url-pick { margin-top: 14px; }
.url-pick .row { margin-top: 8px; }
.thumb-sm { width: 64px; height: 48px; object-fit: cover; border-radius: 4px; display: block; background: #f0f2f5; }
.thumb-sm.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.lm input[type=text] { font-size: 13px; padding: 6px 8px; }
.lm h3:first-child { margin-top: 0; }
.bg-row { display: flex; gap: 16px; align-items: center; padding: 8px 0; }
.bg-thumb { width: 160px; height: 100px; object-fit: cover; border-radius: 6px; background: #f0f2f5; flex: none; }
.bg-thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; }
.bg-row p { margin: 2px 0 8px; word-break: break-all; }
.history-list { margin-top: 14px; }

/* ---------- editor shell */
body.editor-shell { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.edit-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); flex: none; }
.edit-title select { font-weight: 600; max-width: 340px; }
.edit-actions { display: flex; gap: 4px; margin-left: auto; }
.save-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.save-status::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c5cad3; margin-right: 6px; vertical-align: 1px; }
.save-status.saved::before { background: var(--ok); }
.save-status.dirty::before, .save-status.saving::before { background: #e0a100; }
.save-status.error { color: var(--danger); }
.save-status.error::before { background: var(--danger); }
#frame { flex: 1; width: 100%; border: 0; background: #fff; }
@media (max-width: 900px) { .edit-actions .btn.ghost { padding: 6px 8px; } .save-status { display: none; } }

/* ---------- section library */
.lib { display: grid; grid-template-columns: 340px 1fr; gap: 18px; height: 100%; min-height: 0; }
.modal.full .modal-body { display: flex; flex-direction: column; min-height: 0; }
.lib-left { display: flex; flex-direction: column; min-height: 0; }
.lib-list { overflow: auto; margin-top: 10px; flex: 1; border: 1px solid var(--line); border-radius: 6px; }
.lib-group { position: sticky; top: 0; background: #f3f5f8; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--line); }
.lib-item { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 8px 10px; cursor: pointer; font: inherit; }
.lib-item:hover { background: #f6f8fc; }
.lib-item.active { background: var(--accent-soft); }
.lib-snip { font-size: 13.5px; }
.lib-from { font-size: 12px; color: var(--muted); }
.lib-right { display: flex; flex-direction: column; min-height: 0; }
.lib-preview { flex: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; position: relative; background: #fafbfc; min-height: 300px; }
.lib-preview > p { padding: 20px; }
.lib-preview iframe { width: 1200px; border: 0; transform-origin: 0 0; position: absolute; top: 0; left: 0; pointer-events: none; }
.lib-blank { padding: 30px; }
@media (max-width: 860px) { .lib { grid-template-columns: 1fr; } .lib-right { display: none; } }

/* ---------- backups */
.backup { display: grid; grid-template-columns: 210px 1fr auto; gap: 18px; padding: 14px 0; border-bottom: 1px solid var(--line); align-items: start; }
.backup:last-child { border-bottom: 0; }
.backup-when .pill { margin: 6px 6px 0 0; }
.pill.plain { background: #eef0f3; color: var(--muted); }
.backup-note { white-space: pre-wrap; font-weight: 500; }
.backup-note.muted { font-weight: 400; font-style: italic; }
.backup-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
ul.changes { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; }
ul.changes li { margin-bottom: 2px; }
.linkish { border: 0; background: none; color: var(--accent); padding: 0; font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; }
@media (max-width: 860px) { .backup { grid-template-columns: 1fr; } .backup-actions { justify-content: flex-start; } }
