/* designer.css — Report Designer UI (light, compact, professional) */

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --grid-line: rgba(37, 99, 235, 0.10);
  --margin-line: #9ca3af;
  --region-tint: rgba(37, 99, 235, 0.05);
  --ruler-bg: #f3f4f6;
  --ruler-fg: #6b7280;
  --ruler-page: #e5e7eb;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.08);
  --radius: 6px;
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Liberation Mono", monospace;
  --toolbar-h: 40px;
  --fmtbar-h: 36px;
  --status-h: 24px;
  --left-w: 268px;
  --right-w: 320px;
  /* preview drawer: ~42% of the window, but always leave >= --canvas-min-preview for the canvas.
     --drawer-reserve = what the drawer can never take (side panels + canvas floor); preview.js writes
     the dragged width as min(<px>, calc(100vw - var(--drawer-reserve))) so the panels stay in charge. */
  --canvas-min-preview: 300px;
  --drawer-reserve: calc(var(--left-w) + var(--right-w) + var(--canvas-min-preview));
  --drawer-w: min(clamp(320px, 42vw, 960px), calc(100vw - var(--drawer-reserve)));
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
svg { display: inline-block; vertical-align: middle; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.row { display: flex; align-items: center; }
.row.gap { gap: 6px; }
.row.wrap { flex-wrap: wrap; }

/* ------------------------------------------------------------------ */
/* App layout                                                          */
/* ------------------------------------------------------------------ */

.app { display: flex; flex-direction: column; height: 100vh; }
.workspace { flex: 1; display: grid; grid-template-columns: var(--left-w) 1fr var(--right-w); min-height: 0; position: relative; }
body.preview-open .workspace { grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w) var(--drawer-w); }

.banner { padding: 8px 14px; font-size: 13px; display: flex; align-items: center; gap: 10px; flex: none; }
.banner-error { background: var(--danger-soft); color: #7f1d1d; border-bottom: 1px solid #fca5a5; }
.banner-warning { background: var(--warning-soft); color: #78350f; border-bottom: 1px solid #fcd34d; }
.banner-info { background: var(--accent-soft); color: #1e3a8a; border-bottom: 1px solid #93c5fd; }
.banner-text { flex: 1; min-width: 0; line-height: 1.4; }
.banner-action { flex: none; }
/* The banners sit above .app (height: 100vh): keep the whole thing inside the window. */
body { display: flex; flex-direction: column; }
.app { flex: 1; min-height: 0; height: auto; }

/* Embed mode (SPEC-API-V2 §7): no app title; toolbar features the host did not enable are
   hidden by main.js (`hidden` attribute on [data-feature] elements). */
body.embed .brand { display: none; }
body.embed .toolbar { padding-left: 6px; }

/* ------------------------------------------------------------------ */
/* Toolbar                                                             */
/* ------------------------------------------------------------------ */

/* Two rows (SPEC-DESIGNER-V2 §0): row 1 = #toolbar (commands), row 2 = #fmtbar (format bar,
   filled by formatBar.js; collapsed while empty). Both scroll horizontally as a last resort. */
.toolbars { display: flex; flex-direction: column; flex: none; }
.toolbar {
  height: var(--toolbar-h);
  display: flex; align-items: center; gap: 4px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
}
.fmtbar {
  min-height: var(--fmtbar-h); display: flex; align-items: center; gap: 4px; padding: 0 10px;
  background: var(--panel-2); border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden; white-space: nowrap; scrollbar-width: thin;
}
.fmtbar:empty { display: none; }
.tb-group[data-group] { flex: none; }
/* The document group (template name · Kết nối · language · ?) is the only shrinkable item of
   row 1: the name truncates (ellipsis, ≥ 40 px) before any button is pushed off-screen, e.g.
   when the Kiểm tra badge appears or a long name is typed. Its buttons / select never shrink. */
.toolbar .tb-group[data-group="doc"] { flex: 0 1 auto; min-width: 0; }
.toolbar .tb-group[data-group="doc"] > :not(.template-name) { flex: none; }
.toolbar .template-name { flex: 0 1 auto; min-width: 40px; }
/* Row-1 metrics: compact values apply below 1500 px (media query) and whenever main.js sets
   body.tb-compact because the row would overflow. */
.toolbar { --tb-pad: 7px; --tb-pad-icon: 5px; --tb-gap: 1px; --tb-sep: 5px; --tb-zoom-w: 76px; --tb-name-w: 130px; --tb-zoom-min: 48px; }   /* name width trimmed (220→130) so the always-visible "Xem trang" button fits on one row at 1920 px */
/* The app name needs a wide window; the brand mark and the document title carry it otherwise */
.toolbar .brand-name { display: none; }
@media (min-width: 2100px) { .toolbar .brand-name { display: inline; } }
.toolbar .tb-btn { padding: 0 var(--tb-pad); }
.toolbar .tb-btn.icon-only { padding: 0 var(--tb-pad-icon); }
.toolbar .tb-group, .toolbar .tb-zoom, .toolbar .tb-view-items { gap: var(--tb-gap); }
.toolbar .tb-sep { margin: 0 var(--tb-sep); }
.toolbar .template-name { max-width: var(--tb-name-w); }
.toolbar .zoom-value { min-width: var(--tb-zoom-min); }
.toolbar.compact, body.tb-compact .toolbar { --tb-pad: 4px; --tb-pad-icon: 4px; --tb-gap: 1px; --tb-sep: 3px; --tb-zoom-w: 64px; --tb-name-w: 110px; --tb-zoom-min: 42px; }
body.tb-compact .toolbar .tb-lbl { display: none !important; }
/* …but the Xem toggles moved into the "Xem" menu keep their labels (icon-only rows would show
   six bare icons: three of them eye-like). */
body.tb-compact .toolbar .menu .tb-view-collapsed .tb-lbl { display: inline !important; }
body.tb-compact .toolbar .brand-name { display: none; }
body.tb-compact .toolbar .brand { margin-right: 2px; }
body.tb-compact .toolbar .tb-caret { display: none; }
body.tb-compact .toolbar .zoom-value { padding: 0 2px; }
body.tb-compact .toolbar [data-action="pageSize"] { width: 68px; padding: 0 2px; }
body.tb-compact .toolbar .lang-select { width: 46px; padding: 0 2px; }
body.tb-compact .toolbar .template-name { margin-right: 4px; }
/* compact row 1 (< 1500 px): the always-visible "Xem theo trang" button costs ~30 px, so the name may shrink a bit
   further before the Xem toggles have to collapse (fitToolbar treats a squeezed name as overflow) */
body.tb-compact .toolbar .template-name { max-width: 84px; }
.tb-caret { width: 10px !important; margin-left: -2px; opacity: 0.6; }
.tb-caret svg { width: 10px !important; height: 10px !important; }
.tb-zoom { display: inline-flex; align-items: center; gap: 2px; }
.tb-view-items { display: inline-flex; align-items: center; gap: 2px; }
.tb-zoom-slider {
  width: var(--tb-zoom-w, 84px); height: 16px; margin: 0 4px; padding: 0; background: transparent; accent-color: var(--accent); cursor: pointer; flex: none;
}
.tb-zoom-slider:focus-visible { outline: 2px solid var(--accent-soft); border-radius: 4px; }
/* Menu rows that are not buttons (label + select, e.g. "Bước lưới") */
.menu .menu-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 10px; font-size: 12.5px; }
.menu .menu-row .tb-select { height: 26px; }
/* Row-1 buttons moved into the "Xem" menu on narrow windows (main.js collapseViewGroup) */
.menu .tb-view-collapsed:empty { display: none; }
.menu .tb-view-collapsed .tb-btn { width: 100%; justify-content: flex-start; height: 30px; padding: 0 10px; border-radius: 4px; }
.menu .tb-view-collapsed .tb-lbl { display: inline !important; }
.menu .tb-view-collapsed .tb-btn[aria-pressed="true"]::after { content: "✓"; margin-left: auto; font-size: 11px; }
.menu .tb-view-collapsed + hr { margin-top: 4px; }
/* Canvas context menu (#canvas-menu): same look as the toolbar dropdowns */
.ctx-menu { min-width: 220px; }
.ctx-menu .menu-hint { max-width: 260px; }
/* Find bar slot above the layers list (findBar.js) */
.find-bar { flex: none; }
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; height: 24px; background: var(--border); margin: 0 6px; flex: none; }
.tb-spacer { flex: 1; }
.brand { gap: 6px; margin-right: 6px; }
.brand-mark { color: var(--accent); font-size: 16px; }
.brand-name { font-weight: 600; font-size: 13.5px; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 8px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  color: var(--text-2);
}
.tb-btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.tb-btn.active, .tb-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-2); border-color: transparent; }
.tb-btn.open { background: var(--panel-2); border-color: var(--border); }
.tb-btn.icon-only { padding: 0 6px; }
.tb-btn .ico { display: inline-flex; width: 16px; height: 16px; }
.tb-btn .ico svg { width: 16px; height: 16px; }
/* [token-attach] SPEC-TOKEN-ATTACH §2: the "Token dữ liệu" button carries the state of the company
   data token in `data-token-state` (main.js sets it). The dot is the indicator that survives
   `body.tb-compact` / narrow screens, where the label is hidden — a colour-only cue would vanish
   exactly when the toolbar is tightest, and this button is the one that says whether printing works.
   Border + text colour repeat the state for anyone who cannot tell the three dots apart. */
.tb-data-token { gap: 4px; }
.tb-data-token .dt-dot {
  display: inline-block !important; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); border: 1px solid rgba(0, 0, 0, 0.12); flex: 0 0 auto;
}
.tb-data-token[data-token-state="ok"] { color: var(--success); border-color: var(--success-soft); }
.tb-data-token[data-token-state="ok"] .dt-dot { background: var(--success); }
.tb-data-token[data-token-state="expired"] { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.tb-data-token[data-token-state="expired"] .dt-dot { background: var(--danger); }

/* The "Token dữ liệu" dialog (main.js openDataTokenDialog). `.dlg-*` comes from dialogs.js. */
.dlg-datatoken { width: min(560px, 94vw); }
.dlg-datatoken .dtok-input { width: 100%; min-height: 84px; resize: vertical; font-family: var(--font-mono); font-size: 12px; word-break: break-all; }
.dlg-datatoken .dtok-info { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 10px 0 0; font-size: 12.5px; }
.dlg-datatoken .dtok-info dt { color: var(--muted); }
.dlg-datatoken .dtok-info dd { margin: 0; }
.dlg-datatoken .dtok-state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.dlg-datatoken .dtok-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dlg-datatoken[data-token-state="ok"] .dtok-state { color: var(--success); }
.dlg-datatoken[data-token-state="ok"] .dtok-state::before { background: var(--success); }
.dlg-datatoken[data-token-state="expired"] .dtok-state { color: var(--danger); }
.dlg-datatoken[data-token-state="expired"] .dtok-state::before { background: var(--danger); }
.dlg-datatoken .dtok-status { margin: 8px 0 0; font-size: 12.5px; }
.dlg-datatoken .dtok-status.warn { color: var(--danger); }
.dlg-datatoken .dtok-status.ok { color: var(--success); }

.zoom-value { min-width: 52px; justify-content: center; font-variant-numeric: tabular-nums; }
.tb-select {
  height: 28px; padding: 0 6px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); color: var(--text-2);
}
.tb-select:focus { outline: none; border-color: var(--accent); }
.template-name { font-weight: 600; margin-right: 8px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.lang-select { width: 52px; }

/* The toolbar clips its overflow (horizontal scroll on narrow screens), so dropdown menus are
   positioned `fixed` from JS (openMenu in main.js) instead of absolutely inside the toolbar —
   otherwise they were cut off just below the toolbar edge. */
.tb-menu { position: relative; }
.menu {
  position: fixed; top: 0; left: 0; z-index: 500; max-height: calc(100vh - 60px); overflow-y: auto;
  min-width: 200px; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  white-space: nowrap;
}
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 10px; border: 0; background: transparent; border-radius: 4px; text-align: left; color: var(--text);
}
.menu button:hover { background: var(--panel-2); }
.menu button:disabled { opacity: 0.45; cursor: not-allowed; }
.menu button:disabled:hover { background: transparent; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu .ico { display: inline-flex; width: 16px; }
.menu-hint { margin: 4px 10px 6px; color: var(--muted); font-size: 11.5px; white-space: normal; max-width: 220px; }

/* ------------------------------------------------------------------ */
/* Side panels                                                         */
/* ------------------------------------------------------------------ */

.side { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.side-left { border-right: 1px solid var(--border); }
.side-right { border-left: 1px solid var(--border); }
.side-section { padding: 10px 10px 8px; border-bottom: 1px solid var(--border); }
.side-section.fill { flex: 1; min-height: 0; overflow: auto; border-bottom: 0; padding-top: 0; }
.side-section.fill .side-title { position: sticky; top: 0; z-index: 1; background: var(--panel); padding: 10px 0 6px; margin: 0 0 2px; }
.side-title { margin: 0 0 8px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; }
.side-title .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.side-hint { margin: 6px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.empty-state { padding: 14px 4px; }
.field-hint { grid-column: 1 / -1; margin: -2px 0 2px; }
.field-hint.warn { color: #92400e; background: var(--warning-soft); padding: 4px 6px; border-radius: var(--radius); }
select.warn { border-color: var(--warning); }

/* toolbox */
.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); color: var(--text-2);
  font-size: 10.5px; line-height: 1;
}
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover { border-color: var(--border-strong); color: var(--text); }
.tool-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }

/* layers */
.layer-list { list-style: none; margin: 0; padding: 0; }
.layer {
  display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 6px; border-radius: 4px; cursor: pointer;
  border: 1px solid transparent; position: relative;
}
.layer:hover { background: var(--panel-2); }
.layer.selected { background: var(--accent-soft); border-color: transparent; }
.layer.hidden-el .layer-name { opacity: 0.45; text-decoration: line-through; }
.layer.cond-hidden .layer-name { opacity: 0.6; font-style: italic; }
.layer.cond-hidden .layer-cond { display: inline-flex; color: var(--muted); margin-right: 2px; }
.layer.cond-hidden .layer-cond svg { width: 12px; height: 12px; }
.layer.locked .layer-name { color: var(--muted); }
.layer.dragging { opacity: 0.4; }
.layer.drop-before::before, .layer.drop-after::after { content: ""; position: absolute; left: 4px; right: 4px; height: 2px; background: var(--accent); }
.layer.drop-before::before { top: -1px; }
.layer.drop-after::after { bottom: -1px; }
.layer-icon { display: inline-flex; color: var(--muted); flex: none; }
.layer-icon svg { width: 16px; height: 16px; }
.layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.layer-actions { display: none; gap: 0; flex: none; }
/* Row action buttons: comfortably clickable (28×26 px, 16 px icons) */
.layer-actions { gap: 2px; }
.layer-actions .icon-btn { width: 26px; height: 26px; border-radius: 4px; }
.layer-actions .icon-btn:hover { background: rgba(37, 99, 235, 0.12); }
.layer-actions .icon-btn svg { width: 16px; height: 16px; }
.layer:hover .layer-actions, .layer.selected .layer-actions { display: inline-flex; }
.layer.locked .layer-actions { display: inline-flex; }
.layer.locked .layer-actions .icon-btn:not([data-act="lock"]) { display: none; }
.layer.locked:hover .layer-actions .icon-btn, .layer.locked.selected .layer-actions .icon-btn { display: inline-flex; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border: 0; background: transparent; border-radius: 4px; color: var(--muted);
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.06); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn svg { width: 14px; height: 14px; }

/* tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.tab { flex: 1; padding: 9px 4px; border: 0; background: transparent; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-2); border-bottom-color: var(--accent); background: var(--panel); }
.panel { flex: 1; min-height: 0; overflow: auto; padding: 0 0 20px; display: flex; flex-direction: column; }
.panel > .prop-section.fill { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.prop-section-body.fill { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.prop-section-body.fill .code-editor { flex: 1; min-height: 240px; }

/* ------------------------------------------------------------------ */
/* Forms (properties / page / data)                                    */
/* ------------------------------------------------------------------ */

.prop-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 4px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-2); font-size: 11.5px; font-weight: 600; }
.prop-section { border-bottom: 1px solid var(--border); }
.prop-section-title {
  margin: 0; padding: 8px 12px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none;
}
.prop-section-title:hover { color: var(--text); }
.prop-section-title .chev { width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform 0.15s; margin-right: 2px; }
.prop-section.collapsed .prop-section-title .chev { transform: rotate(-45deg); }
.prop-section.collapsed .prop-section-body { display: none; }
.prop-section-body { padding: 2px 12px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.field { display: flex; flex-direction: column; gap: 3px; grid-column: 1 / -1; min-width: 0; }
.field.half { grid-column: auto; }
.field > span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field.check { flex-direction: row; align-items: center; gap: 6px; padding: 4px 0; }
.field.check > span { color: var(--text); overflow: visible; white-space: normal; }
.field input[type="text"], .field input[type="number"], .field select, .field textarea, .dlg-input, .fmt-new-name, .sets-select {
  height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); min-width: 0; width: 100%;
}
.field textarea { height: auto; padding: 6px 8px; resize: vertical; line-height: 1.4; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus, .dlg-input:focus, .code-editor:focus, .fmt-new-name:focus, .sets-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field input[type="checkbox"] { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.mini { display: flex; flex-direction: column; gap: 2px; }
.mini > span { font-size: 10.5px; color: var(--muted); }
.mini input { height: 26px; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; width: 100%; }
.check-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.check-row .field.check { grid-column: auto; width: auto; }

.tgl-group { display: flex; gap: 4px; grid-column: 1 / -1; }
.tgl {
  min-width: 30px; height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); color: var(--text-2);
  font-weight: 600;
}
.tgl:hover { border-color: var(--border-strong); }
.tgl.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.tgl-b { font-weight: 700; }
.tgl-i { font-style: italic; font-family: Georgia, serif; }
.tgl-u { text-decoration: underline; }
.sides { display: flex; gap: 4px; }
.sides .tgl { flex: 1; font-weight: 500; font-size: 12px; }

.color-field { display: flex; align-items: center; gap: 4px; height: 28px; }
.color-field input[type="color"] { width: 32px; height: 28px; padding: 0 2px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); cursor: pointer; flex: none; }
.color-field.empty input[type="color"] { opacity: 0.35; }
.color-field .hex { flex: 1; height: 28px; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; font-family: var(--font-mono); font-size: 12px; min-width: 0; }
.color-field .icon-btn { flex: none; }

.image-field { display: flex; gap: 4px; align-items: center; }
.image-field input[type="text"] { flex: 1; height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; min-width: 0; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; padding: 0; }
.image-thumb { margin-top: 6px; max-width: 100%; max-height: 90px; border: 1px solid var(--border); border-radius: 4px; background: repeating-conic-gradient(#eee 0 25%, #fff 0 50%) 0 0 / 12px 12px; }

.substyle { grid-column: 1 / -1; margin: 0 0 4px; padding: 6px 8px 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.substyle legend { font-size: 11px; color: var(--muted); padding: 0 4px; }
.substyle .tgl-group { margin-bottom: 6px; }

.columns-editor { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; }
.col-card, .fmt-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px 8px; background: var(--panel-2); }
.col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.col-head strong { font-size: 12px; }
.col-actions { display: inline-flex; }
.fmt-card { margin-bottom: 6px; }
.fmt-card select { height: 26px; padding: 0 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); }

.btn {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border-strong); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: #fca5a5; }
/* Confirm dialogs mark the OK button both primary and danger (dialogs.js): a solid red button with
   white text — not red text on the blue primary background. */
.btn-primary.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-primary.btn-danger:hover:not(:disabled) { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-xs { height: 20px; padding: 0 4px; font-size: 11px; border-radius: 3px; }
.btn svg { width: 14px; height: 14px; }

.code-editor {
  width: 100%; min-height: 160px; padding: 8px; border: 1px solid var(--border); border-radius: 4px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.45; resize: vertical; tab-size: 2; white-space: pre; overflow: auto;
  background: #fbfbfc;
}
.code-editor.invalid { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.panel-status { min-height: 16px; margin: 6px 0; font-size: 12px; }
.panel-status.ok { color: var(--success); }
.panel-status.error { color: var(--danger); }
.panel-status.warning { color: var(--warning); background: var(--warning-soft); padding: 4px 6px; border-radius: var(--radius); line-height: 1.35; }
.problems h5 { margin: 8px 0 4px; font-size: 12px; }
.problem-list { margin: 0; padding-left: 16px; font-size: 12px; }
.problem-list li.err { color: var(--danger); }
.problem-list li.warn { color: var(--warning); }
.problem-list .mono { color: var(--text-2); }

/* field tree */
.tree { list-style: none; margin: 0; padding-left: 14px; }
.tree-root { padding-left: 0; }
.tree-row { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 4px; cursor: grab; font-size: 12px; }
.tree-row:hover { background: var(--accent-soft); }
.tree-toggle { width: 14px; height: 14px; border: 0; background: transparent; padding: 0; position: relative; flex: none; cursor: pointer; }
.tree-toggle.none { cursor: default; }
.tree-toggle:not(.none)::before { content: ""; position: absolute; left: 4px; top: 3px; width: 5px; height: 5px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); }
.tree-node.open > .tree-row .tree-toggle::before { transform: rotate(45deg); }
.tree-key { font-weight: 500; }
.tree-meta { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.tree-actions { display: inline-flex; gap: 2px; opacity: 0.55; }
.tree-row:hover .tree-actions { opacity: 1; }

/* ------------------------------------------------------------------ */
/* Canvas area                                                         */
/* ------------------------------------------------------------------ */

.canvas-area {
  display: grid; grid-template-columns: 22px minmax(0, 1fr); grid-template-rows: 22px minmax(0, 1fr);
  min-width: 0; min-height: 0; background: var(--bg); position: relative; overflow: hidden;
}
.canvas-area.no-rulers { grid-template-columns: 0 minmax(0, 1fr); grid-template-rows: 0 minmax(0, 1fr); }
.ruler-corner { background: var(--ruler-bg); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.ruler { display: block; background: var(--ruler-bg); max-width: 100%; max-height: 100%; }
.ruler-top { border-bottom: 1px solid var(--border); grid-column: 2; grid-row: 1; width: 100%; }
.ruler-left { border-right: 1px solid var(--border); grid-column: 1; grid-row: 2; height: 100%; }
/* min-width/height 0: a grid item defaults to min-content, which would let the page overflow the panels */
.viewport { grid-column: 2; grid-row: 2; overflow: auto; position: relative; outline: none; min-width: 0; min-height: 0; }
.viewport.pan-ready { cursor: grab; }
.viewport.panning { cursor: grabbing; }
.viewport.dragging { cursor: move; }
.canvas-inner { display: inline-block; min-width: 100%; padding: 32px 40px 60px; box-sizing: border-box; }
.page-wrap { position: relative; margin: 0 auto; }
.page-bg { position: absolute; left: 0; top: 0; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 6px 20px rgba(0, 0, 0, 0.12); }
.page-grid { position: absolute; inset: 0; pointer-events: none; }
.page-margin { position: absolute; border: 1px dashed var(--margin-line); pointer-events: none; }
.page-header-region, .page-footer-region { position: absolute; background: var(--region-tint); pointer-events: none; }
.page-header-region { border-bottom: 1px dashed var(--accent); }
.page-footer-region { border-top: 1px dashed var(--accent); }
.page { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.elements { position: absolute; inset: 0; }
.overlay { position: absolute; left: 0; top: 0; pointer-events: none; }
.overlay > div { position: absolute; inset: 0; }

/* Elements (WYSIWYG, unscaled 96dpi px inside the scaled page) */
.el { position: absolute; box-sizing: border-box; overflow: hidden; cursor: move; user-select: none; font-synthesis: none; }
.el.el-locked { cursor: default; }
.el.el-locked::after {
  content: ""; position: absolute; right: 1px; top: 1px; width: 11px; height: 11px; pointer-events: none; opacity: 0.75;
  background: rgba(255, 255, 255, 0.85) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round'%3E%3Crect x='3.5' y='7' width='9' height='7' rx='1'/%3E%3Cpath d='M5.5 7V5a2.5 2.5 0 015 0v2'/%3E%3C/svg%3E") center / 9px 9px no-repeat;
  border-radius: 2px;
}
/* visibleIf false with the sample data: not printed → dimmed (outline + badge live in .ov-cond, unscaled) */
.el.el-cond-hidden { opacity: 0.45 !important; }
.el-text { display: flex; flex-direction: column; }
.el-text-inner { width: 100%; word-wrap: break-word; overflow-wrap: break-word; min-height: 1em; }
.el-text-inner.editing { outline: none; user-select: text; cursor: text; caret-color: var(--accent); background: rgba(37, 99, 235, 0.06); }
.el-editing { overflow: visible; }
.el-image img { display: block; width: 100%; height: 100%; pointer-events: none; }
.el-image.img-broken img { opacity: 0.2; }
.img-placeholder { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: #9ca3af; background: repeating-linear-gradient(45deg, #f9fafb 0 8px, #f3f4f6 0 16px); border: 1px dashed #d1d5db; font-size: 11px; }
.img-placeholder svg { width: 22px; height: 22px; }
.el-checkbox { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.cb-box { display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box; background: transparent; }
.cb-box svg { width: 100%; height: 100%; }
.el-line { overflow: visible; }
.el-line svg { display: block; }
.el-qrcode svg { display: block; }
.el-table table { border-collapse: collapse; table-layout: fixed; width: 100%; }
.el-table th, .el-table td { overflow: hidden; word-wrap: break-word; }
.el-table td.ph { color: #6b7280; font-style: italic; }
.el-unknown { border: 1px dashed var(--danger); color: var(--danger); font-size: 10px; }

/* Selection overlay */
.sel-box { position: absolute; border: 1px solid var(--accent); pointer-events: none; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7) inset; }
.sel-box.sel-locked { border-style: dashed; border-color: var(--muted); }
.group-box { position: absolute; border: 1px dashed var(--accent); pointer-events: none; }
/* Condition-hidden marker (elements omitted by the layout engine because visibleIf is false) */
.cond-box { position: absolute; outline: 1px dashed var(--muted); outline-offset: 1px; pointer-events: none; box-sizing: border-box; background: repeating-linear-gradient(45deg, rgba(107, 114, 128, 0.08) 0 4px, transparent 4px 8px); }
.cond-badge { position: absolute; right: 0; top: 100%; display: inline-flex; align-items: center; gap: 3px; font: 10px/14px var(--font-ui); color: #fff; background: var(--muted); padding: 0 5px 0 3px; border-radius: 0 0 3px 3px; white-space: nowrap; pointer-events: none; }
.cond-badge svg { width: 11px; height: 11px; }
/* Page-flow overlay: where the layout engine really prints an element (page 1) */
.flow-box { position: absolute; border: 1px dashed var(--warning); background: rgba(217, 119, 6, 0.05); pointer-events: none; box-sizing: border-box; }
.flow-box.flow-push { border-style: dotted; border-color: rgba(217, 119, 6, 0.55); background: transparent; }
.flow-box.flow-page { border-style: dotted; background: repeating-linear-gradient(135deg, rgba(217, 119, 6, 0.08) 0 4px, transparent 4px 8px); }
.flow-tag { position: absolute; right: 0; top: 100%; font: 10px/14px var(--font-ui); color: #fff; background: var(--warning); padding: 0 4px; border-radius: 0 0 3px 3px; white-space: nowrap; }
.flow-box.flow-page .flow-tag { top: 0; }
.sel-handle {
  position: absolute; width: 9px; height: 9px; margin: -5px 0 0 -5px; background: #fff; border: 1.5px solid var(--accent); border-radius: 2px;
  pointer-events: auto; z-index: 2;
}
.sel-handle.h-n, .sel-handle.h-s { cursor: ns-resize; }
.sel-handle.h-e, .sel-handle.h-w { cursor: ew-resize; }
.sel-handle.h-ne, .sel-handle.h-sw { cursor: nesw-resize; }
.sel-handle.h-nw, .sel-handle.h-se { cursor: nwse-resize; }
.guide-v { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid #ec4899; }
.guide-h { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid #ec4899; }
.marquee { position: absolute; border: 1px solid var(--accent); background: rgba(37, 99, 235, 0.08); }
.create-box { position: absolute; border: 1px dashed var(--accent); background: rgba(37, 99, 235, 0.06); }

/* Print view (SPEC-DESIGNER-V2 §4.2, printView.js toggles body.print-view): the page as printed —
   no grid, rulers, margin / region lines, flow & condition overlays or lock badges; paper shadow.
   Selection boxes and handles stay so the page remains editable. */
body.print-view .canvas-area { grid-template-columns: 0 minmax(0, 1fr); grid-template-rows: 0 minmax(0, 1fr); background: #d9dce2; }
body.print-view .ruler, body.print-view .ruler-corner { display: none; }
body.print-view .page-grid, body.print-view .page-margin, body.print-view .page-header-region, body.print-view .page-footer-region { display: none; }
body.print-view .ov-flow, body.print-view .ov-cond, body.print-view .ov-guides { display: none; }
body.print-view .el.el-locked::after { display: none; }
body.print-view .el.el-cond-hidden { display: none; }
body.print-view .page-bg { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12), 0 12px 32px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.16); }

/* ------------------------------------------------------------------ */
/* Preview drawer                                                      */
/* ------------------------------------------------------------------ */

.drawer { display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--border); min-width: 0; min-height: 0; position: relative; }
.drawer-grip { position: absolute; left: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 3; }
.drawer-grip:hover, .drawer-grip.active { background: var(--accent-soft); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.drawer-head h3 { margin: 0; font-size: 13px; white-space: nowrap; }
.preview-frame { flex: 1; border: 0; width: 100%; background: #525659; }
.preview-status { padding: 6px 10px; font-size: 12px; background: var(--panel-2); border-bottom: 1px solid var(--border); }
.preview-status.error { color: var(--danger); background: var(--danger-soft); }
.preview-status.loading { color: var(--accent-2); }
.preview-status.warning { color: #92400e; background: var(--warning-soft); max-height: 40%; overflow: auto; }
.preview-warn-title { font-weight: 600; margin-bottom: 2px; }
.preview-warn-list { margin: 0; padding-left: 16px; }
.preview-warn-list li { margin: 1px 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-2); text-decoration: underline; cursor: pointer; font: inherit; }

/* ------------------------------------------------------------------ */
/* Status bar                                                          */
/* ------------------------------------------------------------------ */

.statusbar {
  height: var(--status-h); display: flex; align-items: center; gap: 18px; padding: 0 12px;
  background: var(--panel); border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-2);
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden;
}
.status-item { min-width: 0; }
.status-spacer { flex: 1; }

/* ------------------------------------------------------------------ */
/* Toasts                                                              */
/* ------------------------------------------------------------------ */

.toasts { position: fixed; right: 16px; bottom: 36px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; max-width: 380px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out; font-size: 12.5px; flex-wrap: wrap;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-msg { flex: 1; min-width: 0; line-height: 1.4; word-break: break-word; }
.toast-actions { display: flex; gap: 6px; width: 100%; justify-content: flex-end; }
.toast-close { border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 2px; }
.toast-out { opacity: 0; transform: translateX(10px); transition: all 0.18s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ */
/* Dialogs                                                             */
/* ------------------------------------------------------------------ */

.dlg { border: 0; border-radius: 8px; padding: 0; width: 420px; max-width: calc(100vw - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); color: var(--text); }
.dlg::backdrop { background: rgba(17, 24, 39, 0.4); }
.dlg-form { display: flex; flex-direction: column; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dlg-head h3 { margin: 0; font-size: 14px; }
.dlg-body { padding: 14px 16px; max-height: 60vh; overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--panel-2); }
.dlg-msg { margin: 0; line-height: 1.5; }
.dlg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dlg-row { display: flex; align-items: center; gap: 4px; }
.dlg-row-main { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); text-align: left; }
.dlg-row-main:hover { background: var(--accent-soft); border-color: var(--accent); }
.dlg-row-title { font-weight: 600; }
.dlg-row-sub { font-size: 11.5px; color: var(--muted); }

/* [open-tabs] "Mở mẫu": tab phạm vi (mẫu của trạm / dùng chung) + ô tìm kiếm */
.dlg-row[hidden] { display: none; } /* .dlg-row is a flex row: `hidden` alone would not hide it */
.dlg-list-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.dlg-tabs { display: flex; gap: 4px; }
.dlg-tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--panel-2); color: var(--text-2, var(--muted)); font-size: 12px; cursor: pointer;
}
.dlg-tab:hover { border-color: var(--accent); }
.dlg-tab.active { background: var(--accent-soft); border-color: var(--accent); color: inherit; font-weight: 600; }
.dlg-tab-n { font-size: 11px; padding: 0 5px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); font-variant-numeric: tabular-nums; font-weight: 400; }
.dlg-search { flex: 1; min-width: 160px; padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: inherit; font-size: 12px; }
.dlg-row-badge { font-size: 10.5px; font-weight: 400; padding: 0 5px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.dlg-nomatch { margin: 10px 2px 0; }

/* [copy-id] nút chép mã báo cáo trên mỗi hàng của hộp thoại "Mở mẫu" */
.dlg-row-copy { font-size: 13px; line-height: 1; }
.dlg-row-copy.ok { color: var(--ok, #16a34a); border-color: var(--ok, #16a34a); }
.dlg-row-id {
  font-family: var(--font-mono); font-size: 11px; padding: 0 4px; border-radius: 4px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-2, var(--muted));
  user-select: all; /* one click selects the whole id for a manual copy */
}

/* "Kết nối máy chủ" dialog (auth.js) */
.dlg-connect { width: 460px; }
.connect-form { display: flex; flex-direction: column; gap: 10px; }
.connect-form .field > span { white-space: normal; }
.connect-form textarea.dlg-input { height: auto; min-height: 64px; padding: 6px 8px; resize: vertical; font-family: var(--font-mono); font-size: 12px; line-height: 1.4; word-break: break-all; }
.connect-status { margin: 0; font-size: 12px; line-height: 1.4; }
.connect-status.warn { color: #92400e; background: var(--warning-soft); padding: 4px 6px; border-radius: var(--radius); }

/* ETag conflict modal (main.js): three buttons, none is the default so Enter never overwrites */
.dlg-conflict .dlg-foot { flex-wrap: wrap; }

/* Page tab › "Nguồn dữ liệu" JSON textareas */
.ds-json { font-family: var(--font-mono); font-size: 11.5px; }

/* Import from Excel modal (importDialog.js) — same .dlg chrome, own body layout */
.dlg-import { width: 480px; }
.dlg-import.busy .dlg-body { opacity: 0.7; }
.import-form { display: flex; flex-direction: column; gap: 10px; }
.import-form .field { gap: 4px; }
.import-form .field > span { white-space: normal; }
.import-file { word-break: break-word; }
.import-options { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px 8px; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.import-options legend { font-size: 11px; color: var(--muted); padding: 0 4px; }
.import-options .field.check { padding: 3px 0 0; }
.import-options .field-hint { margin: 0 0 4px 20px; font-size: 11px; }
.import-status { margin: 0; min-height: 1.2em; font-size: 12px; }
.import-status:empty { display: none; }
.import-result { display: flex; flex-direction: column; gap: 10px; }
.import-warnings { border: 1px solid #fcd34d; background: var(--warning-soft); border-radius: var(--radius); padding: 6px 10px; }
.import-warnings summary { cursor: pointer; font-weight: 600; color: #92400e; }
.import-warn-list { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; line-height: 1.4; }
.import-warn-code { font-family: var(--font-mono); font-size: 11px; color: #92400e; background: rgba(255, 255, 255, 0.6); border-radius: 3px; padding: 0 4px; margin-right: 2px; }
.import-no-warnings { color: var(--success); }
/* "Cần xử lý" callout: action-required import warnings (unbound table, overflow …) sit above the informational list */
.import-action { border: 1px solid #f87171; border-left-width: 4px; background: var(--danger-soft); border-radius: var(--radius); padding: 8px 10px; }
.import-action-title { margin: 0; font-weight: 700; color: #7f1d1d; }
.import-action-list { padding-left: 18px; }
.import-action-list .import-warn-item { font-weight: 600; color: #7f1d1d; }
.import-action-list .import-warn-code { color: #7f1d1d; }
.import-action-hint { margin: 6px 0 0; font-size: 11.5px; color: #7f1d1d; font-weight: 400; }
.import-cell { font-weight: 700; font-family: var(--font-mono); }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

/* Row-1 labels (.tb-lbl): every button has an icon + title, so labels are progressive —
   tier A (Chèn, Nhóm, Xem trước, Kiểm tra) from 1500 px, tier B (file / edit / export buttons)
   from 2560 px, the view toggles from 3000 px; everything is icon-only below 1500 px
   (SPEC-DESIGNER-V2 §0) or when main.js sets body.tb-compact because the row would overflow. */
.toolbar .tb-lbl { display: none; }
.toolbar [data-menu="insert"] .tb-lbl, .toolbar [data-action="group:make"] .tb-lbl, .toolbar [data-action="preview"] .tb-lbl, .toolbar [data-action="check:open"] .tb-lbl { display: inline; }
@media (min-width: 2560px) {
  .toolbar [data-group="file"] .tb-lbl, .toolbar [data-group="edit"] .tb-lbl, .toolbar [data-group="export"] .tb-lbl, .toolbar [data-action="printView:toggle"] .tb-lbl { display: inline; }
}
@media (min-width: 3000px) {
  .toolbar .tb-view-items .tb-lbl { display: inline; }
}
@media (max-width: 1500px) {
  .toolbar { --tb-pad: 4px; --tb-pad-icon: 4px; --tb-gap: 1px; --tb-sep: 3px; --tb-zoom-w: 64px; --tb-name-w: 84px; --tb-zoom-min: 42px; }
  .toolbar .tb-lbl { display: none !important; }
  .toolbar .menu .tb-view-collapsed .tb-lbl { display: inline !important; }
  .toolbar .brand-name { display: none; }
  .toolbar .brand { margin-right: 2px; }
  .toolbar .tb-caret { display: none; }
  .toolbar .zoom-value { padding: 0 2px; }
  .toolbar .tb-zoom-slider { margin: 0 2px; }
  .toolbar [data-action="pageSize"] { width: 68px; padding: 0 2px; }
  .toolbar .lang-select { width: 46px; padding: 0 2px; }
  .toolbar .template-name { margin-right: 4px; }
  /* Preview on a laptop-sized window: the four-column layout would squeeze the canvas to
     ~280 px (page at 27 %). Collapse the toolbox/layers column while the drawer is open and
     size the drawer so the canvas keeps at least 440 px (page stays readable & editable;
     tool hotkeys T/I/B/C/L/R/Q still insert elements). */
  :root { --canvas-min-preview: 440px; --drawer-reserve: calc(var(--right-w) + var(--canvas-min-preview)); --drawer-w: min(clamp(320px, 40vw, 960px), calc(100vw - var(--drawer-reserve))); }
  body.preview-open .side-left { display: none; }
  body.preview-open .workspace { grid-template-columns: minmax(0, 1fr) var(--right-w) var(--drawer-w); }
}
@media (max-width: 1320px) {
  .toolbar { gap: 2px; padding: 0 6px; --tb-name-w: 100px; }
}
/* Overflow guard (main.js fitToolbar): compact = no labels; collapse-view = the Xem toggles live
   in the "Xem" menu (always below 1200 px, SPEC-DESIGNER-V2 §0) */
body.tb-compact .toolbar .tb-lbl { display: none !important; }
body.tb-compact .toolbar .menu .tb-view-collapsed .tb-lbl { display: inline !important; }
body.tb-compact .toolbar .brand-name { display: none; }
body.tb-collapse-view .toolbar .tb-zoom-slider { display: none; }
body.tb-collapse-view .toolbar .template-name { max-width: 90px; }
@media (max-width: 1100px) {
  :root { --left-w: 220px; --right-w: 280px; } /* 220 = the left minimum of panelResize.js (keyboard / ARIA contract) */
  .tb-btn > span:not(.ico) { display: none; }
  .toolbar .menu .tb-view-collapsed .tb-btn > .tb-lbl { display: inline !important; }
  .tb-btn { padding: 0 5px; }
  .brand-name { display: none; }
  .toolbar .tb-zoom-slider { display: none; }
  .toolbar { --tb-name-w: 90px; }
}
@media (max-width: 1000px) {
  body.preview-open .side-left { display: flex; }
  body.preview-open .workspace { grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w); }
  body.preview-open .drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(90vw, 720px); z-index: 40; box-shadow: var(--shadow); }
}
@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .side-left { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); max-height: 140px; }
  .side-left .side-section { flex: 1; overflow: auto; }
  .side-right { max-height: 40vh; border-left: 0; border-top: 1px solid var(--border); }
  body.preview-open .workspace { grid-template-columns: 1fr; }
  .drawer { position: fixed; inset: calc(var(--toolbar-h) + var(--fmtbar-h)) 0 var(--status-h) 0; z-index: 40; }
}
