:root {
  --paper: #f6eedc;
  --paper-2: #efe3c6;
  --ink: #3a2418;
  --ink-soft: #6b5446;
  --yellow: #f2c14e;
  --green: #4f8a5b;
  --red: #b5432f;
  --blue: #3f6e8c;
  --card: #fffaf0;
  --radius: 14px;
  --shadow: 0 4px 0 var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
a { color: var(--blue); }
code { background: var(--paper-2); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--ink-soft); }
.err { color: var(--red); min-height: 1.2em; margin: .5em 0 0; }
.hint { color: var(--ink-soft); font-size: .85rem; margin: .3em 0 1em; }

.card { background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px; }
.btn { font: inherit; font-weight: 600; border: 2.5px solid var(--ink); border-radius: 10px; padding: 7px 14px; background: var(--card); color: var(--ink); cursor: pointer; box-shadow: 0 3px 0 var(--ink); transition: transform .05s; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--yellow); }
.btn.danger { background: #f3d2c8; }
.btn.ghost { box-shadow: none; border-color: transparent; background: transparent; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.chip { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--paper-2); border: 1.5px solid var(--ink); vertical-align: middle; }

input, select, textarea { font: inherit; color: var(--ink); width: 100%; border: 2px solid var(--ink); border-radius: 9px; padding: 7px 10px; background: #fff; margin-top: 4px; }
textarea { font-size: 16px; line-height: 1.7; resize: vertical; font-family: "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, system-ui, sans-serif; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 500; padding-top: 22px; }
label.check.inline { padding-top: 0; margin: 0; }
label.check input { width: auto; margin: 0; }
.grid2, .grid3, .grid4 { display: grid; gap: 0 16px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1.4fr 1fr 1fr; }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.advanced { margin: 4px 0 14px; }
.advanced summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }
.actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card input { margin: 10px 0 14px; }

/* layout */
.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 22px; border-bottom: 2.5px solid var(--ink); background: var(--yellow); }
.brand { font-weight: 800; font-size: 1.15rem; }
.top-right { display: flex; gap: 12px; align-items: center; }
.banner { background: #f3d2c8; border-bottom: 2px solid var(--ink); padding: 8px 22px; font-size: .9rem; }
.layout { display: grid; grid-template-columns: 280px 1fr; gap: 22px; padding: 22px; max-width: 1400px; margin: 0 auto; }
.sidebar { position: sticky; top: 16px; align-self: start; }
.job-list { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 160px); overflow: auto; }
.job-list li { background: var(--card); border: 2px solid var(--ink); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.job-list li.active { background: #fff3c4; }
.job-list .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-list .s { font-size: .8rem; color: var(--ink-soft); display: flex; justify-content: space-between; gap: 6px; }

.status { font-size: .75rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1.5px solid var(--ink); white-space: nowrap; }
.status.draft { background: #fff; }
.status.queued { background: #dfe9f1; }
.status.running { background: var(--yellow); }
.status.done { background: #cfe5cf; }
.status.failed { background: #f3d2c8; }
.status.cancelled { background: #e6e0d4; }

/* job view */
.job-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.job-head h2 { margin: 0 0 4px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0; }
.kv div { background: var(--paper-2); border-radius: 10px; padding: 8px 10px; }
.kv b { display: block; font-size: 1.15rem; }
.kv span { font-size: .78rem; color: var(--ink-soft); }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; gap: 10px; align-items: center; padding: 5px 0; border-bottom: 1px dashed #d7c8a6; }
.steps li:last-child { border: 0; }
.steps .ico { width: 22px; text-align: center; }
.steps .ms { margin-left: auto; font-size: .8rem; color: var(--ink-soft); }
.progress { margin-top: 10px; font-weight: 600; }
.warn { background: #fff3c4; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; margin: 10px 0; font-size: .9rem; }
.error { background: #f3d2c8; border: 2px solid var(--ink); border-radius: 10px; padding: 8px 12px; margin: 10px 0; white-space: pre-wrap; }
.outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.out { border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; background: #fff; }
.out video, .out img { display: block; width: 100%; background: #000; }
.out.portrait video { max-height: 420px; }
.out .meta { padding: 8px 10px; display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: .88rem; }
.out .cap { padding: 0 10px 10px; direction: rtl; font-size: .92rem; }
.out .cap b { display: block; }
.previews { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.previews img { width: 100%; border: 2px solid var(--ink); border-radius: 10px; }
pre.log { background: #2b1d14; color: #f6eedc; padding: 12px; border-radius: 10px; max-height: 360px; overflow: auto; font-size: .78rem; white-space: pre-wrap; direction: ltr; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row select { width: auto; margin: 0; }
.chunks { font-size: .85rem; color: var(--ink-soft); direction: rtl; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .sidebar { position: static; }
  .job-list { max-height: 220px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  label.check { padding-top: 0; }
}

.thumbs { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.thumbs figure { margin: 0; max-width: 300px; }
.thumbs img { width: 100%; border: 2px solid var(--ink); border-radius: 10px; display: block; }
.thumbs figcaption { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 13px; }

.writer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 16px; }

.thumbs.small figure { max-width: 200px; }

/* YouTube publishing */
.yt { margin-top: 8px; font-size: .92rem; }
.yt.ok { color: #1f7a3a; }
.yt summary { cursor: pointer; font-weight: 600; }
.ytp { display: grid; gap: 8px; margin-top: 8px; }
.ytp label { display: grid; gap: 4px; font-size: .85rem; }
.ytp .row { align-items: end; flex-wrap: wrap; }
#ytBox { margin-right: 10px; }
