:root {
  --bg: #f4f5f7; --card: #fff; --text: #111827; --muted: #4b5563; --line: #e5e7eb;
  --primary: #2563eb; --danger: #dc2626; --ok: #059669; --radius: 12px;
  font-family: system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: .5rem 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar nav { display: flex; align-items: center; gap: .75rem; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
main { max-width: 760px; margin: 1.5rem auto; padding: 0 1rem; }
main.wide { max-width: 1200px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; margin: -.5rem 0 .75rem; }
.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: .5rem .75rem; border-radius: 8px; }
.error-text { color: var(--danger); }
.ok { color: var(--ok); }
.warn { color: #b45309; }
label { display: block; margin-bottom: .75rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=tel], input:not([type]), textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .55rem .7rem; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
textarea { resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .25rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; min-height: 44px; white-space: nowrap; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:hover { background: #f9fafb; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.ghost { background: transparent; }
.btn.small { padding: 0 .6rem; min-height: 44px; min-width: 44px; font-size: 1rem; }
.auth { max-width: 420px; margin: 3rem auto; }
.auth .btn.primary { width: 100%; }
.create { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.create label { flex: 1; min-width: 200px; margin: 0; }
.qr-list { list-style: none; padding: 0; margin: 0; }
.qr-item { display: flex; gap: 1rem; align-items: flex-start; }
.qr-thumb { flex-shrink: 0; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.qr-info { flex: 1; min-width: 0; }
.qr-info h2 { margin: 0; }
.qr-info h2 a { color: var(--text); text-decoration: none; }
.qr-info p { margin: .2rem 0; }
.link-line code, .link-line a { word-break: break-all; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.actions form { margin: 0; }
.badge { display: inline-block; padding: 0 .5rem; border-radius: 99px; font-size: .8rem; }
.badge.on { background: #d1fae5; color: #065f46; }
.badge.off { background: #f3f4f6; color: #4b5563; }
.empty { text-align: center; color: var(--muted); }
.page-head { margin-bottom: 1rem; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 1.5rem; align-items: start; }
.editor-preview { position: sticky; top: 1rem; }
.phone { border: 10px solid #111827; border-radius: 32px; overflow: hidden; height: 720px; max-height: 80vh; background: #fff; }
.phone iframe { width: 100%; height: 100%; border: 0; display: block; }
.blocks { list-style: none; padding: 0; margin: 0; }
.block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.check { display: flex; gap: .6rem; align-items: center; margin: 0; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.color { display: flex; gap: .5rem; align-items: center; }
.color input { width: 52px; height: 44px; cursor: pointer; padding: 0; border: 1px solid var(--line); border-radius: 6px; }
.image-picker { margin-bottom: .75rem; }
.image-picker .label, .add .label { display: block; font-weight: 500; margin-bottom: .25rem; }
.thumb { display: block; max-width: 160px; max-height: 120px; border-radius: 8px; margin-bottom: .4rem; border: 1px solid var(--line); }
.add { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
/* .savebar replaced by .publishbar in v1.3 */
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .editor-preview { position: static; }
  .phone { height: 520px; border-width: 6px; border-radius: 20px; }
}
@media (max-width: 520px) {
  .qr-item { flex-direction: column; }
  .topbar .muted { display: none; }
  .create .btn { width: 100%; }
  main { margin-top: 1rem; }
}

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.file-btn:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.empty-state { text-align: center; padding: 2rem 1.25rem; }
.empty-state h2 { margin: 0 0 .25rem; color: var(--text); }
.empty-state ol { list-style: none; padding: 0; margin: 1rem auto 0; max-width: 320px; text-align: start; display: grid; gap: .5rem; }
.empty-state li { display: flex; gap: .6rem; align-items: center; color: var(--text); }
.empty-state li span { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; background: #dbeafe; color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }

[hidden] { display: none !important; }
.topbar nav { gap: .25rem; flex-wrap: wrap; }
.navlink { display: inline-flex; align-items: center; min-height: 44px; padding: 0 .6rem; color: var(--text); text-decoration: none; border-radius: 8px; }
.navlink:hover { background: #f3f4f6; }
.notice { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; padding: .6rem .8rem; border-radius: 8px; margin: 0 0 1rem; }
.credentials p { margin: 0 0 .4rem; }
.credentials dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0; text-align: left; }
.credentials dt { font-weight: 600; }
.credentials dd { margin: 0; }
.credentials code { font-size: 1.05rem; user-select: all; word-break: break-all; }
.user-list { list-style: none; padding: 0; margin: 0; }
.user-head { display: flex; align-items: center; gap: .5rem; }
.user-head h2 { margin: 0; word-break: break-all; }
.user-item p { margin: .2rem 0; }
.inline-form { display: flex; gap: .4rem; flex: 1; min-width: 220px; }
.inline-form input { margin: 0; flex: 1; min-height: 44px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 520px) {
  .topbar { padding: .5rem .75rem; }
  .navlink { padding: 0 .45rem; }
}

/* ---- v1.2 editor controls ---- */
.block-head .row { gap: .35rem; }
.style-panel { margin-top: .25rem; border-top: 1px solid var(--line); }
.style-panel > summary { list-style: none; display: flex; align-items: center; gap: .5rem; min-height: 44px; cursor: pointer; font-weight: 500; color: var(--primary); }
.style-panel > summary::-webkit-details-marker { display: none; }
.style-panel > summary::before { content: "◂"; transition: transform .15s; display: inline-block; }
.style-panel[open] > summary::before { transform: rotate(-90deg); }
.style-panel .style-summary { color: var(--muted); font-weight: 400; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.style-grid { display: grid; gap: .75rem; padding: .25rem 0 .5rem; }
.ctl { display: grid; gap: .3rem; }
.ctl > .ctl-label { font-size: .85rem; font-weight: 500; color: var(--muted); }

.seg { display: inline-flex; border: 1px solid #d1d5db; border-radius: 10px; overflow: hidden; background: #fff; max-width: 100%; }
.seg label { margin: 0; font-weight: 400; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 .7rem; cursor: pointer; border-inline-start: 1px solid #e5e7eb; white-space: nowrap; }
.seg label:first-child span { border-inline-start: 0; }
.seg input:checked + span { background: var(--primary); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -3px; }
.seg svg { width: 20px; height: 20px; fill: currentColor; }

.color-ctl { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.color-ctl input[type=color] { width: 52px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.color-ctl .is-auto { font-size: .85rem; color: var(--muted); }
.ctl select { min-height: 44px; padding: 0 .6rem; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff; max-width: 100%; }
.toggle-btn[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

.social-fields label { display: grid; grid-template-columns: 28px 1fr; align-items: center; column-gap: .5rem; }
.social-fields label .soc-mini { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; grid-row: span 2; color: #fff; }
.social-fields label .soc-mini svg { width: 15px; height: 15px; fill: currentColor; }
.social-fields input { grid-column: 2; }

.themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .5rem; margin-bottom: .75rem; }
.theme-swatch { display: grid; gap: .35rem; justify-items: center; padding: .6rem .4rem; min-height: 88px; border: 2px solid transparent; border-radius: 12px; cursor: pointer; font: inherit; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.theme-swatch .sw-text { font-size: 1.2rem; line-height: 1; }
.theme-swatch .sw-btn { width: 70%; height: 14px; border-radius: 99px; }
.theme-swatch .sw-name { font-size: .75rem; }
.theme-swatch[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px #fff inset; }
.theme-swatch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (min-width: 900px) { .themes { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.ctl .seg { display: flex; width: 100%; }
.ctl .seg label { flex: 1; min-width: 0; }
.ctl .seg span { width: 100%; padding: 0 .4rem; }
.block-head { gap: .5rem; }
.block-head .row { flex-wrap: nowrap; flex-shrink: 0; }

/* ---- v1.3: draft / publish, live preview ---- */
.state-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; min-height: 44px; }
.pub-state { display: inline-flex; align-items: center; gap: .45rem; font-weight: 600; }
.pub-state::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--dot, #9ca3af); flex-shrink: 0; }
.pub-state.st-new { --dot: #9ca3af; }
.pub-state.st-live { --dot: #059669; }
.pub-state.st-changes { --dot: #d97706; }
.pub-state.st-hidden { --dot: #4b5563; }

.badge.new { background: #fff; color: #4b5563; box-shadow: inset 0 0 0 1px #d1d5db; }
.badge.changes { background: #fef3c7; color: #92400e; }
.badge.hidden { background: #e5e7eb; color: #374151; }

.publishbar {
  position: sticky; bottom: 0; z-index: 20; margin: 0 -1rem; padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: .5rem;
}
.publishbar .save-state { flex: 1; min-width: 0; font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.publishbar .save-state.saving::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #cbd5e1; border-top-color: var(--primary); animation: spin .8s linear infinite; }
.publishbar .save-state.saved { color: var(--ok); }
.publishbar .save-state.failed { color: var(--danger); }
.publishbar .btn.primary { min-width: 96px; }
.publishbar .btn.primary:disabled { background: #e5e7eb; border-color: #e5e7eb; color: #4b5563; opacity: 1; }
.preview-toggle { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .publishbar .save-state.saving::before { animation: none; } }

.publish-error { margin: 0 0 .75rem; }
.publish-error button { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; min-height: 0; }
.block.has-error { box-shadow: 0 0 0 2px var(--danger); }

/* Mobile: preview becomes a full-height sheet opened from the bar. */
@media (max-width: 900px) {
  .preview-toggle { display: inline-flex; }
  .editor-preview { display: none; }
  .editor-preview.sheet-open {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 40; background: #0b1220; padding: .5rem .5rem calc(.5rem + env(safe-area-inset-bottom));
  }
  .editor-preview.sheet-open > h2 { display: none; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; color: #fff; padding: 0 .25rem .5rem; }
  .sheet-head .btn { background: #fff; }
  .editor-preview.sheet-open .phone { flex: 1; height: auto; max-height: none; border-width: 0; border-radius: 16px; }
}
@media (min-width: 901px) { .sheet-head { display: none; } }

.icon-sample { display: flex; gap: .5rem; align-items: center; }
.contrast-hint { font-size: .8rem; color: #92400e; }
