/* Trislee Digital – Trình chỉnh sửa ảnh. Dùng token của app.css, luôn ở giao diện tối. */
.ed-header-inner { padding: 0 16px; }

.editor {
  --stage: #070B14;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr) auto;
  height: calc(100vh - 61px); height: calc(100dvh - 61px); min-height: 560px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.ed-top { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); min-width: 0; }
.ed-top h1 { font-size: 15px; font-weight: 700; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-top h1 .hl { color: var(--accent); }
.ed-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.ed-export { min-height: 36px; padding: 6px 14px; font-size: 14px; }

/* ---------- Nút thanh công cụ ---------- */
.tb { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--fg); font-size: 13.5px; font-weight: 500; white-space: nowrap; transition: border-color .15s, background-color .15s, color .15s, opacity .15s; touch-action: manipulation; }
.tb svg { width: 16px; height: 16px; }
.tb:hover:not(:disabled) { border-color: var(--border-strong); background: color-mix(in srgb, var(--fg) 8%, var(--surface-2)); }
.tb:disabled { opacity: .4; cursor: not-allowed; }
.tb-icon { width: 36px; padding: 0; }
.tb-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.tb-accent { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); color: var(--accent-hover); }
.tb-block { width: 100%; margin-top: 8px; }
.tb.is-on { background: var(--info-bg); border-color: var(--secondary); color: var(--secondary); }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
@media (pointer: coarse) { .tb { min-height: 44px; } .tb-icon { width: 44px; } }

/* ---------- Vùng xem ảnh ---------- */
.ed-stage { grid-column: 1; grid-row: 2; position: relative; display: grid; place-items: center; overflow: hidden; background: var(--stage); min-width: 0; min-height: 0; }
.ed-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; width: calc(100% - 32px); height: calc(100% - 32px); padding: 24px 16px; text-align: center; cursor: pointer; border: 2px dashed var(--border-strong); border-radius: var(--radius); transition: border-color .15s, background-color .15s; }
.ed-empty:hover, .is-over .ed-empty { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.ed-lead { max-width: 56ch; margin-top: 10px; font-size: 14px; color: var(--fg-muted); }
.is-over .ed-stage::after { content: ""; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: var(--radius); pointer-events: none; }
.ed-frame { position: relative; }
.ed-frame canvas { display: block; width: 100%; height: 100%; }
#logoView { position: absolute; pointer-events: none; user-select: none; }
.ed-msg { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; padding: 6px 12px; font-size: 13px; color: var(--fg-muted); background: color-mix(in srgb, var(--surface) 85%, transparent); border-radius: 999px; }
.ed-msg.is-error { position: static; transform: none; color: var(--danger); background: none; max-width: 44ch; text-align: center; }

/* ---------- Khung cắt ---------- */
.crop { position: absolute; inset: 0; touch-action: none; }
.crop-shade { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.crop-shade div { position: absolute; box-shadow: 0 0 0 9999px rgba(4, 7, 13, .62); }
.crop-box {
  position: absolute; cursor: move; outline: 1px solid rgba(255, 255, 255, .9);
  background-image: linear-gradient(rgba(255, 255, 255, .35), rgba(255, 255, 255, .35)), linear-gradient(rgba(255, 255, 255, .35), rgba(255, 255, 255, .35)), linear-gradient(rgba(255, 255, 255, .35), rgba(255, 255, 255, .35)), linear-gradient(rgba(255, 255, 255, .35), rgba(255, 255, 255, .35));
  background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px; background-position: 33.33% 0, 66.66% 0, 0 33.33%, 0 66.66%; background-repeat: no-repeat;
}
.crop-box i { position: absolute; width: 12px; height: 12px; margin: -6px; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.crop-box i::after { content: ""; position: absolute; inset: -10px; }
.crop-box [data-h="nw"] { left: 0; top: 0; cursor: nwse-resize; }
.crop-box [data-h="n"] { left: 50%; top: 0; cursor: ns-resize; }
.crop-box [data-h="ne"] { left: 100%; top: 0; cursor: nesw-resize; }
.crop-box [data-h="e"] { left: 100%; top: 50%; cursor: ew-resize; }
.crop-box [data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.crop-box [data-h="s"] { left: 50%; top: 100%; cursor: ns-resize; }
.crop-box [data-h="sw"] { left: 0; top: 100%; cursor: nesw-resize; }
.crop-box [data-h="w"] { left: 0; top: 50%; cursor: ew-resize; }

/* ---------- Dải ảnh & đồng bộ ---------- */
.ed-strip { grid-column: 1; grid-row: 3; border-top: 1px solid var(--border); min-width: 0; }
.sync { display: flex; align-items: center; gap: 6px; padding: 8px 12px 0; overflow-x: auto; scrollbar-width: none; }
.sync::-webkit-scrollbar { display: none; }
.sync .tb { flex: none; }
.sync-check { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 13px; color: var(--fg-muted); cursor: pointer; padding: 0 4px; min-height: 36px; }
.sync-check input { width: 16px; height: 16px; accent-color: var(--accent); }
.sync-count { margin-left: auto; flex: none; font-size: 13px; color: var(--fg-subtle); font-variant-numeric: tabular-nums; padding-left: 8px; }
.film { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 10px; min-height: 88px; scrollbar-width: thin; }
.th { position: relative; flex: none; height: 68px; min-width: 40px; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--surface-2); opacity: .7; outline: 2px solid transparent; outline-offset: -2px; transition: opacity .15s; }
.th canvas { display: block; height: 100%; width: auto; }
.th:hover { opacity: 1; }
.th[aria-selected="true"] { opacity: 1; outline-color: var(--secondary); }
.th.is-current { opacity: 1; outline-color: #fff; }
.th-x { position: absolute; top: 3px; right: 3px; display: none; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .7); color: #fff; font-size: 14px; line-height: 1; }
.th:hover .th-x, .th.is-current .th-x { display: grid; }
.th-dot { position: absolute; left: 4px; bottom: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px rgba(0, 0, 0, .55); }
.th .spinner { position: absolute; inset: 0; margin: auto; }
.th.is-error { display: grid; place-items: center; width: 68px; font-size: 11px; font-weight: 700; color: var(--danger); }
.th.is-error canvas { display: none; }

/* ---------- Bảng chỉnh sửa ---------- */
.ed-panel { grid-column: 2; grid-row: 2 / 4; display: flex; flex-direction: column; border-left: 1px solid var(--border); min-height: 0; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--border); flex: none; }
.tabs button { min-height: 44px; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--fg-muted); font-size: 13.5px; font-weight: 600; transition: color .15s, border-color .15s; }
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.tab-panel { flex: 1; overflow-y: auto; padding: 4px 16px 16px; scrollbar-width: thin; }
.tab-panel h3 { margin: 16px 0 8px; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-subtle); }
.tab-panel .help strong { color: var(--fg); }

.sl { margin-bottom: 6px; }
.sl-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.sl-row label { color: var(--fg-muted); }
.sl-row output { color: var(--fg); font-variant-numeric: tabular-nums; }
.editor input[type="range"], .dlg input[type="range"] { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 24px; margin: 0; background: transparent; cursor: pointer; }
.editor input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }
.editor input[type="range"]::-webkit-slider-runnable-track, .dlg input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--track, var(--border-strong)); }
.editor input[type="range"]::-moz-range-track, .dlg input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track, var(--border-strong)); }
.editor input[type="range"]::-webkit-slider-thumb, .dlg input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .5); }
.editor input[type="range"]::-moz-range-thumb, .dlg input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .5); }
.r-temp { --track: linear-gradient(90deg, #3B82F6, #CBD5E1, #F59E0B); }
.r-tint { --track: linear-gradient(90deg, #22C55E, #CBD5E1, #D946EF); }
.r-sat { --track: linear-gradient(90deg, #64748B, #F43F5E); }
@media (pointer: coarse) { .editor input[type="range"] { height: 34px; } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }

.logo-pick { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.logo-thumb { display: grid; place-items: center; width: 72px; height: 72px; flex: none; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2) repeating-conic-gradient(var(--border) 0 25%, transparent 0 50%) 0 0 / 12px 12px; overflow: hidden; }
.logo-thumb img { max-width: 100%; max-height: 100%; }
.logo-on { margin-top: 4px; }
.pos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 132px; margin-bottom: 14px; }
.pos-grid button { height: 32px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); position: relative; }
.pos-grid button::after { content: ""; position: absolute; inset: 0; margin: auto; width: 8px; height: 8px; border-radius: 2px; background: var(--fg-subtle); }
.pos-grid button:hover { border-color: var(--border-strong); }
.pos-grid button[aria-pressed="true"] { border-color: var(--accent); background: var(--success-bg); }
.pos-grid button[aria-pressed="true"]::after { background: var(--accent); }

/* ---------- Hộp thoại xuất ---------- */
.dlg { width: min(480px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(4, 7, 13, .65); }
.dlg h2 { font-size: 1.125rem; font-weight: 700; margin-bottom: 16px; }
.dlg .field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg input[type="text"] { width: 100%; min-height: 44px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 16px; }
.dlg input[type="text"]:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.x-progress { display: grid; gap: 6px; margin-top: 12px; font-size: 13px; color: var(--fg-muted); }
.x-progress progress { width: 100%; height: 8px; accent-color: var(--accent); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Màn hình hẹp: xếp dọc ---------- */
@media (max-width: 900px) {
  .editor { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 46vh auto auto; height: auto; min-height: 0; }
  .ed-panel { grid-column: 1; grid-row: 4; border-left: 0; border-top: 1px solid var(--border); }
  .tab-panel { overflow: visible; }
  .ed-actions .tb span, .ed-top h1 { display: none; }
  .ed-actions { flex: 1; justify-content: flex-end; }
}
@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; gap: 0; }
  /* Điện thoại không chọn được cả thư mục, bỏ nút để thanh công cụ vừa một hàng */
  #addDirBtn, .tb-sep { display: none; }
  .ed-actions { gap: 4px; }
}
