:root {
  --paper: #f6f5f2;
  --card: #ffffff;
  --ink: #111111;
  --muted: #6b6864;
  --line: #e4e1db;
  --line-strong: #cfcac2;
  --accent: #b8798a;
  --ok: #1f7a4d;
  --bad: #b3261e;
  --warn: #9a6a00;
  --side: #121212;
  --radius: 12px;
  --serif: "Libre Baskerville", Baskerville, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: inherit; }
h1, h2 { font-family: var(--serif); font-weight: 700; margin: 0; }
h1 { font-size: 26px; letter-spacing: .01em; }
h2 { font-size: 17px; margin-bottom: 16px; }
.muted { color: var(--muted); }
p { margin: 0; }
.ic { width: 18px; height: 18px; flex: none; }

/* ───────── sidebar ───────── */
.side { position: fixed; inset: 0 auto 0 0; width: 256px; background: var(--side); color: #eceae6; display: flex; flex-direction: column; padding: 22px 14px; overflow-y: auto; z-index: 30; }
.brand { text-decoration: none; padding: 0 10px 22px; display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid #2a2a2a; margin-bottom: 14px; }
.brand span { font-family: var(--serif); font-size: 20px; letter-spacing: .28em; }
.brand small { color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: .16em; }
.side nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.side nav a, .side-foot a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; text-decoration: none; color: #c9c6c0; font-size: 14px; transition: background .15s, color .15s; }
.side nav a:hover, .side-foot a:hover { background: #1e1e1e; color: #fff; }
.side nav a.on { background: #fff; color: #111; font-weight: 600; }
.nav-title { text-transform: uppercase; letter-spacing: .14em; font-size: 10.5px; color: #77736d; padding: 16px 12px 6px; }
.side-foot { border-top: 1px solid #2a2a2a; padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.side-foot em { color: #8a867f; font-style: normal; font-size: 12px; }

/* ───────── main ───────── */
.main { margin-left: 256px; padding: 0 36px 60px; min-height: 100vh; }
.login-page .main, body:not(:has(.side)) .main { margin-left: 0; max-width: 760px; margin-inline: auto; padding-top: 40px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 28px 0 18px; }
.page-head p { margin-top: 4px; max-width: 60ch; }
.page-head.sticky { position: sticky; top: 0; z-index: 20; background: linear-gradient(var(--paper) 82%, transparent); }
.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.save-state { font-size: 13px; color: var(--muted); min-width: 110px; text-align: right; }
.save-state.ok { color: var(--ok); }
.save-state.dirty { color: var(--warn); }
.save-state.err { color: var(--bad); }

.flash { padding: 12px 16px; border-radius: 10px; margin: 18px 0 0; font-size: 14px; border: 1px solid; }
.flash.ok { background: #eaf6ef; border-color: #b9dfca; color: #14532d; }
.flash.err { background: #fdecea; border-color: #f3c0bb; color: #8c1d18; }
.flash.warn { background: #fff5dd; border-color: #f1d99a; color: #7a5200; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 18px; }
.card.narrow { max-width: 480px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; margin-bottom: 22px; }
.doc-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; transition: transform .2s, box-shadow .2s, border-color .2s; }
.doc-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px -14px rgba(0,0,0,.28); border-color: var(--line-strong); }
.doc-card strong { font-family: var(--serif); font-size: 16px; }
.doc-card .muted { font-size: 13.5px; }
.doc-card em { font-style: normal; font-size: 12px; color: var(--accent); margin-top: auto; padding-top: 8px; }
.doc-ic { width: 38px; height: 38px; border-radius: 10px; background: var(--paper); display: grid; place-items: center; margin-bottom: 6px; }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checks li { display: flex; gap: 10px; align-items: center; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--bad); }
.checks span { color: var(--ink); }

/* ───────── controls ───────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--ink); background: #fff; color: var(--ink); font: 600 14px var(--sans); cursor: pointer; text-decoration: none; transition: transform .12s, background .15s, color .15s, opacity .15s; }
.btn:hover { background: var(--ink); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #2b2b2b; }
.btn.ghost { border-color: var(--line-strong); background: transparent; }
.btn.ghost:hover { background: var(--ink); border-color: var(--ink); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.ico { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer; display: inline-grid; place-items: center; color: var(--muted); }
.ico:hover { background: var(--paper); color: var(--ink); border-color: var(--line); }
.ico .ic { width: 16px; height: 16px; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }

.lbl { display: block; font-weight: 600; font-size: 13.5px; margin: 0 0 6px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; font: inherit; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(17,17,17,.08); }
textarea.input { resize: vertical; min-height: 84px; }
select.input { appearance: auto; }

.switch-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input[type=checkbox] { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; background: #d6d2ca; border-radius: 99px; transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked ~ i { background: var(--ink); }
.switch input:checked ~ i::after { transform: translateX(18px); }
.switch input:focus-visible ~ i { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-weight: 600; font-size: 14px; }

.color-field { display: flex; gap: 8px; align-items: center; }
.color-pick { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; cursor: pointer; }
.color-text { max-width: 140px; font-family: ui-monospace, Consolas, monospace; }
.range-field { display: flex; gap: 14px; align-items: center; }
.range-field input { flex: 1; accent-color: var(--ink); }
.range-field output { min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* image field */
.img-field { display: flex; gap: 14px; align-items: flex-start; }
.img-preview { width: 112px; height: 112px; flex: none; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; display: grid; place-items: center; color: var(--muted); font-size: 12px;
  background: conic-gradient(#efece6 25%, #fff 0 50%, #efece6 0 75%, #fff 0) 0 0 / 16px 16px; }
.img-preview img { width: 100%; height: 100%; object-fit: contain; }
.img-meta { flex: 1; min-width: 0; display: grid; gap: 8px; }
.img-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.img-input { font-size: 12.5px; color: var(--muted); }

/* repeater */
.rep { display: grid; gap: 10px; }
.rep-items { display: grid; gap: 10px; }
.home-rows, .home-rows-items { display: grid; gap: 10px; }
.rep-item { border: 1px solid var(--line-strong); border-radius: 10px; background: #fbfaf8; }
.rep-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 4px; }
.rep-toggle { flex: 1; text-align: left; background: none; border: 0; padding: 9px 10px; font: 600 14px var(--sans); cursor: pointer; display: flex; align-items: center; gap: 10px; color: var(--ink); }
.rep-toggle::before { content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .18s; flex: none; margin-right: 2px; }
.rep-item.open > .rep-head .rep-toggle::before { transform: rotate(45deg); }
.rep-btns { display: flex; gap: 2px; }
.rep-body { display: none; padding: 6px 16px 16px; border-top: 1px solid var(--line); }
.rep-item.open > .rep-body { display: block; padding-top: 16px; }
.rep-body .rep-item { background: #fff; }
.rep .rep-add { justify-self: start; }
.rep-item:first-child .rep-up, .rep-item:last-child .rep-down { opacity: .3; pointer-events: none; }

/* ───────── edit layout ───────── */
.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; align-items: start; }
.form-foot { display: flex; justify-content: flex-end; margin-top: 6px; }
.preview-pane { display: none; }
@media (min-width: 1360px) {
  .has-preview .edit-layout { grid-template-columns: minmax(0, 720px) minmax(380px, 1fr); }
  .preview-pane { display: flex; }
  #togglePreview { display: none; }
}
.preview-pane { position: sticky; top: 108px; flex-direction: column; height: calc(100vh - 128px); border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: #fff; }
.preview-pane.floating { display: flex; position: fixed; inset: 20px; top: 20px; height: auto; z-index: 60; box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); }
.preview-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--muted); background: var(--paper); }
.preview-pane iframe { flex: 1; width: 100%; border: 0; background: var(--paper); }

/* ───────── media ───────── */
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 30px; display: grid; place-items: center; gap: 4px; text-align: center; background: #fff; transition: border-color .15s, background .15s; margin-bottom: 22px; }
.dropzone .ic { width: 28px; height: 28px; color: var(--accent); }
.dropzone.over { border-color: var(--ink); background: #faf8f4; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.media-item { position: relative; border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; cursor: default; text-align: left; padding: 0; font: inherit; color: inherit; }
.media-item .thumb { aspect-ratio: 1; display: grid; place-items: center; background: conic-gradient(#efece6 25%, #fff 0 50%, #efece6 0 75%, #fff 0) 0 0 / 16px 16px; }
.media-item img { width: 100%; height: 100%; object-fit: contain; }
.media-item .meta { padding: 8px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-item .meta b { display: block; color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.media-item .del { position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,.95); border-color: var(--line); }
.media-item .seed { position: absolute; top: 8px; left: 8px; background: var(--ink); color: #fff; font-size: 10px; padding: 2px 7px; border-radius: 99px; letter-spacing: .06em; text-transform: uppercase; }
.pick .media-item { cursor: pointer; }
.pick .media-item:hover, .pick .media-item:focus-visible { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); outline: none; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(10,10,10,.55); padding: 24px; }
.modal-box { background: var(--paper); border-radius: 16px; width: min(960px, 100%); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 40px 100px -20px rgba(0,0,0,.6); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); background: #fff; }
.modal-head h3 { margin: 0; font: 700 17px var(--serif); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body .dropzone { padding: 18px; margin-bottom: 16px; }

/* ───────── phone preview ───────── */
.preview-fab { position: fixed; right: 24px; bottom: 24px; z-index: 70; width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; cursor: pointer; box-shadow: 0 14px 32px -10px rgba(0,0,0,.5); transition: transform .18s, background .18s; }
.preview-fab:hover { background: #2b2b2b; transform: translateY(-2px); }
.preview-fab .ic { width: 24px; height: 24px; }
.preview-modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(10,10,10,.62); padding: 20px; }
.preview-modal[hidden] { display: none; }
.phone-frame { width: min(390px, 100%); height: min(800px, 88vh); background: #101010; border-radius: 36px; padding: 12px; box-shadow: 0 50px 120px -20px rgba(0,0,0,.7); display: flex; flex-direction: column; }
.phone-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 8px 10px; color: #d9d6d0; font-size: 12px; }
.phone-bar-actions { display: flex; gap: 2px; flex: none; }
.phone-bar .ico { color: #d9d6d0; }
.phone-bar .ico:hover { background: #262626; color: #fff; }
.phone-frame iframe { flex: 1; width: 100%; min-height: 0; border: 0; border-radius: 22px; background: #fff; }
@media (max-width: 560px) {
  .preview-fab { right: 14px; bottom: 14px; width: 48px; height: 48px; }
  .preview-fab .ic { width: 21px; height: 21px; }
  .preview-modal { padding: 0; }
  .phone-frame { width: 100%; height: 100%; border-radius: 0; padding: 8px; }
  .phone-frame iframe { border-radius: 14px; }
}

/* ───────── login ───────── */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: radial-gradient(1200px 500px at 50% -10%, #ffffff 0%, var(--paper) 60%); }
.login-card { width: min(400px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 34px 32px; box-shadow: 0 30px 60px -30px rgba(0,0,0,.25); }
.login-card h1 { margin: 22px 0 4px; font-size: 22px; }
.login-card .lbl { margin-top: 16px; }
.login-card .btn { margin-top: 22px; }
.login-brand { text-align: center; }
.login-brand span { font: 400 26px var(--serif); letter-spacing: .32em; padding-left: .32em; }
.login-brand small { display: block; margin-top: 4px; font-size: 10.5px; letter-spacing: .22em; text-transform: uppercase; color: var(--accent); }
.back-link { display: block; text-align: center; margin-top: 18px; color: var(--muted); font-size: 13px; }
.row-actions { margin-top: 22px; }

/* ───────── catalog CRUD ───────── */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 20px; }
.form-grid .field.full { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 10px 10px; border-bottom: 1px solid var(--line-strong); }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--paper); display: block; }
table.data .row-actions { display: flex; gap: 6px; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--paper); color: var(--muted); }
.badge.on { background: #eaf6ef; color: var(--ok); }
.btn.danger { border-color: #e3b3ae; color: var(--bad); }
.btn.danger:hover { background: var(--bad); border-color: var(--bad); color: #fff; }
form.inline { display: inline; }

/* ───────── responsive ───────── */
.mobile-bar { display: none; }
.side-close { display: none; }
.side-scrim { display: none; }

@media (max-width: 960px) {
  .mobile-bar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--side); color: #eceae6; }
  .mobile-bar-btn { display: grid; place-items: center; width: 38px; height: 38px; margin: -8px; border: 0; border-radius: 9px; background: none; color: inherit; cursor: pointer; transition: background .15s; }
  .mobile-bar-btn:hover, .mobile-bar-btn:active { background: #1e1e1e; }
  .mobile-bar-btn .ic { width: 22px; height: 22px; }
  .mobile-bar-brand { font-family: var(--serif); font-size: 15px; letter-spacing: .22em; }
  .mobile-bar-brand em { font-style: normal; color: var(--accent); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; margin-left: 8px; }

  .side-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(10, 10, 10, .55); opacity: 0; pointer-events: none; transition: opacity .3s ease; }
  .side-scrim.show { opacity: 1; pointer-events: auto; }

  .side { position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px); flex-direction: column; padding: 22px 14px; z-index: 60; transform: translateX(-100%); transition: transform .34s cubic-bezier(.22, 1, .36, 1); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5); }
  .side.open { transform: translateX(0); }
  .side-close { display: grid; position: absolute; right: 12px; top: 18px; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: #c9c6c0; cursor: pointer; }
  .side-close:hover { background: #1e1e1e; color: #fff; }
  .side-close .ic { width: 18px; height: 18px; }
  .side nav { flex-direction: column; overflow-y: auto; gap: 2px; }
  .nav-title { display: block; }
  .side-foot { flex-direction: column; }

  .main { margin-left: 0; padding: 0 16px 50px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; padding: 18px 0 14px; }
  .page-head.sticky { position: static; }
  .head-actions { width: 100%; }
  .save-state { text-align: left; }
  .img-field { flex-direction: column; }
  .card { padding: 18px 16px; }
}

@media (max-width: 680px) {
  h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .form-grid .field { margin-bottom: 18px; }
  .cards { grid-template-columns: 1fr; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  table.data { font-size: 12.5px; }
  table.data th, table.data td { padding: 8px 6px; }
  table.data .thumb { width: 36px; height: 36px; }
  .row-actions { flex-wrap: wrap; gap: 6px; }
  .modal { padding: 0; }
  .modal-box { width: 100%; height: 100%; max-height: 100vh; border-radius: 0; }
  .modal-body { padding: 14px; }
  .dropzone { padding: 20px 14px; }
  .login-card { padding: 26px 22px; }
  .brand span { font-size: 17px; letter-spacing: .2em; }
}

/* ───────── docked live preview (wide screens) ───────── */
@media (min-width: 1200px) {
  body:has(#previewFab) .main { margin-right: 452px; }
  body:has(#previewFab) .preview-fab, body:has(#previewFab) #previewFabClose { display: none; }
  body:has(#previewFab) .preview-modal, body:has(#previewFab) .preview-modal[hidden] { display: grid; position: fixed; inset: 0 0 0 auto; width: 452px; padding: 18px 20px 18px 6px; background: transparent; z-index: 20; pointer-events: none; place-items: stretch; }
  body:has(#previewFab) .phone-frame { width: 100%; height: 100%; pointer-events: auto; box-shadow: 0 30px 70px -30px rgba(0,0,0,.6); }
}
