/* Create Card — nền giao diện chung (màu, chữ, nút, ô nhập, hộp thoại, bảng chọn) + bố cục trình thiết kế.
   Mọi trang (màn hình chính, trình thiết kế, đăng nhập, quản trị) dùng chung các biến màu dưới đây.
   Nguyên tắc: một màu nhấn duy nhất (--primary) cho hành động chính và trạng thái đang chọn; còn lại là các lớp xám xanh. */
:root {
  --bg: #0E1218; --canvas-outer: #090C11; --rail: #121720; --drawer: #151B24; --header: #19202B; --group: #19202B;
  --input: #1D2531; --hover: #273142; --line: #242D3A; --control: #344154; --line-soft: #1F2733;
  --fg: #ECEFF4; --fg2: #BAC3CF; --muted: #8492A4; --title: #9DBAFF;
  --primary: #3C6DF0; --primary-hover: #5380FF; --focus: #6F98FF;
  --ok: #3DD68C; --ok-bg: #0F2E22; --ok-solid: #1FA765; --warn: #F2B544; --warn-bg: #2E2410; --bad: #FF7A7A; --bad-bg: #3A1518; --bad-solid: #E5484D;
  --toggle: #3C6DF0; --toggle-bd: #6F98FF; --star: #F5B301;
  --sel: #4C82FF; --guide: #F43F5E; --handle-fill: #FFFFFF; --grid: rgba(120, 136, 160, .30);
  --ruler: #121720; --ruler-fg: #8492A4;
  --shadow: 0 12px 32px rgba(0,0,0,.5); --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  --tint: color-mix(in srgb, var(--primary) 18%, transparent);
  --r: 8px; --r-sm: 6px; --r-lg: 12px;
  --font-ui: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F2F4F7; --canvas-outer: #E3E7ED; --rail: #FFFFFF; --drawer: #FFFFFF; --header: #F6F7F9; --group: #F6F7F9;
    --input: #FFFFFF; --hover: #ECEFF4; --line: #DCE1E8; --control: #C6CDD8; --line-soft: #E8EBF0;
    --fg: #131A26; --fg2: #3B4657; --muted: #677384; --title: #1A3A94;
    --primary: #1C40A6; --primary-hover: #2450C4; --focus: #2F62E8;
    --ok: #0E8A5F; --ok-bg: #E8F7F0; --ok-solid: #15996A; --warn: #A8650A; --warn-bg: #FDF3DC; --bad: #D0342C; --bad-bg: #FDECEB; --bad-solid: #D93F38;
    --toggle: #1C40A6; --toggle-bd: #2F62E8; --star: #E5A100;
    --sel: #2563EB; --guide: #E11D48; --handle-fill: #FFFFFF; --grid: rgba(100, 116, 139, .30);
    --ruler: #F6F7F9; --ruler-fg: #5A6677; --shadow: 0 10px 28px rgba(19,26,38,.16); --shadow-sm: 0 1px 2px rgba(19,26,38,.08);
    --tint: color-mix(in srgb, var(--primary) 10%, transparent);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F2F4F7; --canvas-outer: #E3E7ED; --rail: #FFFFFF; --drawer: #FFFFFF; --header: #F6F7F9; --group: #F6F7F9;
  --input: #FFFFFF; --hover: #ECEFF4; --line: #DCE1E8; --control: #C6CDD8; --line-soft: #E8EBF0;
  --fg: #131A26; --fg2: #3B4657; --muted: #677384; --title: #1A3A94;
  --primary: #1C40A6; --primary-hover: #2450C4; --focus: #2F62E8;
  --ok: #0E8A5F; --ok-bg: #E8F7F0; --ok-solid: #15996A; --warn: #A8650A; --warn-bg: #FDF3DC; --bad: #D0342C; --bad-bg: #FDECEB; --bad-solid: #D93F38;
  --toggle: #1C40A6; --toggle-bd: #2F62E8; --star: #E5A100;
  --sel: #2563EB; --guide: #E11D48; --handle-fill: #FFFFFF; --grid: rgba(100, 116, 139, .30);
  --ruler: #F6F7F9; --ruler-fg: #5A6677; --shadow: 0 10px 28px rgba(19,26,38,.16); --shadow-sm: 0 1px 2px rgba(19,26,38,.08);
  --tint: color-mix(in srgb, var(--primary) 10%, transparent);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 13px/1.4 var(--font-ui); overflow: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
::selection { background: color-mix(in srgb, var(--primary) 45%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--control) transparent; }
.ccd { height: 100%; display: flex; flex-direction: column; padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px); }

/* biểu tượng (js/icons.js) */
.ic { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.22em; pointer-events: none; }
.ic.green { color: var(--ok); } .ic.amber { color: var(--warn); } .ic.blue { color: var(--focus); } .ic.red { color: var(--bad); } .ic.star { color: var(--star); } .ic.dim { color: var(--muted); }

/* nút chung */
button { cursor: pointer; background: var(--input); border: 1px solid var(--control); border-radius: var(--r-sm); padding: 5px 11px; color: var(--fg); white-space: nowrap; transition: background-color .12s, border-color .12s, color .12s; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary, .btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.success { background: var(--ok-solid); border-color: var(--ok-solid); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, var(--control)); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--bad-bg); }
button.danger-text { color: var(--bad); }
button.active, button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--fg2); }
button.ghost:hover:not(:disabled) { background: var(--hover); color: var(--fg); }
button.link { background: none; border: none; padding: 0 2px; color: var(--title); font-weight: 600; font-size: 12px; height: auto; min-height: 0; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
.ico { display: inline-block; min-width: 1.1em; text-align: center; }
.ico.blue { color: var(--focus); } .ico.amber { color: var(--warn); }
input[type="text"], input[type="number"], input[type="search"], input[type="url"], select, textarea {
  background: var(--input); border: 1px solid var(--control); border-radius: var(--r-sm); padding: 5px 8px; width: 100%; min-width: 0; color: var(--fg);
  transition: border-color .12s, box-shadow .12s;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="search"]:focus, input[type="url"]:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 15px; height: 15px; margin: 0; flex: none; }
input[type="color"] { width: 34px; height: 28px; padding: 1px; border: 1px solid var(--control); border-radius: var(--r-sm); background: var(--input); cursor: pointer; }
textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 11.5px; margin: 0; }

/* thanh công cụ trên (trình thiết kế) */
.topbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--rail); border-bottom: 1px solid var(--line); min-height: 46px; overflow-x: auto; scrollbar-width: none; }
.tb-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tb-group.right { margin-left: auto; gap: 4px; }
.tb { padding: 5px 9px; background: transparent; border-color: transparent; color: var(--fg2); min-height: 32px; }
.tb:hover:not(:disabled) { color: var(--fg); }
.tb.icon { width: 32px; padding: 5px 0; font-size: 15px; line-height: 1; }
.tb.zoom { min-width: 54px; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tb.boxed { border-color: var(--control); color: var(--fg); background: var(--input); }
.tb.primary { background: var(--primary); color: #fff; border-color: var(--primary); padding: 5px 14px; }
.tb.toggle.on { background: var(--tint); border-color: transparent; color: var(--title); }
.tb.success { background: var(--ok-solid); border-color: var(--ok-solid); color: #fff; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; flex: none; }
.tb-name { display: flex; align-items: center; gap: 6px; flex: 1 1 160px; min-width: 120px; max-width: 340px; margin-left: 6px; }
.tb-name input { background: transparent; border-color: transparent; font-weight: 600; color: var(--fg); font-size: 13.5px; }
.tb-name input:hover, .tb-name input:focus { border-color: var(--control); background: var(--input); }
.dirty { color: var(--warn); font-size: 12px; }

/* khung làm việc */
.workspace { flex: 1; min-height: 0; display: flex; position: relative; }
.rail { width: 48px; flex: none; background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 8px; }
.rail-btn { width: 36px; height: 36px; padding: 0; font-size: 17px; background: transparent; border-color: transparent; color: var(--muted); border-radius: var(--r); }
.rail-btn.active { background: var(--tint); color: var(--title); }
.drawer { width: 300px; flex: none; background: var(--drawer); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.drawer.floating { position: absolute; left: 48px; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow); }
.drawer.collapsed { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 14px; height: 42px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.pin { width: 30px; height: 28px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); }
.pin.on { background: var(--tint); color: var(--title); }
.drawer-body { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
fieldset.group { border: none; border-radius: 0; background: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
fieldset.group > legend { color: var(--muted); font-weight: 600; padding: 0; margin-bottom: 0; font-size: 11.5px; letter-spacing: .02em; float: left; width: 100%; }
fieldset.group > legend + * { clear: both; }
.props-body > fieldset.group + fieldset.group, .drawer-body > fieldset.group + fieldset.group { border-top: 1px solid var(--line-soft); padding-top: 12px; }
.modal-body fieldset.group { border: 1px solid var(--line-soft); border-radius: var(--r); background: var(--group); padding: 10px 12px 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid2 > button, .grid3 > button { text-align: center; overflow: hidden; text-overflow: ellipsis; }
.add-grid > button { text-align: left; padding: 7px 10px; }
.add-grid > button .ic { margin-right: 4px; color: var(--title); }
.iconrow { display: flex; gap: 4px; }
.iconrow > button { flex: 1 1 0; padding: 0; height: 32px; min-width: 0; font-size: 14px; }
.iconrow > button.danger-text:hover:not(:disabled) { background: var(--bad-bg); }
details.keys-box > summary { cursor: pointer; color: var(--muted); font-size: 11.5px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; }
details.keys-box > summary::-webkit-details-marker { display: none; }
details.keys-box > summary::before { content: "›"; display: inline-block; transition: transform .12s; font-size: 14px; }
details.keys-box[open] > summary::before { transform: rotate(90deg); }
details.keys-box > dl { margin-top: 8px; }
.wide { width: 100%; }
dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 12px; }
dl.keys dt { color: var(--fg2); font-weight: 600; } dl.keys dd { margin: 0; color: var(--muted); }
.layer-title { color: var(--muted); font-weight: 600; font-size: 11.5px; }
.layers { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line-soft); border-radius: var(--r); flex: 1; min-height: 160px; overflow: auto; background: var(--group); }
.layers li { display: grid; grid-template-columns: 26px 26px 1fr auto; align-items: center; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line-soft); cursor: pointer; font-size: 12.5px; }
.layers li:last-child { border-bottom: none; }
.layers li.sel { background: var(--tint); box-shadow: inset 2px 0 0 var(--focus); }
.layers li.hiddenobj .lname { opacity: .45; text-decoration: line-through; }
.layers li .lname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers li .z { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.layers li button { padding: 0; width: 24px; height: 22px; background: transparent; border-color: transparent; font-size: 12px; }
.layers li.drag-over { box-shadow: inset 0 2px 0 var(--focus); }
.layer-actions { margin-top: 2px; }

/* vùng vẽ */
.stage { flex: 1; min-width: 0; position: relative; background: var(--canvas-outer); display: grid; grid-template-columns: 22px 1fr; grid-template-rows: 22px 1fr; }
.ruler-corner { grid-row: 1; grid-column: 1; background: var(--ruler); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 9px; color: var(--ruler-fg); display: grid; place-items: center; }
.ruler-x { grid-row: 1; grid-column: 2; width: 100%; height: 22px; display: block; }
.ruler-y { grid-row: 2; grid-column: 1; width: 22px; height: 100%; display: block; }
.viewport { grid-row: 2; grid-column: 2; position: relative; overflow: hidden; outline: none; cursor: default; }
.viewport canvas { position: absolute; inset: 0; display: block; touch-action: none; }
.viewport.panning, .viewport.space { cursor: grab; }
.inline-editor { position: absolute; z-index: 5; margin: 0; padding: 0; border: 1px dashed var(--sel); background: rgba(255,255,255,.92); color: #000; resize: none; overflow: hidden; line-height: 1.1; transform-origin: 0 0; }
.cropbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; gap: 6px; align-items: center; padding: 6px 8px; background: var(--drawer); border: 1px solid var(--focus); border-radius: var(--r-lg); box-shadow: var(--shadow); flex-wrap: wrap; max-width: calc(100% - 20px); }
.cropbar .crop-title { color: var(--title); font-weight: 700; font-size: 12px; padding: 0 4px; }
.cropbar .ok { background: var(--primary); border-color: var(--primary); color: #fff; }
.cropbar .cancel { background: transparent; border-color: var(--control); color: var(--fg2); }

/* bảng thuộc tính */
.props { width: 372px; flex: none; background: var(--drawer); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.props-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 14px; height: 42px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13px; }
.x { width: 28px; height: 28px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); }
.props-body { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.row > label { flex: none; color: var(--fg2); font-size: 12px; min-width: 72px; }
.row > .grow { flex: 1; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.xywh { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 8px; align-items: center; }
.xywh label { font-weight: 600; color: var(--muted); }
.unit { position: relative; }
.unit input { padding-right: 34px; }
.unit::after { content: attr(data-unit); position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 11px; pointer-events: none; }
.btnrow { display: flex; gap: 4px; flex-wrap: wrap; }
.btnrow button { padding: 4px 8px; }
.btnrow button.sq { width: 30px; padding: 4px 0; font-weight: 700; }
.seg { display: inline-flex; border: 1px solid var(--control); border-radius: var(--r-sm); overflow: hidden; background: var(--input); }
.seg button { border: none; border-radius: 0; background: transparent; padding: 4px 10px; color: var(--fg2); }
.seg button + button { border-left: 1px solid var(--control); }
.seg button.on { background: var(--primary); color: #fff; }
.vis-row { display: flex; align-items: center; gap: 10px; }
.vis-btn { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--control)); background: var(--ok-bg); font-weight: 600; }
.vis-btn.off { color: var(--muted); border-color: var(--control); background: var(--input); }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: var(--fg2); }
.field-btn { background: var(--tint); border-color: transparent; color: var(--title); font-weight: 600; padding: 3px 10px; }
.card-info { color: var(--fg); font-weight: 600; }
.radii { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.radii label { font-size: 10.5px; color: var(--muted); text-align: center; display: block; }
.qr-preview { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--ok); background: var(--input); border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 6px 8px; white-space: pre-wrap; word-break: break-all; max-height: 80px; overflow: auto; }

/* thanh trạng thái */
.statusbar { display: flex; gap: 10px; align-items: center; padding: 4px 12px; padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px)); background: var(--rail); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); min-height: 28px; }
.msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.statusbar .msg { flex: 1; }
.msg.ok { color: var(--ok); } .msg.bad { color: var(--bad); }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; white-space: nowrap; }
.coord { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* menu */
.menu { position: fixed; z-index: 100; min-width: 220px; background: var(--drawer); border: 1px solid var(--line); border-radius: var(--r); padding: 4px; box-shadow: var(--shadow); }
.menu button { display: flex; width: 100%; gap: 8px; text-align: left; border: none; background: transparent; padding: 7px 12px 7px 10px; border-radius: 5px; font-size: 12.5px; }
.menu button:hover:not(:disabled) { background: var(--hover); }
.menu hr { border: none; border-top: 1px solid var(--line-soft); margin: 4px 6px; }

/* hộp thoại */
.modal-back { position: fixed; inset: 0; z-index: 90; background: rgba(4, 8, 16, .58); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); animation: cc-fade .12s ease-out; }
.modal { position: relative; background: var(--drawer); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); width: min(880px, 100%); max-height: 100%; display: flex; flex-direction: column; min-height: 0; animation: cc-pop .14s ease-out; }
.modal.sm { width: min(500px, 100%); }
.modal.lg { width: min(1040px, 100%); height: min(760px, 100%); }
.modal-head { padding: 16px 52px 8px 20px; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 700; color: var(--fg); text-wrap: balance; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.modal-x { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; padding: 0; background: transparent; border-color: transparent; color: var(--muted); display: grid; place-items: center; }
.modal-body { padding: 10px 20px 14px; overflow: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; flex: 1 1 auto; }
.modal-foot { padding: 12px 20px; display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line-soft); }
.modal-foot > button { min-height: 32px; padding-left: 14px; padding-right: 14px; }
.modal-foot .left { margin-right: auto; color: var(--muted); font-size: 12px; }
@keyframes cc-fade { from { opacity: 0; } }
@keyframes cc-pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r); max-height: 52vh; background: var(--drawer); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.tbl th { position: sticky; top: 0; background: var(--header); color: var(--muted); font-weight: 600; font-size: 12px; text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); z-index: 1; }
table.tbl td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.pick { cursor: pointer; }
table.tbl tr.pick:hover td { background: var(--hover); }
table.tbl tr.on td { background: var(--tint); }
.tag { font-family: ui-monospace, Consolas, monospace; color: var(--title); font-weight: 600; }
.sample { color: var(--muted); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-ok { color: var(--ok); font-weight: 600; } .st-warn { color: var(--warn); font-weight: 600; } .st-bad { color: var(--bad); font-weight: 600; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; align-content: start; }
.tile { position: relative; border: 1px solid var(--line); border-radius: 10px; background: var(--group); padding: 8px 8px 10px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; text-align: left; white-space: normal; }
.tile:hover { border-color: var(--control); background: var(--group); }
.tile.on, .tile.on:hover { border-color: var(--focus); box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 45%, transparent); background: var(--group); }
.tile .thumb { height: 118px; display: grid; place-items: center; background: var(--canvas-outer); border-radius: 7px; margin-bottom: 5px; }
.tile .thumb canvas { max-width: 100%; max-height: 108px; box-shadow: 0 2px 8px rgba(0,0,0,.28); border-radius: 2px; }
.tile b { font-size: 12.5px; font-weight: 600; color: var(--fg); line-height: 1.3; }
.tile small { color: var(--muted); font-size: 11px; }
.banner { border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent); background: var(--ok-bg); color: var(--ok); border-radius: var(--r); padding: 8px 12px; font-size: 12px; }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: var(--warn-bg); color: var(--warn); }
.pv-stage { background: var(--canvas-outer); border-radius: var(--r); padding: 18px; display: grid; place-items: center; min-height: 260px; }
.pv-stage canvas { max-width: 100%; height: auto; box-shadow: var(--shadow); }
.bg-prev { background: var(--canvas-outer); border: 1px dashed var(--control); border-radius: var(--r); padding: 12px; display: grid; place-items: center; }
.bg-prev canvas { max-width: 100%; max-height: 260px; box-shadow: var(--shadow); }
.size-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.size-list button { text-align: left; white-space: normal; font-size: 12px; }
.size-list button small { display: block; color: var(--muted); font-variant-numeric: tabular-nums; }

/* hẹp: ngăn kéo và bảng thuộc tính nổi trên vùng vẽ */
@media (max-width: 1100px) {
  .props { position: absolute; right: 0; top: 0; bottom: 0; z-index: 25; box-shadow: var(--shadow); width: min(372px, calc(100% - 48px)); }
  .drawer { position: absolute; left: 48px; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow); width: min(300px, calc(100% - 48px)); }
  .tb-name { display: none; }
  .tb .lbl { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* điện thoại: thanh công cụ xuống hàng thay vì bị cắt; bảng nổi chiếm gần hết bề ngang */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; overflow: visible; gap: 6px; row-gap: 6px; padding: 6px 8px; }
  .topbar .sep { display: none; }
  .tb-group { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; gap: 4px; }
  .tb-group.right { margin-left: 0; flex: 1 1 100%; }
  .tb { min-height: 36px; padding: 4px 9px; font-size: 13px; }
  .tb.icon { width: 36px; }
  .tb.zoom { min-width: 52px; }
  .rail { width: 44px; }
  .rail-btn { width: 36px; height: 40px; }
  .props { width: 100%; }
  .drawer { left: 44px; width: calc(100% - 44px); }
  .statusbar { flex-wrap: wrap; row-gap: 2px; }
  .statusbar .msg { flex-basis: 100%; white-space: normal; }
  .iconrow > button { height: 40px; }
}

/* ───────── bảng lựa chọn dùng chung (js/filechooser.js): nơi lấy / nơi lưu file, danh sách mẫu, menu thao tác ───────── */
.fc-back { position: fixed; inset: 0; z-index: 140; background: transparent; }
.fc-back.dim { background: rgba(4, 8, 16, .5); }
.fc-pop { position: fixed; z-index: 141; width: 340px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto; background: var(--drawer); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 6px; font-family: var(--font-ui); animation: cc-pop .12s ease-out; }
.fc-pop.sheet { left: 0 !important; right: 0; bottom: 0; top: auto !important; width: auto !important; max-width: none; max-height: 85vh; border-radius: 16px 16px 0 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
.fc-title { font-weight: 700; font-size: 13px; padding: 6px 8px 6px; color: var(--fg); overflow-wrap: anywhere; }
.fc-glabel { font-size: 11px; font-weight: 600; color: var(--muted); padding: 9px 8px 4px; letter-spacing: .02em; }
.fc-glabel:empty { display: none; }
.fc-group { display: flex; flex-direction: column; gap: 1px; }
.fc-group + .fc-group { border-top: 1px solid var(--line-soft); margin-top: 4px; padding-top: 4px; }
.fc-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: transparent; color: var(--fg); padding: 6px 8px; border-radius: 7px; cursor: pointer; min-height: 40px; }
.fc-item:hover:not(:disabled), .fc-item:focus-visible { background: var(--hover); outline: none; }
.fc-item.on { background: var(--tint); }
.fc-item.on .fc-tx b { color: var(--title); }
.fc-item.danger .fc-tx b, .fc-item.danger .fc-ic { color: var(--bad); }
.fc-item[hidden], .fc-group[hidden], .fc-glabel[hidden] { display: none; }
.fc-item:disabled { opacity: .45; cursor: default; }
.fc-ic { flex: 0 0 28px; height: 28px; display: grid; place-items: center; font-size: 15px; border-radius: 7px; background: var(--input); color: var(--fg2); }
.fc-tx { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.fc-tx b { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-tx small { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-sbox { padding: 2px 2px 6px; }
.fc-pop.compact .fc-item { min-height: 32px; padding: 4px 8px; gap: 8px; }
.fc-pop.compact .fc-ic { flex: 0 0 16px; width: 16px; height: auto; background: none; font-size: 13px; border-radius: 0; }
.fc-pop.compact .fc-tx b { font-weight: 500; }
.fc-pop.compact .fc-glabel { padding: 8px 8px 3px; }
.fc-item.add .fc-tx b { font-weight: 700; color: var(--title); }
.fc-link { display: flex; gap: 6px; padding: 0 4px 2px; }
.fc-in { flex: 1 1 auto; min-width: 0; height: 34px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid var(--control); background: var(--input); color: var(--fg); font: inherit; font-size: 13px; }
.fc-in:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.fc-hint { margin: 6px 6px 4px; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
@media (max-width: 700px) { .fc-item { min-height: 48px; } .fc-pop.compact .fc-item { min-height: 42px; } .fc-in { height: 42px; font-size: 16px; } .fc-link .primary { min-height: 42px; } }

/* nút nguồn (thay ô chọn): biểu tượng + tên nguồn hiện tại + mũi tên */
.src-btn { display: flex; align-items: center; gap: 8px; min-width: 0; width: 100%; text-align: left; justify-content: flex-start; padding: 0 9px; }
.src-btn .src-ic { flex: 0 0 16px; display: grid; place-items: center; color: var(--fg2); }
.src-btn .src-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.src-btn .src-caret { flex: 0 0 auto; color: var(--muted); display: grid; place-items: center; font-size: 12px; }
.src-btn.warn { border-color: color-mix(in srgb, var(--warn) 70%, var(--control)); }

/* ───────── chọn phông chữ ───────── */
.font-btn { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; min-width: 0; }
.font-btn .fb-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.font-note { display: block; color: var(--warn); font-size: 11.5px; margin-top: -2px; }
.font-cats { margin: 8px 0; flex-wrap: wrap; }
.font-list { max-height: min(52vh, 460px); overflow: auto; border: 1px solid var(--line); border-radius: var(--r); padding: 4px; }
.font-glabel { font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 10px 8px 4px; position: sticky; top: -4px; background: var(--drawer); z-index: 1; }
.font-row { display: flex; align-items: center; gap: 4px; }
.font-pick { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; white-space: normal; }
.font-pick:hover, .font-pick:focus-visible { background: var(--hover); border-color: var(--line); outline: none; }
.font-row.on .font-pick { border-color: var(--focus); }
.font-pick b { font-size: 12px; font-weight: 600; color: var(--fg2); }
.font-sample { font-size: 18px; line-height: 1.25; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
@media (max-width: 700px) { .font-sample { font-size: 16px; } .font-list { max-height: 50vh; } }

/* cú bấm luôn rơi vào chính nút (phần tử con có thể được vẽ lại bất cứ lúc nào) */
.src-btn > *, .font-btn > *, .fc-item > *, button > .ic { pointer-events: none; }
