/* Thiết kế (#/studio/canvas). Uses the Xưởng ảnh tokens from studio.css (.xs + data-theme). */
.cv { display: flex; flex-direction: column; }
.cv-spacer { flex: 1 1 auto; }
.cv .ms { font-size: 20px; }

/* ---------- start screen ---------- */
.cv-start { display: flex; flex-direction: column; gap: 28px; padding: 22px 24px 32px; overflow: auto; }
.cv-sec { display: flex; flex-direction: column; gap: 12px; }
.cv-sec-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.cv-h2 { margin: 0; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 600; font-size: 20px; letter-spacing: -.01em; }
.cv-sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cv-size { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--node); color: var(--text); text-align: left; font-size: 13px; }
.cv-size b { font-weight: 700; }
.cv-size[aria-pressed="true"] { border-color: var(--sel); box-shadow: 0 0 0 2px var(--tint), inset 0 0 0 1px var(--sel); }
.cv-size-shape { --ar: 1; height: 44px; aspect-ratio: var(--ar); max-width: 100%; border-radius: 6px; border: 2px solid var(--line2); margin-bottom: 6px; background: var(--inset); }
.cv-size[aria-pressed="true"] .cv-size-shape { border-color: var(--sel); background: var(--tint); }
.cv-size--custom { gap: 8px; grid-column: span 2; }
.cv-wh { display: flex; align-items: center; gap: 4px; width: 100%; color: var(--muted); }
.cv-wh .xs-input { flex: 1; width: 0; min-width: 0; padding: 6px 6px; min-height: 32px; }
.cv-wh input { text-align: center; -moz-appearance: textfield; }
.cv-wh input::-webkit-inner-spin-button, .cv-wh input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.cv-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px; }
.cv-tpl { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 0; border: 0; background: transparent; color: var(--text); text-align: left; font-size: 12px; }
.cv-tpl-open { display: flex; flex-direction: column; gap: 4px; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; }
.cv-tpl-thumb { --ar: 1; display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: var(--ar); max-height: 260px; border-radius: 16px; overflow: hidden; background: var(--inset); border: 1px solid var(--line); transition: border-color .15s, transform .15s; }
.cv-tpl-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cv-tpl:hover .cv-tpl-thumb, .cv-ptpl:hover .cv-tpl-thumb { border-color: var(--sel); }
.cv-tpl-thumb--blank { color: var(--muted); }
.cv-tpl-thumb--blank .ms { font-size: 36px; }
.cv-tpl-name { font-size: 13px; font-weight: 700; margin-top: 4px; }
.cv-tpl-del { position: absolute; top: 8px; right: 8px; background: var(--float); box-shadow: var(--shadow); opacity: 0; }
.cv-tpl--design:hover .cv-tpl-del, .cv-tpl-del:focus-visible { opacity: 1; }

/* ---------- editor shell ---------- */
.cv--edit { height: calc(100vh - 48px); min-height: 620px; }
.cv-top { flex-wrap: nowrap; gap: 8px; }
.cv-top .xs-btn span:not(.ms) { white-space: nowrap; }
.cv-name { min-width: 120px; width: min(320px, 26vw); border: 1px solid transparent; background: transparent; border-radius: 10px; padding: 7px 10px; font-family: 'Bricolage Grotesque', sans-serif; font-size: 17px; font-weight: 600; color: var(--text); }
.cv-name:hover { border-color: var(--line); }
.cv-name:focus { border-color: var(--sel); outline: none; background: var(--inset); }
.cv-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.cv-chip .ms { font-size: 17px; }
.cv-save { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.cv-save .ms { font-size: 17px; }
.cv-save[data-state="error"] { color: var(--bad); }
.cv-save[data-state="saving"] .ms { animation: cv-spin 1s linear infinite; }
@keyframes cv-spin { to { transform: rotate(360deg); } }
#cv-share[aria-pressed="true"] { background: var(--tint); color: var(--sel); }

.cv-body { flex: 1; min-height: 0; display: flex; }
.cv-rail { padding-top: 10px; }
.cv-panel { flex: none; width: 320px; overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; background: var(--frame); }
.cv-ph { margin: 0; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 600; font-size: 18px; }
.cv-ph4 { margin: 6px 0 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cv-panel .xs-muted { margin: 0; }
.cv-main { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--canvas); }

/* context toolbar */
.cv-ctx { flex: none; display: flex; align-items: center; gap: 4px; min-height: 54px; padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--node); overflow-x: auto; scrollbar-width: thin; }
.cv-ctx > * { flex: none; }
.cv-ctx .xs-muted { font-size: 12px; white-space: nowrap; }
.cv-ctx-label { font-size: 12.5px; font-weight: 600; color: var(--muted); padding-right: 4px; white-space: nowrap; }
.cv-sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.cv-ib, .cv-tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 36px; height: 36px; padding: 0 8px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.cv-ib:hover:not(:disabled), .cv-tb:hover { background: var(--inset); }
.cv-ib[aria-pressed="true"] { background: var(--tint); color: var(--sel); }
.cv-ib[data-rot] .ms { transform: rotate(90deg); }
.cv-tb--primary { background: var(--pill); color: var(--pill-text); padding: 0 14px; }
.cv-tb--primary:hover { background: var(--pill); opacity: .9; }
.cv-font { min-width: 150px; justify-content: space-between; border: 1px solid var(--line); }
.cv-font span:first-child { max-width: 140px; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.cv-num { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; }
.cv-num .cv-ib { min-width: 30px; height: 34px; padding: 0 4px; }
.cv-num input { width: 56px; height: 34px; border: 0; background: transparent; text-align: center; font-weight: 700; font-size: 13px; -moz-appearance: textfield; }
.cv-num input::-webkit-inner-spin-button { -webkit-appearance: none; }
.cv-swbtn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: transparent; padding: 0; }
.cv-swbtn:hover { background: var(--inset); }
.cv-swdot { width: 24px; height: 24px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(14,21,48,.18); display: inline-block; flex: none; }
.cv-ctx .xs-seg button { min-height: 28px; padding: 0 10px; font-size: 12px; }

/* stage */
.cv-stage { position: relative; flex: 1; min-height: 0; overflow: auto; display: flex; padding: 32px;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 22px 22px; }
.cv-stage.is-drop { box-shadow: inset 0 0 0 3px var(--sel); }
.cv-board { margin: auto; flex: none; box-shadow: 0 18px 50px -20px rgba(14,21,48,.45), 0 0 0 1px var(--line); background: #fff; }
.cv-foot { flex: none; display: flex; align-items: center; gap: 4px; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--node); }
.cv-hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-zoom { min-width: 56px; height: 32px; border: 0; border-radius: 8px; background: var(--inset); color: var(--text); font-size: 12px; font-weight: 700; }

/* popover */
.cv-pop { position: absolute; z-index: 30; width: 300px; max-height: min(520px, calc(100% - 70px)); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 18px; background: var(--node); border: 1px solid var(--line); box-shadow: var(--shadow), 0 20px 50px -20px rgba(14,21,48,.35); }
.cv-pop[data-kind="font"] { width: 320px; }
.cv-pop h5 { margin: 4px 0 0; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cv-pop .xs-btn--primary { width: 100%; }
.cv-pop .xs-seg { width: 100%; }
.cv-pop .xs-seg button { flex: 1; }
.cv-fonts { display: flex; flex-direction: column; gap: 2px; }
.cv-fontbtn { display: flex; flex-direction: column; align-items: flex-start; gap: 0; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; font-size: 16px; }
.cv-fontbtn .xs-muted { font-size: 12px; }
.cv-fontbtn:hover, .cv-fontbtn.is-on { background: var(--inset); }
.cv-fontbtn.is-on { box-shadow: inset 0 0 0 1px var(--sel); }
.cv-weights { display: flex; flex-wrap: wrap; gap: 4px; }
.cv-slider { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; }
.cv-slider span { display: flex; justify-content: space-between; }
.cv-slider b { font-variant-numeric: tabular-nums; color: var(--muted); }
.cv-slider input { width: 100%; accent-color: var(--a1); }
.cv-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.cv-toggle input { width: 18px; height: 18px; accent-color: var(--a1); }
.cv-custom { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.cv-custom input[type="color"] { width: 44px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: transparent; }
.cv-custom .xs-input { flex: 1; min-width: 0; padding: 8px 10px; }
.cv-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.cv-grid3 .cv-ib { width: 100%; background: var(--inset); }

/* shared bits */
.cv-stack { display: flex; flex-direction: column; gap: 6px; }
.cv-listbtn { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 38px; padding: 6px 10px; border: 0; border-radius: 10px; background: var(--inset); color: var(--text); font-size: 13px; font-weight: 600; text-align: left; }
.cv-listbtn:hover, .cv-listbtn[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--sel); }
.cv-listbtn .xs-muted { margin-left: auto; }
.cv-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cv-chipbtn { min-height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; font-weight: 700; }
.cv-chipbtn[aria-pressed="true"] { background: var(--pill); color: var(--pill-text); border-color: var(--pill); }
.cv-note { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--tint); font-size: 12.5px; }
.cv-note span:not(.ms) { flex: 1; min-width: 0; }
.cv-link { border: 0; background: transparent; color: var(--sel); font-weight: 700; font-size: 12.5px; padding: 0; }
.cv-swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.cv-sw { position: relative; width: 100%; aspect-ratio: 1; border: 0; border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(14,21,48,.14); padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); background: var(--inset); }
.cv-sw:hover { transform: scale(1.06); }
.cv-sw.is-on { box-shadow: 0 0 0 2px var(--node), 0 0 0 4px var(--sel); }
.cv-sw--none { background: linear-gradient(135deg, transparent 45%, var(--bad) 45%, var(--bad) 55%, transparent 55%), var(--node); }
.cv-sw--custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

/* panels */
.cv-pgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cv-ptpl { display: flex; flex-direction: column; gap: 4px; padding: 0; border: 0; background: transparent; color: var(--text); font-size: 12px; font-weight: 600; text-align: left; }
.cv-ptpl .cv-tpl-thumb { border-radius: 12px; max-height: 200px; }
.cv-addtext { width: 100%; padding: 12px 14px; border: 0; border-radius: 12px; background: var(--inset); color: var(--text); text-align: left; font-family: 'Be Vietnam Pro', sans-serif; }
.cv-addtext:hover, .cv-combo:hover, .cv-el:hover, .cv-icon:hover, .cv-photo:hover { box-shadow: inset 0 0 0 1px var(--sel); }
.cv-addtext--0 { font-size: 22px; font-weight: 800; }
.cv-addtext--1 { font-size: 16px; font-weight: 600; }
.cv-addtext--2 { font-size: 13px; }
.cv-combos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cv-combo { min-height: 74px; display: flex; align-items: center; justify-content: center; padding: 8px; border: 0; border-radius: 12px; background: var(--inset); overflow: hidden; }
.xs[data-theme="dark"] .cv-combo { background: #F3F6FF; }
.cv-combo-txt { font-size: 19px; line-height: 1.15; text-align: center; overflow-wrap: anywhere; }
.cv-combo-txt.is-italic { font-style: italic; }
.cv-combo.is-label .cv-combo-txt { font-size: 13px; padding: 6px 12px; border-radius: 999px; }
.cv-drop { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 18px 12px; border-radius: 16px; border: 1.5px dashed var(--line2); background: var(--inset); text-align: center; font-size: 13px; cursor: pointer; }
.cv-drop .ms { font-size: 28px; color: var(--sel); }
.cv-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cv-drop:hover { border-color: var(--sel); }
.cv-drop--small { padding: 12px; }
.cv-search { display: flex; gap: 6px; }
.cv-search .xs-input { flex: 1; min-width: 0; padding: 8px 12px; }
.cv-list { display: flex; flex-direction: column; gap: 4px; }
.cv-photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cv-photo { aspect-ratio: 1; padding: 4px; border: 0; border-radius: 10px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.cv-photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cv-egrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cv-el { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 72px; padding: 6px; border: 0; border-radius: 12px; background: var(--inset); color: var(--text); font-size: 11.5px; font-weight: 600; text-align: center; }
.cv-el .ms { font-size: 28px; color: var(--sel); }
.cv-igrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.cv-icon { aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--inset); color: var(--text); display: flex; align-items: center; justify-content: center; }
.cv-icon .ms { font-size: 24px; }
.cv-layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cv-layer { display: flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 12px; background: var(--inset); color: var(--muted); cursor: grab; }
.cv-layer.is-on { box-shadow: inset 0 0 0 1.5px var(--sel); color: var(--sel); }
.cv-layer.is-hidden .cv-layer-name { opacity: .45; }
.cv-layer.is-over { box-shadow: inset 0 2px 0 var(--sel); }
.cv-layer-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: transparent; color: var(--text); font-size: 13px; font-weight: 600; text-align: left; padding: 8px 4px; }
.cv-layer .cv-ib { min-width: 30px; height: 30px; color: var(--muted); }

@media (max-width: 1100px) {
  .cv-top .xs-btn span:not(.ms) { display: none; }
  .cv-top .xs-btn { width: 40px; padding: 0; }
  .cv-panel { width: 270px; }
  .cv-hint { display: none; }
}
@media (max-width: 760px) {
  .cv-body { flex-direction: column; }
  .cv-rail { flex-direction: row; width: auto; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px; }
  .cv-panel { width: auto; max-height: 34vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .cv-chip, .cv-save { display: none; }
}
.cv-combo.is-dark, .xs[data-theme="dark"] .cv-combo.is-dark { background: #0E1530; }

/* AI assistant: previews are canvas images, UI colours use the existing studio tokens. */
.cv-ai-field { font-size: 13px; font-weight: 600; }
.cv-ai-brief { width: 100%; min-height: 96px; resize: vertical; }
.cv-ai-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.cv-ai-status > span { flex: 1; }
.cv-ai-results { display: grid; gap: 12px; }
.cv-ai-option { display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 10px; text-align: left; background: var(--node); color: var(--text); border: 1px solid var(--line); border-radius: 14px; overflow-wrap: anywhere; }
.cv-ai-option:hover { border-color: var(--sel); }
.cv-ai-option img { width: 100%; border-radius: 8px; }
.cv-ai-option small { color: var(--muted); }
.cv-ai-option b { font-size: 12px; color: var(--sel); }
.cv-ai-skeleton { height: 100px; border-radius: 14px; background: var(--inset); animation: cv-ai-pulse 1.4s ease-in-out infinite alternate; }
.cv-panel [data-ai-mode], .cv-panel [data-ai-quick], .cv-panel [data-ai-run], .cv-panel [data-ai-cancel] { min-height: 44px; }
.cv-ai-option:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
@keyframes cv-ai-pulse { to { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .cv-ai-skeleton { animation: none; } }
@media (max-width: 760px) {
  .cv-panel:has(.cv-ai-results) { max-height: 45vh; }
  .cv-top { flex-wrap: wrap; }
  .cv-top .cv-name { flex: 1 1 calc(100% - 68px); min-width: 0; }
  .cv-top .cv-spacer { display: none; }
}
.cv-ai-refs { display: flex; gap: 8px; margin-block: 8px; }
.cv-ai-refs img { width: 64px; height: 64px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; }
.cv-media-preview { display: block; width: 100%; max-height: 300px; object-fit: contain; background: repeating-conic-gradient(var(--inset) 0% 25%, var(--line) 0% 50%) 0 0 / 16px 16px; margin-block: 12px; }
.cv-ai-field input[type="file"] { display: block; width: 100%; margin-block: 8px; }
.cv-screen-map { position: relative; }
.cv-screen-map img { display: block; width: 100%; }
.cv-screen-map svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.cv-screen-map polygon { fill: #2b57f230; stroke: #2b57f2; stroke-width: .5; }
.cv-screen-map circle { fill: white; stroke: #2b57f2; stroke-width: 1; cursor: move; }
.cv-effect-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cv-effect-presets .cv-ai-option img { height: 110px; object-fit: contain; background: #141820; }
.cv-screen-coordinates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-block: 12px; }
.cv-screen-coordinates input { width: 100%; min-height: 44px; color: var(--text); background: var(--inset); border: 1px solid var(--line); border-radius: 6px; }
