/* ==========================================================================
   CRM Setup — shared styles for the four owner-only configuration screens.
   Tokens are lifted verbatim from design-system.md; no new colours introduced.
   ========================================================================== */

/* ---- App-style fixed layout: only the content scrolls (matches settings.html) ---- */
html, body { height: 100%; margin: 0; overflow: hidden; }
body { display: flex; flex-direction: column; background: #F5F7FA; }
.demo-banner { flex-shrink: 0; }
.app-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 264px 1fr; }
.app-grid > * { min-height: 0; min-width: 0; overflow: hidden; }
.app-grid .app-sidebar { position: relative; top: auto; height: 100%; }
.page-main { display: flex; flex-direction: column; background: #FFFFFF; height: 100%; }
.page-topbar { flex-shrink: 0; background: #FFFFFF; border-bottom: 1px solid #E2E8F0; padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.page-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.18em; font-weight: 700; color: #64748B; }
.page-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; color: #0F172A; line-height: 1.15; }
.page-sub { font-size: 12.5px; color: #64748B; margin-top: 2px; }
.page-scroll { flex: 1; overflow-y: auto; padding: 18px 28px 48px; background: #F5F7FA; }

.btn-primary { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px; font-size: 12.5px; font-weight: 700; color: #fff; background: linear-gradient(135deg, #15B5C7, #0E9DAE); box-shadow: 0 6px 16px -6px rgba(14,157,174,0.6); border: 0; cursor: pointer; transition: transform .15s ease; }
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 9px; font-size: 12px; font-weight: 600; color: #1E293B; background: #fff; border: 1px solid #E2E8F0; cursor: pointer; }
.btn-ghost:hover { background: #F0F4F8; }
.btn-navy { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px; font-size: 12.5px; font-weight: 700; color: #fff; background: #0B1F35; border: 0; cursor: pointer; }
.btn-navy:hover { background: #15324F; }

.owner-pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; background: #F0F4F8; border: 1px solid #E2E8F0; color: #475569; font-size: 11px; font-weight: 700; }
.owner-pill i { color: #0E9DAE; }

.mono, .k { font-family: 'JetBrains Mono', monospace; }
.k { font-size: 0.9em; background: #F0F4F8; color: #15324F; padding: 1px 5px; border-radius: 4px; border: 1px solid #E2E8F0; }

/* ==========================================================================
   Master / detail — one screen for record types and everything about them
   ========================================================================== */
.md-wrap { flex: 1; min-height: 0; display: grid; grid-template-columns: 244px 1fr; }
.md-wrap > * { min-height: 0; min-width: 0; }

.md-list { border-right: 1px solid #E2E8F0; background: #fff; overflow-y: auto; padding: 12px; }
.md-list-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.md-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; transition: background .12s ease; }
.md-item:hover { background: #F0F4F8; }
.md-item.on { background: #F0F4F8; border-color: #E2E8F0; }
.md-item.on .cs-name { color: #0B1F35; }

.md-detail { display: flex; flex-direction: column; background: #F5F7FA; overflow: hidden; }
.md-detail-head { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 24px; background: #fff; border-bottom: 1px solid #E2E8F0; flex-wrap: wrap; }
.md-scroll { flex: 1; overflow-y: auto; padding: 20px 24px 48px; }

/* ---- Content blocks down the detail page (replaces sub-tabs) ---- */
.blk { margin-bottom: 30px; }
.blk-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.blk-t { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 800; color: #0F172A; letter-spacing: -0.01em; }
.blk-t i { color: #0E9DAE; font-size: 16px; }
.blk-d { font-size: 12px; color: #64748B; margin-top: 3px; line-height: 1.6; max-width: 640px; }

/* ---- Record template cards ---- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; }
.tpl { display: block; background: #fff; border: 1px solid #E2E8F0; border-radius: 13px; padding: 15px; text-decoration: none; color: inherit; transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease; }
.tpl:hover { border-color: #15B5C7; box-shadow: 0 6px 18px -10px rgba(11,31,53,.28); transform: translateY(-1px); }
.tpl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.tpl-name { font-size: 13.5px; font-weight: 800; color: #0F172A; }
.tpl-meta { font-size: 11.5px; color: #64748B; }
.tpl-used { font-size: 11.5px; color: #475569; margin-top: 9px; padding-top: 9px; border-top: 1px solid #EDF1F5; }
.tpl-used strong { color: #0F172A; }
.tpl-unused { color: #94A3B8; }
.tpl-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.tpl-chips .chip-f { font-size: 10.5px; padding: 3px 8px; }
.tpl-add { border-style: dashed; border-color: #CBD5E1; background: #FAFCFD; text-align: center; display: grid; place-content: center; cursor: pointer; min-height: 148px; }
.tpl-add:hover { border-color: #15B5C7; background: #ECFDFD; }
.tpl-add > i { font-size: 20px; color: #0E9DAE; }

/* ---- Tab list header: the toggle and the role picker were unlabelled ---- */
.tab-head { display: flex; align-items: center; gap: 11px; padding: 9px 14px; background: #FAFCFD; border-bottom: 1px solid #EDF1F5;
  font-size: 9.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: #94A3B8; }
.th-drag { width: 41px; flex: none; }          /* grip + kind icon */
.th-name { flex: 1; min-width: 0; }
.th-role { width: 132px; flex: none; }
.th-on { width: 34px; flex: none; text-align: center; }

/* ---- Role picker: a real select, so it reads as a control not a badge ---- */
.role-sel { width: 132px; flex: none; font-family: inherit; font-size: 11.5px; font-weight: 700;
  padding: 5px 8px; border-radius: 8px; border: 1px solid #E2E8F0; background: #fff; color: #475569;
  cursor: pointer; outline: 0; transition: border-color .12s ease, box-shadow .12s ease; }
.role-sel:hover { border-color: #CBD5E1; }
.role-sel:focus { border-color: #15B5C7; box-shadow: 0 0 0 3px rgba(21,181,199,.15); }
.role-sel.owner { background: #FFFBEB; color: #B45309; border-color: #FDE68A; }
.role-sel.owner:hover { border-color: #FCD34D; }

.col-chips { background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; padding: 13px; }
.col-chips .chip-f[data-col] { cursor: grab; }
.col-chips .chip-f[data-col]:active { cursor: grabbing; }
.col-chips .chip-f.dragging { opacity: .35; }
.col-chips .chip-f.drop-before { box-shadow: inset 3px 0 0 0 #15B5C7; }
.col-chips .chip-f i.ph-x { cursor: pointer; color: #94A3B8; padding: 1px; border-radius: 3px; }
.col-chips .chip-f i.ph-x:hover { color: #B91C1C; background: rgba(185,28,28,.08); }

/* Live preview of the registry row */
.col-preview { margin-top: 12px; border: 1px solid #E2E8F0; border-radius: 12px; overflow: hidden; background: #fff; }
.cp-head { padding: 9px 14px; background: #FAFCFD; border-bottom: 1px solid #EDF1F5; font-size: 9.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: #94A3B8; }
.cp-row { display: flex; gap: 0; overflow-x: auto; }
.cp-row > span { flex: 1 0 132px; padding: 9px 14px; font-size: 9.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #94A3B8; border-bottom: 1px solid #EDF1F5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-row.body > span { font-size: 12px; font-weight: 500; letter-spacing: 0; text-transform: none; color: #475569; border-bottom: 0; }
.cp-row.body > span.strong { font-weight: 700; color: #0F172A; }

/* Add-column picker */
.col-avail { display: flex; flex-direction: column; gap: 5px; max-height: 260px; overflow-y: auto; }
.ca-i { display: flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid #E2E8F0; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: #0F172A; cursor: pointer; background: #fff; }
.ca-i:hover { border-color: #15B5C7; background: #ECFDFD; color: #0E9DAE; }
.ca-i i { font-size: 12px; color: #0E9DAE; flex: none; }
.ca-i em { margin-left: auto; font-style: normal; font-size: 10.5px; font-weight: 700; color: #0E9DAE; }
.ca-empty { padding: 18px; text-align: center; font-size: 12px; color: #94A3B8; }

/* ---- Read-only tabs x templates map ---- */
.mtx { background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; margin-top: 12px; overflow: hidden; }
.mtx-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; background: #FAFCFD; border-bottom: 1px solid #EDF1F5; flex-wrap: wrap; }
.mtx-note { font-size: 10.5px; color: #94A3B8; font-weight: 600; }
.mtx-t { width: 100%; border-collapse: collapse; font-size: 12px; }
.mtx-t th { text-align: left; font-size: 9.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #94A3B8; padding: 9px 14px; border-bottom: 1px solid #EDF1F5; }
.mtx-t th:not(:first-child), .mtx-t td:not(:first-child) { text-align: center; width: 132px; }
.mtx-t td { padding: 10px 14px; border-bottom: 1px solid #F1F5F9; color: #0F172A; font-weight: 600; }
.mtx-t tr:last-child td { border-bottom: 0; }
.mtx-y { display: inline-block; min-width: 26px; padding: 2px 8px; border-radius: 999px; background: #ECFDFD; color: #0E9DAE; font-weight: 800; font-size: 11px; border: 1px solid #B6EAEF; font-variant-numeric: tabular-nums; }
.mtx-n { color: #CBD5E1; font-weight: 700; }
.mtx-foot { display: flex; align-items: flex-start; gap: 8px; padding: 11px 14px; border-top: 1px solid #EDF1F5; background: #FAFCFD; font-size: 11px; line-height: 1.6; color: #64748B; }
.mtx-foot i { color: #0E9DAE; font-size: 13px; margin-top: 1px; flex: none; }

/* ---- Page-level tab strip ---- */
.setup-tabs { display: flex; gap: 18px; border-bottom: 1px solid #E2E8F0; margin-bottom: 18px; }
.setup-tab { font-size: 12.5px; font-weight: 700; color: #64748B; padding: 9px 2px; border-bottom: 2px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap; }
.setup-tab:hover { color: #0F172A; }
.setup-tab.tab-active { color: #0F172A; border-bottom-color: #15B5C7; }

/* ---- Cards & rows ---- */
.cs-card { background: #fff; border: 1px solid #E2E8F0; border-radius: 14px; overflow: hidden; }
.cs-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #EDF1F5; text-decoration: none; color: inherit; }
.cs-row:last-child { border-bottom: 0; }
.cs-head { background: #FAFCFD; font-size: 9.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #94A3B8; padding-top: 9px; padding-bottom: 9px; }
.cs-link { cursor: pointer; transition: background .12s ease; }
.cs-link:hover { background: #FAFCFD; }
.cs-link.is-new { background: #ECFDFD; }
.cs-link.is-new:hover { background: #DFF8FA; }
.cs-name { font-size: 13px; font-weight: 700; color: #0F172A; }
.cs-name-red { color: #B91C1C; }
.cs-sub { font-size: 11px; color: #64748B; margin-top: 1px; }
.cs-sub-cyan { font-size: 11px; color: #0E9DAE; font-weight: 600; margin-top: 1px; }
.cs-num { font-size: 12.5px; color: #475569; font-variant-numeric: tabular-nums; }
.cs-muted { color: #94A3B8; }
.cs-caret { font-size: 13px; color: #CBD5E1; flex: none; }
.cs-avatar { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 14px; flex: none; }

.tag { font-size: 9.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px; letter-spacing: 0.04em; display: inline-block; }
.tag-grey { background: #F0F4F8; color: #475569; }
.tag-green { background: rgba(34,197,94,0.12); color: #047857; }
.tag-amber { background: #FFFBEB; color: #B45309; }
.tag-cyan { background: #ECFDFD; color: #0E9DAE; border: 1px solid #B6EAEF; }
.tag-red { background: #FEF2F2; color: #B91C1C; }

.cs-note { display: flex; align-items: flex-start; gap: 8px; margin-top: 14px; padding: 12px 14px; background: #fff; border: 1px solid #E2E8F0; border-radius: 11px; font-size: 11.5px; line-height: 1.65; color: #475569; }
.cs-note i { color: #0E9DAE; font-size: 14px; margin-top: 1px; flex: none; }

.cs-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.cs-mini { background: #fff; border: 1px solid #E2E8F0; border-radius: 12px; padding: 15px; }
.cs-mini > i { font-size: 17px; color: #0E9DAE; display: block; margin-bottom: 9px; }
.cs-mini-t { font-size: 12.5px; font-weight: 800; color: #0F172A; margin-bottom: 4px; }
.cs-mini-d { font-size: 11.5px; line-height: 1.6; color: #64748B; }

/* ---- Entity type header (screen 2) ---- */
.cs-crumb { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: #64748B; margin-bottom: 12px; flex-wrap: wrap; }
.cs-crumb a { color: #64748B; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.cs-crumb a:hover { color: #0F172A; }
.cs-crumb .sep { color: #CBD5E1; }
.cs-crumb .cur { color: #0F172A; font-weight: 700; }

.type-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.type-id { display: flex; align-items: center; gap: 13px; }
.type-h { font-size: 18px; font-weight: 800; color: #0F172A; letter-spacing: -0.015em; }
.type-sub { font-size: 12px; color: #64748B; margin-top: 2px; }

.unpub { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; background: #FFFBEB; border: 1px solid #FDE68A; color: #B45309; font-size: 11px; font-weight: 700; }

/* ---- Two-column config layout ---- */
.cfg-grid { display: grid; grid-template-columns: 1fr 264px; gap: 16px; align-items: start; }

/* ---- Draggable tab / field rows ---- */
.drag-row { display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-bottom: 1px solid #EDF1F5; background: #fff; }
.drag-row:last-child { border-bottom: 0; }
.drag-row.dragging { opacity: .4; }
.drag-row.drop-above { box-shadow: inset 0 2px 0 0 #15B5C7; }
.drag-row.drop-below { box-shadow: inset 0 -2px 0 0 #15B5C7; }
.drag-row.is-new { background: #ECFDFD; }
.drag-row.is-off { opacity: .55; }
.grip { color: #CBD5E1; font-size: 14px; cursor: grab; flex: none; }
.grip:active { cursor: grabbing; }
.row-ico { font-size: 14px; flex: none; }
.row-ico.fieldtab { color: #0E9DAE; }
.row-ico.system { color: #0B1F35; }
.row-ico.related { color: #B45309; }
.row-link { font-size: 11px; font-weight: 700; color: #0E9DAE; cursor: pointer; white-space: nowrap; }
.row-link:hover { text-decoration: underline; }
.row-link.dim { color: #CBD5E1; cursor: default; }
.row-link.dim:hover { text-decoration: none; }

.toggle { width: 34px; height: 19px; border-radius: 999px; background: #15B5C7; position: relative; flex: none; cursor: pointer; transition: background .15s ease; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 17px; width: 15px; height: 15px; border-radius: 999px; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s ease; }
.toggle.off { background: #CBD5E1; }
.toggle.off::after { left: 2px; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; border-bottom: 1px solid #EDF1F5; background: #FAFCFD; }
.card-head-t { font-size: 9.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #94A3B8; }

/* ---- Side rail ---- */
.rail-card { background: #fff; border: 1px solid #E2E8F0; border-radius: 13px; padding: 14px; margin-bottom: 12px; }
.rail-t { font-size: 9.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #94A3B8; margin-bottom: 10px; }
.rail-p { font-size: 11.5px; line-height: 1.65; color: #64748B; }
.dropzone { border: 1.5px dashed #CBD5E1; border-radius: 11px; background: #FAFCFD; padding: 14px; text-align: center; cursor: pointer; transition: all .15s ease; }
.dropzone:hover { border-color: #15B5C7; background: #ECFDFD; }
.dropzone i { font-size: 17px; color: #0E9DAE; }
.dropzone-t { font-size: 11.5px; font-weight: 700; color: #0F172A; margin-top: 4px; }
.dropzone-d { font-size: 10.5px; color: #94A3B8; margin-top: 2px; }

/* ---- Field chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-f { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 8px; font-size: 11.5px; font-weight: 600; background: #fff; color: #1E293B; border: 1px solid #CBD5E1; cursor: grab; user-select: none; transition: all .12s ease; }
.chip-f:hover { border-color: #94A3B8; box-shadow: 0 2px 6px -2px rgba(15,23,42,.15); }
.chip-f:active { cursor: grabbing; }
.chip-f.dragging { opacity: .35; }
.chip-f.sys i { color: #94A3B8; font-size: 10px; }
.chip-f.new { background: #ECFDFD; color: #0E9DAE; border-color: #B6EAEF; }
.chip-f.locked { cursor: not-allowed; background: #F8FAFC; color: #94A3B8; }

/* ==========================================================================
   Template builder — field-type palette on the left, form canvas on the right
   ========================================================================== */
.bx { flex: 1; min-height: 0; display: grid; grid-template-columns: 236px 1fr; }
.bx > * { min-height: 0; min-width: 0; }

/* ---- Left: field elements ---- */
.bx-palette { border-right: 1px solid #E2E8F0; background: #fff; overflow-y: auto; padding: 14px; }
.pal-search { display: flex; align-items: center; gap: 7px; border: 1px solid #E2E8F0; border-radius: 9px; padding: 7px 10px; margin-bottom: 14px; }
.pal-search i { color: #94A3B8; font-size: 12px; }
.pal-search input { border: 0; outline: 0; font-size: 11.5px; width: 100%; background: transparent; color: #0F172A; font-family: inherit; }

.pal-group { margin-bottom: 16px; }
.pal-h { display: flex; align-items: center; gap: 6px; font-size: 9.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: #94A3B8; margin-bottom: 8px; }
.pal-n { background: #F0F4F8; color: #475569; border-radius: 999px; padding: 1px 6px; font-size: 9px; }
.pal-hint { font-size: 10.5px; line-height: 1.5; color: #94A3B8; margin: -4px 0 8px; }

.pal-tiles { display: grid; grid-template-columns: 1fr; gap: 5px; }
.tile { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid #E2E8F0; border-radius: 9px; background: #fff; cursor: grab; user-select: none; transition: border-color .12s ease, box-shadow .12s ease; }
.tile:hover { border-color: #15B5C7; box-shadow: 0 2px 8px -4px rgba(11,31,53,.25); }
.tile:active { cursor: grabbing; }
.tile.dragging { opacity: .4; }
.tile i { font-size: 14px; color: #0E9DAE; flex: none; }
.tile span { font-size: 11.5px; font-weight: 600; color: #1E293B; line-height: 1.3; }

.pal-reuse { display: flex; flex-direction: column; gap: 5px; }
.reuse { display: flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid #E2E8F0; border-radius: 9px; background: #FAFCFD; cursor: grab; user-select: none; }
.reuse:hover { border-color: #94A3B8; background: #fff; }
.reuse:active { cursor: grabbing; }
.reuse.dragging { opacity: .4; }
.reuse i { font-size: 13px; color: #94A3B8; flex: none; }
.reuse span { font-size: 11.5px; font-weight: 600; color: #1E293B; }

/* ---- Right: canvas ---- */
.bx-canvas { display: flex; flex-direction: column; background: #F5F7FA; overflow: hidden; }
/* No overflow here — the "Use another tab" menu is absolutely positioned and would be
   clipped by a scroll container. Tabs wrap to a second line instead. */
.bx-tabs { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 12px 22px; background: #fff; border-bottom: 1px solid #E2E8F0; flex-wrap: wrap; position: relative; z-index: 20; }
.bx-tab { display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 9px; font-size: 12.5px; font-weight: 700; color: #64748B; background: #F5F7FA; border: 1px solid transparent; cursor: pointer; white-space: nowrap; transition: all .12s ease; }
.bx-tab:hover { background: #F0F4F8; color: #0F172A; }
.bx-tab.on { background: #0B1F35; color: #fff; }
.bx-tab.drop-on { background: #ECFDFD; color: #0E9DAE; border-color: #15B5C7; }
.bx-n { font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 999px; background: rgba(15,23,42,.08); }
.bx-tab.on .bx-n { background: rgba(255,255,255,.18); }
.bx-tabs-lbl { font-size: 9.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: #94A3B8; margin-right: 4px; white-space: nowrap; }
/* Built-in panels read differently from field tabs — they always render regardless. */
.bx-tab.sys { background: #fff; border: 1px solid #E2E8F0; color: #475569; }
.bx-tab.sys:hover { border-color: #CBD5E1; background: #FAFCFD; }
.bx-tab.sys.on { background: #15324F; border-color: #15324F; color: #fff; }
.bx-sysico { font-size: 11px; opacity: .7; }
.panel-banner { display: flex; align-items: flex-start; gap: 8px; padding: 11px 14px; border-radius: 11px; font-size: 11.5px; line-height: 1.6; margin-bottom: 14px; }
.panel-banner i { font-size: 14px; margin-top: 1px; flex: none; }
.panel-banner.child { background: #ECFDFD; border: 1px solid #B6EAEF; color: #15324F; }
.panel-banner.child i { color: #0E9DAE; }
.panel-banner.system { background: #F0F4F8; border: 1px solid #E2E8F0; color: #475569; }
.panel-banner.system i { color: #64748B; }
.bx-addmenu-i span { display: flex; flex-direction: column; gap: 1px; }
.bx-addmenu-i em { font-style: normal; font-size: 10px; font-weight: 500; color: #94A3B8; }
.bx-addmenu-i:hover em { color: #0E9DAE; }
.bx-addmenu-i em.dflt { color: #0E9DAE; font-weight: 700; }
.bx-addmenu-i em.dflt.none { color: #CBD5E1; font-weight: 500; }
.bx-addmenu-sep { height: 1px; background: #EDF1F5; margin: 6px 4px; }
.bx-addmenu-i.mk { background: #ECFDFD; }
.bx-addmenu-i.mk strong, .bx-addmenu-i.mk span { color: #0E9DAE; }
.bx-addmenu-i.mk i { color: #0E9DAE; }
.bx-addmenu-i.mk:hover { background: #DFF8FA; }

/* ---- Per-tab default layout controls ---- */
.panel-tools { display: flex; align-items: center; gap: 14px; padding: 9px 14px; margin-bottom: 14px; background: #fff; border: 1px solid #E2E8F0; border-radius: 11px; flex-wrap: wrap; }
.pt-l { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: #64748B; }
.pt-l i { font-size: 13px; color: #94A3B8; }
.pt-l strong { color: #0F172A; font-variant-numeric: tabular-nums; }
.pt-a { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; color: #0E9DAE; cursor: pointer; white-space: nowrap; }
.pt-a:first-of-type { margin-left: auto; }
.pt-a:hover { text-decoration: underline; }
.pt-a i { font-size: 12px; }
.bx-x { font-size: 10px; opacity: 0; margin-left: -2px; padding: 2px; border-radius: 4px; transition: opacity .12s ease, background .12s ease; }
.bx-tab:hover .bx-x { opacity: .55; }
.bx-x:hover { opacity: 1 !important; background: rgba(15,23,42,.1); }
.bx-tab.on .bx-x:hover { background: rgba(255,255,255,.22); }
.bx-tabs-hint { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: #94A3B8; margin-left: auto; white-space: nowrap; }

/* "Use another tab" — a field tab only exists where a template fills it */
.bx-addtab { position: relative; display: inline-flex; align-items: center; gap: 5px; padding: 7px 12px; border-radius: 9px; border: 1.5px dashed #CBD5E1; font-size: 11.5px; font-weight: 700; color: #64748B; cursor: pointer; white-space: nowrap; }
.bx-addtab:hover { border-color: #15B5C7; color: #0E9DAE; background: #ECFDFD; }
.bx-addtab > i { font-size: 11px; }
/* Right-anchored: the chip sits toward the right of the bar, so opening leftward
   keeps the menu on screen. */
/* white-space is reset here on purpose: .bx-addtab sets nowrap for its own chip
   label, and the menu is a child of it, so without this the footnote runs off
   the card instead of wrapping. */
.bx-addmenu { display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: 288px; background: #fff; border: 1px solid #E2E8F0; border-radius: 11px; box-shadow: 0 16px 36px -14px rgba(11,31,53,.3); padding: 6px; cursor: default; white-space: normal; user-select: none; }
.bx-addmenu.open { display: block; }
.bx-addmenu-h { font-size: 9.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #94A3B8; padding: 7px 9px 5px; }
.bx-addmenu-i { display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 8px; font-size: 12px; font-weight: 700; color: #0F172A; cursor: pointer; }
.bx-addmenu-i:hover { background: #ECFDFD; color: #0E9DAE; }
.bx-addmenu-i i { font-size: 13px; color: #0E9DAE; }
.bx-addmenu-n { font-size: 10.5px; line-height: 1.55; color: #94A3B8; padding: 7px 9px 4px; margin-top: 3px; border-top: 1px solid #EDF1F5; }

.bx-scroll { flex: 1; overflow-y: auto; padding: 18px 22px 48px; }

/* ---- Section card ---- */
.sec { background: #fff; border: 1px solid #E2E8F0; border-radius: 13px; margin-bottom: 14px; overflow: hidden; }
.sec.is-new { border-color: #B6EAEF; }
.sec-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; user-select: none; }
.sec.is-new .sec-head { background: #ECFDFD; }
.sec-caret { font-size: 12px; color: #94A3B8; transition: transform .15s ease; }
.sec.collapsed .sec-caret { transform: rotate(-90deg); }
.sec.collapsed .sec-body { display: none; }
.sec-title { font-size: 13.5px; font-weight: 800; color: #0F172A; }
.sec-edit { font-size: 13px; color: #CBD5E1; cursor: pointer; }
.sec-edit:hover { color: #475569; }
.sec-spacer { flex: 1; }
.sec-add { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700; color: #0E9DAE; cursor: pointer; white-space: nowrap; }
.sec-add:hover { text-decoration: underline; }
.sec-body { padding: 4px 16px 16px; }

.sec-add-btn { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 14px; border: 1.5px dashed #CBD5E1; border-radius: 12px; background: #FAFCFD; font-size: 12.5px; font-weight: 700; color: #0E9DAE; cursor: pointer; transition: all .12s ease; }
.sec-add-btn:hover { border-color: #15B5C7; background: #ECFDFD; }

/* ---- Field grid + rows ---- */
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; align-items: start; border-radius: 10px; padding: 4px; transition: background .12s ease, box-shadow .12s ease; }
.fgrid.drop-on { background: #ECFDFD; box-shadow: inset 0 0 0 1.5px #15B5C7; }

.fr { display: flex; flex-direction: column; gap: 4px; position: relative; }
.fr.dragging { opacity: .35; }
/* Insertion point when reordering — shows where the dragged field will land. */
.fr.drop-before::before { content: ''; position: absolute; left: -7px; top: 16px; bottom: 0; width: 3px; border-radius: 2px; background: #15B5C7; }
.fr-lbl { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: #475569; padding-left: 2px; }
.fr-lbl i { font-size: 11px; color: #B91C1C; }
.fr-box { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 1px solid #E2E8F0; border-radius: 9px; background: #fff; cursor: grab; }
.fr-box:hover { border-color: #CBD5E1; }
.fr-box:active { cursor: grabbing; }
.fr.new .fr-box { border-color: #B6EAEF; background: #F8FEFF; }
.fr.locked .fr-box { background: #F8FAFC; cursor: not-allowed; }
.fr-grip { font-size: 13px; color: #CBD5E1; flex: none; }
.fr-name { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; color: #0F172A; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fr.new .fr-name { color: #0E9DAE; }
.fr-type { font-weight: 500; color: #94A3B8; font-size: 11px; }
.fr-acts { display: flex; align-items: center; gap: 7px; flex: none; }
.fr-acts i { font-size: 13px; color: #CBD5E1; cursor: pointer; }
.fr-acts i:hover { color: #475569; }
.fr-acts i.ph-trash:hover { color: #B91C1C; }

.fslot { border: 1.5px dashed #CBD5E1; border-radius: 9px; background: #FAFCFD; min-height: 56px; display: grid; place-items: center; font-size: 11px; color: #94A3B8; font-weight: 600; margin-top: 17px; }
.fspacer { border: 1px dashed #E2E8F0; border-radius: 9px; background: #FAFCFD; min-height: 56px; display: grid; place-items: center; font-size: 10.5px; color: #CBD5E1; font-weight: 700; margin-top: 17px; }

/* ---- Old canvas styles (kept: preview modal reuses .pv-*) ---- */
.tb-canvas { background: #fff; border: 1px solid #E2E8F0; border-radius: 14px; padding: 16px; }
.tb-intro { display: flex; align-items: flex-start; gap: 8px; padding: 11px 14px; background: #ECFDFD; border: 1px solid #B6EAEF; border-radius: 11px; font-size: 12px; line-height: 1.6; color: #15324F; margin-bottom: 16px; }
.tb-intro i { color: #0E9DAE; font-size: 14px; margin-top: 1px; flex: none; }

/* ---- Tab bands: a template covers the whole record, grouped by tab ---- */
.band { margin-bottom: 18px; }
.band-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 9px; }
.band-head > i { color: #0E9DAE; font-size: 14px; }
.band-name { font-size: 12.5px; font-weight: 800; color: #0F172A; }
.band-count { font-size: 11px; color: #94A3B8; font-variant-numeric: tabular-nums; }
.dropzone.add-sec { padding: 10px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.dropzone.add-sec i { font-size: 13px; }
.dropzone.add-sec span { font-size: 11.5px; font-weight: 700; color: #64748B; }

.key-hint { font-size: 11px; color: #94A3B8; line-height: 1.55; margin-top: 6px; }

/* ---- Preview tab bar ---- */
.pv-tabbar { display: flex; gap: 14px; border-bottom: 1px solid #E2E8F0; margin-bottom: 14px; overflow-x: auto; }
.pv-tab { font-size: 12px; font-weight: 600; color: #64748B; padding: 8px 2px; white-space: nowrap; border-bottom: 2px solid transparent; }
.pv-tab.on { color: #0F172A; font-weight: 700; border-bottom-color: #15B5C7; }
.tb-cols { display: grid; gap: 14px; }
.tb-cols[data-cols="1"] { grid-template-columns: 1fr; }
.tb-cols[data-cols="2"] { grid-template-columns: 1fr 1fr; }
.tb-cols[data-cols="3"] { grid-template-columns: 1fr 1fr 1fr; }
.tb-col { display: flex; flex-direction: column; gap: 14px; min-height: 80px; }

.section { border: 1px solid #E2E8F0; border-radius: 12px; padding: 12px; background: #fff; transition: border-color .12s ease, background .12s ease; }
.section.is-new { border-color: #B6EAEF; background: #ECFDFD; }
.section.drop-in { border-color: #15B5C7; background: #ECFDFD; box-shadow: 0 0 0 3px rgba(21,181,199,.15); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-title { display: flex; align-items: center; gap: 6px; }
.section-title i.sec-ico { color: #0E9DAE; font-size: 13px; }
.section-title span { font-size: 11.5px; font-weight: 800; color: #0F172A; }
.section-drop { min-height: 34px; }
.sec-menu { color: #CBD5E1; font-size: 14px; cursor: pointer; }
.sec-menu:hover { color: #475569; }

.palette-search { display: flex; align-items: center; gap: 7px; border: 1px solid #E2E8F0; border-radius: 9px; padding: 7px 10px; margin-bottom: 10px; }
.palette-search i { color: #94A3B8; font-size: 12px; }
.palette-search input { border: 0; outline: 0; font-size: 11.5px; width: 100%; background: transparent; color: #0F172A; font-family: inherit; }
.pal-label { font-size: 9.5px; font-weight: 800; letter-spacing: 0.08em; color: #94A3B8; margin-bottom: 7px; text-transform: uppercase; }

/* ---- Preview (record render) ---- */
.pv-wrap { background: #F5F7FA; border-radius: 12px; padding: 16px; }
.pv-card { background: #fff; border: 1px solid #E2E8F0; border-radius: 14px; padding: 18px; }
.pv-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.16em; font-weight: 800; color: #64748B; margin-bottom: 14px; }
.pv-cols { display: grid; gap: 22px; }
.pv-sec + .pv-sec { margin-top: 20px; }
.pv-sec-label { display: flex; align-items: center; gap: 6px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; font-weight: 800; color: #0E9DAE; margin-bottom: 9px; }
.pv-kv { display: grid; grid-template-columns: 128px 1fr; gap: 7px 14px; margin: 0; }
.pv-kv dt { font-size: 11.5px; color: #64748B; }
.pv-kv dd { font-size: 12px; color: #0F172A; font-weight: 600; margin: 0; }
.pv-new { color: #0E9DAE; }

/* ---- Modals ---- */
.mc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid #EDF1F5; }
.mc-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.16em; font-weight: 800; color: #64748B; }
.mc-title { font-size: 17px; font-weight: 800; color: #0F172A; letter-spacing: -0.015em; margin-top: 2px; }
.mc-x { border: 0; background: transparent; color: #94A3B8; font-size: 17px; cursor: pointer; display: flex; padding: 2px; }
.mc-x:hover { color: #475569; }
.mc-body { padding: 18px 20px; max-height: 62vh; overflow-y: auto; }
.mc-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px; border-top: 1px solid #EDF1F5; background: #FAFCFD; border-radius: 0 0 16px 16px; }
.mc-callout { display: flex; align-items: flex-start; gap: 8px; padding: 11px 13px; border-radius: 10px; background: #ECFDFD; border: 1px solid #B6EAEF; font-size: 11.5px; line-height: 1.6; color: #15324F; margin-top: 14px; }
.mc-callout i { color: #0E9DAE; font-size: 14px; margin-top: 1px; flex: none; }
.mc-callout.warn { background: #FFFBEB; border-color: #FDE68A; color: #78350F; }
.mc-callout.warn i { color: #B45309; }

/* ---- Form fields ---- */
.fld { margin-bottom: 14px; }
/* Direct child only. `.fld label` would also match the <label> wrapping each radio
   card and force it to display:block — beating `.radio`'s flex on specificity, which
   stacks the control above its text. */
.fld > label { display: block; font-size: 11.5px; font-weight: 700; color: #475569; margin-bottom: 5px; }
.lbl-note { font-weight: 500; color: #94A3B8; }
/* Text-ish inputs only. Radios and checkboxes must NOT get width:100% — it stretches
   the control across the row and drops its label onto the next line. */
.fld input:not([type="radio"]):not([type="checkbox"]),
.fld select, .fld textarea { width: 100%; border: 1px solid #E2E8F0; border-radius: 9px; padding: 9px 11px; font-size: 12.5px; font-family: inherit; color: #0F172A; outline: 0; background: #fff; }
.fld input:not([type="radio"]):not([type="checkbox"]):focus,
.fld select:focus, .fld textarea:focus { border-color: #15B5C7; box-shadow: 0 0 0 3px rgba(21,181,199,0.15); }
.fld input[readonly] { background: #F8FAFC; color: #64748B; }
.fld input[type="radio"], .fld input[type="checkbox"] { width: 15px; height: 15px; flex: none; margin: 0; accent-color: #15B5C7; }
.fld-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.icon-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.ip, .sw { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; border: 1px solid #E2E8F0; cursor: pointer; background: #fff; font-size: 15px; color: #475569; }
.ip.on, .sw.on { border-color: #15B5C7; box-shadow: 0 0 0 3px rgba(21,181,199,0.15); }
.sw { border: 2px solid #fff; box-shadow: 0 0 0 1px #E2E8F0; }
.sw.on { box-shadow: 0 0 0 2px #15B5C7; }

.radio-row { display: flex; flex-direction: column; gap: 7px; }
.radio { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; border: 1px solid #E2E8F0; border-radius: 9px; font-size: 12px; color: #475569; cursor: pointer; text-align: left; }
.radio:hover { border-color: #CBD5E1; }
.radio.on { border-color: #15B5C7; background: #ECFDFD; color: #15324F; }
.radio input { accent-color: #15B5C7; margin-top: 1px; flex: none; }
.radio > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.radio strong { font-size: 12.5px; font-weight: 800; color: #0F172A; }
.radio em { font-style: normal; font-size: 11px; line-height: 1.5; color: #64748B; }
.radio.on em { color: #15324F; }

.check-row { display: flex; align-items: flex-start; gap: 9px; padding: 10px 0; border-bottom: 1px solid #EDF1F5; }
.check-row:last-child { border-bottom: 0; }
.check-row input { accent-color: #15B5C7; margin-top: 2px; }
.check-t { font-size: 12.5px; font-weight: 700; color: #0F172A; }
.check-d { font-size: 11px; color: #64748B; line-height: 1.55; margin-top: 2px; }

/* ---- Data type picker grid ---- */
.dt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.dt { display: flex; align-items: center; gap: 6px; padding: 8px 9px; border: 1px solid #E2E8F0; border-radius: 9px; font-size: 11.5px; font-weight: 600; color: #475569; cursor: pointer; background: #fff; }
.dt i { font-size: 13px; color: #94A3B8; }
.dt:hover { border-color: #94A3B8; }
.dt.on { border-color: #15B5C7; background: #ECFDFD; color: #15324F; }
.dt.on i { color: #0E9DAE; }

/* ---- AI budget meter ---- */
.meter { height: 6px; border-radius: 999px; background: #E2E8F0; overflow: hidden; margin: 8px 0 6px; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, #15B5C7, #0E9DAE); border-radius: 999px; }
.meter-lbl { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: #64748B; }
.meter-lbl strong { color: #0F172A; font-variant-numeric: tabular-nums; }

/* ---- Diff list (publish modal) ---- */
.diff { border: 1px solid #E2E8F0; border-radius: 11px; overflow: hidden; }
.diff-row { display: flex; align-items: flex-start; gap: 9px; padding: 10px 13px; border-bottom: 1px solid #EDF1F5; font-size: 12px; color: #334155; line-height: 1.55; }
.diff-row:last-child { border-bottom: 0; }
.diff-row i { font-size: 13px; margin-top: 1px; flex: none; }
.diff-add i { color: #047857; }
.diff-mod i { color: #B45309; }
.diff-rem i { color: #B91C1C; }

/* ==========================================================================
   Tap to place — the touch and keyboard path alongside drag
   ========================================================================== */
.fr-move { cursor: pointer; }
.tile.armed, .reuse.armed { border-color: #15B5C7; background: #ECFDFD; box-shadow: 0 0 0 3px rgba(21,181,199,.18); }
.fr.armed .fr-box { border-color: #15B5C7; background: #ECFDFD; box-shadow: 0 0 0 3px rgba(21,181,199,.18); }

/* While armed, every valid destination advertises itself. */
body.is-arming .fgrid { outline: 1.5px dashed #B6EAEF; outline-offset: 3px; border-radius: 10px; }
body.is-arming .fgrid:hover { outline-color: #15B5C7; background: #ECFDFD; }
body.is-arming .bx-tab:not(.on) { outline: 1.5px dashed #B6EAEF; outline-offset: 2px; }
body.is-arming .fslot { border-color: #15B5C7; color: #0E9DAE; }

.arm-bar {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(240%);
  z-index: 120; display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 11px 14px; border-radius: 12px; background: #0B1F35; color: #fff;
  box-shadow: 0 18px 40px -14px rgba(11,31,53,.6); font-size: 12.5px; font-weight: 600;
  max-width: calc(100vw - 32px); transition: transform .18s cubic-bezier(.32,.72,0,1);
  /* Not hit-testable while hidden. A translated-off-screen fixed bar still
     intercepts pointer events wherever it overlaps, which silently ate the
     mouse-up at the end of a drag. */
  pointer-events: none;
}
.arm-bar.show { transform: translateX(-50%) translateY(0); pointer-events: auto; }
.arm-bar > i { color: #15B5C7; font-size: 15px; }
.arm-hint { color: #94A3B8; font-weight: 500; }
.arm-bar button {
  margin-left: 4px; padding: 5px 11px; border-radius: 8px; border: 1px solid rgba(255,255,255,.18);
  background: transparent; color: #fff; font: inherit; font-size: 11.5px; font-weight: 700; cursor: pointer;
}
.arm-bar button:hover { background: rgba(255,255,255,.1); }

.phone-gate { display: none; }

/* ---- Mobile field sheet: the palette, as a bottom sheet ---- */
.sheet-scrim { position: fixed; inset: 0; background: rgba(6,21,37,.45); z-index: 130; opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.sheet-scrim.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 131;
  background: #fff; border-radius: 18px 18px 0 0; max-height: 82vh;
  display: flex; flex-direction: column; transform: translateY(100%);
  transition: transform .22s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -12px 40px -12px rgba(11,31,53,.35);
}
.sheet.show { transform: translateY(0); }
.sheet-grab { width: 38px; height: 4px; border-radius: 999px; background: #CBD5E1; margin: 9px auto 4px; flex: none; }
.sheet-head { display: flex; align-items: baseline; gap: 8px; padding: 6px 16px 10px; border-bottom: 1px solid #EDF1F5; flex: none; }
.sheet-title { font-size: 14px; font-weight: 800; color: #0F172A; }
.sheet-sub { font-size: 11.5px; color: #64748B; }
.sheet-body { overflow-y: auto; padding: 14px 16px 22px; }
/* The sheet reuses the palette's own markup, so there is one source of truth
   for what a field type is and how it looks. */
.sheet-body .pal-group { margin-bottom: 15px; }
.sheet-body .pal-tiles { grid-template-columns: repeat(2, 1fr); }
.sheet-body .tile, .sheet-body .reuse { cursor: pointer; padding: 11px 12px; }
.sheet-body .pal-search { display: none; }

/* Floating "add field" on phones, for when no section is in view */
.fab-add {
  display: none; position: fixed; right: 16px; bottom: 16px; z-index: 90;
  align-items: center; gap: 7px; padding: 12px 16px; border: 0; border-radius: 999px;
  background: linear-gradient(135deg, #15B5C7, #0E9DAE); color: #fff;
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 10px 24px -8px rgba(14,157,174,.75);
}
@media (max-width: 767px) { .tpl-editor .fab-add { display: inline-flex; } }

/* ---- Responsive ---- */
@media (max-width: 1180px) {
  .cfg-grid { grid-template-columns: 1fr; }
  .cs-grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .app-grid { grid-template-columns: 1fr; }
  .page-scroll { padding: 16px 18px 40px; }
  .page-topbar { padding: 14px 18px; }
  /* A 2-column template stacks on narrow screens — the record page does the same. */
  .tb-cols[data-cols="2"], .tb-cols[data-cols="3"] { grid-template-columns: 1fr; }
  .pv-cols { grid-template-columns: 1fr !important; }
  /* Master/detail collapses to a horizontal type picker above the detail. */
  .md-wrap { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .md-list { border-right: 0; border-bottom: 1px solid #E2E8F0; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 10px 14px; }
  .md-list-head { display: none; }
  .md-item { flex: none; }
  .md-item .cs-sub { display: none; }
  .md-detail-head { padding: 14px 18px; }
  .md-scroll { padding: 16px 18px 40px; }
  /* Builder: palette becomes a horizontal strip above the canvas. */
  .bx { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .bx-palette { border-right: 0; border-bottom: 1px solid #E2E8F0; max-height: 208px; }
  .pal-tiles { grid-template-columns: repeat(3, 1fr); }
  .bx-tabs { padding: 10px 16px; }
  .bx-tabs-hint { display: none; }
  .bx-scroll { padding: 14px 16px 40px; }
  /* Two-up field grid stacks — the record page does the same. */
  .fgrid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .pal-tiles { grid-template-columns: repeat(2, 1fr); }
}

/* ==========================================================================
   Phone: the editor stays fully editable. The palette becomes a bottom sheet
   so the canvas gets the whole screen, and each section opens it with itself
   as the target — on mobile that is fewer taps than the desktop drag.
   ========================================================================== */
@media (max-width: 767px) {
  .bx-palette { display: none; }
  .bx { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .bx-tabs { padding: 10px 14px; gap: 6px; }
  .bx-tabs-lbl { display: none; }
  .bx-scroll { padding: 12px 14px 96px; }
  .tb-intro { font-size: 11.5px; padding: 10px 12px; }

  /* Field rows: give the name the width, drop the inline type onto its own line */
  .fr-box { padding: 10px 9px; gap: 6px; }
  .fr-name { white-space: normal; }
  .fr-type { display: block; font-size: 10.5px; margin-top: 1px; }
  .fr-acts i { font-size: 15px; padding: 2px; }

  .panel-tools { gap: 8px; padding: 10px 12px; }
  .pt-a:first-of-type { margin-left: 0; }
  .sec-body { padding: 4px 12px 12px; }
  .sec-head { padding: 11px 12px; }
  .arm-bar { left: 12px; right: 12px; bottom: 12px; transform: translateY(240%); max-width: none; }
  .arm-bar.show { transform: translateY(0); }
  .arm-hint { display: none; }
}
}
@media (max-width: 860px) {
  .cs-hide-md { display: none !important; }
  /* Narrow screens: shrink the role picker rather than truncating the tab name. */
  .role-sel, .th-role { width: 104px; }
  .role-sel { font-size: 11px; padding: 5px 6px; }
  .dt-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .cs-hide-lg { display: none !important; }
  .fld-row { grid-template-columns: 1fr; }
  .pv-kv { grid-template-columns: 1fr; gap: 2px 0; }
  .pv-kv dd { margin-bottom: 8px; }
}
