/* Holarch base styles and the app shell. Tokens (colours, type scale, spacing, radii, density) are in tokens.css. */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: var(--fs-md)/1.45 var(--font); color: var(--text); background: var(--bg); color-scheme: light; -webkit-font-smoothing: antialiased; }
[data-theme=dark] body { color-scheme: dark; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 600; }
h2 { font-size: var(--fs-xl); } h3 { font-size: var(--fs-lg); }
.muted { color: var(--muted); }
.pad { padding: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; }
.hidden { display: none !important; }
/* Keyboard focus: a 2px ring (≥3:1 against panel and page in both themes). */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: 0 0 0 5px var(--focus-halo); }
.input:focus-visible, .inline-edit:focus-visible { outline-offset: 0; }
[data-press]:focus-visible, [role=grid] [tabindex]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.modal:focus { outline: none; }
.rail :focus-visible { outline-color: var(--brand-300); box-shadow: 0 0 0 4px rgba(143, 219, 224, .35); }
.modal.modal-nudge { animation: modal-nudge .25s; }
@keyframes modal-nudge { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }


/* ---------- layout ---------- */
.main { flex: 1; min-height: 0; overflow: auto; position: relative; }
.page { max-width: 1280px; margin: 0 auto; padding: 20px 24px 40px; }
.page.full { max-width: none; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-card); }
.card-head { padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 14px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* split view with sidebar (used by database, diagrams, documents) */
.split { display: flex; height: 100%; min-height: 0; }
.split > .sidebar { width: 260px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.split > .sidebar.right { border-right: 0; border-left: 1px solid var(--line); width: 320px; }
.split > .content { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; }
.sidebar h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 14px 6px; font-weight: 600; }
.side-item { display: flex; align-items: center; gap: 8px; padding: 5px 14px; cursor: pointer; color: var(--text); }
.side-item:hover { background: var(--line-2); text-decoration: none; }
.side-item.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.side-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; flex: none; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar .title { font-weight: 600; margin-right: 8px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--text); padding: 6px 12px; border-radius: var(--r-ctl); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--line-strong); background: var(--panel-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.primary, .modal-foot .btn.danger { background: var(--danger); border-color: var(--danger); color: var(--on-status); }
.btn.small { padding: 3px 8px; font-size: var(--fs-xs); }
.btn.active { background: var(--accent-2); border-color: var(--accent); color: var(--accent); }
.icon-btn { background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: var(--r-sm); }
.icon-btn:hover { background: var(--line-2); color: var(--text); }
.input { font: inherit; border: 1px solid var(--line-strong); border-radius: var(--r-ctl); padding: 6px 8px; background: var(--input-bg); color: var(--text); width: 100%; }
.input:focus, .inline-edit:focus { outline: 2px solid var(--focus); border-color: var(--accent); }
select.input { width: auto; max-width: 100%; }
textarea.input { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.form .field:last-child { margin-bottom: 0; }
.checkbox { display: inline-flex; gap: 6px; align-items: center; }

.cls-badge { display: inline-block; color: var(--on-fill); font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 3px; white-space: nowrap; vertical-align: 1px; }
.label-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--chip-bg); border: 1px solid var(--chip-line); color: var(--chip-text); font-size: 11.5px; padding: 0 7px; border-radius: 10px; margin: 1px 3px 1px 0; white-space: nowrap; }
.label-chip button { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; }
.ent-link { color: var(--text); }
.ent-link:hover { color: var(--accent); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; flex: 1; }
table.grid-table { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--panel); }
.grid-table th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; cursor: pointer; user-select: none; }
.grid-table td { padding: 6px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.grid-table tr:hover td { background: var(--hover); }
.grid-table tr.selected td { background: var(--accent-2); }
.grid-table td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.grid-table td.desc { max-width: 520px; color: var(--text-2); }
.grid-table .chk { width: 30px; }
.inline-edit { border: 1px solid transparent; border-radius: 3px; padding: 1px 4px; margin: -2px -5px; min-height: 1.4em; }
.inline-edit:hover { border-color: var(--line); background: var(--panel); }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 26, 51, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding-top: 8vh; }
.modal { background: var(--panel); color: var(--text); border-radius: var(--r-card); box-shadow: var(--shadow-pop); width: 480px; max-width: calc(100vw - 32px); max-height: 84vh; display: flex; flex-direction: column; }
.modal.wide { width: 860px; }
.modal-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pick-list { margin-top: 10px; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.pick-row { display: flex; gap: 8px; align-items: center; padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.pick-row:hover { background: var(--accent-2); }

/* dropdown */
.dropdown { position: fixed; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-pop); padding: 4px 0; z-index: 120; min-width: 180px; max-height: 70vh; overflow: auto; }
.dd-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 14px; color: var(--text); }
.dd-item:hover:not(:disabled) { background: var(--accent-2); }
.dd-item:disabled { color: var(--muted); opacity: .6; }
.dd-div { height: 1px; background: var(--line); margin: 4px 0; }
.dd-head { padding: 6px 14px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--brand-800); color: var(--on-fill); padding: 9px 14px; border-radius: var(--r-ctl); box-shadow: var(--shadow); transition: opacity .3s; max-width: 380px; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.toast.out { opacity: 0; }

.error-box { margin: 24px; padding: 16px; background: var(--danger-bg); border: 1px solid var(--danger-line); border-radius: 6px; }
.error-box pre { white-space: pre-wrap; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty h3 { color: var(--text); }

/* stat tiles */
.stat { padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 600; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

/* diagram canvas */
.canvas-wrap { position: relative; flex: 1; overflow: hidden; background: var(--canvas-bg); background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px); background-size: 20px 20px; }
.canvas-wrap svg { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.zoom-box { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 2px; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-ctl); box-shadow: 0 2px 8px rgba(0,0,0,.06); padding: 3px; }
.zoom-box button { border: 0; background: none; color: var(--text); width: 30px; height: 28px; border-radius: 4px; }
.zoom-box button:hover { background: var(--line-2); }
.zoom-box span { min-width: 46px; text-align: center; align-self: center; font-size: 12px; color: var(--muted); }

@media (max-width: 760px) {
  .split > .sidebar { display: none; }
  .page { padding: 16px; }
}
@media print {
  .topbar, .rail, .edtabs, .insp, .rail-peek, .skip-link, #focus-pill, .toolbar, .sidebar, .no-print { display: none !important; }
  .shell, .work, .shell-body { display: block !important; height: auto !important; overflow: visible !important; }
  .main { overflow: visible; }
  body { background: #fff; }
}

/* Edge tab shown in place of a collapsed sidebar */
.side-rail { flex: none; width: 22px; border: 0; background: var(--panel); color: var(--muted); font-size: 16px; padding: 0; cursor: pointer; }
.side-rail.left { border-right: 1px solid var(--line); }
.side-rail.right { border-left: 1px solid var(--line); }
.side-rail:hover { background: var(--accent-2); color: var(--accent); }

/* Filterable dropdown */
.dropdown.filterable { display: flex; flex-direction: column; overflow: hidden; padding-top: 0; }
.dropdown.filterable .dd-list { overflow-y: auto; flex: 1; min-height: 0; }
.dd-filter { margin: 6px 6px 4px; width: calc(100% - 12px); padding: 5px 8px; font-size: 13px; flex: none; }
.dd-item.active { background: var(--accent-2); color: var(--accent); }
.dd-empty { padding: 8px 14px; color: var(--muted); font-size: 13px; }


/* ======================================================================
   Shell: rail | work [ top bar · editor tabs · body [ main | inspector ] ]
   ====================================================================== */
.shell { display: flex; height: 100%; overflow: hidden; position: relative; }
.work { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.shell-body { flex: 1; min-height: 0; display: flex; position: relative; }
.main { flex: 1; min-width: 0; min-height: 0; overflow: auto; position: relative; }
.main:focus { outline: none; box-shadow: none; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; }
.kbd { font: 500 11px/1 var(--font); padding: 3px 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: var(--r-sm); color: var(--text-2); background: var(--surface); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 300; background: var(--surface); color: var(--text); padding: 6px 10px; border-radius: var(--r-ctl); box-shadow: var(--shadow-pop); }
.skip-link:focus { top: 8px; }
.logo-mark { display: inline-flex; flex: none; }

/* ----- rail */
.rail { flex: none; width: var(--rail-w); background: var(--rail-bg); color: var(--rail-text); display: flex; flex-direction: column; padding: 6px 6px 8px; gap: 1px; z-index: 40; min-height: 0; }
[data-theme=dark] .rail { border-right: 1px solid var(--border); }
.rail .brand { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 6px; margin-bottom: 6px; color: var(--rail-text-strong); font-weight: 650; font-size: var(--fs-lg); border-radius: var(--r-ctl); flex: none; letter-spacing: .01em; }
.rail .brand:hover { text-decoration: none; background: var(--rail-hover); }
.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 1px; }
.rail-tools { display: flex; flex-direction: column; gap: 1px; flex: none; }
.rg { position: relative; }
.rail .ri { display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 10px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--rail-text); font: 500 var(--fs-sm)/1 var(--font); text-align: left; cursor: pointer; position: relative; white-space: nowrap; }
.rail .ri:hover { background: var(--rail-hover); color: var(--rail-text-strong); text-decoration: none; }
.rail .ri[aria-current], .rail .ri.in { background: var(--rail-sel); color: var(--rail-text-strong); }
.rail .ri.in::before { content: ""; position: absolute; left: -6px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand-300); }
.rail .ri .lbl { overflow: hidden; text-overflow: ellipsis; }
.rail .badge { margin-left: auto; font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: rgba(255, 255, 255, .16); color: var(--rail-text-strong); display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.rail .badge.hot { background: var(--rail-hot); color: var(--brand-900); }
.rail .badge[hidden], .rail .badge-dot { display: none; }
.rail .pages { margin: 2px 0 6px 20px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, .16); display: flex; flex-direction: column; gap: 1px; }
.rail .pages a { display: block; height: 28px; line-height: 28px; padding: 0 8px; border-radius: var(--r-ctl); color: var(--rail-text-2); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail .pages a:hover { background: var(--rail-hover); color: var(--rail-text-strong); text-decoration: none; }
.rail .pages a[aria-current=page] { color: var(--rail-text-strong); font-weight: 600; background: rgba(143, 219, 224, .14); }
.rail .sep { height: 1px; background: rgba(255, 255, 255, .12); margin: 6px 4px; flex: none; }
/* Flyouts: page lists in the icons state; Settings and Help lists in every state */
.fly { display: none; position: absolute; left: calc(100% + 4px); top: 0; z-index: 60; flex-direction: column; min-width: 210px; padding: 6px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-pop); }
.fly::before { content: ""; position: absolute; left: -8px; top: 0; bottom: 0; width: 8px; }
.fly .fh { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); padding: 4px 8px 6px; }
.fly a, .fly button { display: flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--text); font: var(--fs-sm)/1 var(--font); text-align: left; white-space: nowrap; cursor: pointer; }
.fly a:hover, .fly button:hover { background: var(--hover-bg); text-decoration: none; }
.fly [aria-current=page] { background: var(--sel-bg); font-weight: 600; }
.fly .ai-ico { color: var(--warn); }
.fly.tip { min-width: 0; padding: 6px 10px; font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; top: 2px; pointer-events: none; }
.rail-tools .rg:hover > .tool-fly, .rail-tools .rg:focus-within > .tool-fly, .rail-tools .rg.kb > .tool-fly, .rail-tools .tool-fly.open { display: flex; top: auto; bottom: 0; }
.shell[data-rail=icons] .rail { width: var(--rail-icons-w); }
.shell[data-rail=icons] .rail .lbl, .shell[data-rail=icons] .rail .badge, .shell[data-rail=icons] .rail .wm, .shell[data-rail=icons] .rail .pages { display: none; }
.shell[data-rail=icons] .rail .ri, .shell[data-rail=icons] .rail .brand { justify-content: center; padding: 0; }
.shell[data-rail=icons] .rail .badge-dot:not([hidden]) { display: block; position: absolute; top: 5px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--rail-hot); }
.shell[data-rail=icons] .rail-scroll { overflow: visible; }
.shell[data-rail=icons] .rg:hover > .fly, .shell[data-rail=icons] .rg:focus-within > .fly, .shell[data-rail=icons] .rg.kb > .fly, .rail .rg.kbr > .fly { display: flex; }
/* Hidden: a 8 px left-edge peek zone slides the rail over the content */
.rail-peek { display: none; }
.shell[data-rail=hidden] .rail { position: absolute; left: 0; top: 0; bottom: 0; transform: translateX(-102%); visibility: hidden; transition: none; }
.shell[data-rail=hidden].peek .rail { transform: none; visibility: visible; box-shadow: var(--shadow-pop); transition: transform .16s ease; }
.shell[data-rail=hidden] .rail-peek { display: block; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; z-index: 39; }
.shell[data-rail=hidden] .rail-peek:hover { background: linear-gradient(90deg, rgba(14, 74, 89, .35), transparent); }
.top-rail { display: none !important; }
.shell[data-rail=hidden] .top-rail { display: inline-flex !important; }
@media (prefers-reduced-motion: reduce) { .rail, .shell[data-rail=hidden] .rail { transition: none !important; } }

/* ----- top bar (one 44 px row) */
.topbar { flex: none; height: var(--topbar-h); display: flex; align-items: center; gap: 4px; padding: 0 var(--sp-3) 0 var(--sp-4); border-bottom: 1px solid var(--border); background: var(--surface); min-width: 0; position: relative; z-index: 30; }
.topbar > * { flex: none; }
.crumb { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 4px; font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; overflow: hidden; }
.crumb svg.sep { width: 12px; height: 12px; color: var(--text-3); }
.crumb a.c { color: var(--text-2); flex: none; }
.crumb a.c:hover { color: var(--text); }
.crumb .c { flex: none; }
.top-title { font-size: var(--fs-sm); line-height: 20px; margin: 0; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.top-project { display: inline-flex; align-items: center; gap: 2px; max-width: 220px; height: 28px; padding: 0 4px 0 6px; margin-left: -6px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; flex: 0 1 auto; min-width: 0; }
.top-project .pn { overflow: hidden; text-overflow: ellipsis; }
.top-project:hover { background: var(--hover-bg); color: var(--text); }
.top-actions, .top-status { display: flex; gap: 6px; align-items: center; }
.top-actions[hidden], .top-status[hidden] { display: none; }
.topbar .vsep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.top-icon { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: var(--r-ctl); background: none; color: var(--text-2); }
.top-icon:hover:not(:disabled) { background: var(--hover-bg); color: var(--text); }
.top-icon:disabled { opacity: .35; cursor: default; }
.top-icon[aria-pressed=true] { background: var(--sel-bg); color: var(--text); }
.top-icon[hidden], .top-search[hidden], .top-ai[hidden], .top-problems[hidden], .top-save[hidden] { display: none !important; }
.top-search { display: flex; align-items: center; gap: 6px; height: 30px; width: 168px; padding: 0 6px 0 8px; margin: 0 4px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-sm); cursor: text; }
.top-search:hover { border-color: var(--text-3); }
.top-search .kbd { margin-left: auto; }
.topbar .top-ai { height: 30px; padding: 0 10px; border-radius: var(--r-ctl); font-size: var(--fs-sm); gap: 2px; }
.top-problems { display: inline-flex; align-items: center; gap: 4px; height: 30px; padding: 0 8px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--warn); font-weight: 600; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.top-problems.none { color: var(--text-3); font-weight: 500; }
.top-problems:hover { background: var(--hover-bg); }
.top-save { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--text-2); font-size: var(--fs-xs); white-space: nowrap; cursor: default; }
.top-save .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.top-save[data-state=saving] .dot { background: var(--info); }
.top-save[data-state=failed] { color: var(--danger); font-weight: 600; cursor: pointer; }
.top-save[data-state=failed] .dot { background: var(--danger); }
@media (max-width: 1280px) {
  .top-search { width: 32px; padding: 0; justify-content: center; }
  .top-search .lbl2, .top-search .kbd, .topbar .top-ai .lbl2, .top-save .st { display: none; }
  .topbar .top-ai { padding: 0 8px; }
}

/* ----- editor tabs */
.edtabs { flex: none; display: flex; align-items: stretch; height: var(--tabs-h); background: var(--surface-2); border-bottom: 1px solid var(--border); padding-left: 4px; }
.edtabs[hidden] { display: none; }
.edtabs-strip { display: flex; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.edtabs-strip::-webkit-scrollbar { display: none; }
.edtab { display: flex; align-items: center; flex: 0 1 260px; min-width: 120px; border-right: 1px solid var(--border); position: relative; }
.edtab.on { background: var(--surface); }
.edtab.on::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--sel-edge); }
.edtab-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 2px 0 10px; color: var(--text-2); font-size: var(--fs-xs); white-space: nowrap; }
.edtab-link:focus-visible { outline-offset: -2px; box-shadow: none; }
.edtab.on .edtab-link { color: var(--text); }
.edtab-link:hover { text-decoration: none; color: var(--text); }
.edtab-link .t { overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.edtab-link .s { color: var(--text-3); flex: none; }
.edtab-x { flex: none; width: 22px; height: 22px; margin-right: 4px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-3); opacity: .55; }
.edtab:hover .edtab-x, .edtab.on .edtab-x, .edtab-x:focus-visible { opacity: 1; }
.edtab-x:hover { background: var(--hover-bg); color: var(--text); }
.edtab.drag { opacity: .5; }
.edtab.over { box-shadow: inset 3px 0 0 var(--sel-edge); }
.edtabs-more { flex: none; display: inline-flex; align-items: center; gap: 2px; padding: 0 10px; border: 0; border-left: 1px solid var(--border); background: none; color: var(--text-2); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.edtabs-more:hover { color: var(--text); background: var(--hover-bg); }

/* ----- inspector (right): open / edge tab / none */
.insp { flex: none; position: relative; background: var(--surface); border-left: 1px solid var(--border); display: none; flex-direction: column; min-height: 0; }
.insp[data-state=open] { display: flex; width: var(--insp-w, 340px); }
.insp[data-state=edge] { display: flex; width: 28px; }
.insp-head { display: flex; align-items: center; gap: 2px; padding: 6px 6px 6px 14px; border-bottom: 1px solid var(--border); flex: none; }
.insp-title { font-size: var(--fs-xs); font-weight: 600; margin: 0; color: var(--text-2); text-transform: none; }
.insp-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 0; border-radius: var(--r-ctl); background: none; color: var(--text-2); }
.insp-btn:hover { background: var(--hover-bg); color: var(--text); }
.insp-btn[aria-pressed=true] { background: var(--sel-bg); color: var(--text); }
.insp-body { flex: 1; min-height: 0; overflow: auto; }
.insp-empty { color: var(--text-2); font-size: var(--fs-sm); padding: var(--sp-5) var(--sp-4); text-align: center; }
.insp-resize { position: absolute; left: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 5; touch-action: none; }
.insp-resize:hover, .insp-resize:focus-visible { background: var(--sel-edge); opacity: .5; outline: none; box-shadow: none; }
.insp-edge { display: flex; align-items: center; gap: 6px; writing-mode: vertical-rl; width: 100%; height: 100%; padding: 12px 0; border: 0; background: var(--surface-2); color: var(--text-2); font: 600 var(--fs-xs)/1 var(--font); cursor: pointer; white-space: nowrap; overflow: hidden; }
.insp-edge:hover { background: var(--hover-bg); color: var(--text); }
.insp-edge svg { transform: rotate(90deg); }
.insp .db-panel-head { position: sticky; top: 0; z-index: 2; background: var(--surface); }

/* ----- focus mode: content only */
:root[data-focus="1"] .rail, :root[data-focus="1"] .rail-peek, :root[data-focus="1"] .topbar, :root[data-focus="1"] .edtabs, :root[data-focus="1"] .insp { display: none !important; }
#focus-pill { position: fixed; top: 8px; right: 8px; z-index: 95; display: none; box-shadow: var(--shadow-pop); }
:root[data-focus="1"] #focus-pill { display: inline-flex; }

/* ----- command palette */
.pal-scrim { position: fixed; inset: 0; background: rgba(15, 26, 51, .45); z-index: 150; }
.pal { position: fixed; z-index: 151; top: 12vh; left: 50%; transform: translateX(-50%); width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; max-height: 70vh; }
.pal-in { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); color: var(--text-2); }
.pal-input { flex: 1; border: 0; background: none; font: var(--fs-lg) var(--font); color: var(--text); outline: none; height: 28px; min-width: 0; }
.pal-input:focus-visible { box-shadow: none; outline: none; }
.pal-list { overflow: auto; padding: var(--sp-2); margin: 0; list-style: none; }
.pal-g { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); padding: var(--sp-2) var(--sp-2) 4px; }
.pal-o { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); height: 36px; border-radius: var(--r-ctl); cursor: pointer; font-size: var(--fs-md); color: var(--text); }
.pal-o svg.i { color: var(--text-2); }
.pal-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-sub { margin-left: auto; padding-left: 12px; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; flex: none; }
.pal-o[aria-selected=true] { background: var(--sel-bg); box-shadow: inset 3px 0 0 var(--sel-edge); }
.pal-cls { width: 10px; height: 10px; border-radius: 2px; flex: none; margin: 0 3px; }
.pal-ai { display: inline-flex; color: var(--brand-800); background: var(--amber); border-radius: var(--r-sm); padding: 1px; flex: none; }
.pal-ai .ai-ico { color: var(--brand-800); }
.pal-empty { color: var(--text-2); font-size: var(--fs-sm); padding: var(--sp-5) var(--sp-4); text-align: center; }
.pal-foot { display: flex; gap: var(--sp-4); padding: var(--sp-2) var(--sp-4); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-2); }
.pal mark { background: none; color: inherit; font-weight: 700; text-decoration: underline; text-decoration-color: var(--sel-edge); text-underline-offset: 2px; }

/* ======================================================================
   Home, stage overviews, RVTM, Interface Register (new pages)
   ====================================================================== */
.hpage { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--gap); max-width: 1440px; }
:root[data-density=compact] .hpage { padding: var(--sp-4); }
.hpage h1 { font-size: var(--fs-2xl); line-height: 34px; margin: 0; }
.hpage.rvtm h1, .hpage.ifreg h1 { font-size: var(--fs-xl); line-height: 28px; }
.hpage h2 { font-size: var(--fs-lg); line-height: 24px; margin: 0; }
.hp-head { display: flex; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; }
.hp-titles { flex: 1; min-width: 240px; }
.hp-titles p { margin: 4px 0 0; }
.hp-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.hp-toolbar { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.hp-search { width: 280px; }
.health { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--gap); }
.health > div { display: flex; }
.hc { flex: 1; display: flex; flex-direction: column; gap: 6px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--tone, var(--border-strong)); border-radius: var(--r-card); padding: var(--pad); cursor: pointer; color: var(--text); font: inherit; min-width: 0; }
a.hc:hover, button.hc:hover { border-color: var(--border-strong); border-top-color: var(--tone, var(--border-strong)); background: var(--hover-bg); text-decoration: none; }
div.hc { cursor: default; }
.hc.on { box-shadow: inset 0 0 0 2px var(--sel-edge); }
.hc .v { font-size: var(--fs-2xl); line-height: 32px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hc .v.small-v { font-size: var(--fs-xl); line-height: 32px; }
.hc .t { display: flex; gap: 6px; align-items: center; font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.hc .d { font-size: var(--fs-xs); color: var(--text-2); }
.hc .lv { font-size: var(--fs-lg); font-weight: 600; }
.hc.danger { --tone: var(--danger); } .hc.warn { --tone: var(--warn); } .hc.ok { --tone: var(--ok); } .hc.info { --tone: var(--info); } .hc.plain { --tone: var(--border-strong); }
.metrics .hc .t { font-weight: 500; color: var(--text-2); }
.lc { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap); }
.lc .hc { border-top-width: 1px; }
.lc .hc .t { color: var(--text-2); }
.bar { display: block; height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand-700); }
[data-theme=dark] .bar > i { background: var(--brand-300); }
.hpage .cols-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--gap); }
@media (max-width: 1100px) { .hpage .cols-2 { grid-template-columns: minmax(0, 1fr); } }
.hp-card { padding: var(--pad); display: flex; flex-direction: column; gap: var(--sp-2); }
.hlist { list-style: none; margin: 0; padding: 0; }
.hlist li { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.hlist li:last-child { border-bottom: 0; }
.hlist li svg { color: var(--text-2); }
.hlist .meta { margin-left: auto; font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; padding-left: 8px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
.dot.danger { background: var(--danger); } .dot.warn { background: var(--warn); } .dot.info { background: var(--info); } .dot.ok { background: var(--ok); }
.stage-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--gap); }
.stage-page { display: flex; flex-direction: column; gap: 4px; padding: var(--pad); color: var(--text); }
.stage-page:hover { text-decoration: none; background: var(--hover-bg); border-color: var(--border-strong); }
.stage-page .muted { font-size: var(--fs-xs); }
.stage-types { display: flex; flex-wrap: wrap; gap: 6px; padding-top: var(--sp-2); border-top: 1px solid var(--border); }
.chip-link { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-xs); }
.chip-link:hover { background: var(--sel-bg); color: var(--text); text-decoration: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 500; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); } .chip.warn { background: var(--warn-bg); color: var(--warn); } .chip.danger { background: var(--danger-bg); color: var(--danger); } .chip.info { background: var(--info-bg); color: var(--info); }
.tblwrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: auto; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.tbl th { position: sticky; top: 0; z-index: 1; text-align: left; font-weight: 600; font-size: var(--fs-xs); color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 0 var(--sp-3); height: 32px; white-space: nowrap; }
.tbl td { padding: 6px var(--sp-3); height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl td.id { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.tbl td.num { font-variant-numeric: tabular-nums; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--hover-bg); }
.tbl tbody tr.sel td { background: var(--sel-bg); }
.tbl tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--sel-edge); }
.tbl tbody tr:focus-visible { outline-offset: -2px; box-shadow: none; }
:root[data-density=compact] .tbl td { padding-top: 3px; padding-bottom: 3px; }

/* ----- density: compact tightens shared controls */
:root[data-density=compact] .toolbar { padding: 5px 10px; }
:root[data-density=compact] .grid-table td { padding-top: 4px; padding-bottom: 4px; }
:root[data-density=compact] .btn { padding: 4px 10px; }
:root[data-density=compact] .btn.small { padding: 2px 7px; }

/* ----- view page anatomy (UI-MGMT pass): the title lives in the top bar, page actions in .top-actions
   (secondary first, primary last); one in-page view bar: tabs · filters · spacer · view options · search. */
.top-actions .btn { height: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.topbar > .crumb { min-width: 160px; }
.crumb .top-title { flex: 0 0 auto; max-width: 320px; }
/* Below 1600 px the AI control collapses to the sparkle (+ ▾); it stays one control. */
@media (max-width: 1599px) { .topbar .top-ai-ask .lbl2 { display: none; } .topbar .top-ai-ask { padding: 0 8px; } }
/* With page actions, the search box and labels compact earlier so the breadcrumb keeps its room. */
@media (max-width: 1600px) {
  .topbar:has(.top-actions:not([hidden])) .top-search { width: 32px; padding: 0; justify-content: center; }
  .topbar:has(.top-actions:not([hidden])) :is(.top-search .lbl2, .top-search .kbd, .top-ai .lbl2, .top-save .st) { display: none; }
  .topbar:has(.top-actions:not([hidden])) .top-ai { padding: 0 8px; }
}
.vpage { max-width: none; margin: 0; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--gap); min-height: 0; }
:root[data-density=compact] .vpage { padding: var(--sp-4); }
.vbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; flex: none; min-height: var(--ctl-h); }
.vbar .vnote { font-size: var(--fs-sm); color: var(--text-2); }
.vbar .vsearch { width: 220px; }
.vtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); flex: none; }
.vtab { flex: none; display: inline-flex; align-items: center; gap: 6px; height: var(--tabs-h); padding: 0 10px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; color: var(--text-2); font: 500 var(--fs-sm)/1 var(--font); }
.vtab:hover { color: var(--text); text-decoration: none; }
.vtab[aria-selected=true] { color: var(--text); border-bottom-color: var(--sel-edge); font-weight: 600; }
