@font-face { font-family: 'IRANSansX'; src: url('/fonts/IRANSansXFaNum-Regular.ttf'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IRANSansX'; src: url('/fonts/IRANSansXFaNum-Medium.ttf'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'IRANSansX'; src: url('/fonts/IRANSansXFaNum-Bold.ttf'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Dibaj'; src: url('/fonts/DibajFaNum-MediumContrastExtraBold.ttf'); font-weight: 800; font-display: swap; }

:root {
  --red: #DA0826;
  --red-dark: #b0061e;
  --yellow: #F7D21B;
  --ink: #16161a;
  --muted: #6b6b75;
  --line: #e7e7ea;
  --bg: #f6f6f7;
  --card: #ffffff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IRANSansX', Tahoma, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(circle, #e9e9ec 9px, transparent 9.5px);
  background-size: 36px 36px;
  min-height: 100vh;
}
.hidden { display: none !important; }
h1, h2 { font-family: 'Dibaj', 'IRANSansX', sans-serif; font-weight: 800; margin: 0; }
h2 { font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.err { color: var(--red); font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }

/* buttons & inputs */
.btn { font: inherit; border: 0; border-radius: 10px; padding: 11px 20px; cursor: pointer; font-weight: 700; transition: background .15s, opacity .15s; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--red-dark); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: #c9c9cf; }
.btn.small { padding: 6px 12px; font-size: 13px; font-weight: 500; white-space: nowrap; text-decoration: none; display: inline-block; }
input, textarea {
  font: inherit; width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid rgba(218, 8, 38, .25); border-color: var(--red); }
textarea { min-height: 96px; resize: vertical; line-height: 1.8; }
label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--card); padding: 32px 28px; border-radius: 18px; box-shadow: 0 10px 40px rgba(0,0,0,.08); display: grid; gap: 10px; text-align: center; }
.login-card label { text-align: right; margin-top: 8px; }
.login-logo { width: 110px; margin: 0 auto 4px; }
.login-card h1 { font-size: 24px; margin-bottom: 6px; }

/* layout */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; background: #fff; border-bottom: 3px solid var(--red); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; font-family: 'Dibaj', sans-serif; font-weight: 800; font-size: 20px; }
.brand img { height: 38px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; align-items: start; }
.panel { background: var(--card); border-radius: 18px; padding: 22px; box-shadow: 0 4px 24px rgba(0,0,0,.05); }
#jobsPanel { position: sticky; top: 90px; max-height: calc(100vh - 110px); overflow: auto; }
.step + .step { margin-top: 26px; padding-top: 22px; border-top: 1px dashed var(--line); }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.num { width: 30px; height: 30px; border-radius: 50%; background: var(--red); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }

/* templates */
.templates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.tpl { border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; cursor: pointer; background: #fff; text-align: right; font: inherit; color: inherit; display: flex; flex-direction: column; gap: 8px; transition: border-color .15s, transform .15s; }
.tpl:hover { border-color: #cfcfd5; }
.tpl.active { border-color: var(--red); box-shadow: 0 0 0 3px rgba(218,8,38,.12); }
.tpl .thumb { background: #ececef; border-radius: 10px; overflow: hidden; height: 190px; display: flex; align-items: center; justify-content: center; }
.tpl .thumb img { height: 190px; width: auto; max-width: 100%; object-fit: contain; display: block; }
.tpl b { font-size: 15px; }
.tpl small { color: var(--muted); font-size: 12px; line-height: 1.7; }
.tag { display: inline-block; background: #fff6cc; color: #6b5500; border-radius: 6px; padding: 1px 8px; font-size: 12px; width: fit-content; }

/* upload */
.drop { border: 2px dashed #d3d3d9; border-radius: var(--radius); padding: 30px 16px; display: grid; gap: 6px; text-align: center; cursor: pointer; background: #fcfcfd; transition: border-color .15s, background .15s; margin: 0; }
.drop:hover, .drop.over { border-color: var(--red); background: #fff6f7; }
.drop-title { font-weight: 700; }
.upload-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.bar { height: 6px; background: #eee; border-radius: 4px; overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }
.bar.done i { background: #1e9e5a; }
video#player { width: 100%; max-height: 360px; background: #000; border-radius: 12px; margin-top: 12px; }
.trim { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.inline { display: flex; gap: 6px; }
.inline input { direction: ltr; text-align: center; }

/* fields */
.fields { display: grid; gap: 14px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .count { float: left; color: var(--muted); font-size: 12px; font-weight: 400; }
.field.check label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.field.check input { width: auto; }
.actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 16px; flex-wrap: wrap; }
.preview { margin-top: 16px; }
.preview img { max-width: 100%; max-height: 520px; border-radius: 12px; display: block; margin: 0 auto; box-shadow: 0 4px 20px rgba(0,0,0,.12); }

/* jobs */
.jobs { display: grid; gap: 12px; }
.job { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 8px; }
.job-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.job-title { font-weight: 700; line-height: 1.6; }
.job-meta { color: var(--muted); font-size: 12px; }
.chip { font-size: 12px; border-radius: 20px; padding: 2px 10px; white-space: nowrap; flex: none; }
.chip.queued { background: #eef0f4; color: #4a4f5c; }
.chip.rendering { background: #fff3c4; color: #6b5500; }
.chip.done { background: #dff5e9; color: #146c3e; }
.chip.error { background: #fde3e6; color: var(--red-dark); }
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.job-err { color: var(--red-dark); font-size: 12px; direction: ltr; text-align: left; word-break: break-word; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

dialog { border: 0; border-radius: 16px; padding: 14px; max-width: min(92vw, 900px); background: #111; }
dialog::backdrop { background: rgba(0,0,0,.7); }
dialog video { max-width: 100%; max-height: 80vh; display: block; margin-bottom: 10px; }

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; padding: 16px; }
  #jobsPanel { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .templates { grid-template-columns: 1fr; }
  .tpl { flex-direction: row; align-items: center; }
  .tpl .thumb { height: 110px; width: 110px; flex: none; }
  .tpl .thumb img { height: 110px; }
  .trim { grid-template-columns: 1fr; }
  .top { padding: 12px 16px; }
  .panel { padding: 16px; }
}

/* font size control */
.size-ctl { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.size-ctl input { width: 64px; padding: 5px 6px; text-align: center; direction: ltr; }
.size-ctl .step { width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font: inherit; font-size: 16px; line-height: 1; color: var(--ink); }
.size-ctl .step:hover { border-color: var(--red); color: var(--red); }
.size-ctl .reset { border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px; text-decoration: underline; padding: 0 4px; }
