/* ---------------------------------------------------------------------------
 * styles.css — one system, light and dark, RTL-first.
 *
 * Direction-sensitive properties use logical equivalents throughout
 * (inset-inline-*, border-inline-*, text-align: start/end), so the whole
 * layout mirrors correctly from the <html dir="rtl"> alone. Nothing here
 * hardcodes "left" or "right" except where a value is genuinely physical.
 * ------------------------------------------------------------------------ */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --border:    #dfe3e8;
  --text:      #16191d;
  --text-dim:  #5c6570;
  --text-mute: #8b939d;

  --accent:      #3d5afe;
  --accent-text: #ffffff;
  --accent-soft: #e8ebff;

  --ok:      #12805c;
  --ok-soft: #dff3ec;
  --warn:      #9a6400;
  --warn-soft: #fdf0d5;
  --run:      #1a6fb5;
  --run-soft: #dcecfa;
  --danger:      #c0362c;
  --danger-soft: #fbe4e2;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);

  /* Vazirmatn first if the page loaded it (see the commented <link> in
   * index.html), then the fonts Iranian desktops actually ship. Tahoma is
   * the reliable fallback — it renders Persian correctly on Windows, which
   * most of your users will be on. */
  --font: "Vazirmatn", "IRANSansX", "IRANSans", "Segoe UI", Tahoma,
          system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1216;
    --surface:   #171b21;
    --surface-2: #1e242c;
    --border:    #2a323c;
    --text:      #e8ecf1;
    --text-dim:  #a3adba;
    --text-mute: #6f7a87;

    --accent:      #7c8cff;
    --accent-text: #0f1216;
    --accent-soft: #232a4a;

    --ok:      #4ad3a4;
    --ok-soft: #12312a;
    --warn:      #e0aa4c;
    --warn-soft: #33280f;
    --run:      #63b3ed;
    --run-soft: #14283c;
    --danger:      #f08479;
    --danger-soft: #3a1c19;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is what every show/hide in app.js sets, and the
 * browser implements it as `[hidden] { display: none }` in the UA stylesheet
 * — a single attribute selector, which ANY class selector outranks.
 *
 * So `.auth-screen { display: grid }` silently beat `hidden` and the login
 * screen stayed on top of the app after signing in, and `.stack` did the same
 * to the two auth forms, showing both at once. The bug looks like broken
 * JavaScript and is entirely CSS specificity.
 *
 * This one rule makes `hidden` mean hidden regardless of what any class says.
 * It must stay above every layout rule below. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  /* Persian glyphs sit taller than Latin ones; the extra leading keeps
   * descenders and diacritics from crowding the line below. */
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; line-height: 1.4; font-weight: 700; }
p { margin: 0; }

/* Phone numbers, codes, IDs and arrangement codes are Latin/numeric and
 * must not be reordered by the RTL algorithm. */
.ltr { direction: ltr; text-align: start; unicode-bidi: isolate; }

/* --- primitives --------------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: .55rem 1rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.6;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: .32rem .7rem; font-size: .875rem; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.iconbtn {
  background: none; border: 0; cursor: pointer;
  color: var(--text-dim); font-size: 1.05rem; line-height: 1;
  padding: .4rem; border-radius: 6px;
}
.iconbtn:hover { background: var(--surface-2); color: var(--text); }

.linkbtn {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-size: .875rem;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .5rem .7rem;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select { cursor: pointer; }
::placeholder { color: var(--text-mute); }

input.mini, select.mini {
  padding: .25rem .45rem;
  font-size: .875rem;
  border-radius: 6px;
}
input.num { max-width: 5.5rem; text-align: end; }

.field { display: grid; gap: .3rem; }
.field > span { font-size: .8125rem; font-weight: 700; color: var(--text-dim); }
.field-hint { font-size: .75rem; color: var(--text-mute); line-height: 1.6; }
.opt { font-weight: 400; color: var(--text-mute); }

.stack { display: grid; gap: 1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.pad { padding: 1.5rem; }
.muted { color: var(--text-mute); }
.tiny { font-size: .75rem; }
.strong { font-weight: 700; }
.mono { font-family: var(--mono); font-size: .875rem; }
.num { text-align: end; }
.sub {
  font-size: .8125rem; letter-spacing: .02em;
  color: var(--text-mute); margin-top: .5rem; font-weight: 700;
}

.error-box {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: 8px;
  padding: .6rem .8rem;
  font-size: .875rem;
  line-height: 1.7;
}

.empty {
  grid-column: 1 / -1;
  display: grid;
  gap: .75rem;
  justify-items: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-mute);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* --- auth screen -------------------------------------------------------- */

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 2rem;
  display: grid;
  gap: 1.15rem;
}

.auth-brand { font-size: 1.5rem; }
.auth-sub { color: var(--text-dim); font-size: .9375rem; margin-top: -.7rem; }
.hint { font-size: .875rem; color: var(--text-dim); }
.hint-new { color: var(--accent); margin-bottom: .75rem; }

/* --- shell -------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: .65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.brand { font-weight: 700; font-size: 1.05rem; }

.tabs { display: flex; gap: .25rem; flex: 1; }

.tab {
  background: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 600; font-size: .9375rem;
  color: var(--text-dim);
  padding: .35rem .75rem;
  border-radius: 7px;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab-active { background: var(--accent-soft); color: var(--accent); }

.me { display: flex; align-items: center; gap: .75rem; }
.me-text { display: grid; line-height: 1.4; text-align: end; }
.me-text > span:first-child { font-weight: 700; font-size: .875rem; }
.me-meta { font-size: .75rem; color: var(--text-mute); }

.page { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }

.view-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.view-head h2 { font-size: 1.35rem; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 9.5rem; font-size: .875rem; padding: .35rem .6rem; }

/* --- cards -------------------------------------------------------------- */

.cards, .box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, border-color .12s;
  display: flex; flex-direction: column;
}
.cards .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.box-grid .card { cursor: default; }
.card-muted { opacity: .62; }

.card-thumb {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: grid; place-items: center;
  overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-ph { color: var(--text-mute); font-size: .8125rem; }
.thumb-fail { color: var(--danger); font-size: 1.5rem; }

.card-body { padding: .8rem 1rem 1rem; display: grid; gap: .55rem; }
.card-top { display: flex; align-items: start; justify-content: space-between; gap: .5rem; }
.card-title {
  font-size: .9375rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-error {
  font-size: .8125rem; color: var(--danger); line-height: 1.6;
  background: var(--danger-soft); padding: .4rem .55rem; border-radius: 6px;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

.meta { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem .75rem; margin: 0; }
.meta > div { display: grid; min-width: 0; }
.meta dt { font-size: .6875rem; color: var(--text-mute); line-height: 1.5; }
.meta dd { margin: 0; font-size: .8125rem; line-height: 1.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- badges ------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .75rem; font-weight: 700; line-height: 1.6;
  padding: .1rem .5rem; border-radius: 999px;
  white-space: nowrap; flex-shrink: 0;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.badge-pending  { background: var(--warn-soft);   color: var(--warn); }
.badge-running  { background: var(--run-soft);    color: var(--run); }
.badge-complete { background: var(--ok-soft);     color: var(--ok); }
.badge-failed   { background: var(--danger-soft); color: var(--danger); }
.badge-running .dot { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner, .badge-running .dot { animation: none; }
  .card { transition: none; }
}

/* --- pager -------------------------------------------------------------- */

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.pager-label { font-size: .875rem; color: var(--text-mute); }

/* --- forms -------------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span2 { grid-column: 1 / -1; }

.prefs {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1.25rem 1.25rem;
  margin: 0;
  background: var(--surface-2);
}
.prefs legend { font-size: .8125rem; font-weight: 700; padding: 0 .4rem; color: var(--text-dim); }

.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.credits-note { font-size: .8125rem; color: var(--text-mute); }

/* --- table -------------------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { padding: .6rem .9rem; text-align: start; border-bottom: 1px solid var(--border); }
.table th {
  font-size: .75rem; color: var(--text-mute);
  font-weight: 700; background: var(--surface-2);
}
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: end; }

/* --- drawer ------------------------------------------------------------- */

.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(8, 11, 15, .5); backdrop-filter: blur(2px); }

/* inset-inline-end, not right: in RTL the drawer slides in from the left,
 * which is the edge a Persian reader's eye ends on. */
.drawer-panel {
  position: absolute; top: 0; bottom: 0;
  inset-inline-end: 0;
  width: min(560px, 100%);
  background: var(--bg);
  border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(-20px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel { animation: none; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.drawer-head h3 { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 1.25rem; overflow-y: auto; flex: 1; }

.detail-head { display: flex; align-items: center; gap: .75rem; }

.gallery { display: grid; gap: 1rem; }
.shot {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.shot img { width: 100%; display: block; background: var(--surface-2); }
.shot figcaption {
  display: flex; align-items: center; justify-content: space-between;
  padding: .45rem .75rem; font-size: .8125rem; color: var(--text-dim);
  border-top: 1px solid var(--border);
}

.facts {
  display: grid; grid-template-columns: 1fr 1fr; gap: .55rem 1rem;
  margin: 0; padding: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.facts > div { display: grid; gap: .05rem; min-width: 0; }
.facts dt { font-size: .6875rem; color: var(--text-mute); line-height: 1.5; }
.facts dd { margin: 0; font-size: .875rem; line-height: 1.7; overflow-wrap: anywhere; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- toasts ------------------------------------------------------------- */

.toasts {
  position: fixed; bottom: 1.25rem; z-index: 100;
  inset-inline-end: 1.25rem;
  display: grid; gap: .5rem; max-width: min(380px, calc(100vw - 2.5rem));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: .65rem .9rem;
  font-size: .875rem;
  line-height: 1.7;
  animation: toast-in .2s ease-out;
}
.toast-error { border-inline-start-color: var(--danger); color: var(--danger); }
.toast-out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* --- responsive --------------------------------------------------------- */

@media (max-width: 720px) {
  .form-grid, .row, .facts { grid-template-columns: 1fr; }
  .topbar-inner { gap: .75rem; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .me-text { text-align: start; }
  .view-head { align-items: stretch; }
  .filters input, .filters select { flex: 1; min-width: 7rem; }
}

/* ---------------------------------------------------------------------------
 * Admin surfaces: modal forms, card actions, the "مدیر" chip
 * ------------------------------------------------------------------------ */

/* Marks a control or view the API restricts to admins. Small and quiet —
 * it labels, it doesn't shout. */
.adm {
  display: inline-block;
  font-size: .625rem;
  font-weight: 700;
  line-height: 1.6;
  padding: 0 .35rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
  margin-inline-start: .25rem;
}
.btn .adm { background: rgba(255, 255, 255, .22); color: inherit; }
h2 .adm { font-size: .6875rem; }

.note {
  font-size: .8125rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .85rem;
  margin: 0 0 1rem;
  line-height: 1.8;
}

/* Cards in the asset grids are not clickable as a whole — their buttons are.
 * Without this they inherit the jobs grid's pointer and hover lift, which
 * promises a click target that does nothing. */
.card-static { cursor: default; }
.card-static:hover { transform: none; box-shadow: var(--shadow); border-color: var(--border); }

.card-actions {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  padding-top: .6rem;
  margin-top: .2rem;
  border-top: 1px solid var(--border);
}
.card-actions .btn { flex: 1; min-width: 4.5rem; }

.nowrap { white-space: nowrap; }

.excerpt {
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: start;
}

/* --- modal -------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 60; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 11, 15, .55); backdrop-filter: blur(2px); }

.modal-panel {
  position: absolute;
  inset-inline: 0;
  top: 50%;
  transform: translateY(-50%);
  margin: 0 auto;
  width: min(560px, calc(100% - 2rem));
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: modal-in .16s ease-out;
}
@keyframes modal-in { from { transform: translateY(calc(-50% + 10px)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .modal-panel { animation: none; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-head h3 { font-size: 1.05rem; }

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex: 1;
}

.modal-err { margin: 0 1.25rem; }

.modal-foot {
  display: flex; justify-content: flex-end; gap: .5rem;
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Checkboxes read left-to-right even in RTL — box first, then label — so
 * this is a flex row rather than the stacked .field grid. */
.check-field {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}
.check-field input[type="checkbox"] {
  width: 1.05rem; height: 1.05rem;
  accent-color: var(--accent);
  margin: 0; flex: none; cursor: pointer;
}
.check-field .field-hint { flex-basis: 100%; font-weight: 400; }

textarea {
  resize: vertical;
  min-height: 8rem;
  font-family: var(--mono);
  font-size: .8125rem;
  line-height: 1.7;
}

input[type="file"] {
  padding: .35rem;
  font-size: .8125rem;
  cursor: pointer;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2);
  color: var(--text-mute);
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .modal-body { grid-template-columns: 1fr; }
  .excerpt { max-width: 12rem; }
}
