/* ==========================================================================
   editor.css — چیدمان ویرایشگر (موبایل و دسکتاپ)، صحنه‌ی پیش‌نمایش، نوار ابزار
   ========================================================================== */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ---------------- نوار بالا ---------------- */
.ed-top {
  flex: 0 0 auto; height: calc(52px + var(--safe-t)); padding: var(--safe-t) 8px 0; display: flex; align-items: center; gap: 6px;
  background: var(--bg); border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.ed-title { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.25; }
.ed-title button { font-size: 14px; font-weight: 800; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 2px 8px; border-radius: 8px; }
.ed-title button:hover { background: rgba(255,255,255,0.06); }
.ed-sub { font-size: 10.5px; color: var(--tx3); display: flex; align-items: center; gap: 4px; }
.ed-sub .dot { width: 5px; height: 5px; background: var(--ok); }
.ed-sub.saving .dot { background: var(--warn); }
.ed-top .btn.pri { min-height: 36px; padding: 0 16px; border-radius: 11px; font-size: 13.5px; }
.ed-top-desk { display: none; align-items: center; gap: 4px; }
.res-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--tx2); padding: 0 8px; height: 30px; border-radius: 9px; background: rgba(255,255,255,0.05); }

/* ---------------- میانه ---------------- */
.ed-main { flex: 1 1 auto; min-height: 0; display: flex; position: relative; }
.ed-center { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; position: relative; }
.ed-assets, .ed-inspector { display: none; }

/* صحنه‌ی پیش‌نمایش */
.stage {
  flex: 1 1 auto; min-height: 120px; position: relative; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #121219 0%, #08080c 70%); overflow: hidden; touch-action: none;
}
.stage-box { position: relative; background: #000; box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 20px 50px -20px rgba(0,0,0,0.8); }
.stage-box canvas { width: 100%; height: 100%; }
.stage-ov { position: absolute; inset: 0; pointer-events: none; }
.stage-ov > * { pointer-events: auto; }
.stage-wait { position: absolute; top: 10px; left: 10px; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.stage-wait.on { opacity: 1; }
.stage-badge { position: absolute; top: 10px; right: 10px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: rgba(0,0,0,0.55); color: #fff; pointer-events: none; }

/* کادر انتخاب روی پیش‌نمایش */
.selbox { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; }
.selbox .frame { position: absolute; inset: -1px; border: 1.5px solid #fff; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,0.35), 0 0 18px rgba(124,92,255,0.35); }
.selbox .hdl {
  position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: #fff; color: #111;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,0.5); pointer-events: auto; touch-action: none;
}
.selbox .hdl .ic { width: 15px; height: 15px; stroke-width: 2.4; }
.selbox .hdl.tl { left: 0; top: 0; }
.selbox .hdl.tr { left: 100%; top: 0; }
.selbox .hdl.bl { left: 0; top: 100%; }
.selbox .hdl.br { left: 100%; top: 100%; background: var(--ac); color: #fff; }
.selbox .hdl.del { background: #fff; color: #e11d48; }
.guide { position: absolute; background: #ff3d9a; pointer-events: none; opacity: 0; transition: opacity 0.12s; box-shadow: 0 0 6px rgba(255,61,154,0.8); }
.guide.v { top: 0; bottom: 0; width: 1px; left: 50%; }
.guide.h { left: 0; right: 0; height: 1px; top: 50%; }
.guide.on { opacity: 1; }
.safe-zones { position: absolute; inset: 0; pointer-events: none; }
.safe-zones i { position: absolute; border: 1px dashed rgba(255,255,255,0.35); border-radius: 6px; }
.grid-lines { position: absolute; inset: 0; pointer-events: none; background-image: linear-gradient(rgba(255,255,255,0.18) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.18) 1px, transparent 1px); background-size: 33.333% 33.333%; background-position: -1px -1px; }

/* حالت خالی */
.stage-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; }
.add-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 26px 30px; border-radius: 24px;
  border: 1.5px dashed rgba(255,255,255,0.18); background: rgba(255,255,255,0.03); color: var(--tx2); text-align: center; max-width: 320px;
}
.add-card .plus { width: 58px; height: 58px; border-radius: 18px; background: var(--grad); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: var(--sh-ac); }
.add-card b { color: var(--tx); font-size: 15px; }
.add-card span { font-size: 12.5px; }

/* ---------------- کنترل پخش ---------------- */
.transport { flex: 0 0 auto; height: 46px; display: flex; align-items: center; gap: 4px; padding: 0 8px; background: var(--bg); border-top: 1px solid var(--line); direction: ltr; }
.transport .time { font-size: 12.5px; font-weight: 700; color: var(--tx); direction: ltr; min-width: 96px; text-align: left; font-feature-settings: "tnum" 1; }
.transport .time span { color: var(--tx3); font-weight: 600; }
.transport .spacer { flex: 1; }
.play-btn { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--tx); }
.play-btn .ic { width: 26px; height: 26px; }
.play-btn:active { transform: scale(0.9); }
.kf-btn.has { color: var(--warn); }
.kf-btn.on { color: #fff; background: rgba(251,191,36,0.2); }

/* ---------------- پایین: خط زمان و ابزارها ---------------- */
.ed-bottom { flex: 0 0 auto; display: flex; flex-direction: column; background: var(--bg1); border-top: 1px solid var(--line); position: relative; }
.tl-wrap { height: clamp(176px, 31vh, 300px); position: relative; }
.tools {
  flex: 0 0 auto; height: calc(70px + var(--safe-b)); padding-bottom: var(--safe-b); display: flex; align-items: stretch;
  background: var(--bg); border-top: 1px solid var(--line); position: relative;
}
.tools-back { flex: 0 0 auto; width: 52px; display: flex; align-items: center; justify-content: center; border-left: 1px solid var(--line); color: var(--tx2); }
.tools-list { flex: 1 1 auto; display: flex; align-items: stretch; gap: 2px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
.tools-list::-webkit-scrollbar { display: none; }
.tool {
  flex: 0 0 auto; min-width: 62px; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  color: var(--tx2); font-size: 11px; font-weight: 600; border-radius: 12px; position: relative; transition: color 0.15s, background 0.15s;
}
.tool .ic { width: 23px; height: 23px; color: var(--tx); stroke-width: 1.7; }
.tool:active { background: rgba(255,255,255,0.06); }
.tool.on { color: var(--tx); }
.tool.on::after { content: ""; position: absolute; bottom: 3px; width: 4px; height: 4px; border-radius: 50%; background: var(--ac-l); }
.tool .tag { position: absolute; top: 4px; left: 8px; }
.tool.dis { opacity: 0.35; }
.tools-title { flex: 0 0 auto; display: flex; align-items: center; padding: 0 10px; font-size: 12px; font-weight: 800; color: var(--tx); border-left: 1px solid var(--line); white-space: nowrap; }

/* شیت روی بخش پایین می‌نشیند و پیش‌نمایش کوچک‌شده بالای آن کامل دیده می‌شود */
#editor.with-sheet .ed-bottom { flex: 0 0 var(--sheet-h, 50%); overflow: hidden; transition: flex-basis 0.25s var(--ease); }
#editor.with-sheet .ed-bottom > * { visibility: hidden; }
.sheet.ed-sheet { max-height: min(62%, 520px); }
.sheet.ed-sheet.tall { max-height: 82%; }

/* ---------------- تمام‌صفحه ---------------- */
.ed-full .ed-top, .ed-full .ed-bottom, .ed-full .ed-assets, .ed-full .ed-inspector { display: none !important; }
.ed-full .stage { background: #000; }

/* ---------------- حالت افقی/دسکتاپ ---------------- */
@media (min-width: 900px) and (min-height: 560px) {
  .ed-top { height: 56px; padding: 0 12px; }
  .ed-title { align-items: flex-start; }
  .ed-top-desk { display: flex; }
  .ed-assets, .ed-inspector { display: flex; flex-direction: column; flex: 0 0 auto; background: var(--bg1); min-height: 0; }
  .ed-assets { width: clamp(300px, 26vw, 400px); border-left: 1px solid var(--line); flex-direction: row; }
  .ed-inspector { width: clamp(280px, 22vw, 340px); border-right: 1px solid var(--line); }
  .tools { display: none; }
  .transport { height: 48px; justify-content: center; }
  .transport .m-only { display: none; }
  .tl-wrap { height: clamp(220px, 34vh, 420px); }
  .stage { padding: 18px; }
}
@media (max-width: 899px), (max-height: 559px) {
  .d-only { display: none !important; }
}
@media (min-width: 900px) and (min-height: 560px) {
  .m-only { display: none !important; }
}

/* ریل و پنل دارایی‌ها (دسکتاپ) */
.rail { width: 74px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; border-left: 1px solid var(--line); overflow-y: auto; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 2px; border-radius: 12px; font-size: 10.5px; font-weight: 700; color: var(--tx3); }
.rail button .ic { color: var(--tx2); }
.rail button.on { background: var(--ac-soft); color: var(--tx); }
.rail button.on .ic { color: var(--ac-l); }
.rail button:hover { color: var(--tx); }
.asset-pane { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.pane-head { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 14px; font-size: 14px; font-weight: 800; border-bottom: 1px solid var(--line); }
.pane-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 14px 18px; }
.pane-body.nopad { padding: 0 0 12px; }
.insp-empty { padding: 26px 18px; color: var(--tx3); text-align: center; font-size: 13px; }
.insp-tabs { flex: 0 0 auto; display: flex; gap: 2px; padding: 8px 8px 0; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.insp-tabs button { height: 34px; padding: 0 10px; border-radius: 10px 10px 0 0; font-size: 12.5px; font-weight: 700; color: var(--tx3); display: inline-flex; align-items: center; gap: 6px; }
.insp-tabs button.on { color: var(--tx); background: var(--bg3); }
.insp-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 4px; }
.insp-head .sw { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; flex: 0 0 auto; }
.insp-head b { font-size: 14px; }
.insp-head small { display: block; color: var(--tx3); font-size: 11.5px; }

/* بخش‌های داخل پنل‌ها */
.sec { padding: 6px 0 10px; }
.sec + .sec { border-top: 1px solid var(--line); }
.sec-t { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 800; color: var(--tx); margin: 4px 0 8px; gap: 8px; }
.sec-t .act { font-size: 12px; font-weight: 700; color: var(--ac-l); }
.kv { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; font-size: 13px; }
.kv > span { color: var(--tx2); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 0; min-width: 0; }
.grid-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid-actions button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px; background: rgba(255,255,255,0.04); border: 1px solid var(--line); font-size: 11.5px; color: var(--tx2); font-weight: 600; }
.grid-actions button .ic { color: var(--tx); }
.grid-actions button.on { border-color: var(--ac); background: var(--ac-soft); color: var(--tx); }
.grid-actions button:active { transform: scale(0.96); }
