/* App Kit UI -- tokens, then layout, then components. No external assets. */
:root {
  --primary: #4f46e5; --primary-ink: #fff; --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --bg: #f6f7fb; --panel: #fff; --panel-2: #f1f3f9; --ink: #161a2b; --ink-2: #4a5169; --ink-3: #7b8299;
  --line: #e3e6f0; --danger: #d92d3a; --danger-soft: #fde8ea; --ok: #12875a; --ok-soft: #dff5ea; --warn: #b7791f; --warn-soft: #fdf3dc;
  --radius: 12px; --radius-sm: 8px; --shadow: 0 1px 2px rgba(20,24,45,.06), 0 8px 24px rgba(20,24,45,.06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --side: 248px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #0f1220; --panel: #171b2e; --panel-2: #1e2339; --ink: #eef0f8; --ink-2: #b4bad1; --ink-3: #8189a6; --line: #2a3050;
    --danger-soft: #3a1a20; --ok-soft: #123226; --warn-soft: #3a2f12; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-mode="dark"] {
  --bg: #0f1220; --panel: #171b2e; --panel-2: #1e2339; --ink: #eef0f8; --ink-2: #b4bad1; --ink-3: #8189a6; --line: #2a3050;
  --danger-soft: #3a1a20; --ok-soft: #123226; --warn-soft: #3a2f12; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--ink-3); } .small { font-size: .85rem; } .right { margin-left: auto; }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; height: 100vh; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* shell */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.1rem .8rem; font-weight: 700; font-size: 1.05rem; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-weight: 800; }
.nav { padding: .4rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: .9rem .6rem .3rem; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.side .foot { margin-top: auto; padding: .8rem; border-top: 1px solid var(--line); font-size: .85rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .75rem 1.5rem; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line); }
.burger { display: none; }
.content { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-3); }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(82vw, 300px); transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .burger { display: inline-flex; }
  .content { padding: 1rem; }
}

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .pad, .pad { padding: 1.1rem 1.25rem; }
.card-head { display: flex; align-items: center; gap: .6rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--line); }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.content { container-type: inline-size; }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@container (max-width: 860px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 720px) { .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 > :last-child:nth-child(odd) { grid-column: 1 / -1; } }
@container (max-width: 400px) { .grid.c3, .grid.c4 { grid-template-columns: minmax(0, 1fr); } }
.stat { padding: 1rem 1.2rem; }
.stat .v { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--ink-3); font-size: .85rem; }
.btn { display: inline-flex; align-items: center; gap: .45rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: .5rem .9rem; border-radius: var(--radius-sm); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); } .btn.danger.solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { padding: .4rem; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--ink-2); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 96px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
label.f .help { font-weight: 400; color: var(--ink-3); font-size: .82rem; }
label.f .err, .err { color: var(--danger); font-weight: 500; font-size: .85rem; }
.form-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .search { flex: 1; min-width: 180px; max-width: 360px; position: relative; }
.badge { display: inline-flex; align-items: center; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--panel-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--primary-soft); color: var(--primary); }
.table-wrap { overflow: auto; container-type: inline-size; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: .6rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: default; }
table.t th.sortable { cursor: pointer; user-select: none; }
table.t td { padding: .7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover { background: var(--panel-2); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-3); }
.pager { display: flex; align-items: center; gap: .5rem; padding: .75rem 1rem; border-top: 1px solid var(--line); color: var(--ink-3); font-size: .9rem; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow: auto; }
.tabs a { padding: .6rem .9rem; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); text-decoration: none; }
.toast-wrap { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); max-width: 340px; }
.toast.bad { background: var(--danger); color: #fff; }
.overlay { position: fixed; inset: 0; background: rgba(10,12,25,.5); display: grid; place-items: center; z-index: 60; padding: 1rem; }
.modal { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); width: min(640px, 100%); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(860px, 100%); }
.modal .mh { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: .6rem; }
.modal .mb { padding: 1.25rem; overflow: auto; }
.modal .mf { padding: .85rem 1.25rem; border-top: 1px solid var(--line); display: flex; gap: .6rem; justify-content: flex-end; }
.change { display: flex; gap: .6rem; padding: .55rem .7rem; border-radius: var(--radius-sm); background: var(--panel-2); margin-bottom: .4rem; align-items: flex-start; }
.change.destructive { background: var(--danger-soft); }
.callout { padding: .75rem 1rem; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); margin-bottom: .8rem; }
.callout.bad { background: var(--danger-soft); color: var(--danger); } .callout.info { background: var(--primary-soft); color: var(--primary); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(400px, 100%); padding: 2rem; }
.login .logo { width: 48px; height: 48px; margin-bottom: 1rem; border-radius: 14px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-size: 1.4rem; font-weight: 800; }
.chart { width: 100%; height: 220px; }
.chart text { fill: var(--ink-3); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: .75rem; font-size: .82rem; color: var(--ink-2); margin-top: .5rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: .35rem; }
.field-row { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); margin-bottom: .5rem; }
.field-row .grow { flex: 1; min-width: 0; }
.field-row .ty { font-size: .78rem; color: var(--ink-3); }
.block-row { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); margin-bottom: .6rem; }
.block-row .bh { display: flex; align-items: center; gap: .5rem; padding: .55rem .75rem; background: var(--panel-2); border-radius: var(--radius-sm) var(--radius-sm) 0 0; font-weight: 600; }
.block-row .bb { padding: .8rem .9rem; }
.perm-grid { display: grid; grid-template-columns: minmax(140px, 1.4fr) repeat(5, minmax(60px, 1fr)); gap: .25rem .5rem; align-items: center; font-size: .9rem; }
.perm-grid .h { font-size: .75rem; text-transform: uppercase; color: var(--ink-3); letter-spacing: .05em; }
.perm-grid select { padding: .25rem .4rem; font-size: .85rem; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: .5rem 1rem; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.pill-input { display: flex; flex-wrap: wrap; gap: .4rem; }
.pill-input label { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .6rem; border: 1px solid var(--line); border-radius: 999px; font-size: .85rem; cursor: pointer; background: var(--panel); }

@media print {
  body > *:not(.overlay):not(.toast-wrap) { display: none !important; }
  .overlay { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; width: 100%; max-height: none; }
  .modal .mh, .modal .mf { display: none; }
  body { background: #fff; color: #000; }
}
svg.i.flip { transform: rotate(180deg); }

/* ───────── live editor ───────── */
.ed { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: grid; grid-template-rows: 56px 54px 1fr; }
.ed-top { display: flex; align-items: center; gap: .6rem; padding: 0 .9rem; border-bottom: 1px solid var(--line); background: var(--panel); min-width: 0; }
.ed-name { white-space: nowrap; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; }
.ed-grow { flex: 1; }
.ed-select { width: auto; max-width: 16rem; padding: .35rem .6rem; }
.ed-ib { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); cursor: pointer; }
.ed-ib:hover:not([disabled]) { background: var(--panel-2); }
.ed-ib[disabled] { opacity: .35; cursor: default; }
svg.i.flip-x { transform: scaleX(-1); }
.ed-seg { display: inline-flex; background: var(--panel-2); border-radius: var(--radius-sm); padding: 2px; }
.ed-seg button { border: 0; background: transparent; padding: .3rem .55rem; border-radius: 6px; color: var(--ink-2); cursor: pointer; }
.ed-seg button.on { background: var(--panel); color: var(--primary); box-shadow: var(--shadow); }
.ed-status { color: var(--ink-3); font-size: .85rem; display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.ed-main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; min-height: 0; }
.ed-main.hide-side { grid-template-columns: minmax(0, 1fr) 0; }
.ed-main.hide-side .ed-side { display: none; }
.ed-stage-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.ed-hint { display: flex; align-items: center; gap: .5rem; padding: .45rem .9rem; background: var(--primary-soft); color: var(--primary); font-size: .85rem; border-bottom: 1px solid var(--line); }
.ed-hint .ed-ib { margin-left: auto; width: 26px; height: 26px; }
.ed-stage { flex: 1; min-height: 0; background: color-mix(in srgb, var(--bg) 70%, #000 6%); overflow: auto; display: flex; justify-content: center; padding: 1rem; }
.ed-frame-wrap { transition: width .2s; max-width: none; height: 100%; min-height: 400px; background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.ed-frame { width: 100%; height: 100%; border: 0; background: var(--bg); }
.ed-side { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ed-tabs { display: flex; gap: 2px; padding: .4rem; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.ed-tabs button { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .6rem; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.ed-tabs button.on { background: var(--primary-soft); color: var(--primary); }
.ed-body-panel { padding: 1rem; overflow: auto; flex: 1; min-height: 0; }
.ed-body-panel .page-head { margin-bottom: .6rem; }
.ed-body-panel .grid.cols-2 { grid-template-columns: 1fr; }
.ed-body-panel .form-grid { grid-template-columns: 1fr; }
.ed-body-panel .perm-grid { grid-template-columns: minmax(90px, 1.2fr) repeat(5, minmax(48px, 1fr)); font-size: .8rem; }
.ed-body-panel .builder-split { grid-template-columns: 1fr !important; }
.ed-body-panel .modal { max-width: 94vw; }
.block-row.sel { outline: 2px solid var(--primary); }
@media (max-width: 1000px) { .ed-main { grid-template-columns: 1fr; grid-template-rows: 45% 55%; } .ed-side { border-left: 0; border-top: 1px solid var(--line); } .ed-name { display: none; } }
/* edit mode inside the preview iframe */
body.ab-edit [data-path] { cursor: pointer; border-radius: 12px; transition: outline-color .1s; outline: 2px dashed transparent; outline-offset: 4px; position: relative; }
body.ab-edit [data-path]:hover { outline-color: color-mix(in srgb, var(--primary) 60%, transparent); }
body.ab-edit [data-path].ab-sel { outline: 2px solid var(--primary); }
body.ab-edit [data-path] [data-path]:hover { outline-color: color-mix(in srgb, var(--primary) 60%, transparent); }
.ab-bar { position: absolute; top: -18px; right: 8px; z-index: 30; display: flex; gap: 2px; padding: 3px; background: var(--panel); border: 1px solid var(--primary); border-radius: 10px; box-shadow: var(--shadow); }
.ab-bar button { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: .82rem; font-weight: 600; padding: .25rem .5rem; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.ab-bar button:hover { background: var(--primary-soft); color: var(--primary); }
.ab-bar button.ai { background: var(--primary); color: var(--primary-ink); }
.ab-bar button.ai:hover { filter: brightness(1.1); background: var(--primary); color: var(--primary-ink); }
/* Ask AI */
.ai-wrap { display: flex; flex-direction: column; gap: .8rem; height: 100%; }
.ai-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: .6rem; min-height: 200px; }
.ai-msg.user { align-self: flex-end; max-width: 88%; }
.ai-msg.assistant { align-self: flex-start; max-width: 94%; }
.ai-bubble { padding: .6rem .8rem; border-radius: 12px; background: var(--panel-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.ai-msg.user .ai-bubble { background: var(--primary); color: var(--primary-ink); }
.ai-card { margin-top: .4rem; padding: .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.ai-card ul { margin: .3rem 0 .6rem; padding-left: 1.1rem; font-size: .88rem; }
.ai-ideas { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: .25rem .6rem; font: inherit; font-size: .8rem; color: var(--ink-2); cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.ai-compose { display: flex; gap: .5rem; align-items: flex-end; }
.ai-input { min-height: 64px; }

.ed-main.wide { grid-template-columns: minmax(0, 1fr) minmax(520px, 56vw); }
table.grid-edit td { padding: .25rem .4rem; }
.cell-input { border-color: transparent; background: transparent; padding: .3rem .4rem; min-width: 90px; }
.cell-input:hover { border-color: var(--line); }
.cell-input.saved { background: var(--ok-soft); }
.cell-input.bad { border-color: var(--danger); }
pre.code { background: #0f172a; color: #e2e8f0; padding: .8rem; border-radius: 10px; overflow: auto; font-size: .78rem; max-height: 280px; }
.ed-body-panel h3 { margin: 0 0 .4rem; font-size: 1rem; }
.ed-body-panel h4 { margin: .8rem 0 .3rem; font-size: .9rem; }

.nav a.edit-cta { background: var(--primary); color: var(--primary-ink); font-weight: 700; margin-bottom: .4rem; }
.nav a.edit-cta:hover { filter: brightness(1.08); text-decoration: none; }

.ai-scope { display: flex; align-items: center; gap: .5rem; justify-content: space-between; padding: .45rem .6rem; background: var(--primary-soft); color: var(--primary); border-radius: var(--radius-sm); font-size: .88rem; }
/* roomier content: the app should breathe, never feel crowded */
.content { padding: 2rem 2.25rem; }
.page-head { margin-bottom: 1.4rem; }
.blk { margin-bottom: 1.35rem !important; }
.grid > div > .blk:last-child { margin-bottom: 0 !important; }
.grid { gap: 1.25rem; }
.stat { padding: 1.15rem 1.35rem; }
.stat .v { font-size: 2rem; }
.card.pad, .card > .pad { padding: 1.3rem 1.5rem; }
.card-head { padding: 1rem 1.4rem; }
table.t th { padding: .75rem 1.1rem; }
table.t td { padding: .85rem 1.1rem; }
@media (max-width: 900px) { .content { padding: 1.1rem; } }

.bell-wrap { position: relative; }
.bell { position: relative; }
.bell-count { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
.bell-list { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; max-height: 360px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); z-index: 40; }
.bell-item { padding: .65rem .9rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.bell-item.unread { background: var(--primary-soft); }

.ai-fab { position: absolute; right: 410px; bottom: 22px; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink); font-size: 1.4rem; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.28); z-index: 5; }
.ed-main.hide-side ~ .ai-fab, .ai-fab.hidden { display: none; }
.ai-x { color: var(--primary); }
.ai-ask:hover { filter: brightness(1.06); }
.block-row .bh .ai-x { width: 28px; height: 28px; font-size: .95rem; }

/* top bar menus + slim tools bar (the Site Builder arrangement) */
.ed-menu { display: flex; align-items: center; gap: 2px; background: var(--panel-2); border-radius: 14px; padding: 4px; flex: none; }
.ed-menu button, .ed-menu-btn { display: inline-flex; align-items: center; gap: .45rem; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: .85rem; font-weight: 600; padding: .4rem .7rem; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.ed-menu button:hover, .ed-menu-btn:hover { color: var(--primary); }
.ed-menu button.on, .ed-menu-btn.on { background: var(--panel); color: var(--primary); box-shadow: var(--shadow); }
.ed-menu.ai button { background: var(--primary); color: var(--primary-ink); }
.ed-more-wrap { position: relative; }
.ed-more { position: absolute; top: calc(100% + 6px); left: 0; z-index: 70; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .35rem; min-width: 190px; }
.ed-more button { display: flex; width: 100%; align-items: center; gap: .55rem; border: 0; background: transparent; color: var(--ink); font: inherit; padding: .5rem .65rem; border-radius: 8px; cursor: pointer; text-align: left; }
.ed-more button:hover, .ed-more button.on { background: var(--primary-soft); color: var(--primary); }
.ed-tools { display: flex; align-items: center; gap: .75rem; padding: 0 .9rem; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.ed-div { width: 1px; height: 28px; background: var(--line); flex: none; }
.ed-ctx { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.ed-ctx::-webkit-scrollbar { display: none; }
.ed-chip { background: var(--primary-soft); color: var(--primary); border-radius: 9px; padding: .3rem .65rem; font-size: .82rem; white-space: nowrap; margin-right: .3rem; }
.ed-ctx-btn { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: .84rem; font-weight: 600; padding: .4rem .6rem; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.ed-ctx-btn:hover { background: var(--panel-2); }
.ed-ctx-btn.ai { color: var(--primary); }
.ed-ctx-btn.danger { color: var(--danger); }
.ed-muted { color: var(--ink-3); font-size: .85rem; white-space: nowrap; }
.ed-switch { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.ed-side-head { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding-right: .3rem; flex: none; }
.ed-side-head .ed-tabs { flex: 1; border-bottom: 0; }
.ed-tabs button { padding: .45rem .55rem; }
.ed-handle { position: absolute; right: 0; top: 50%; z-index: 40; width: 22px; height: 64px; border: 1px solid var(--line); border-right: 0; background: var(--panel); border-radius: 12px 0 0 12px; cursor: pointer; color: var(--ink-2); display: none; }
.ed.side-hidden .ed-handle { display: grid; place-items: center; }
.ed.side-hidden .ai-fab { right: 40px; }
@media (max-width: 1250px) { .ed-menu button span, .ed-top .btn .lbl { display: none; } }
@media (max-width: 900px) { .ed-switch span { display: none; } }

/* visitors */
.pub { min-height: 100vh; background: var(--bg); }
.pub-head { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.pub-head a:not(.btn) { color: var(--ink-2); font-weight: 600; }
.pub-body { max-width: 980px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.pub-title { margin-bottom: 1.4rem; }
.pub.embed .pub-body { padding: 1rem; max-width: none; }
.pub.embed { background: transparent; }
.pub-thanks { text-align: center; padding: 1.6rem 1rem; }
.pub-thanks p { font-size: 1.05rem; color: var(--ink); margin: .4rem 0 0; }
.pub-tick { width: 52px; height: 52px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center; font-size: 1.6rem; background: var(--primary); color: var(--primary-ink); }

body.ab-edit .ab-bar button.grip { cursor: grab; }
.ab-drop-before { box-shadow: 0 -4px 0 var(--primary); }
.ab-drop-after { box-shadow: 0 4px 0 var(--primary); }
body.ab-edit [data-type="heading"]:hover, body.ab-edit [data-type="text"]:hover { cursor: text; }

body.ab-opening-editor #app { visibility: hidden; }
body.ab-opening-editor::before { content: ""; position: fixed; inset: 0; background: var(--bg); z-index: 900; }
body.ab-opening-editor::after { content: ""; position: fixed; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; z-index: 901; animation: ab-spin .8s linear infinite; }
@keyframes ab-spin { to { transform: rotate(360deg); } }

/* dedicated full-width pages for every area other than the live preview */
.ed-page { display: none; overflow: auto; min-height: 0; background: var(--bg); }
.ed-main.area { grid-template-columns: minmax(0, 1fr); }
.ed-main.area .ed-stage-col, .ed-main.area .ed-side { display: none; }
.ed-main.area .ed-page { display: block; }
.ed-main.area.ai-open .ed-side { display: flex; position: fixed; right: 0; top: 110px; bottom: 0; width: min(420px, 100vw); z-index: 60; box-shadow: -12px 0 32px rgba(0,0,0,.28); }
.ed-main.area ~ .ed-handle { display: none !important; }
.ed-main.area ~ .ai-fab { right: 28px; }
.ed-page-head { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; padding: 1rem 2rem .2rem; max-width: 1240px; margin: 0 auto; }
.ed-page-head h2 { margin: 0; font-size: 1.35rem; }
.ed-subtabs { display: inline-flex; gap: 2px; background: var(--panel-2); border-radius: 12px; padding: 3px; flex-wrap: wrap; }
.ed-subtabs button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: .88rem; font-weight: 600; padding: .4rem .8rem; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.ed-subtabs button:hover { color: var(--primary); }
.ed-subtabs button.on { background: var(--panel); color: var(--primary); box-shadow: var(--shadow); }
.ed-page-body { max-width: 1240px; margin: 0 auto; padding: 1rem 2rem 4rem; }
.ed-page-body .page-head { margin-bottom: 1rem; }
.ed-page-body .ai-ask { display: inline-flex; }
.ed-side-title { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .7rem; font-weight: 700; }
@media (max-width: 900px) { .ed-page-head, .ed-page-body { padding-left: 1rem; padding-right: 1rem; } }

/* Ask AI: saved conversations */
.ai-hist { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); max-height: 260px; overflow: auto; }
.ai-hist-row { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.ai-hist-row.on { background: var(--primary-soft); }
.ai-hist-row > button.grow { flex: 1; border: 0; background: transparent; text-align: left; padding: .5rem .7rem; color: var(--ink); cursor: pointer; font: inherit; min-width: 0; }
.ai-hist-row > button.grow > div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-card .badge { margin-right: .4rem; }

.share-preview { padding: 1rem; border: 1px dashed var(--line); border-radius: var(--radius); background: color-mix(in srgb, var(--bg) 60%, #fff 40%); min-height: 70px; display: flex; align-items: center; }
.share-preview iframe { max-width: 100%; }

.share-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.4rem; align-items: start; }
.share-grid .form-grid { grid-template-columns: 1fr 1fr; }
.modal.wide { max-width: min(1080px, 96vw); }
@media (max-width: 900px) { .share-grid { grid-template-columns: 1fr; } }

.share-more { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.share-more summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .9rem; }

/* board (kanban) */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: .9rem; overflow-x: auto; padding-bottom: .6rem; align-items: start; }
.board-head { display: flex; align-items: center; gap: .8rem; margin-bottom: .8rem; }
.board-head h3 { margin: 0; }
.board-col { background: var(--panel-2); border-radius: var(--radius); padding: .6rem; min-height: 140px; border: 2px solid transparent; transition: border-color .12s; }
.board-col.over { border-color: var(--primary); background: var(--primary-soft); }
.board-col-head { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: .88rem; padding: .2rem .3rem .6rem; }
.board-dot { width: 9px; height: 9px; border-radius: 50%; }
.board-count { margin-left: auto; font-weight: 600; color: var(--ink-3); background: var(--panel); border-radius: 999px; padding: .05rem .5rem; font-size: .78rem; }
.board-col-body { display: flex; flex-direction: column; gap: .5rem; }
.board-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .75rem; cursor: pointer; box-shadow: 0 1px 0 rgba(0,0,0,.03); }
.board-card:hover { border-color: var(--primary); }
.board-card.drag { opacity: .45; }
.board-title { font-weight: 600; margin-bottom: .3rem; overflow-wrap: anywhere; }
.board-meta { display: flex; flex-wrap: wrap; gap: .3rem; }
.board-chip { font-size: .78rem; color: var(--ink-2); background: var(--panel-2); border-radius: 8px; padding: .1rem .45rem; }
.board-empty { color: var(--ink-3); font-size: .85rem; text-align: center; padding: 1rem 0; }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 10px; padding: 3px; margin-right: .5rem; }
.seg button { border: 0; background: transparent; padding: .3rem .8rem; border-radius: 8px; color: var(--ink-2); font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; }
.seg button.on { background: var(--panel); color: var(--primary); box-shadow: var(--shadow); }

/* printing: just the content, as a clean sheet */
.print-head { display: none; }
@media print {
  .side, .topbar, .toolbar, .pager, .rec-actions, .page-head .btn, .page-head .seg, .page-head .right, .btn, .icon-btn, .ed, .ai-fab, .toast-wrap, .callout.info, .bell-wrap, .board-head .btn { display: none !important; }
  body, .shell, .main, .content { background: #fff !important; color: #000 !important; display: block !important; padding: 0 !important; margin: 0 !important; }
  .print-head { display: block; border-bottom: 2px solid #000; padding-bottom: .4rem; margin-bottom: 1rem; font-size: 12px; }
  .card, .stat { box-shadow: none !important; border: 1px solid #bbb !important; break-inside: avoid; background: #fff !important; }
  input, select, textarea { border: 0 !important; border-bottom: 1px solid #bbb !important; background: transparent !important; color: #000 !important; padding: 2px 0 !important; appearance: none; -webkit-appearance: none; }
  textarea { height: auto; resize: none; }
  .form-grid { display: block !important; }
  .form-grid .f { display: block; margin-bottom: .6rem; break-inside: avoid; }
  a { color: #000 !important; text-decoration: none !important; }
  .table-wrap { overflow: visible !important; }
  table.t th, table.t td { padding: .35rem .5rem !important; border-bottom: 1px solid #ccc !important; }
  .board { grid-auto-flow: row !important; grid-auto-columns: auto !important; }
}
.rec-badges { display: inline-flex; gap: .4rem; align-items: center; margin-left: .6rem; }
.page-head h1 { overflow-wrap: anywhere; }

/* a table in a narrow column (half a page, a side panel) is stacked the same way a phone shows it */
@container (max-width: 470px) {
  table.t.stack thead { display: none; }
  table.t.stack, table.t.stack tbody, table.t.stack tr, table.t.stack td { display: block; width: 100%; }
  table.t.stack tr { border: 1px solid var(--line); border-radius: 12px; margin: .6rem; padding: .35rem .8rem; width: auto; background: var(--panel); }
  table.t.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .35rem 0 !important; border: 0 !important; text-align: right; overflow-wrap: anywhere; }
  table.t.stack td::before { content: attr(data-label); color: var(--ink-3); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; max-width: 40%; }
  table.t.stack td:empty { display: none; }
}
/* phones: tables become stacked cards, one per record, each value labelled */
@media (max-width: 640px) {
  table.t.stack thead { display: none; }
  table.t.stack, table.t.stack tbody, table.t.stack tr, table.t.stack td { display: block; width: 100%; }
  table.t.stack tr { border: 1px solid var(--line); border-radius: 12px; margin: .6rem; padding: .35rem .8rem; width: auto; background: var(--panel); }
  table.t.stack tr:hover { border-color: var(--primary); }
  table.t.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .35rem 0 !important; border: 0 !important; text-align: right; overflow-wrap: anywhere; }
  table.t.stack td::before { content: attr(data-label); color: var(--ink-3); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; max-width: 40%; }
  table.t.stack td:empty { display: none; }
  .table-wrap { overflow: visible; }
  .page-head { flex-wrap: wrap; gap: .5rem; }
  .content { padding: 1rem .9rem; }
}

:root[data-mode="dark"] .badge[style*="color"], :root[data-mode="dark"] .board-chip[style*="color"] { filter: brightness(1.5) saturate(1.1); }

/* one-tap answers inside a record (checklist run) */
.qrow { display: flex; align-items: center; gap: .8rem; padding: .6rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.qtitle { flex: 1 1 200px; font-weight: 600; cursor: pointer; overflow-wrap: anywhere; }
.qseg { display: inline-flex; gap: .3rem; flex-wrap: wrap; }
.qseg button { border: 1px solid var(--line); background: var(--panel); color: var(--ink-2); font: inherit; font-weight: 600; font-size: .85rem; padding: .45rem .8rem; border-radius: 10px; cursor: pointer; min-height: 40px; }
.qseg button.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.rec-summary { display: flex; flex-wrap: wrap; gap: .6rem; margin: 0 0 1.2rem; }
.rec-chip { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .5rem .85rem; min-width: 110px; }
.rec-chip-l { color: var(--ink-3); font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
.rec-chip-v { font-weight: 700; font-size: 1.02rem; margin-top: .1rem; overflow-wrap: anywhere; }

.timeline { display: flex; flex-direction: column; gap: .7rem; }
.tl-item { display: flex; gap: .7rem; align-items: flex-start; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-top: .45rem; flex: none; }
.tl-item.comment .tl-dot { background: var(--primary); }
.tl-body { flex: 1; min-width: 0; font-size: .92rem; }
.tl-head { display: flex; align-items: center; gap: .3rem; }
.tl-del { margin-left: auto; width: 24px; height: 24px; }
.tl-text { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2); border-radius: 10px; padding: .5rem .7rem; margin-top: .25rem; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.cal-head h3 { margin: 0; }
.cal-title { min-width: 9.5rem; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--panel-2); padding: .4rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; color: var(--ink-3); text-align: center; }
.cal-day { background: var(--panel); min-height: 96px; padding: .3rem; cursor: pointer; min-width: 0; }
.cal-day:hover { background: var(--primary-soft); }
.cal-day.other { background: var(--panel-2); opacity: .7; }
.cal-day.today .cal-num { background: var(--primary); color: var(--primary-ink); border-radius: 999px; }
.cal-num { width: 24px; height: 24px; display: grid; place-items: center; font-size: .78rem; font-weight: 700; margin-bottom: .2rem; }
.cal-ev { font-size: .75rem; padding: .12rem .4rem; border-radius: 6px; margin-bottom: 3px; background: var(--primary-soft); color: var(--primary); border: 1px solid transparent; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.cal-more { font-size: .72rem; color: var(--ink-3); padding-left: .3rem; }
@media (max-width: 640px) { .cal-day { min-height: 64px; padding: .15rem; } .cal-ev { font-size: .66rem; padding: .05rem .2rem; } }

.search-wrap { position: relative; display: flex; align-items: center; gap: .5rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 0 .7rem; width: min(380px, 46vw); color: var(--ink-3); }
.search-wrap input { border: 0; background: transparent; flex: 1; min-width: 0; padding: .55rem 0; outline: none; color: var(--ink); }
.search-wrap:focus-within { border-color: var(--primary); }
.search-list { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 380px; overflow: auto; z-index: 45; }
.search-item { display: flex; gap: .7rem; align-items: baseline; padding: .55rem .8rem; color: var(--ink); border-bottom: 1px solid var(--line); text-decoration: none; }
.search-item:hover { background: var(--primary-soft); }
.search-kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-3); min-width: 5.5rem; }
@media (max-width: 640px) { .search-wrap { width: auto; flex: 1; } }
.pick-find { margin-bottom: .35rem; padding: .35rem .6rem; font-size: .85rem; }
.i.flip { transform: scaleY(-1); }
.bulk-bar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .55rem .9rem; border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; z-index: 2; }
.bulk-bar.hidden { display: none; }
table.t th.pick, table.t td.pick { width: 2.2rem; padding-right: 0; }
@media (max-width: 640px) { table.t.stack td.pick { justify-content: flex-start; } table.t.stack td.pick::before { content: none; } }
.badge { white-space: nowrap; }

/* a small list on a dashboard shows only its first four columns when it is stacked (phone / narrow column) */
@container (max-width: 470px) { table.t.stack.mini td:nth-child(n+5) { display: none; } }
@media (max-width: 640px) { table.t.stack.mini td:nth-child(n+5) { display: none; } }
.kv-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kv-row { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.kv-row:last-child { border-bottom: 0; }
.onb { margin-bottom: 1.25rem; border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.onb h3 { margin-right: .6rem; }
.onb-steps { display: grid; gap: .55rem; margin-top: .8rem; }
.onb-step { display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); }
.onb-step.done { opacity: .6; }
.onb-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; color: var(--primary-ink); }
.onb-step.done .onb-dot { background: var(--primary); border-color: var(--primary); }
.onb-dot .i { width: 14px; height: 14px; }
.onb-step .grow { flex: 1; min-width: 0; }
.onb-step .btn { white-space: nowrap; flex: none; }
.more-wrap { position: relative; }
.more-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 190px; display: grid; gap: .35rem; padding: .5rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.more-menu.hidden { display: none; }
.more-menu .btn { justify-content: flex-start; width: 100%; }

.pbar { display: inline-flex; align-items: center; gap: .55rem; }
.pbar-track { display: block; width: 72px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; flex: none; }
.pbar-fill { display: block; height: 100%; border-radius: 3px; background: var(--primary); }
.pbar-n { font-size: .85rem; }
