/* The editor and AI apps (Phase 3). Colours, sizes and spacing come from tokens.css; no colours of its own.
   Phone under 40rem, tablet 40rem to 63.99rem, desktop 64rem and wider (media queries can't read tokens). */
body.editing .top { display: none; }
body.editing { overflow: hidden; }
main.editor { max-width: none; padding: 0; }
.icon { flex: none; vertical-align: middle; }
button .icon, .ui-btn .icon { margin-right: var(--ui-space-1); }
button.icon-btn { width: auto; min-width: var(--ui-tap); margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.mono { font-family: var(--ui-font-mono); overflow-wrap: anywhere; }
.warn { color: var(--ui-warn); }
.check { display: flex; align-items: center; font-weight: var(--ui-fw-normal); }
.toast-link { color: var(--ui-ink-invert); }

/* Layout */
.ed { display: flex; flex-direction: column; height: 100dvh; }
.offline-bar { background: var(--ui-warn-soft); color: var(--ui-warn); text-align: center; padding: var(--ui-space-1); font-size: var(--ui-fs-sm); }
.plan-bar { margin: 0; border-radius: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--ui-space-3); }
.plan-bar button { margin: 0; width: auto; min-width: 0; }
.ed-top { display: flex; align-items: center; gap: var(--ui-space-2); min-height: var(--ui-topbar-h); padding: 0 var(--ui-space-3); background: var(--ui-surface); border-bottom: 1px solid var(--ui-line); overflow-x: auto; }
.ed-top button, .ed-top .ui-btn { margin: 0; width: auto; min-width: 0; min-height: var(--ui-tap); white-space: nowrap; }
.ed-back .site-name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; }
.ed-pagebtn { display: none !important; }
.seg { display: inline-flex; border: 1px solid var(--ui-line-strong); border-radius: var(--ui-radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; }
.seg button[aria-pressed="true"] { background: var(--ui-accent-soft); color: var(--ui-accent); }
.save { color: var(--ui-muted); white-space: nowrap; }
.save.error { color: var(--ui-error); }
.save.offline { color: var(--ui-warn); }
.only-desktop { display: none; }
.ed-body { flex: 1; display: flex; min-height: 0; position: relative; }
.ed-pages { width: var(--ui-sidebar-w); overflow-y: auto; background: var(--ui-surface); border-right: 1px solid var(--ui-line); padding: var(--ui-space-3); flex: none; }
.ed-stage { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; padding: var(--ui-space-4); overflow: auto; background: var(--ui-surface-2); }
.frame-box { position: relative; flex: none; overflow: hidden; background: var(--ui-surface); box-shadow: var(--ui-shadow-1); }
.frame-box.full { width: 100%; height: 100%; flex: 1; }
.ed-frame { display: block; border: 0; background: var(--ui-surface); }
.frame-box.full .ed-frame { width: 100%; height: 100%; }
.tap-bar { display: flex; align-items: center; gap: var(--ui-space-2); margin-bottom: var(--ui-space-2); padding: var(--ui-space-2) var(--ui-space-3); border-radius: var(--ui-radius); background: var(--ui-info-soft); color: var(--ui-info); }
.tap-bar button { margin: 0; width: auto; min-width: 0; }
.ed-sheet { width: var(--ui-panel-w); flex: none; display: flex; flex-direction: column; overflow-y: auto; background: var(--ui-surface); border-left: 1px solid var(--ui-line); }
.ed-panel { padding: 0 var(--ui-space-3) var(--ui-space-5); }
.grab, .ed-bottom { display: none; }

/* Tablet and phone: the page list is a drawer, the panel slides in over the preview */
@media (max-width: 63.99rem) {
  .ed-pagebtn { display: inline-flex !important; }
  .ed-pages { position: absolute; left: 0; top: 0; bottom: 0; z-index: var(--ui-z-drawer); transform: translateX(-100%); transition: transform var(--ui-dur) var(--ui-ease); box-shadow: var(--ui-shadow-2); }
  .ed-pages.open { transform: translateX(0); }
  .ed-sheet { position: absolute; right: 0; top: 0; bottom: 0; z-index: var(--ui-z-drawer); transform: translateX(100%); transition: transform var(--ui-dur) var(--ui-ease); box-shadow: var(--ui-shadow-2); max-width: 100%; }
  .ed-sheet.open { transform: translateX(0); }
}
@media (min-width: 64rem) { .only-desktop { display: inline; } }

/* Phone: the preview is the phone; the panel is a bottom sheet */
@media (max-width: 39.99rem) {
  .ed-back .site-name, .ed-preview, .seg, .zoom { display: none; }
  .ed-stage { padding: 0; }
  .ed-body:has(.ed-sheet.open) .ed-stage { flex: none; height: 45dvh; }
  .ed-pages { top: auto; width: 100%; height: 60dvh; transform: translateY(100%); border-radius: var(--ui-radius-lg) var(--ui-radius-lg) 0 0; }
  .ed-pages.open { transform: translateY(0); }
  .ed-sheet { position: relative; width: 100%; flex: 1; transform: none; box-shadow: none; border-left: 0; border-top: 1px solid var(--ui-line); display: none; }
  .ed-sheet.open { display: flex; }
  .ed-sheet.full { position: absolute; inset: 0; z-index: var(--ui-z-drawer); }
  .grab { display: block; width: 100%; margin: 0; border: 0; border-radius: 0; min-height: var(--ui-tap); }
  .ed-bottom { display: flex; border-top: 1px solid var(--ui-line); background: var(--ui-surface); }
  .ed-bottom > * { flex: 1; margin: 0; border: 0; border-radius: 0; }
}

/* Panel head, tabs, chips */
.panel-head { position: sticky; top: 0; z-index: 1; padding: var(--ui-space-3) 0 var(--ui-space-2); background: var(--ui-surface); border-bottom: 1px solid var(--ui-line); }
.panel-top { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-2); }
.panel-top h2, .panel-title { margin: 0; font-size: var(--ui-fs-md); }
.panel-empty { padding-top: var(--ui-space-4); }
.panel-acts { margin: var(--ui-space-2) 0; }
.panel-acts button, .item-foot button { margin: 0; }
.panel-foot { position: sticky; bottom: 0; display: flex; flex-direction: column; gap: var(--ui-space-2); padding: var(--ui-space-3) 0; background: var(--ui-surface); border-top: 1px solid var(--ui-line); }
.panel-foot button { margin: 0; }
.tabs2 { display: flex; gap: var(--ui-space-1); margin-top: var(--ui-space-2); }
.tab { flex: 1; margin: 0; border-radius: var(--ui-radius-sm); }
.tab[aria-selected="true"] { background: var(--ui-accent-soft); }
.tab.ai { color: var(--ui-ai); border-color: var(--ui-ai); }
.tab.ai[aria-selected="true"] { background: var(--ui-ai-soft); }
.chips { display: flex; flex-wrap: wrap; gap: var(--ui-space-2); margin: var(--ui-space-2) 0; }
.chip { width: auto; min-width: 0; margin: 0; min-height: 40px; padding: var(--ui-space-1) var(--ui-space-3); border-radius: var(--ui-radius-pill); }

/* The form */
fieldset { min-width: 0; border: 0; padding: 0; margin: 0 0 var(--ui-space-3); }
legend { padding: 0; font-weight: var(--ui-fw-bold); }
.f { margin-bottom: var(--ui-space-3); }
.f > label, .f > .lbl { display: block; }
.hint { margin: 0 0 var(--ui-space-1); }
.stack { display: grid; gap: var(--ui-space-2); }
.ui-err { margin: var(--ui-space-1) 0 0; color: var(--ui-error); font-size: var(--ui-fs-sm); }
.ui-counter { margin: var(--ui-space-1) 0 0; text-align: right; color: var(--ui-muted); }
.ui-counter.over { color: var(--ui-error); }
.f.bad input, .f.bad textarea, .f.bad select { border: 2px solid var(--ui-error); }
.group .f.group, details.more { margin-left: var(--ui-space-2); padding-left: var(--ui-space-3); border-left: 2px solid var(--ui-line); }
.opts { display: flex; flex-wrap: wrap; gap: var(--ui-space-2); }
.opt { position: relative; display: flex; flex-direction: column; align-items: center; width: 5rem; margin: 0; font-weight: var(--ui-fw-normal); font-size: var(--ui-fs-sm); text-align: center; }
.opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.opt .dot { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--ui-line-strong); border-radius: 50%; }
.opt input:checked + .dot { box-shadow: 0 0 0 3px var(--ui-surface), 0 0 0 6px var(--ui-accent); }
.opt input:focus-visible + .dot { box-shadow: var(--ui-focus); }
.segmented .opt { width: auto; flex-direction: row; padding: var(--ui-space-2) var(--ui-space-3); min-height: var(--ui-tap); border: 1px solid var(--ui-line-strong); border-radius: var(--ui-radius-pill); }
.segmented .dot { display: none; }
.segmented .opt:has(input:checked) { background: var(--ui-accent-soft); border-color: var(--ui-accent); }
.fonts .opts { flex-direction: column; }
.fonts .opt { width: auto; flex-direction: row; gap: var(--ui-space-2); }
.fonts .dot { width: auto; border: 0; border-radius: 0; font-size: var(--ui-fs-md); }
.dot.small { display: inline-block; width: 14px; height: 14px; margin-right: var(--ui-space-1); border: 1px solid var(--ui-line); border-radius: 50%; vertical-align: middle; }
input[role="switch"] { appearance: none; position: relative; flex: none; width: 44px; height: 26px; margin: 0; border-radius: var(--ui-radius-pill); background: var(--ui-line-strong); cursor: pointer; }
input[role="switch"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ui-surface); transition: transform var(--ui-dur) var(--ui-ease); }
input[role="switch"]:checked { background: var(--ui-accent); }
input[role="switch"]:checked::after { transform: translateX(18px); }
.switch-row { margin: var(--ui-space-2) 0; }

/* Lists of items */
.item { margin-bottom: var(--ui-space-2); border: 1px solid var(--ui-line); border-radius: var(--ui-radius); background: var(--ui-surface); }
.item.bad { border-color: var(--ui-error); }
.item-head { display: flex; align-items: center; width: 100%; margin: 0; border: 0; background: none; color: var(--ui-ink); text-align: left; }
.item-body { padding: var(--ui-space-3); border-top: 1px solid var(--ui-line); }
.line { padding: var(--ui-space-2); border: 1px solid var(--ui-line); border-radius: var(--ui-radius); }
.part-row { display: flex; gap: var(--ui-space-2); }
.part-row select { width: auto; flex: none; }
.part-row button { margin: 0; width: auto; min-width: var(--ui-tap); }

/* Ask AI, changes, versions */
.ai-btn, .ai-btn:hover { background: var(--ui-ai); border-color: var(--ui-ai); }
.ai-soft { margin: var(--ui-space-3) 0; padding: var(--ui-space-3); border-radius: var(--ui-radius); background: var(--ui-ai-soft); }
.ai blockquote { margin: var(--ui-space-2) 0; color: var(--ui-muted); }
.diff { list-style: none; margin: var(--ui-space-2) 0; padding: 0; }
.diff li { margin-bottom: var(--ui-space-1); }
.diff-del { background: var(--ui-diff-del); color: var(--ui-error); text-decoration: line-through; }
.diff-add { background: var(--ui-diff-add); color: var(--ui-ok); text-decoration: none; }
.change { padding: var(--ui-space-2) 0 0; border-top: 1px solid var(--ui-line); }
.change p { margin: 0 0 var(--ui-space-1); }
.change-group h3 { margin-top: var(--ui-space-4); }
.version { padding: var(--ui-space-3) 0; border-top: 1px solid var(--ui-line); }
.version p { margin: 0 0 var(--ui-space-1); }
.version button { margin-top: var(--ui-space-2); }

/* Pages */
.page-item { margin-bottom: var(--ui-space-1); }
.page-row { display: flex; align-items: center; width: 100%; margin: 0; border: 0; background: none; color: var(--ui-ink); text-align: left; }
.page-row .small { display: block; }
.page-row[aria-current="page"] { background: var(--ui-accent-soft); }
.section-row { display: block; width: 100%; min-height: 40px; margin: 0; padding-left: var(--ui-space-5); border: 0; background: none; color: var(--ui-ink); text-align: left; font-weight: var(--ui-fw-normal); }
.section-row[aria-current="true"] { background: var(--ui-surface-2); }
.menu-more summary { display: flex; align-items: center; min-height: var(--ui-tap); padding: 0 var(--ui-space-3); cursor: pointer; }
.menu-more button { margin: 0; }
.every { margin-top: var(--ui-space-4); }
.add-list { display: grid; gap: var(--ui-space-2); }
.add-item { display: flex; flex-direction: column; align-items: flex-start; margin: 0; color: var(--ui-ink); text-align: left; }

/* AI apps */
.tech { margin-top: var(--ui-space-5); }
dialog.ui-dialog textarea.mono { font-family: var(--ui-font-mono); }
