
:root {
  --bg: #e9ecf1;
  --chrome: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eceef2;
  --border: #d3d8e0;
  --border-strong: #b9c0cb;
  --text: #1c2230;
  --muted: #5b6475;
  --faint: #8a93a3;
  --accent: #1f5fbf;
  --accent-hover: #1a52a6;
  --accent-text: #ffffff;
  --accent-weak: #e2ecfa;
  --select: #cfe0f8;
  --danger: #c4314b;
  --danger-weak: #fbe9ec;
  --ok: #1e7a47;
  --ok-weak: #e3f4ea;
  --warn: #8a5a00;
  --warn-weak: #fdf1d8;
  --chart-bar: #2a78d6;
  --shadow: 0 8px 28px rgba(20, 30, 50, .18), 0 1px 3px rgba(20, 30, 50, .12);
  --titlebar: #1f5fbf;
  --titlebar-text: #ffffff;
  --status: #1f5fbf;
  --status-text: #ffffff;
  --radius: 6px;
  --font: "Dubai", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16181c;
  --chrome: #1e2126;
  --surface: #23262c;
  --surface-2: #292d34;
  --surface-3: #30353d;
  --border: #383d46;
  --border-strong: #4a515c;
  --text: #e6e8ec;
  --muted: #a0a8b6;
  --faint: #737c8a;
  --accent: #4c8ee8;
  --accent-hover: #6aa2ee;
  --accent-text: #0d1420;
  --accent-weak: #22344d;
  --select: #2c4a73;
  --danger: #f0707f;
  --danger-weak: #3d2228;
  --ok: #5fcf8e;
  --ok-weak: #1d3527;
  --warn: #e8b552;
  --warn-weak: #3a2f19;
  --chart-bar: #3987e5;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  --titlebar: #1a1d22;
  --titlebar-text: #e6e8ec;
  --status: #2a3e5c;
  --status-text: #e6e8ec;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.svg-ico { display: inline-flex; width: 16px; height: 16px; flex: none; }
.svg-ico svg { width: 100%; height: 100%; }

/* ------------------------------------------------------------ shell */
#app { height: 100vh; display: grid; grid-template-rows: 34px 32px 1fr 24px; }
.titlebar { background: var(--titlebar); color: var(--titlebar-text); display: flex; align-items: center; gap: 10px; padding: 0 12px; user-select: none; }
.titlebar .logo { width: 20px; height: 20px; border-radius: 5px; background: rgba(255,255,255,.18); display: grid; place-items: center; }
.titlebar .app-name { font-weight: 700; }
.titlebar .doc-name { opacity: .85; }
.titlebar .spacer { flex: 1; }
.titlebar .tb-user { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: .95; }
.titlebar button { background: transparent; border: 0; color: inherit; height: 26px; min-width: 30px; border-radius: 4px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; padding: 0 6px; }
.titlebar button:hover { background: rgba(255,255,255,.16); }

.menubar { background: var(--chrome); border-bottom: 1px solid var(--border); display: flex; align-items: stretch; padding: 0 4px; user-select: none; position: relative; z-index: 50; }
.menubar > .menu-root { position: relative; }
.menubar > .menu-root > button { height: 100%; border: 0; background: transparent; padding: 0 11px; cursor: default; border-radius: 3px; }
.menubar > .menu-root > button:hover, .menubar > .menu-root.open > button { background: var(--surface-3); }
.menubar > .spacer { flex: 1; }
.menubar > .icon-btn { align-self: center; width: 28px; height: 28px; margin-inline-start: 2px; }   /* quick buttons at the end of the bar */

.dropdown { position: fixed; min-width: 230px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px; z-index: 1000; }
.dropdown .mi { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 5px 10px; border-radius: 4px; text-align: start; cursor: default; white-space: nowrap; }
.dropdown .mi:hover:not(:disabled), .dropdown .mi.active { background: var(--accent); color: var(--accent-text); }
.dropdown .mi:disabled { color: var(--faint); }
.dropdown .mi .kbd { margin-inline-start: auto; font-size: 12px; opacity: .7; direction: ltr; padding-inline-start: 24px; }
.dropdown .mi.danger:not(:disabled) { color: var(--danger); }
.dropdown .mi.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.dropdown .sep { height: 1px; background: var(--border); margin: 4px 6px; }

.toolbar { background: var(--chrome); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 2px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
.tbtn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px; border: 1px solid transparent; border-radius: 4px; background: transparent; cursor: pointer; white-space: nowrap; }
.tbtn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); }
.tbtn:active:not(:disabled) { background: var(--select); }
.tbtn:disabled { opacity: .45; cursor: default; }
.tbtn.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); }
.tbtn.primary { background: var(--accent); color: var(--accent-text); }
.tbtn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: transparent; }
.tsep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; flex: none; }
.tspacer { flex: 1; }

.main { display: grid; grid-template-columns: var(--explorer-w, 260px) 5px 1fr; min-height: 0; }
.main.no-explorer { grid-template-columns: 0 0 1fr; }
.main.no-explorer .explorer { visibility: hidden; }
.splitter { cursor: col-resize; background: var(--bg); border-inline: 1px solid var(--border); }
.splitter:hover, .splitter.drag { background: var(--accent); }

.explorer { background: var(--surface-2); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; border-bottom: 1px solid var(--border); flex: none; }
.panel-head .spacer { flex: 1; }
.icon-btn { border: 0; background: transparent; width: 24px; height: 24px; border-radius: 4px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.explorer-search { margin: 8px; }
.tree { flex: 1; overflow: auto; padding: 0 4px 8px; }
.tree-group { display: flex; align-items: center; gap: 6px; padding: 4px 6px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; user-select: none; }
.tree-group .chev { transition: transform .15s; }
.tree-group.collapsed .chev { transform: rotate(90deg); }
.tree-item { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 6px; padding-inline-start: 22px; border-radius: 4px; cursor: default; user-select: none; white-space: nowrap; }
.tree-item:hover { background: var(--surface-3); }
.tree-item.active { background: var(--select); }
.tree-item .name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.badge { font-size: 11px; line-height: 18px; min-width: 20px; text-align: center; padding: 0 6px; border-radius: 9px; background: var(--surface-3); color: var(--muted); }
.badge.draft { background: var(--warn-weak); color: var(--warn); }
.badge.closed { background: var(--danger-weak); color: var(--danger); }
.badge.ok { background: var(--ok-weak); color: var(--ok); }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.tabs { display: flex; align-items: flex-end; background: var(--chrome); border-bottom: 1px solid var(--border); height: 36px; padding: 0 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; flex: none; }
.tab { display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 10px 0 6px; max-width: 240px; border: 1px solid transparent; border-bottom: 0; border-radius: 6px 6px 0 0; color: var(--muted); cursor: default; user-select: none; white-space: nowrap; flex: none; }
.tab:hover { background: var(--surface-3); }
.tab.active { background: var(--surface); color: var(--text); border-color: var(--border); position: relative; top: 1px; box-shadow: inset 0 2px 0 var(--accent); }
.tab .title { overflow: hidden; text-overflow: ellipsis; }
.tab .dirty { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tab .close { border: 0; background: transparent; width: 20px; height: 20px; border-radius: 4px; display: grid; place-items: center; color: inherit; opacity: .6; cursor: pointer; }
.tab .close:hover { background: var(--surface-3); opacity: 1; }
.tab-body { flex: 1; min-height: 0; position: relative; }
.tab-page { position: absolute; inset: 0; display: flex; flex-direction: column; }

.statusbar { background: var(--status); color: var(--status-text); display: flex; align-items: center; gap: 18px; padding: 0 12px; font-size: 12px; user-select: none; white-space: nowrap; overflow: hidden; }
.statusbar .spacer { flex: 1; }
.statusbar .item { display: inline-flex; align-items: center; gap: 5px; }

/* ------------------------------------------------------------ controls */
.input, select.input, textarea.input { width: 100%; height: 32px; padding: 4px 9px; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface); }
textarea.input { height: auto; min-height: 84px; resize: vertical; line-height: 1.6; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-weak); }
.input:disabled, .input[readonly] { background: var(--surface-2); color: var(--muted); }
.input.sm { height: 28px; font-size: 13px; }
.input.ltr { direction: ltr; text-align: left; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 16px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.field-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.prop-row { margin-bottom: 12px; }
.prop-row .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ------------------------------------------------------------ dialogs */
.overlay { position: fixed; inset: 0; background: rgba(15, 20, 30, .35); z-index: 900; display: grid; place-items: center; }
.dialog { position: fixed; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); }
.dialog-title { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 6px 0 12px; padding-inline-start: 14px; border-bottom: 1px solid var(--border); background: var(--chrome); border-radius: 8px 8px 0 0; cursor: move; user-select: none; font-weight: 700; flex: none; }
.dialog-title .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-body { padding: 16px; overflow: auto; flex: 1; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-start; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 8px 8px; flex: none; }
.dialog-foot .note { margin-inline-start: auto; align-self: center; font-size: 12px; color: var(--muted); }

.toasts { position: fixed; bottom: 34px; left: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 420px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-inline-start: 4px solid var(--accent); border-radius: 6px; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.ok { border-inline-start-color: var(--ok); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------ login */
.login-wrap { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, var(--bg), var(--surface-3)); }
.login-win { position: relative; width: 380px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
/* the office turning behind the login window (scene.js); its far side fades into the middle colour of this background */
.login-scene { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
/* on a wide screen the window stands on the right and the room turns in the left half (scene.js: shift, the same 760px) */
.login-wrap.with-scene { justify-items: start; padding-inline-start: max(32px, 8vw); background: radial-gradient(ellipse at 35% 50%, #eef2f7, #e4e9f0 45%, #cdd6e2); }
:root[data-theme="dark"] .login-wrap.with-scene { background: radial-gradient(ellipse at 35% 50%, #212b3c, #182030 45%, #0c1119); }
@media (max-width: 759px) { .login-wrap.with-scene { justify-items: center; padding-inline-start: 0; } }
.login-win .dialog-title { cursor: default; background: var(--titlebar); color: var(--titlebar-text); border: 0; border-radius: 0; }
.login-win form { padding: 22px; display: grid; gap: 14px; }
.login-win .big { font-size: 20px; font-weight: 700; margin: 0; }
.login-err { color: var(--danger); background: var(--danger-weak); padding: 6px 10px; border-radius: 4px; font-size: 13px; }

/* ------------------------------------------------------------ home */
.home { overflow: auto; padding: 28px; }
.home h1 { font-size: 24px; margin: 0 0 4px; }
.overview { position: relative; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.overview-close { position: absolute; top: 0; inset-inline-end: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin: 22px 0; }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.card .num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.card .lbl { color: var(--muted); font-size: 13px; }
.quick { display: flex; flex-wrap: wrap; gap: 10px; }
.quick .btn { height: 40px; }
.form-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.form-tile { text-align: start; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; cursor: pointer; display: grid; gap: 4px; }
.form-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.form-tile .t { font-weight: 700; }
.form-tile .m { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }

/* the blog: topic cards like the forms', a page per topic, its replies in the order written; every name on its own light colour */
.home.blog { flex: 1; min-height: 0; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: -10px 0 10px; font-size: 13px; color: var(--faint); }
.crumb { display: inline-flex; align-items: center; gap: 5px; border: 0; background: none; padding: 2px 6px; border-radius: 4px; color: var(--accent); cursor: pointer; }
.crumb:hover { background: var(--surface-3); }
.crumb.cur { color: var(--text); font-weight: 700; cursor: default; background: none; }
.topic-title { display: flex; align-items: center; gap: 10px; }
.topic-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin: 6px 0 14px; }
.topic-body { max-width: 900px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; }
/* the sub-titles: small links at the end (the left) of the topic block, so the replies below belong to the topic itself */
.subs { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.topic-body .md + .subs { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.sub { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 2px 10px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--accent); font-size: 13px; cursor: pointer; }
.sub:hover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.blog h3 { margin: 24px 0 10px; font-size: 15px; }
.replies { display: grid; gap: 10px; max-width: 900px; }
.reply { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.reply-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.reply-head .spacer { flex: 1; }
.reply.removed { border-style: dashed; background: var(--surface-2); }
.reply.removed .md { opacity: .5; margin-top: 6px; }
.removed-note { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.composer, .blog .notice { max-width: 900px; margin-top: 16px; }
.composer-foot { display: flex; align-items: center; gap: 12px; margin-top: 8px; font-size: 12px; }
.blog .notice { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 8px; border: 1px dashed var(--border-strong); background: var(--surface-2); color: var(--muted); }
.who { display: inline-block; padding: 0 9px; border-radius: 10px; line-height: 22px; font-weight: 700; font-size: 13px; color: var(--text); background: hsl(var(--hue), 70%, 88%); }
:root[data-theme="dark"] .who { background: hsl(var(--hue), 30%, 30%); }
.who.gone { background: var(--surface-3); color: var(--muted); }
.kbd-table td { padding: 3px 10px; }
.kbd-table td:first-child { direction: ltr; text-align: right; font-family: Consolas, monospace; font-size: 12px; color: var(--muted); }
kbd { font-family: Consolas, monospace; font-size: 12px; background: var(--surface-3); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

/* ------------------------------------------------------------ rendered form */
.eform { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 16px; }
.eform .ef { grid-column: span 6; min-width: 0; }
.eform .ef.w4 { grid-column: span 4; }
.eform .ef.w3 { grid-column: span 3; }
.eform .ef.w2 { grid-column: span 2; }
@media (max-width: 700px) { .eform .ef.w4, .eform .ef.w3, .eform .ef.w2 { grid-column: span 6; } }
.ef .req { color: var(--danger); margin-inline-start: 3px; }
.ef .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.ef .err { font-size: 12px; color: var(--danger); margin-top: 3px; display: none; }
.ef.invalid .err { display: block; }
.ef.invalid .input { border-color: var(--danger); }
.ef-heading { border-bottom: 2px solid var(--accent); padding-bottom: 4px; margin-top: 6px; }
.ef-heading h3 { margin: 0; font-size: 16px; color: var(--accent); }
.ef-heading p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.choices { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 4px 0; }
.yesno { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; }
.yesno label { padding: 4px 18px; cursor: pointer; user-select: none; }
.yesno input { position: absolute; opacity: 0; pointer-events: none; }
.yesno label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.yesno label + label { border-inline-start: 1px solid var(--border-strong); }
/* long text: Markdown toolbar, half-page counter, preview, formatted display */
.md-bar { display: flex; align-items: center; gap: 2px; margin-bottom: 3px; }
.md-btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 28px; height: 26px; padding: 0 6px; border: 1px solid transparent; border-radius: 4px; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.md-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.md-btn.on { background: var(--accent-weak); color: var(--accent); }
.md-btn:disabled { opacity: .45; cursor: default; }
.md-btn.b { font-weight: 700; }
.md-btn.i { font-style: italic; font-family: Georgia, serif; }
.md-count { margin-inline-start: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.md-count.over { color: var(--danger); font-weight: 700; }
.md-preview { height: auto; overflow: auto; }
.md { white-space: normal; line-height: 1.6; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .45em; }
.md ul, .md ol { margin: 0 0 .45em; padding-inline-start: 1.6em; }
.md .md-h { font-weight: 700; font-size: 1.08em; margin: .5em 0 .2em; }

/* ------------------------------------------------------------ designer */
.designer { flex: 1; display: grid; grid-template-columns: 210px 1fr 300px; min-height: 0; }
.palette, .props { background: var(--surface-2); overflow: auto; min-height: 0; }
.palette { border-inline-end: 1px solid var(--border); }
.props { border-inline-start: 1px solid var(--border); }
.palette .pal-list { padding: 8px; display: grid; gap: 4px; }
.pal-item { display: flex; align-items: center; gap: 9px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; cursor: grab; user-select: none; }
.pal-item:hover { border-color: var(--accent); color: var(--accent); }
.pal-item:active { cursor: grabbing; }
.palette .outline { padding: 4px 8px 12px; }
.outline-item { display: flex; align-items: center; gap: 7px; padding: 3px 8px; border-radius: 4px; cursor: default; font-size: 13px; white-space: nowrap; overflow: hidden; }
.outline-item:hover { background: var(--surface-3); }
.outline-item.sel { background: var(--select); }
.outline-item .n { overflow: hidden; text-overflow: ellipsis; }
.canvas-wrap { overflow: auto; background: var(--bg); padding: 24px; min-height: 0; }
.paper { max-width: 860px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 2px 10px rgba(20, 30, 50, .08); padding: 22px 26px 30px; min-height: 360px; }
.paper-head { border: 1.5px solid transparent; border-radius: 6px; padding: 6px 10px; margin: -6px -10px 16px; cursor: pointer; }
.paper-head:hover { border-color: var(--border-strong); border-style: dashed; }
.paper-head.sel { border-color: var(--accent); border-style: solid; background: var(--accent-weak); }
.paper-head h2 { margin: 0; font-size: 20px; }
.paper-head p { margin: 4px 0 0; color: var(--muted); white-space: pre-wrap; }
.paper .eform { min-height: 120px; }
.fd-block { position: relative; border: 1.5px dashed transparent; border-radius: 6px; padding: 8px 10px; margin: -4px; cursor: pointer; }
.fd-block:hover { border-color: var(--border-strong); }
.fd-block.sel { border: 1.5px solid var(--accent); background: var(--accent-weak); }
.fd-block.dragging { opacity: .35; }
.fd-block .ef-inner { pointer-events: none; }
.fd-block .fd-tools { position: absolute; top: -13px; inset-inline-end: 8px; display: none; gap: 2px; background: var(--accent); border-radius: 4px; padding: 1px; z-index: 2; }
.fd-block.sel .fd-tools { display: flex; }
.fd-tools button { border: 0; background: transparent; color: var(--accent-text); width: 24px; height: 22px; border-radius: 3px; cursor: pointer; display: grid; place-items: center; }
.fd-tools button:hover { background: rgba(255, 255, 255, .22); }
.fd-type { position: absolute; top: 6px; inset-inline-end: 10px; font-size: 11px; color: var(--faint); pointer-events: none; }
.drop-marker { position: absolute; background: var(--accent); border-radius: 2px; pointer-events: none; z-index: 5; box-shadow: 0 0 0 2px var(--accent-weak); }
.empty-canvas { grid-column: span 6; border: 2px dashed var(--border-strong); border-radius: 8px; padding: 40px 20px; text-align: center; color: var(--muted); }
.props-body { padding: 12px; }
.props-type { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; width: 100%; }
.seg button { flex: 1; border: 0; background: var(--surface); padding: 4px 0; cursor: pointer; font-size: 13px; }
.seg button + button { border-inline-start: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ------------------------------------------------------------ data grid */
.grid-wrap { flex: 1; overflow: auto; min-height: 0; }
table.dgrid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
/* header uses the inverse of the page colors, so it flips with the theme */
.dgrid th { position: sticky; top: 0; z-index: 1; background: var(--text); color: var(--surface); border-bottom: 1px solid var(--text); border-inline-end: 1px solid color-mix(in srgb, var(--surface) 22%, var(--text)); padding: 0; font-weight: 700; text-align: start; white-space: nowrap; }
.dgrid th button { width: 100%; border: 0; background: transparent; color: inherit; padding: 7px 10px; text-align: start; cursor: pointer; display: flex; align-items: center; gap: 6px; font-weight: 700; }
.dgrid th button:hover { background: color-mix(in srgb, var(--surface) 14%, var(--text)); }
.dgrid th .sort { color: inherit; opacity: .8; }
.dgrid td { padding: 6px 10px; border-bottom: 1px solid var(--border); border-inline-end: 1px solid var(--border); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; }
.dgrid td.num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.dgrid td.rn { color: var(--faint); width: 1%; text-align: center; background: var(--surface-2); }
.dgrid tbody tr { cursor: default; }
.dgrid tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.dgrid tbody tr:hover td { background: var(--surface-3); }
.dgrid tbody tr.sel td { background: var(--select); }
.grid-empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.grid-foot { display: flex; align-items: center; gap: 2px; height: 40px; padding: 0 8px; border-top: 1px solid var(--border); background: var(--chrome); font-size: 13px; flex: none; overflow-x: auto; scrollbar-width: none; }
.grid-foot .tbtn { height: 30px; }
.foot-info { display: flex; align-items: center; gap: 8px; padding: 0 4px; white-space: nowrap; }
.grid-foot .spacer { flex: 1; }
.pill { display: inline-block; padding: 0 8px; border-radius: 10px; background: var(--surface-3); font-size: 12px; margin-inline-end: 4px; }
.search-box { position: relative; width: 240px; flex: none; }
.search-box .input { padding-inline-start: 30px; height: 30px; }
.search-box .svg-ico { position: absolute; inset-inline-start: 9px; top: 7px; color: var(--faint); }
.banner { padding: 6px 14px; background: var(--warn-weak); color: var(--warn); font-size: 13px; border-bottom: 1px solid var(--border); flex: none; }

/* ------------------------------------------------------------ view / stats */
.kv { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.kv > div { padding: 7px 12px; border-bottom: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv .k { background: var(--surface-2); color: var(--muted); font-weight: 700; }
.kv .sec { grid-column: span 2; background: var(--accent-weak); color: var(--accent); font-weight: 700; }
.stats { display: grid; gap: 18px; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat-block h4 { margin: 0 0 8px; font-size: 14px; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr 64px; align-items: center; gap: 10px; font-size: 13px; padding: 2px 0; border-radius: 4px; }
.bar-row:hover { background: var(--surface-2); }
.bar-row .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { height: 14px; position: relative; }
.bar-row .fill { position: absolute; inset-block: 0; inset-inline-start: 0; background: var(--chart-bar); border-start-end-radius: 4px; border-end-end-radius: 4px; min-width: 2px; }
.bar-row .val { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; color: var(--muted); }
.num-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.num-table th, .num-table td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: start; }
.num-table td.n { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
.list-check { display: grid; gap: 2px; max-height: 50vh; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 6px; }
.list-check label { padding: 5px 8px; border-radius: 4px; }
.list-check label:hover { background: var(--surface-2); }
pre.code { direction: ltr; text-align: left; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 12px; max-height: 60vh; overflow: auto; font: 12px/1.5 Consolas, monospace; margin: 0; }

@media (max-width: 900px) {
  .designer { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .palette, .props { max-height: 220px; border: 0; border-bottom: 1px solid var(--border); }
  .main { grid-template-columns: 0 0 1fr; }
  .main .explorer { visibility: hidden; }
  .search-box { width: 150px; }
}

