/* Reel Studio design system. Plain CSS, no frameworks. */
@font-face {
  font-family: "Vazirmatn";
  src: local("Vazirmatn"), local("Vazirmatn Regular"), url("../fonts/Vazirmatn[wght].woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #0e1013;
  --bg-2: #13161b;
  --panel: #181c22;
  --panel-2: #1f242c;
  --line: #2a303a;
  --ink: #eceff4;
  --ink-2: #aab2c0;
  --ink-3: #7d8796;
  --accent: #f2b134;
  --accent-ink: #1b1403;
  --accent-soft: rgba(242, 177, 52, .14);
  --ok: #4cc38a;
  --warn: #f2b134;
  --bad: #ff6b6b;
  --info: #6cb4ff;
  --violet: #b79cff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font-fa: "Vazirmatn", Tahoma, "Segoe UI", "Noto Naskh Arabic", system-ui, sans-serif;
  --font-ui: var(--font-fa);
  --flip: 1; /* 1 in RTL, -1 in LTR: used where a transform cannot be logical */
  --side: 248px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f1ea; --bg-2: #ece8de; --panel: #fffdf8; --panel-2: #f6f2e8; --line: #ddd6c6;
    --ink: #1b1d22; --ink-2: #4a505c; --ink-3: #6b7280; --accent: #b7791f; --accent-ink: #fff;
    --accent-soft: rgba(183, 121, 31, .12); --ok: #1f8a5b; --warn: #a76a00; --bad: #c0392b; --info: #1f6fb5;
    --violet: #6a4fc4; --shadow: 0 10px 30px rgba(60, 50, 30, .12); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.8 var(--font-ui); letter-spacing: 0;
  overflow-wrap: anywhere; font-feature-settings: "kern", "liga";
}
img, video, audio { max-width: 100%; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.5; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--ink-2); } .faint { color: var(--ink-3); } .small { font-size: .85rem; }
.skip { position: absolute; inset-inline-start: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { inset-inline-start: 8px; top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a:focus-visible { border-radius: 4px; }   /* inputs and buttons keep their own radius when focused */

/* Persian / RTL content */
.fa, [dir="rtl"], textarea.fa, input.fa { font-family: var(--font-fa); }
[dir="auto"] { unicode-bidi: plaintext; }
/* Inherently LTR values (email, address, password, number): typed text is LTR, the Persian placeholder stays on the right. */
input[dir="ltr"], textarea[dir="ltr"] { text-align: start; }
input[dir="ltr"]:placeholder-shown { direction: rtl; }
input[dir="ltr"]:not(:placeholder-shown) { direction: ltr; text-align: end; }
bdi { unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
textarea[dir="auto"], input[dir="auto"] { font-family: var(--font-fa), var(--font-ui); }
.fa-text { direction: rtl; text-align: start; font-family: var(--font-fa); line-height: 2; }

/* Shell */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  background: var(--bg-2); border-inline-end: 1px solid var(--line); padding: 18px 14px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 800; font-size: 1.1rem; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; position: relative;
}
.brand .mark::after { content: ""; position: absolute; inset: 4px; border: 2px solid var(--accent-ink); border-radius: 3px; opacity: .35; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--ink-2);
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--panel); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav .num { width: 22px; height: 22px; flex: none; border-radius: 5px; background: var(--panel-2); font-size: .75rem; display: grid; place-items: center; color: var(--ink-3); }
.nav a[aria-current="page"] .num { background: var(--accent); color: var(--accent-ink); }
.side .grow { flex: 1; }
.main { min-width: 0; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 12px clamp(14px, 3vw, 28px); border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.top .grow { flex: 1; }
.top > * { min-width: 0; }
.menu-btn { display: none; }
.page { padding: clamp(14px, 3vw, 28px); max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .grow { flex: 1; min-width: min(220px, 100%); }

/* Components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .row > .card + .card { margin-top: 0; }   /* the sibling gap only applies to stacked cards, not grid or row items */
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

button, .btn {
  font: inherit; font-weight: 600; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2);
  color: var(--ink); padding: 8px 14px; cursor: pointer; min-height: 38px; text-decoration: none; display: inline-flex;
  align-items: center; gap: 8px; justify-content: center;
}
button:hover, .btn:hover { border-color: var(--ink-3); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
button.ghost { background: transparent; }
button.small, .btn.small { min-height: 30px; padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; min-height: 40px;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.7; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.field { margin-bottom: 14px; }
.hint { font-size: .8rem; color: var(--ink-3); margin-top: 4px; }
.err-text { color: var(--bad); font-size: .85rem; margin-top: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; background: var(--panel-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.draft { color: var(--ink-2); }
.badge.processing { color: var(--info); } .badge.processing::before { animation: pulse 1.2s infinite; }
.badge.completed, .badge.ready, .badge.connected, .badge.pass { color: var(--ok); }
.badge.failed, .badge.fail, .badge.unavailable { color: var(--bad); }
.badge.published { color: var(--violet); }
.badge.warn, .badge.manual, .badge.awaiting_credentials, .badge.not_connected, .badge.awaiting_clip { color: var(--warn); }
@keyframes pulse { 50% { opacity: .25; } }

.progress { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

.alert { border-radius: var(--radius-sm); padding: 11px 14px; border: 1px solid var(--line); background: var(--panel-2); margin-bottom: 14px; }
.alert.warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); background: color-mix(in srgb, var(--warn) 9%, var(--panel)); }
.alert.bad { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); background: color-mix(in srgb, var(--bad) 9%, var(--panel)); }
.alert.ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); background: color-mix(in srgb, var(--ok) 9%, var(--panel)); }
.alert.info { border-color: color-mix(in srgb, var(--info) 55%, var(--line)); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 20px; scrollbar-width: thin; }
.tabs a {
  padding: 10px 14px; color: var(--ink-2); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent;
  font-weight: 600; margin-bottom: -1px; display: flex; gap: 8px; align-items: center;
}
.tabs a[aria-current="step"] { color: var(--accent); border-color: var(--accent); }
.tabs { scroll-snap-type: inline proximity; } .tabs a { scroll-snap-align: center; }
.tabs a .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.tabs a .dot.done { background: var(--ok); }

/* Project cards */
.pcard { display: flex; flex-direction: column; overflow: hidden; padding: 0; text-decoration: none; color: inherit; }
.pcard:hover { border-color: var(--ink-3); }
.pcard .thumb {
  aspect-ratio: 16 / 10; background: repeating-linear-gradient(135deg, var(--panel-2) 0 12px, var(--bg-2) 12px 24px);
  display: grid; place-items: center; color: var(--ink-3); font-size: .85rem; position: relative; overflow: hidden;
}
.pcard .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.pcard .body { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.pcard .title { font-weight: 700; font-size: 1.02rem; }
.chip { font-size: .78rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; color: var(--ink-2); }

/* Timeline */
.timeline { display: flex; gap: 3px; height: 54px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px; overflow-x: auto; }
.timeline button {
  min-width: 36px; height: 100%; padding: 0 6px; font-size: .75rem; border-radius: 4px; flex-shrink: 0; flex-grow: 0;
  background: var(--panel-2); position: relative; overflow: hidden; justify-content: flex-start;
}
.timeline button.ready { background: color-mix(in srgb, var(--ok) 25%, var(--panel-2)); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.timeline button.locked::after { content: "🔒"; font-size: .7rem; position: absolute; inset-inline-end: 3px; bottom: 1px; }

/* Scene cards */
.scene { border-inline-start: 4px solid var(--line); scroll-margin-top: 80px; }
.scene.ready { border-inline-start-color: var(--ok); }
.scene.locked { border-inline-start-color: var(--violet); }
.scene .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.scene .num { font-weight: 800; font-size: 1.05rem; width: 32px; height: 32px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.scene .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 300px); gap: 18px; }
.prompt-box { background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 10px; font-size: .85rem; white-space: pre-wrap; text-align: start; position: relative; overflow-wrap: anywhere; }
.prompt-box.fa-text { direction: rtl; }
.preview-9x16 { aspect-ratio: 9 / 16; width: 100%; max-height: 420px; background: #000; border-radius: var(--radius-sm); border: 1px solid var(--line); object-fit: contain; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--ink-2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

.qc li { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.qc { list-style: none; margin: 0; padding: 0; }
.qc .detail { color: var(--ink-3); font-size: .85rem; }

.job-tray { position: relative; }
.job-pop { position: absolute; top: 44px; inset-inline-end: 0; width: min(320px, calc(100vw - 28px)); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); z-index: 30; }

.toasts { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); inset-inline-end: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: var(--panel); border: 1px solid var(--line); border-inline-start: 4px solid var(--info); border-radius: var(--radius-sm); padding: 10px 14px; box-shadow: var(--shadow); }
.toast.ok { border-inline-start-color: var(--ok); } .toast.bad { border-inline-start-color: var(--bad); }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-3); font-weight: 600; font-size: .82rem; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.table-wrap table { min-width: 460px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(420px, 100%); }
.empty { text-align: center; padding: 42px 16px; color: var(--ink-2); border: 1px dashed var(--line); border-radius: var(--radius); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.saved-ind { font-size: .8rem; color: var(--ink-3); min-width: 70px; }

/* Responsive. Three breakpoints: 1100 (narrow desktop / tablet landscape), 820 (tablet portrait: sidebar becomes a drawer), 540 (phone). */
@media (max-width: 1100px) {
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scene .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: min(290px, 86vw); height: 100dvh; z-index: 60;
    transform: translateX(calc(102% * var(--flip))); transition: transform .2s, visibility .2s; box-shadow: var(--shadow); visibility: hidden;
  }
  body.nav-open .side { transform: none; visibility: visible; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 55; }
  .menu-btn { display: inline-flex; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .job-pop { position: fixed; inset-inline: 14px; top: 58px; width: auto; }
  input, textarea, select { font-size: 16px; }  /* stops iOS from zooming into fields */
}
@media (max-width: 540px) {
  h1 { font-size: 1.4rem; }
  .grid.auto { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 14px; }
  .page-head > .btn, .page-head > button { flex: 1 1 auto; }
  .row > .field { flex: 1 1 100%; }
  .row > .field :is(.w-xs, .w-sm, .w-md) { max-width: none; }
  dialog { padding: 16px; }
  .toasts { inset-inline: 14px; max-width: none; }
  /* Tables turn into stacked cards instead of scrolling sideways. */
  .table-wrap table.stack-sm { min-width: 0; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm thead { display: none; }
  table.stack-sm tr { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; margin-bottom: 8px; }
  table.stack-sm td { border: 0; padding: 3px 0; }
  table.stack-sm td[data-label]:not([data-label=""]) { display: flex; gap: 10px; justify-content: space-between; }
  table.stack-sm td[data-label]:not([data-label=""])::before { content: attr(data-label); color: var(--ink-3); font-size: .82rem; flex: none; }
}
/* Touch targets */
@media (pointer: coarse) {
  button, .btn { min-height: 44px; }
  button.small, .btn.small { min-height: 40px; }
  .nav a { padding-block: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Big option buttons inside a choice dialog */
button.choice { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; padding: 12px 14px; text-align: start; }
button.choice:hover { border-color: var(--accent); background: var(--accent-soft); }
.kind-badge { font-size: .78rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); }
.kind-badge.image { color: var(--info); }

/* Small form helpers: widths without inline styles, so phones can override them */
input.check { width: auto; min-height: 0; flex: none; }
.w-xs { max-width: 120px; } .w-sm { max-width: 200px; } .w-md { max-width: 260px; }
@media (pointer: coarse) { input.check { width: 22px; height: 22px; } }
/* A checkbox and its text stay on one line; long text wraps beside the box instead of under it */
label.row:has(> input.check) { flex-wrap: nowrap; align-items: flex-start; }
label.row:has(> input.check) > strong, label.row:has(> input.check) > span { flex: 1; min-width: 0; }

/* Sign-in (phone + one-time code) */
.login-card { width: min(420px, 100%); }
button.block { width: 100%; }
.phone-row { display: flex; gap: 8px; align-items: stretch; direction: ltr; }   /* a phone number reads left to right: +98 on the left */
.phone-row input[dir="ltr"], .phone-row input[dir="ltr"]:placeholder-shown, .phone-row input[dir="ltr"]:not(:placeholder-shown) { flex: 1; min-width: 0; direction: ltr; text-align: left; }
.phone-prefix { display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); color: var(--ink-2); font-weight: 600; }
.otp-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; padding-inline-start: .5em; font-variant-numeric: tabular-nums; }
.otp-input::placeholder { letter-spacing: .3em; color: var(--ink-3); }

/* Profile and the account link in the sidebar */
.profile-head { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.avatar-lg { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; flex: none; border: 1px solid var(--line); }
.empty-avatar { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 2.2rem; font-weight: 800; }
.me-link { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: var(--radius-sm); text-decoration: none; color: var(--ink); min-width: 0; }
.me-link:hover, .me-link[aria-current="page"] { background: var(--panel); }
.me-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; flex: none; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.completion { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }

/* Picsy pages: text fields align to the right (the reading start of Persian), whatever the typed text's own direction */
#view[data-route="picsy"] :is(input:not(.check):not([type="checkbox"]), textarea) { text-align: right; }

/* Placeholders are Persian: an empty auto-direction field defaults to left-to-right, which would put them on the left. While the
   placeholder shows, the field reads right-to-left; once someone types, dir="auto" takes over again. (Phone/code inputs are dir="ltr" and unaffected.) */
input[dir="auto"]:placeholder-shown, textarea[dir="auto"]:placeholder-shown { direction: rtl; text-align: right; }
