/* Thử Đồ: giao diện ứng dụng (/app). Nạp sau fonts.css và tokens.css.
   Không có thư viện giao diện dùng chung nên các thành phần (nút, ô nhập, chip, hộp thoại) nằm luôn ở đây,
   dùng đúng tên lớp trong DESIGN.md mục 6. Token mới của riêng app khai báo ngay dưới. */

:root {
  --scrim: rgba(18, 18, 24, .52);
  --lb-bg: #0B0B0E;
  --lb-ink: #F2F2F4;
  --lb-line: #34343D;
  --ink-on-dark: #F2F2F4;
  --btn-h: 36px;
  --btn-h-sm: 30px;
  --stitch: repeating-linear-gradient(90deg, var(--line-strong) 0 6px, transparent 6px 10px);
  /* ô màu xem trước nền ảnh (chỉ để người dùng hình dung, không phải màu giao diện) */
  --sw-studio: #D9DAE0; --sw-street: #8E9A97; --sw-white: #FFFFFF; --sw-home: #E7E1D8; --sw-cafe: #A98B76; --sw-park: #86A583;
  --tabbar-h: 56px;
  --gobar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"] { --scrim: rgba(0, 0, 0, .62); --stitch: repeating-linear-gradient(90deg, var(--line-strong) 0 6px, transparent 6px 10px); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 14px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  min-height: 100dvh; overflow-x: hidden;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
.main:focus { box-shadow: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 200; background: var(--ink); color: var(--on-ink); padding: 10px 14px; border-radius: var(--r-md); font-weight: 600; text-decoration: none; transition: top var(--t-fast); }
.skip:focus { top: 12px; }

/* Biểu tượng Phosphor bằng mặt nạ CSS, theo màu chữ */
.ic { display: inline-block; flex: none; width: 18px; height: 18px; background: currentColor; -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; vertical-align: -3px; }
.ic-lg { width: 28px; height: 28px; }
.ic-xl { width: 40px; height: 40px; }
.ic-sm { width: 16px; height: 16px; }
.spin { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--btn-h); padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-md); font-weight: 600; font-size: 14px; line-height: 1; white-space: nowrap;
  text-decoration: none; background: transparent; position: relative;
  transition: background-color var(--t-fast) var(--ease-std), border-color var(--t-fast) var(--ease-std), color var(--t-fast), transform var(--t-fast) var(--ease-std);
}
.btn:active:not(:disabled):not([aria-busy=true]) { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--ring); border-radius: var(--r-md); }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--primary:active { background: var(--accent-press); }
.btn--secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn--secondary:hover { background: var(--sunken); }
.btn--ghost { color: var(--ink-2); }
.btn--ghost:hover { background: var(--sunken); color: var(--ink); }
.btn--danger { background: var(--danger-tint); color: var(--danger-ink); border-color: transparent; }
.btn--danger:hover { border-color: var(--danger); }
.btn--dark { background: rgba(255, 255, 255, .1); color: var(--ink-on-dark); border-color: rgba(255, 255, 255, .16); }
.btn--dark:hover { background: rgba(255, 255, 255, .18); }
.btn--sm { min-height: var(--btn-h-sm); padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn--lg { min-height: 48px; padding: 0 20px; font-size: 15px; }
.btn--icon { padding: 0; width: var(--btn-h); }
.btn--sm.btn--icon { width: var(--btn-h-sm); }
.btn--wide { width: 100%; }
.btn:disabled, .btn[aria-disabled=true] { background: var(--sunken); color: var(--ink-3); border-color: transparent; cursor: not-allowed; }
.btn[aria-busy=true] { cursor: progress; pointer-events: none; }
.btn[aria-pressed=true].btn--icon { color: var(--accent); }
.btn .ic { width: 18px; height: 18px; vertical-align: 0; }
.link-btn { background: none; border: 0; padding: 6px 2px; color: var(--ink); font-weight: 600; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.link-btn:hover { text-decoration-color: var(--ink); }
.kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--r-sm); background: var(--sunken); border: 1px solid var(--line-strong); font-size: 12px; font-weight: 600; line-height: 1; color: var(--ink-2); }
.g-warn-box:empty, .g-state-box:empty { display: none; }
.go-kbd { gap: 4px; }
.kbd--on-accent { background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .3); color: var(--on-accent); }

/* ---------- Ô nhập, nhãn, chip, seg ---------- */
.lbl { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; display: block; }
.opt { font-weight: 400; color: var(--ink-3); }
.hint { font-size: 12px; color: var(--ink-3); line-height: 1.4; margin-top: 6px; letter-spacing: .01em; }
.hint.count { text-align: right; font-variant-numeric: tabular-nums; }
.field { margin-top: 16px; }
.input, .textarea, .select {
  width: 100%; min-height: 40px; padding: 8px 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-input); border-radius: var(--r-md);
  transition: border-color var(--t-fast);
}
.textarea { resize: vertical; line-height: 1.45; min-height: 64px; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-2); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { box-shadow: var(--ring); border-radius: var(--r-md); }
.input--code { font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-variant-numeric: tabular-nums; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); opacity: 1; }
.field__error { font-size: 12px; font-weight: 600; color: var(--danger-ink); margin-top: 6px; }
.input[aria-invalid=true] { border: 1.5px solid var(--danger); }
.select { appearance: none; padding-right: 32px; background-image: none; }
.select-wrap { position: relative; }
.select-wrap::after { content: ""; position: absolute; right: 10px; top: 50%; width: 16px; height: 16px; margin-top: -8px; background: var(--ink-3); -webkit-mask: url(/icons/caret-down.svg) center / contain no-repeat; mask: url(/icons/caret-down.svg) center / contain no-repeat; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: var(--r-full);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); font-weight: 500; font-size: 13px; white-space: nowrap;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.chip:hover { background: var(--sunken); }
.chip[aria-pressed=true] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-on-tint); font-weight: 600; }
.chip .n { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; font-size: 12px; }
.chip[aria-pressed=true] .n { color: var(--accent-on-tint); }
.chip:focus-visible { border-radius: var(--r-full); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.seg { display: inline-flex; padding: 3px; background: var(--sunken); border-radius: var(--r-md); gap: 2px; }
.seg--full { display: flex; }
.seg--full > button { flex: 1; }
.seg > button { min-height: 30px; padding: 0 12px; border: 0; background: transparent; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); transition: background-color var(--t-fast), color var(--t-fast); }
.seg > button:hover { color: var(--ink); }
.seg > button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: var(--e1); }
.seg > button:focus-visible { border-radius: 8px; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: var(--r-full); font-size: 12px; font-weight: 600; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.badge--ok { background: var(--ok-tint); color: var(--ok-ink); }
.badge--warn { background: var(--warn-tint); color: var(--warn-ink); }
.badge--danger { background: var(--danger-tint); color: var(--danger-ink); }
.badge .ic { width: 14px; height: 14px; vertical-align: 0; }

.skeleton, .skel { background: var(--sunken); position: relative; overflow: hidden; }
.skel::after { content: ""; position: absolute; inset: 0; background: var(--surface); opacity: 0; animation: pulse 1.6s var(--ease-std) infinite; }
@keyframes pulse { 50% { opacity: .38; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Khung chính ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-template-rows: var(--topbar-h) minmax(0, 1fr); height: 100dvh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); z-index: var(--z-sticky); }
.brand { font-family: var(--font-display); font-stretch: 112%; font-weight: 700; font-size: 20px; letter-spacing: -.02em; text-decoration: none; color: var(--ink); padding: 4px 6px 4px 0; border-radius: var(--r-sm); line-height: 1.2; }
.top-spacer { flex: 1; }
.worker { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); padding: 0 8px; }
.worker .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.worker[data-s=busy] .dot { background: var(--warn); }
.quota-wrap { position: relative; }
.quota-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border-radius: var(--r-full); border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.quota-chip:hover { background: var(--sunken); }
.quota-chip[data-lv=low] { background: var(--warn-tint); border-color: transparent; color: var(--warn-ink); }
.quota-chip[data-lv=out] { background: var(--danger-tint); border-color: transparent; color: var(--danger-ink); }
.quota-chip .ic { width: 16px; height: 16px; vertical-align: 0; }
.pending-badge { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: var(--r-full); border: 0; background: var(--warn-tint); color: var(--warn-ink); font-weight: 600; font-size: 13px; }
.pop { position: absolute; right: 0; top: calc(100% + 8px); width: 300px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e2); padding: 16px; z-index: var(--z-drawer); animation: rise var(--t-base) var(--ease-out); }
.pop h3 { font-size: 14px; font-weight: 600; }
.pop .pop-n { font-family: var(--font-display); font-stretch: 112%; font-weight: 600; font-size: 40px; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 8px 0 4px; }
.pop p { color: var(--ink-2); font-size: 13px; }
.pop .pop-links { display: flex; flex-direction: column; align-items: flex-start; margin-top: 8px; }
.pop .btn { margin-top: 12px; }

/* Thanh bên */
.rail { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 10px 2px; background: var(--surface); border-right: 1px solid var(--line); z-index: 5; }
.rail button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 54px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink-2); font-size: 11px; font-weight: 600; line-height: 1.1; white-space: nowrap; position: relative; transition: background-color var(--t-fast), color var(--t-fast); }
.rail button .ic { width: 22px; height: 22px; }
.rail button:hover { background: var(--sunken); color: var(--ink); }
.rail button[aria-current=page] { background: var(--accent-tint); color: var(--accent-on-tint); }
.rail button:focus-visible { border-radius: var(--r-md); }
.rail .rail-n { position: absolute; top: 4px; right: 8px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--ink); color: var(--on-ink); font-size: 11px; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.rail .rail-gap { flex: 1; }

.main { min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); position: relative; }
.view { height: 100%; }
.page { overflow-y: auto; padding: 32px 32px 96px; }
.page-in { max-width: 1120px; margin: 0 auto; animation: rise var(--t-slow) var(--ease-out); }
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-h h1 { font-family: var(--font-display); font-stretch: 108%; font-weight: 600; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; }
.page-h p { color: var(--ink-2); margin-top: 4px; max-width: 60ch; }

/* ---------- Studio ---------- */
.studio { display: grid; grid-template-columns: var(--panel-left-w) minmax(0, 1fr); min-height: 0; }
.studio.has-details { grid-template-columns: var(--panel-left-w) minmax(0, 1fr) var(--panel-right-w); }
.setup { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.setup-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 16px; }
.step { padding: 12px 0 8px; position: relative; }
.step + .step { border-top: 1px solid var(--line); }
.step-h { font-size: 14px; }
.step-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0; border: 0; background: none; text-align: left; border-radius: var(--r-sm); }
.step-mark { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--line-input); font-size: 12px; font-weight: 700; flex: none; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.step.done .step-mark { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.step.done .step-mark .ic { width: 14px; height: 14px; vertical-align: 0; }
.step-t { font-weight: 600; font-size: 14px; }
.step-sum { margin-left: auto; font-size: 13px; color: var(--ink-3); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.step-caret { color: var(--ink-3); transition: transform var(--t-base) var(--ease-std); flex: none; }
.step-toggle[aria-expanded=false] .step-caret { transform: rotate(-90deg); }
.step-body { padding: 4px 0 8px 34px; }
.step-body[hidden] { display: none; }

.model-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.m-tile { position: relative; aspect-ratio: 3 / 4; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line-strong); background: var(--sunken); padding: 0; transition: border-color var(--t-fast); }
.m-tile img { width: 100%; height: 100%; object-fit: cover; }
.m-tile[aria-pressed=true] { border: 2px solid var(--accent); }
.m-tile[aria-pressed=true]::after { content: ""; position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent) url(/icons/check.svg) center / 14px no-repeat; }
.m-tile:hover { border-color: var(--ink-2); }
.m-tile:focus-visible { border-radius: var(--r-md); }
.m-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; aspect-ratio: 3 / 4; border-radius: var(--r-md); border: 1.5px dashed var(--line-strong); background: transparent; color: var(--ink-2); font-size: 12px; font-weight: 600; line-height: 1.2; text-align: center; padding: 4px; transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast); }
.m-add:hover { background: var(--sunken); border-color: var(--ink-2); color: var(--ink); }
.m-add .ic { width: 22px; height: 22px; }
.model-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 0; margin-top: 4px; }
.model-meta .hint { margin-top: 8px; }
.m-badge { position: absolute; left: 4px; bottom: 4px; padding: 2px 6px; border-radius: var(--r-sm); background: rgba(23, 23, 28, .72); color: #fff; font-size: 11px; font-weight: 600; line-height: 1.3; }

.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 20px 12px; text-align: center; border-radius: var(--r-md); color: var(--ink-2); cursor: pointer;
  background: var(--surface); border: 1.5px dashed var(--line-strong); transition: background-color var(--t-fast), border-color var(--t-fast); }
@media (hover: hover) { .dropzone:hover { background: var(--accent-tint); border-color: var(--accent); } }
.dropzone.over { background: var(--accent-tint); border-color: var(--accent); }
.dropzone .ic { color: var(--ink-3); }
.dropzone.over .ic { color: var(--accent); }
.dropzone:focus-visible { border-radius: var(--r-md); }
.dz-t { font-weight: 600; color: var(--ink); font-size: 14px; }
.dz-s { font-size: 12px; color: var(--ink-3); }
.dz-s .kbd { height: 18px; min-width: 18px; font-size: 11px; padding: 0 4px; }
.dz-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.dz-actions .link-btn { margin-left: auto; }

.g-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.g-item { display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); animation: rise var(--t-base) var(--ease-out); }
.g-thumb { width: 48px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--sunken); }
.g-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.g-name { min-height: 30px; padding: 4px 8px; font-size: 13px; font-weight: 600; background: transparent; border: 1px solid transparent; border-radius: 8px; width: 100%; text-overflow: ellipsis; }
.g-name:hover { border-color: var(--line-strong); background: var(--surface); }
.g-name:focus-visible { background: var(--surface); border-color: var(--line-input); box-shadow: var(--ring); border-radius: 8px; }
.g-type { min-height: 30px; padding: 4px 28px 4px 8px; font-size: 13px; border-radius: 8px; }
.g-warn { display: flex; gap: 6px; align-items: flex-start; font-size: 12px; color: var(--warn-ink); background: var(--warn-tint); border-radius: 8px; padding: 6px 8px; line-height: 1.35; grid-column: 2 / -1; }
.g-warn .ic { width: 14px; height: 14px; margin-top: 1px; vertical-align: 0; }
.g-warn a { color: inherit; font-weight: 600; }
.g-prog { height: 4px; border-radius: 2px; background: var(--sunken); overflow: hidden; }
.g-prog i { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform var(--t-base) var(--ease-std); }
.g-state { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; }
.g-state.err { color: var(--danger-ink); font-weight: 600; }
.g-rm { align-self: start; }
.mode-box { margin-top: 14px; }

.pack-group-t { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 14px 0 6px; letter-spacing: .01em; }
.pack-list { display: flex; flex-direction: column; gap: 8px; }
.pack { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; text-align: left; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); transition: border-color var(--t-fast), background-color var(--t-fast); }
.pack:hover { background: var(--bg); }
.pack[aria-pressed=true] { border: 1.5px solid var(--accent); padding: 9.5px 11.5px; background: var(--accent-tint); }
.pack b { font-size: 14px; font-weight: 600; }
.pack[aria-pressed=true] b { color: var(--accent-on-tint); }
.pack small { grid-column: 1; font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.pack[aria-pressed=true] small { color: var(--accent-on-tint); }
.pack-n { grid-row: 1; grid-column: 2; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; align-self: start; }
.pack[aria-pressed=true] .pack-n { color: var(--accent-on-tint); }
.pack-shots { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.shot { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px 6px 2px 3px; line-height: 1.3; }
.pack[aria-pressed=true] .shot { background: var(--surface); }
.sw { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line-strong); flex: none; background: var(--sw, var(--sunken)); }
.sw[data-sw=keep] { background: linear-gradient(135deg, var(--sunken) 50%, var(--surface) 50%); }
.sw[data-sw=studio] { --sw: var(--sw-studio); } .sw[data-sw=street] { --sw: var(--sw-street); } .sw[data-sw=white] { --sw: var(--sw-white); }
.sw[data-sw=home] { --sw: var(--sw-home); } .sw[data-sw=cafe] { --sw: var(--sw-cafe); } .sw[data-sw=park] { --sw: var(--sw-park); }
.chip .sw { width: 16px; height: 16px; }
.chip-grp + .lbl, .style-box + .style-box { margin-top: 16px; }
.style-box { margin-top: 14px; }
.style-box > .lbl { margin-bottom: 8px; }
.ratio-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ratio { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px 6px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); font-size: 12px; font-weight: 600; color: var(--ink-2); min-height: 44px; transition: border-color var(--t-fast), background-color var(--t-fast); }
.ratio:hover { background: var(--bg); }
.ratio i { display: block; width: calc(26px * var(--rw)); height: calc(26px * var(--rh)); border: 1.5px dashed var(--ink-3); border-radius: 3px; }
.ratio[aria-pressed=true] { border: 1.5px solid var(--accent); background: var(--accent-tint); color: var(--accent-on-tint); padding: 7.5px 3.5px 5.5px; }
.ratio[aria-pressed=true] i { border-color: var(--accent); }
.ratio:focus-visible { border-radius: var(--r-md); }

/* Thanh tạo ảnh dính đáy panel */
.go-bar { padding: 12px 16px calc(12px + var(--safe-b) * 0); border-top: 1px solid var(--line); background: var(--surface); }
.go-row { display: flex; flex-direction: column; gap: 8px; }
.go-info { order: 2; display: flex; flex-direction: column; gap: 1px; font-size: 12px; color: var(--ink-3); line-height: 1.35; min-height: 32px; }
.go-info strong { font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.btn--go { order: 1; min-height: 48px; width: 100%; font-size: 15px; gap: 10px; }
.btn--go .go-kbd { margin-left: 4px; height: 20px; font-size: 11px; }
.go-err { margin-bottom: 8px; padding: 8px 10px; border-radius: var(--r-md); background: var(--danger-tint); color: var(--danger-ink); font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: flex-start; line-height: 1.35; }
.go-err .ic { margin-top: 1px; vertical-align: 0; }

/* ---------- Khu làm việc ---------- */
.work { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--sunken); }
.work-bar { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 8px 16px; flex-wrap: wrap; }
.work-bar .wb-title { font-weight: 600; font-size: 14px; }
.work-bar .wb-sp { flex: 1; }
.work-bar .m-only { display: none; }
.nav-n { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
.banner { margin: 0 16px; padding: 8px 12px; border-radius: var(--r-md); background: var(--warn-tint); color: var(--warn-ink); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.stage-area { flex: 1; min-height: 0; display: grid; place-items: center; padding: 8px 24px 16px; container-type: size; position: relative; overflow: hidden; }
.stage-area.flow { container-type: normal; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 16px 24px 32px; }
.stage-area.flow > * { margin-block: auto; flex: none; }
.frame { position: relative; width: min(100cqw, calc(100cqh * var(--arn, .75))); aspect-ratio: var(--ar, 3 / 4); border-radius: var(--r-md); overflow: hidden; background: var(--surface); box-shadow: var(--e2); user-select: none; -webkit-user-select: none; }
.frame > img, .frame .fill { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.frame .orig-hold { opacity: 0; transition: opacity var(--t-fast); background: var(--surface); }
.frame.hold-orig .orig-hold { opacity: 1; }
.frame > img.fade { animation: fadeIn var(--t-base) var(--ease-std); }
.tag { position: absolute; top: 10px; padding: 3px 8px; border-radius: var(--r-sm); background: rgba(23, 23, 28, .72); color: #fff; font-size: 12px; font-weight: 600; line-height: 1.3; z-index: 3; pointer-events: none; }
.tag-l { left: 10px; } .tag-r { right: 10px; }

.compare { position: absolute; inset: 0; cursor: ew-resize; touch-action: pan-y; --pos: 50%; }
.compare:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); border-radius: 0; }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.compare .c-before { clip-path: inset(0 calc(100% - var(--pos)) 0 0); background: var(--surface); }
.c-line { position: absolute; top: 0; bottom: 0; left: var(--pos); width: 0; z-index: 2; border-left: 1.5px dashed #fff; filter: drop-shadow(0 0 1px rgba(0, 0, 0, .5)); pointer-events: none; }
.c-handle { position: absolute; top: 50%; left: 0; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; background: #fff; color: var(--ink); display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }
.c-handle .ic { width: 20px; height: 20px; vertical-align: 0; }
.compare:hover .c-handle, .compare:focus-visible .c-handle { transform: scale(1.06); }
.c-handle { transition: transform var(--t-fast); }

.frame--busy { background: var(--sunken); box-shadow: 0 0 0 1px var(--line-strong); }
.frame--busy .ghost { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .16; filter: blur(6px) saturate(.6); transform: scale(1.06); }
.busy-card { position: absolute; left: 50%; top: 50%; width: min(86%, 340px); transform: translate(-50%, -50%); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e2); padding: 18px; z-index: 2; }
.busy-card h2 { font-size: 15px; font-weight: 600; line-height: 1.3; }
.busy-time { font-family: var(--font-display); font-stretch: 112%; font-weight: 600; font-size: 30px; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 10px 0 2px; }
.busy-card .sub { font-size: 12px; color: var(--ink-3); }
.est { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; padding-top: 12px; position: relative; }
.est::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1.5px; background: var(--stitch); }
.est li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); }
.est li .d { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--line-input); flex: none; display: grid; place-items: center; }
.est li[data-s=now] { color: var(--ink); font-weight: 600; }
.est li[data-s=now] .d { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 3px, transparent 3.5px); }
.est li[data-s=done] { color: var(--ink-2); }
.est li[data-s=done] .d { background: var(--ok); border-color: var(--ok); }
.est li[data-s=done] .d::after { content: ""; width: 10px; height: 10px; background: var(--surface); -webkit-mask: url(/icons/check.svg) center / contain no-repeat; mask: url(/icons/check.svg) center / contain no-repeat; }
.busy-fine { margin-top: 12px; font-size: 12px; color: var(--ink-2); line-height: 1.4; display: flex; gap: 6px; }
.busy-fine .ic { width: 14px; height: 14px; margin-top: 1px; vertical-align: 0; flex: none; }
.est-note { margin-top: 8px; font-size: 11px; color: var(--ink-3); }

/* Bố cục dạng cuộn trong khu làm việc */
.flow-in { width: 100%; max-width: 920px; }
.state-card { max-width: 440px; margin: 8vh auto 0; text-align: center; padding: 8px; }
.state-card .ic-xl { color: var(--ink-3); }
.state-card h2 { font-family: var(--font-display); font-stretch: 108%; font-weight: 600; font-size: 24px; line-height: 1.2; letter-spacing: -.02em; margin: 12px 0 8px; }
.state-card p { color: var(--ink-2); line-height: 1.55; }
.state-card .acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }
.state-card.err .ic-xl { color: var(--danger); }
.fail-card { max-width: 480px; margin: 6vh auto 0; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e1); padding: 24px; }
.fail-card .err-box { display: flex; gap: 10px; align-items: flex-start; background: var(--danger-tint); color: var(--danger-ink); border-radius: var(--r-md); padding: 12px; }
.fail-card .err-box h2 { font-size: 15px; font-weight: 700; }
.fail-card .err-box p { margin-top: 2px; font-weight: 500; line-height: 1.45; }
.fail-card .refund { margin-top: 12px; display: flex; gap: 8px; align-items: center; font-weight: 600; color: var(--ok-ink); }
.fail-card .field { margin-top: 12px; }
.fail-card .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.fail-card .guide-link { display: inline-block; margin-top: 14px; }

/* Trạng thái trống lần đầu */
.empty { max-width: 780px; width: 100%; padding-top: 3vh; animation: rise var(--t-slow) var(--ease-out); }
.empty-trio { display: grid; grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr) 40px minmax(0, 1fr); align-items: center; gap: 4px; max-width: 560px; margin: 0 auto; }
.empty-trio figure { position: relative; }
.empty-trio img { width: 100%; height: auto; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--r-md); background: var(--sunken); box-shadow: var(--e1); }
.empty-trio figcaption { font-size: 12px; color: var(--ink-3); text-align: center; margin-top: 6px; }
.empty-trio .plus, .empty-trio .eq { display: grid; place-items: center; color: var(--ink-3); }
.empty-trio .eq { position: relative; height: 2px; align-self: center; margin-bottom: 22px; }
.empty-trio .eq::before { content: ""; width: 100%; height: 1.5px; background: var(--stitch); }
.empty-trio .eq::after { content: ""; position: absolute; right: -2px; top: -4px; width: 10px; height: 10px; border-top: 1.5px solid var(--line-strong); border-right: 1.5px solid var(--line-strong); transform: rotate(45deg); }
.empty-trio .plus { margin-bottom: 22px; }
.empty h2 { font-family: var(--font-display); font-stretch: 112%; font-weight: 600; font-size: 26px; line-height: 1.15; letter-spacing: -.02em; text-align: center; margin: 24px 0 6px; }
.empty .lead { text-align: center; color: var(--ink-2); max-width: 52ch; margin: 0 auto; line-height: 1.55; }
.checks { display: flex; flex-direction: column; gap: 8px; max-width: 320px; margin: 18px auto 0; }
.checks li { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 14px; }
.checks li .ic { color: var(--ink-3); }
.checks li.done { color: var(--ink); }
.checks li.done .ic { color: var(--ok); }
.empty .acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }
.empty .fine { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 10px; }

/* Sẵn sàng */
.ready { width: 100%; max-width: 760px; animation: rise var(--t-slow) var(--ease-out); }
.ready-stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, 260px) minmax(0, 1fr); gap: 20px; align-items: center; }
.ready-model { position: relative; aspect-ratio: 3 / 4; border-radius: var(--r-md); overflow: hidden; box-shadow: var(--e2); background: var(--surface); }
.ready-model img { width: 100%; height: 100%; object-fit: cover; }
.pins { display: flex; flex-direction: column; gap: 8px; }
.pins.l { align-items: flex-end; }
.pin { display: flex; align-items: center; gap: 8px; max-width: 200px; background: var(--surface); border-radius: var(--r-md); padding: 6px 10px 6px 6px; box-shadow: var(--e1); }
.pin img { width: 36px; height: 48px; border-radius: 6px; object-fit: cover; flex: none; background: var(--sunken); }
.pin span { font-size: 13px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ready h2 { text-align: center; font-size: 15px; font-weight: 600; margin-top: 18px; }
.ready p.sub { text-align: center; color: var(--ink-2); margin-top: 4px; font-size: 13px; }

/* Lưới bộ ảnh đang tạo */
.group { width: 100%; max-width: 980px; }
.group-h { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.group-h h2 { font-size: 16px; font-weight: 600; }
.group-h .sub { color: var(--ink-2); font-size: 13px; }
.group-h .wb-sp { flex: 1; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; align-items: start; }
.g-card { position: relative; border-radius: var(--r-md); overflow: hidden; background: var(--surface); box-shadow: var(--e1); aspect-ratio: var(--ar); border: 0; padding: 0; width: 100%; display: block; text-align: left; }
.g-card img.main { width: 100%; height: 100%; object-fit: cover; animation: fadeIn var(--t-base) var(--ease-std); }
.g-card .skel { position: absolute; inset: 0; }
.g-card .garm { position: absolute; left: 8px; top: 8px; width: 34px; height: 45px; border-radius: 6px; object-fit: cover; border: 2px solid var(--surface); z-index: 2; }
.g-card .st { position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--surface); border-radius: var(--r-md); padding: 6px 8px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.g-card .st .t { color: var(--ink-2); font-weight: 500; }
.g-card.err { background: var(--danger-tint); }
.g-card.err .st { background: transparent; color: var(--danger-ink); flex-direction: column; align-items: flex-start; }
.g-card:hover { box-shadow: var(--e2); }
.g-card:focus-visible { border-radius: var(--r-md); }

/* Chân khu làm việc */
.stage-foot { padding: 0 16px 8px; }
.act-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
.act-row .sp { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; }
.verify { display: flex; justify-content: center; gap: 6px; align-items: flex-start; margin-top: 8px; font-size: 12px; color: var(--ink-3); text-align: center; line-height: 1.4; }
.verify .ic { width: 14px; height: 14px; margin-top: 1px; vertical-align: 0; flex: none; }

/* Dải ảnh gần đây */
.strip-wrap { padding: 8px 16px 12px; border-top: 1px solid var(--line); background: var(--surface); }
.strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 4px 6px; scrollbar-width: thin; }
.s-item { position: relative; width: 56px; height: 75px; flex: none; border-radius: 8px; overflow: hidden; border: 0; padding: 0; background: var(--sunken); outline: 1px solid var(--line-strong); outline-offset: -1px; }
.s-item img { width: 100%; height: 100%; object-fit: cover; }
.s-item[aria-current=true] { outline: 2px solid var(--accent); outline-offset: -2px; }
.s-item:focus-visible { border-radius: 8px; }
.s-dot { position: absolute; right: 3px; bottom: 3px; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--ink-2); }
.s-dot .ic { width: 12px; height: 12px; vertical-align: 0; }
.s-dot.err { color: var(--danger); }
.s-fav { position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: var(--accent); -webkit-mask: url(/icons/heart-fill.svg) center / contain no-repeat; mask: url(/icons/heart-fill.svg) center / contain no-repeat; filter: drop-shadow(0 0 1px #fff); }

/* ---------- Panel chi tiết ---------- */
.details { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 16px 24px; min-width: 0; display: none; }
.studio.has-details .details { display: block; }
.det-h { display: flex; align-items: center; justify-content: space-between; min-height: 52px; font-size: 14px; font-weight: 600; }
.det-sec { padding: 14px 0; border-top: 1px solid var(--line); }
.det-sec:first-of-type { border-top: 0; padding-top: 4px; }
.det-sec h3 { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.det-sec .sub { font-size: 12px; color: var(--ink-3); margin-bottom: 8px; line-height: 1.4; }
.meta { display: flex; flex-direction: column; }
.meta div { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; padding: 6px 0; font-size: 13px; }
.meta dt { color: var(--ink-3); }
.meta dd { color: var(--ink); font-weight: 500; overflow-wrap: anywhere; }
.chips-sm .chip { min-height: 30px; font-size: 12px; padding: 0 10px; }
.exp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.exp { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 10px; border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface); text-align: left; min-height: 44px; transition: background-color var(--t-fast); }
.exp:hover { background: var(--sunken); }
.exp b { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.exp small { font-size: 12px; color: var(--ink-3); line-height: 1.3; }
.exp:focus-visible { border-radius: var(--r-md); }
.det-sec .btn--wide { margin-top: 8px; }
.sheet-grip { display: none; }
.det-close { display: none; }
.m-only-flex { display: none; }

/* ---------- Thư viện ---------- */
.lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.lib-tools .sp { flex: 1; }
.lib-tools .select-wrap { min-width: 150px; }
.lib-tools .select { min-height: 32px; padding: 4px 30px 4px 10px; font-size: 13px; border-radius: var(--r-full); border-color: var(--line-strong); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 16px; }
.lib-group-h { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 10px; margin-top: 8px; font-size: 13px; font-weight: 600; padding-top: 12px; border-top: 1px solid var(--line); }
.lib-group-h:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.lib-group-h span { color: var(--ink-3); font-weight: 400; }
.card { position: relative; content-visibility: auto; contain-intrinsic-size: 176px 280px; }
.card-img { position: relative; display: block; width: 100%; aspect-ratio: var(--ar, 3 / 4); border-radius: var(--r-md); overflow: hidden; background: var(--sunken); border: 0; padding: 0; box-shadow: 0 0 0 1px var(--line); transition: box-shadow var(--t-fast); }
.card-img img { width: 100%; height: 100%; object-fit: cover; transition: transform var(--t-slow) var(--ease-out); }
.card:hover .card-img { box-shadow: var(--e2); }
.card:hover .card-img img { transform: scale(1.02); }
.card-img:focus-visible { border-radius: var(--r-md); }
.card[data-sel=true] .card-img { box-shadow: 0 0 0 2px var(--accent); }
.card-check, .card-fav { position: absolute; top: 8px; width: 32px; height: 32px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .92); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); opacity: 0; transition: opacity var(--t-fast); z-index: 2; }
.card-check { left: 8px; }
.card-fav { right: 8px; }
.card-check .ic, .card-fav .ic { width: 18px; height: 18px; vertical-align: 0; }
.card:hover .card-check, .card:hover .card-fav, .card:focus-within .card-check, .card:focus-within .card-fav, .lib-grid.selecting .card-check, .card[data-sel=true] .card-check, .card-fav[aria-pressed=true] { opacity: 1; }
.card-check[aria-pressed=true] { background: var(--accent); color: #fff; }
.card-fav[aria-pressed=true] { color: var(--accent); }
.card-check:focus-visible, .card-fav:focus-visible { border-radius: 50%; }
.card-cap { padding: 8px 2px 0; min-width: 0; }
.card-cap b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-cap span { display: block; font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-media { position: relative; }
.card-flag { position: absolute; left: 8px; bottom: 8px; z-index: 2; background: rgba(23, 23, 28, .72); color: #fff; }
.card-ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 12px; text-align: center; font-size: 12px; }
.card-ph b { font-size: 13px; }
.card-ph.err { background: var(--danger-tint); color: var(--danger-ink); }
.card-ph.run { color: var(--ink-2); }
.card-ph.run .skel, .card-ph .skel { position: absolute; inset: 0; }
.card-ph > * { position: relative; z-index: 1; }
.empty-lib { grid-column: 1 / -1; }

.bulk:not([hidden]) ~ .toasts { bottom: 92px; }
.bulk { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: var(--z-drawer); display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; background: var(--ink); color: var(--on-ink); border-radius: var(--r-lg); box-shadow: var(--e3); animation: rise var(--t-base) var(--ease-out); max-width: calc(100vw - 24px); flex-wrap: wrap; }
.bulk b { font-size: 13px; font-variant-numeric: tabular-nums; margin-right: 4px; }
.bulk .btn { background: rgba(255, 255, 255, .12); color: var(--on-ink); border-color: transparent; min-height: 34px; }
:root[data-theme="dark"] .bulk .btn { background: rgba(0, 0, 0, .1); }
.bulk .btn:hover { background: rgba(255, 255, 255, .22); }
.bulk .btn--danger-q { color: #FFB4A3; }
:root[data-theme="dark"] .bulk .btn--danger-q { color: #B3361B; }

/* ---------- Người mẫu ---------- */
.mdl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 16px; }
.mdl { position: relative; }
.mdl-img { position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: var(--r-md); overflow: hidden; background: var(--sunken); border: 0; padding: 0; box-shadow: 0 0 0 1px var(--line-strong); }
.mdl-img img { width: 100%; height: 100%; object-fit: cover; }
.mdl-img[aria-pressed=true] { box-shadow: 0 0 0 2px var(--accent); }
.mdl-img:focus-visible { border-radius: var(--r-md); }
.mdl-use { position: absolute; left: 8px; top: 8px; }
.mdl-cap { display: flex; align-items: center; gap: 4px; margin-top: 8px; min-width: 0; }
.mdl-cap b { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.mdl-cap .btn { flex: none; }
.mdl-tags { font-size: 12px; color: var(--ink-3); }
.mdl-add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; aspect-ratio: 3 / 4; width: 100%; border-radius: var(--r-md); border: 1.5px dashed var(--line-strong); background: transparent; color: var(--ink-2); font-weight: 600; text-align: center; padding: 8px; }
.mdl-add:hover { background: var(--sunken); border-color: var(--ink-2); color: var(--ink); }
.mdl-add small { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { min-height: 40px; padding: 0 14px; border: 0; background: none; font-weight: 600; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--ink); }
.tabs button:focus-visible { border-radius: var(--r-sm); }
.mm-groups { display: flex; flex-direction: column; gap: 14px; margin: 16px 0 0; }
.mm-groups .seg { flex-wrap: wrap; }

/* ---------- Hướng dẫn chụp ---------- */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 24px 32px; }
.guide-item { padding: 16px 0 6px; border-top: 1.5px solid var(--ink); }
.guide-item h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.g-row { display: flex; gap: 8px; font-size: 13px; line-height: 1.45; padding: 6px 0; color: var(--ink-2); }
.g-row + .g-row { border-top: 1px dashed var(--line-strong); }
.g-row .ic { margin-top: 1px; vertical-align: 0; }
.g-row.do .ic { color: var(--ok); } .g-row.dont .ic { color: var(--danger); }
.g-row b { color: var(--ink); font-weight: 600; margin-right: 4px; }
.guide-note { margin-top: 20px; display: flex; gap: 8px; color: var(--ink-3); font-size: 12px; }

/* ---------- Tài khoản ---------- */
.acc-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 24px; align-items: start; }
.acc-card { background: var(--surface); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--e1); }
.acc-card + .acc-card { margin-top: 16px; }
.acc-card h2 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.acc-card .sub { color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.big-n { font-family: var(--font-display); font-stretch: 112%; font-weight: 600; font-size: 56px; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 12px 0 4px; }
.big-n small { font-size: 16px; font-weight: 500; color: var(--ink-2); margin-left: 6px; letter-spacing: 0; font-family: var(--font-ui); font-stretch: 100%; }
.stat-row { display: flex; gap: 20px; flex-wrap: wrap; margin: 12px 0 16px; }
.stat-row div { font-size: 12px; color: var(--ink-3); }
.stat-row b { display: block; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--bg); border: 1px dashed var(--line-strong); }
.code-box code { font-family: var(--font-ui); font-size: 22px; font-weight: 700; letter-spacing: .16em; font-variant-numeric: tabular-nums; }
.warn-box { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border-radius: var(--r-md); background: var(--warn-tint); color: var(--warn-ink); font-size: 13px; line-height: 1.45; }
.warn-box .ic { margin-top: 1px; vertical-align: 0; }
.ord { width: 100%; border-collapse: collapse; font-size: 13px; }
.ord th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12px; padding: 0 8px 8px 0; }
.ord td { padding: 10px 8px 10px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; vertical-align: middle; }
.ord .num { text-align: right; padding-right: 0; }
.ord .code { font-weight: 600; letter-spacing: .04em; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.pref:first-of-type { border-top: 0; }
.pref p { font-size: 13px; color: var(--ink-2); }
.pref b { display: block; font-size: 14px; color: var(--ink); font-weight: 600; }
.switch { position: relative; width: 44px; height: 26px; flex: none; border-radius: var(--r-full); border: 0; background: var(--line-input); transition: background-color var(--t-base); padding: 0; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform var(--t-base) var(--ease-out); }
.switch[aria-checked=true] { background: var(--accent); }
.switch[aria-checked=true]::after { transform: translateX(18px); }
.switch:focus-visible { border-radius: var(--r-full); }

/* ---------- Hộp thoại ---------- */
dialog.modal { border: 0; padding: 20px; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--e3); width: min(92vw, 440px); max-height: 92dvh; overflow-y: auto; margin: auto; }
dialog.modal--pay { width: min(94vw, 880px); padding: 0; }
dialog::backdrop { background: var(--scrim); }
dialog.modal[open] { animation: rise var(--t-slow) var(--ease-out); }
dialog.modal[open]::backdrop { animation: fadeIn var(--t-slow) var(--ease-std); }
.modal-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-h h2 { font-size: 18px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; padding-top: 2px; }
.modal-h .btn { margin: -4px -6px 0 0; }
.modal-p { color: var(--ink-2); line-height: 1.55; }
.modal-f { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

.pay { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.pay-l { padding: 28px; display: flex; flex-direction: column; }
.pay-r { padding: 28px; background: var(--bg); border-left: 1px solid var(--line); border-radius: 0 var(--r-lg) var(--r-lg) 0; }
.pay-l h2 { font-size: 20px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; padding-right: 32px; }
.pay-l .sub { color: var(--ink-2); margin-top: 6px; line-height: 1.5; }
.price-tag { position: relative; margin-top: 18px; padding: 22px 18px 16px; border-radius: var(--r-md); border: 1.5px solid var(--accent); background: var(--surface); }
.price-tag::before { content: ""; position: absolute; left: 50%; top: 8px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--accent); }
.price-tag .p { font-family: var(--font-display); font-stretch: 112%; font-weight: 600; font-size: 40px; line-height: 1; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; margin-top: 4px; }
:root[data-theme="dark"] .price-tag .p { color: var(--accent-on-tint); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .price-tag .p { color: var(--accent-on-tint); } }
.price-tag .per { margin-top: 6px; font-size: 13px; color: var(--ink-2); }
.perks { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.perks li { display: flex; gap: 8px; font-size: 13px; line-height: 1.45; color: var(--ink-2); }
.perks .ic { color: var(--ok); margin-top: 1px; vertical-align: 0; }
.pay-steps { margin-top: 16px; padding-top: 14px; position: relative; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); counter-reset: s; }
.pay-steps::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1.5px; background: var(--stitch); }
.pay-steps li { display: flex; gap: 8px; counter-increment: s; }
.pay-steps li::before { content: counter(s); flex: none; width: 20px; height: 20px; border-radius: 50%; background: var(--sunken); font-size: 12px; font-weight: 700; display: grid; place-items: center; color: var(--ink-2); }
.qr-box { background: #fff; border-radius: var(--r-md); padding: 8px; width: 200px; margin: 0 auto 14px; box-shadow: 0 0 0 1px var(--line-strong); }
.qr-box img { width: 100%; height: auto; aspect-ratio: 1; }
.qr-fail { aspect-ratio: 1; display: grid; place-items: center; text-align: center; padding: 12px; font-size: 12px; color: #4A4A55; }
.pay-rows { display: flex; flex-direction: column; }
.pay-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); min-height: 48px; }
.pay-row:first-child { border-top: 0; }
.pay-row .k { font-size: 12px; color: var(--ink-3); }
.pay-row .v { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pay-row.key .v { color: var(--accent); letter-spacing: .04em; }
:root[data-theme="dark"] .pay-row.key .v { color: var(--accent-on-tint); }
.pay-status { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--r-md); background: var(--bg); font-size: 13px; line-height: 1.45; color: var(--ink-2); margin-top: 14px; }
.pay-status[data-s=claimed] { background: var(--warn-tint); color: var(--warn-ink); }
.pay-status[data-s=error] { background: var(--danger-tint); color: var(--danger-ink); }
.pay-status .ic { margin-top: 1px; vertical-align: 0; }
.pay-r .btn--wide { margin-top: 14px; }
.pay-note { font-size: 12px; color: var(--ink-3); margin-top: 10px; line-height: 1.45; }
.pay-x { position: absolute; right: 12px; top: 12px; }
.pay-done { padding: 40px 32px; text-align: center; max-width: 440px; margin: 0 auto; }
.pay-done .ic-xl { color: var(--ok); width: 48px; height: 48px; }
.pay-done h2 { font-family: var(--font-display); font-stretch: 108%; font-weight: 600; font-size: 26px; margin: 12px 0 6px; letter-spacing: -.02em; }
.pay-done p { color: var(--ink-2); }
.pay-done .btn { margin-top: 20px; }
.pay-load { padding: 28px; }
.pay-load .skel { height: 14px; border-radius: 7px; margin-bottom: 10px; }
.pay-err { padding: 36px 28px; text-align: center; }
.pay-err .ic-xl { color: var(--danger); }
.pay-err h2 { font-size: 18px; margin: 10px 0 6px; font-weight: 600; }
.pay-err p { color: var(--ink-2); margin-bottom: 16px; }

.keys { display: flex; flex-direction: column; margin-top: 8px; }
.keys div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.keys div:first-child { border-top: 0; }
.keys dt { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.keys dd { color: var(--ink); font-weight: 500; text-align: right; }

/* Xem toàn màn hình */
dialog.lightbox { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--lb-bg); color: var(--lb-ink); overflow: hidden; }
dialog.lightbox[open] { display: grid; grid-template-columns: 64px minmax(0, 1fr) 64px; grid-template-rows: auto minmax(0, 1fr) auto; animation: fadeIn var(--t-base) var(--ease-std); }
dialog.lightbox::backdrop { background: var(--lb-bg); }
.lb-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 20px; }
.lb-n { font-size: 13px; font-variant-numeric: tabular-nums; color: #B4B4BE; }
.lb-cap { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; }
.lb-cap b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-cap span { color: #B4B4BE; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-fig { grid-column: 2; grid-row: 2; position: relative; min-height: 0; min-width: 0; }
.lb-fig img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; animation: fadeIn var(--t-base) var(--ease-std); }
.lb-nav { grid-row: 2; align-self: center; justify-self: center; width: 44px; height: 44px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255, 255, 255, .1); }
.lb-nav:hover { background: rgba(255, 255, 255, .2); }
.lb-prev { grid-column: 1; } .lb-next { grid-column: 3; }
.lb-bar { grid-column: 1 / -1; display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px calc(16px + var(--safe-b)); }
.on-dark { color: var(--ink-on-dark); }
.on-dark:hover { background: rgba(255, 255, 255, .14); }
.lightbox :focus-visible { box-shadow: 0 0 0 2px var(--lb-bg), 0 0 0 4px #fff; }
.lb-bar .btn[aria-pressed=true] { color: #FF86AE; }

/* Thông báo nhỏ */
.toasts { position: fixed; inset: auto 0 calc(20px + var(--safe-b)) 0; margin: 0 auto; width: max-content; max-width: calc(100vw - 24px); background: transparent; border: 0; padding: 0; overflow: visible; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: var(--z-toast); }
.toasts:not(:popover-open) { display: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; border-radius: var(--r-md); background: var(--ink); color: var(--on-ink); font-size: 14px; line-height: 1.4; box-shadow: var(--e3); animation: rise var(--t-base) var(--ease-out); max-width: 480px; }
.toast .ic { flex: none; vertical-align: 0; }
.toast button { border: 0; background: rgba(255, 255, 255, .14); color: inherit; font-weight: 600; font-size: 13px; padding: 6px 10px; border-radius: 8px; min-height: 30px; }
:root[data-theme="dark"] .toast button { background: rgba(0, 0, 0, .12); }
.toast button:hover { background: rgba(255, 255, 255, .24); }
.toast.leave { opacity: 0; transform: translateY(6px); transition: opacity var(--t-base), transform var(--t-base); }

.page-state { display: grid; place-items: center; min-height: 50vh; }

/* ---------- Màn hình vừa (dưới 1200px): chi tiết thành ngăn kéo ---------- */
@media (max-width: 1199px) {
  .studio.has-details { grid-template-columns: var(--panel-left-w) minmax(0, 1fr); }
  .studio.has-details .details, .details { display: block; position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: min(92vw, 340px); z-index: var(--z-drawer); transform: translateX(100%); visibility: hidden; transition: transform var(--t-slow) var(--ease-out), visibility 0s linear var(--t-slow); box-shadow: var(--e3); }
  .studio:not(.has-details) .details { display: none; }
  .studio .details.open { transform: none; visibility: visible; transition: transform var(--t-slow) var(--ease-out); }
  .scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: var(--scrim); z-index: calc(var(--z-drawer) - 1); animation: fadeIn var(--t-base); }
  .work-bar .d-only { display: inline-flex !important; }
  .det-close { display: inline-flex; }
}
@media (min-width: 1200px) { .work-bar .d-only { display: none !important; } .scrim { display: none !important; } }

/* ---------- Điện thoại và máy tính bảng nhỏ (dưới 900px) ---------- */
@media (max-width: 899px) {
  :root { --topbar-h: 52px; --panel-left-w: 100%; }
  html, body { height: auto; }
  .shell { display: block; height: auto; min-height: 100dvh; }
  .topbar { position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); padding: 0 8px 0 14px; }
  .worker .w-t, .top-buy, .top-help { display: none; }
  .rail { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-drawer); flex-direction: row; gap: 0; padding: 0 4px var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b)); border-right: 0; border-top: 1px solid var(--line); }
  .rail button { flex: 1; min-height: var(--tabbar-h); min-width: 0; border-radius: 0; }
  .rail .rail-gap { display: none; }
  .rail .rail-n { right: calc(50% - 22px); }
  .main { overflow: visible; padding-top: var(--topbar-h); padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); min-height: 100dvh; }
  .view { height: auto; }
  .page { padding: 20px 16px 32px; overflow: visible; }
  .page-h h1 { font-size: 24px; }
  .studio, .studio.has-details { display: block; }
  .setup { border-right: 0; background: var(--bg); }
  .setup-scroll { overflow: visible; padding: 0 0 calc(var(--gobar-h) + 24px); }
  .step { background: var(--surface); margin: 8px 0 0; padding: 4px 16px 8px; }
  .step + .step { border-top: 0; }
  .step-toggle { min-height: 48px; }
  .go-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: calc(var(--z-drawer) - 2); height: var(--gobar-h); padding: 8px 12px; display: flex; align-items: center; border-top: 1px solid var(--line); }
  .go-row { flex-direction: row; align-items: center; gap: 12px; width: 100%; }
  .go-info { order: 1; flex: 1; min-width: 0; min-height: 0; }
  .go-info strong, .go-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn--go { order: 2; width: auto; min-width: 132px; min-height: 48px; padding: 0 18px; flex: none; }
  .go-kbd { display: none; }
  .go-bar .go-err { position: absolute; left: 12px; right: 12px; bottom: calc(100% + 6px); margin: 0; box-shadow: var(--e2); }
  .studio[data-m=setup] .work, .studio[data-m=setup] .details { display: none !important; }
  .studio[data-m=stage] .setup { display: none; }
  .studio[data-m=stage] .work { min-height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--safe-b)); }
  .work-bar { position: sticky; top: var(--topbar-h); z-index: 6; background: var(--sunken); padding: 8px 12px; }
  .work-bar .m-only { display: inline-flex; }
  .m-only-flex { display: inline-flex; }
  .det-close { display: inline-flex; }
  .stage-area { height: min(64dvh, 600px); flex: none; padding: 4px 16px 12px; }
  .stage-area.flow { height: auto; min-height: 40dvh; padding: 8px 16px 24px; }
  .step-body { padding-left: 0; }
  .stage-foot { padding: 0 12px 12px; }
  .strip-wrap { padding: 8px 12px; }
  .studio .details, .studio.has-details .details { position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 82dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; border-left: 0; transform: translateY(100%); padding: 0 16px calc(24px + var(--safe-b)); z-index: calc(var(--z-drawer) + 2); }
  .studio .details.open { transform: none; }
  .scrim { inset: 0; z-index: calc(var(--z-drawer) + 1); }
  .sheet-grip { display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 8px auto 0; }
  .studio[data-m=setup] .scrim { display: none; }
  .ready-stage { grid-template-columns: 1fr; gap: 12px; }
  .ready-model { max-width: 220px; margin: 0 auto; }
  .pins, .pins.l { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; }
  .empty-trio { grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr) 28px minmax(0, 1fr); }
  .acc-grid { grid-template-columns: 1fr; }
  .pay { grid-template-columns: 1fr; }
  .pay-r { border-left: 0; border-top: 1px solid var(--line); border-radius: 0 0 var(--r-lg) var(--r-lg); }
  .pay-l, .pay-r { padding: 20px; }
  dialog.modal--pay { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  dialog.lightbox[open] { grid-template-columns: 0 minmax(0, 1fr) 0; }
  .lb-nav { position: absolute; top: 50%; width: 44px; height: 44px; margin-top: -22px; z-index: 3; background: rgba(0, 0, 0, .45); }
  .lb-prev { left: 8px; } .lb-next { right: 8px; }
  .lb-bar .btn span { display: none; }
  .lb-bar .btn { min-width: 44px; padding: 0 12px; }
  .lb-bar #lbDl span { display: inline; }
  .bulk { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); left: 12px; right: 12px; transform: none; justify-content: space-between; }
  .toasts { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }
  .studio[data-m=setup] ~ .toasts { bottom: calc(var(--tabbar-h) + var(--gobar-h) + var(--safe-b) + 12px); }
  .pop { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 8px); width: auto; }
}
@media (max-width: 899px), (pointer: coarse) {
  :root { --btn-h: 44px; --btn-h-sm: 44px; }
  .chip { min-height: 44px; padding: 0 14px; }
  .chips-sm .chip { min-height: 40px; }
  .seg > button { min-height: 40px; }
  .input, .textarea, .select { min-height: 44px; font-size: 16px; }
  .g-name, .g-type { min-height: 40px; font-size: 16px; }
  .step-toggle { min-height: 48px; }
  .link-btn { min-height: 44px; display: inline-flex; align-items: center; }
  .card-check, .card-fav { width: 40px; height: 40px; opacity: 1; }
  .lib-tools .select { min-height: 44px; }
  .tabs button { min-height: 44px; }
  .quota-chip { min-height: 40px; }
}
@media (max-width: 480px) {
  .model-row { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .ratio-row { gap: 6px; }
  .exp-grid { grid-template-columns: 1fr 1fr; }
  .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .mdl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .guide-grid { grid-template-columns: 1fr; }
  .page-h { align-items: flex-start; }
  .step-sum { max-width: 110px; }
  .big-n { font-size: 48px; }
  .code-box code { font-size: 20px; }
  .dz-actions .link-btn { margin-left: 0; }
  .btn--go { min-width: 116px; padding: 0 14px; }
}
@media (hover: none) { .card:hover .card-img img { transform: none; } }
