:root {
  --plum: #4E235F; --violet: #773A96; --lav: #F2E8F8; --lav2: #D9BDEB; --gold: #C99B45; --gold-lt: #F3DFB1;
  --ink: #2b2230; --text: #514a57; --muted: #857c8c; --line: #E8DFE9; --bg: #FBF9FC; --white: #fff;
  --ok: #2f7d52; --ok-bg: #e7f4ec; --warn: #9a6a12; --warn-bg: #fdf3dd; --bad: #b3261e; --bad-bg: #fbe9e7;
  --r: 12px; --sans: 'Inter', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow-x: hidden; }
a { color: var(--violet); }
h1, h2, h3 { color: var(--plum); margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(119,58,150,.35); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(ellipse at 50% 0%, #fff 0%, #F2E8F8 70%); }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 36px 30px; box-shadow: 0 20px 60px -30px rgba(78,35,95,.35); text-align: center; }
.login-card .crown { width: 58px; margin: 0 auto 10px; display: block; }
.login-card h1 { font-family: 'Cinzel', serif; font-size: 1.25rem; letter-spacing: .04em; }
.login-card p { color: var(--muted); margin: 6px 0 22px; font-size: .9rem; }
.login-card form { text-align: left; display: grid; gap: 14px; }
.login-help { margin-top: 18px !important; font-size: .8rem !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--plum); text-decoration: none; }
.side-brand svg { width: 34px; flex: none; }
.side-brand span { font-family: 'Cinzel', serif; font-weight: 600; font-size: .78rem; line-height: 1.2; letter-spacing: .03em; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; font-size: .92rem; }
.nav a:hover { background: var(--bg); }
.nav a.on { background: var(--lav); color: var(--plum); }
.nav .ico { width: 18px; height: 18px; flex: none; opacity: .8; }
.nav .count { margin-left: auto; background: var(--violet); color: #fff; border-radius: 99px; font-size: .72rem; padding: 1px 8px; font-weight: 600; }
.side-foot { margin-top: auto; padding: 16px 8px 4px; display: grid; gap: 8px; font-size: .85rem; }
.side-foot a, .side-foot button { color: var(--muted); background: none; border: 0; padding: 0; text-align: left; cursor: pointer; text-decoration: none; }
.side-foot a:hover, .side-foot button:hover { color: var(--violet); }
.main { min-width: 0; padding: 28px clamp(16px, 4vw, 44px) 80px; }
.topbar { display: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.page-head p { color: var(--muted); margin-top: 4px; font-size: .92rem; }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; font-size: .88rem; margin-bottom: 10px; }
.back:hover { color: var(--violet); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .3s ease; box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(43,34,48,.35); z-index: 40; }
  .topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .topbar strong { color: var(--plum); font-family: 'Cinzel', serif; font-size: .82rem; }
  .main { padding: 20px 16px 80px; }
}

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 999px; border: 1px solid transparent; background: var(--violet); color: #fff; font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none; transition: background .2s, box-shadow .2s, transform .2s; white-space: nowrap; }
.btn:hover { background: var(--plum); box-shadow: 0 8px 20px -10px rgba(78,35,95,.6); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: #fff; color: var(--plum); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--lav2); background: var(--lav); box-shadow: none; }
.btn.gold { background: linear-gradient(135deg, #F8E8BC 0%, #D1A85B 45%, #F0D99E 100%); color: var(--plum); }
.btn.danger { background: var(--bad); }
.btn.danger:hover { background: #8c1d17; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .84rem; }
.btn.link { background: none; color: var(--violet); padding: 6px 8px; min-height: 36px; }
.btn.link:hover { background: var(--lav); box-shadow: none; }
.btn.link.danger-text { color: var(--bad); }
.btn.link.danger-text:hover { background: var(--bad-bg); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; display: inline-grid; place-items: center; color: var(--plum); flex: none; }
.icon-btn:hover { background: var(--lav); }
.icon-btn:disabled { opacity: .35; cursor: default; background: #fff; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- cards ---------- */
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.card + .card { margin-top: 18px; }
.card h2 { margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; text-decoration: none; color: inherit; transition: border-color .2s, transform .2s; }
.stat:hover { border-color: var(--lav2); transform: translateY(-2px); }
.stat b { display: block; font-size: 2rem; color: var(--plum); line-height: 1.1; font-weight: 600; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat.alert b { color: var(--violet); }
.quick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 22px; }
.quick .btn { min-height: 58px; border-radius: 14px; font-size: .95rem; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 14px; padding: 11px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.activity li:first-child { border-top: 0; }
.activity time { color: var(--muted); font-size: .82rem; white-space: nowrap; min-width: 120px; }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty b { display: block; color: var(--plum); font-size: 1.05rem; margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* ---------- tables / lists ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.tabs { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: .86rem; color: var(--text); }
.tabs button.on { background: var(--lav); color: var(--plum); }
.list { background: #fff; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.item { display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: #fdfbfe; }
.item.unread .item-title { font-weight: 700; }
.thumb { width: 92px; aspect-ratio: 16/10; border-radius: 8px; background: var(--lav) center/cover no-repeat; display: grid; place-items: center; color: var(--violet); font-size: .7rem; overflow: hidden; flex: none; }
.thumb.book { width: 54px; aspect-ratio: 2/3; }
.thumb.none { background: linear-gradient(135deg, #f7f1fa, #efe4f5); }
.item-title { color: var(--ink); font-weight: 600; }
.item-meta { color: var(--muted); font-size: .84rem; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.item-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 10px; font-size: .74rem; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.published, .badge.active, .badge.completed, .badge.sent { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.draft, .badge.unsubscribed, .badge.archived { background: #f1eff3; color: #6b6470; border-color: transparent; }
.badge.new, .badge.featured { background: var(--lav); color: var(--violet); border-color: transparent; }
.badge.contacted, .badge.skipped, .badge.pending { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.failed { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
@media (max-width: 640px) {
  .item { grid-template-columns: auto 1fr; }
  .item-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .thumb { width: 72px; }
}

/* ---------- forms ---------- */
.form { display: grid; gap: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-weight: 600; color: var(--ink); font-size: .9rem; }
.field .hint { color: var(--muted); font-size: .82rem; }
.field .err { color: var(--bad); font-size: .84rem; font-weight: 500; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--bad); }
input[type=text], input[type=email], input[type=url], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea, .rte {
  width: 100%; min-height: 46px; padding: 11px 14px; border: 1px solid #ddd2df; border-radius: 10px; background: #fff; font-size: 1rem; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus, .rte:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(119,58,150,.14); }
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--violet); flex: none; }
.switch-row { display: flex; gap: 12px; flex-wrap: wrap; }
.choice { flex: 1 1 140px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; background: #fff; font-weight: 500; }
.choice input { accent-color: var(--violet); width: 18px; height: 18px; }
.choice:has(input:checked) { border-color: var(--violet); background: var(--lav); color: var(--plum); }
.savebar { position: sticky; bottom: 0; z-index: 20; margin: 24px -4px 0; padding: 14px 4px; background: linear-gradient(to top, var(--bg) 70%, rgba(251,249,252,0)); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.savebar .state { color: var(--muted); font-size: .86rem; margin-left: auto; }
.savebar .state.dirty { color: var(--warn); }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; align-items: start; }
@media (max-width: 1100px) { .editor-grid { grid-template-columns: 1fr; } }

/* image field */
.imgfield { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.imgfield .preview { width: 150px; aspect-ratio: 4/3; border-radius: 10px; border: 1px dashed #d8c9de; background: #faf6fc center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: .8rem; text-align: center; padding: 6px; }
.imgfield .preview.book { width: 100px; aspect-ratio: 2/3; }
.imgfield .preview.has { border-style: solid; color: transparent; }

/* youtube field */
.yt-preview { display: flex; gap: 12px; align-items: center; margin-top: 8px; padding: 10px; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-size: .88rem; font-weight: 500; }
.yt-preview img { width: 120px; border-radius: 6px; aspect-ratio: 16/9; object-fit: cover; }
.yt-preview.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- block editor ---------- */
.blocks { display: grid; gap: 12px; }
.block { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 14px; position: relative; transition: border-color .2s, box-shadow .2s; }
.block:focus-within { border-color: var(--lav2); box-shadow: 0 6px 24px -16px rgba(78,35,95,.4); }
.block-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.block-type { font-size: .72rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--violet); margin-right: auto; }
.block-head .icon-btn { width: 34px; height: 34px; font-size: .9rem; }
.rte { min-height: 90px; line-height: 1.65; cursor: text; overflow-wrap: anywhere; }
.rte:empty::before { content: attr(data-placeholder); color: #aaa0b0; }
.rte.h { min-height: 46px; font-size: 1.2rem; font-weight: 600; color: var(--plum); }
.rte a { color: var(--violet); }
.minibar { display: flex; gap: 4px; margin-bottom: 6px; }
.minibar button { min-width: 36px; height: 32px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font-size: .85rem; color: var(--plum); }
.minibar button:hover { background: var(--lav); }
.block.quote .rte, .block.scripture .rte { font-style: italic; border-left: 3px solid var(--gold); }
.block .sub { margin-top: 8px; }
.block img.bimg { max-width: 100%; max-height: 260px; border-radius: 8px; display: block; margin-bottom: 8px; }
.add-block { position: relative; }
.add-block > .btn { width: 100%; border-style: dashed; border-width: 2px; min-height: 52px; }
.add-menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.add-menu button { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.add-menu button:hover { background: var(--lav); border-color: var(--lav2); }
.add-menu b { color: var(--plum); font-size: .9rem; }
.add-menu small { color: var(--muted); font-size: .76rem; }

/* ---------- media ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.media { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.media .img { aspect-ratio: 1; background: #f7f2f9 center/cover no-repeat; }
.media .meta { padding: 8px 10px; font-size: .78rem; color: var(--muted); display: grid; gap: 6px; }
.media .meta b { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media.pick { cursor: pointer; border-width: 2px; }
.media.pick:hover { border-color: var(--violet); }
.dropzone { border: 2px dashed #d8c9de; border-radius: 16px; padding: 26px; text-align: center; background: #fff; color: var(--muted); margin-bottom: 18px; transition: background .2s, border-color .2s; }
.dropzone.over { background: var(--lav); border-color: var(--violet); }
.dropzone b { color: var(--plum); display: block; margin-bottom: 4px; }

/* ---------- detail panel ---------- */
.detail dl { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; margin: 0; }
.detail dt { color: var(--muted); font-size: .88rem; }
.detail dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.detail .msg { white-space: pre-wrap; background: var(--bg); border-radius: 12px; padding: 16px; margin-top: 16px; color: var(--ink); }
@media (max-width: 600px) { .detail dl { grid-template-columns: 1fr; gap: 2px; } .detail dd { margin-bottom: 10px; } }
.notice { padding: 12px 16px; border-radius: 12px; background: var(--warn-bg); color: var(--warn); font-size: .9rem; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.notice.info { background: var(--lav); color: var(--plum); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }

/* ---------- dialogs & toasts ---------- */
.dlg { border: 0; border-radius: 18px; padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px -20px rgba(43,34,48,.45); color: var(--text); }
.dlg::backdrop { background: rgba(43,34,48,.45); }
.dlg h2 { margin-bottom: 8px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.dlg-wide { width: min(980px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toasts { position: fixed; z-index: 100; left: 50%; bottom: 22px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 13px 18px; border-radius: 12px; box-shadow: 0 14px 40px -12px rgba(0,0,0,.4); font-weight: 500; font-size: .92rem; animation: tin .3s ease; }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--lav); border-top-color: var(--violet); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drag / arrow ordering ---------- */
.item.sortable { grid-template-columns: auto auto 1fr auto; }
.order { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.order-btn { width: 28px; height: 20px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 9px; line-height: 1; cursor: pointer; }
.order-btn:hover:not(:disabled) { color: var(--violet); border-color: var(--violet); }
.order-btn:disabled { opacity: .3; cursor: default; }
.order-handle { min-width: 28px; padding: 3px 0; text-align: center; font: 600 12px/1 inherit; color: var(--muted); cursor: grab; border-radius: 6px; }
.order-handle:focus-visible { outline: 2px solid var(--violet); outline-offset: 1px; }
.item.dragging { opacity: .45; }
.item.drop-before { box-shadow: inset 0 3px 0 var(--violet); }
.item.drop-after { box-shadow: inset 0 -3px 0 var(--violet); }
.order-hint { margin: 0 0 10px; color: var(--muted); }
@media (max-width: 640px) {
  .item.sortable { grid-template-columns: auto auto 1fr; }
}

/* ---------- PDF block ---------- */
.pdf-block { display: grid; gap: 12px; }
.pdf-file a { display: inline-flex; align-items: center; gap: 10px; color: var(--violet); text-decoration: none; font-size: .9rem; }
.pdf-file a b { font-size: .7rem; letter-spacing: .08em; color: #fff; background: #B2443A; border-radius: 4px; padding: 3px 6px; }
.pdf-file a:hover span { text-decoration: underline; }
