/* مُفرِّغ — Arabic-first lecture transcriber.
   Palette: warm vellum, deep lapis ink, antique gold accent. */

:root {
  --paper: #FBF7EC;
  --paper-2: #F2E9D2;
  --card: #FFFCF2;
  --line: rgba(26, 42, 64, 0.10);
  --line-strong: rgba(26, 42, 64, 0.22);
  --ink: #14233A;
  --ink-soft: #3C4A60;
  --muted: #7A6F58;
  --lapis: #1F4E8C;
  --lapis-deep: #0F2E58;
  --gold: #B98A2F;
  --gold-soft: #D9B86A;
  --rose: #B23A48;
  --ok: #2E7D4F;
  --shadow-sm: 0 1px 2px rgba(20, 35, 58, 0.05), 0 0 0 1px var(--line);
  --shadow-md: 0 10px 30px -12px rgba(20, 35, 58, 0.18), 0 0 0 1px var(--line);
  --shadow-lg: 0 30px 60px -25px rgba(20, 35, 58, 0.30), 0 0 0 1px var(--line);
  --radius: 18px;
  --radius-sm: 10px;
  --r-tajawal: 'Tajawal', system-ui, sans-serif;
  --r-amiri: 'Amiri', 'Tajawal', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { font-family: var(--r-tajawal); color: var(--ink); }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1100px 600px at 100% -10%, rgba(217, 184, 106, 0.18), transparent 70%),
    radial-gradient(900px 600px at 0% 10%, rgba(31, 78, 140, 0.10), transparent 65%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  background-attachment: fixed;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle paper-grain overlay using SVG noise. */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0.35;
  z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.4  0 0 0 0 0.25  0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.page {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* ============== HERO ============== */
.hero { margin-bottom: 28px; }
.hero-inner {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 28px;
}
.brand { display: flex; align-items: center; gap: 18px; }
.brand-mark {
  width: 76px; height: 76px;
  display: grid; place-items: center;
  border-radius: 22px;
  background:
    linear-gradient(140deg, #E7C77B, var(--gold) 60%, #8C661F);
  color: var(--paper);
  font-family: var(--r-amiri);
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.15),
    inset 0 2px 0 rgba(255,255,255,0.35),
    0 14px 30px -12px rgba(184, 138, 47, 0.6);
}
.brand-text h1 {
  font-family: var(--r-amiri);
  font-weight: 700;
  font-size: clamp(38px, 5.5vw, 52px);
  line-height: 1;
  margin: 0 0 6px;
  color: var(--lapis-deep);
  letter-spacing: -0.5px;
}
.brand-text .tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: 16px;
  max-width: 36ch;
}

.hero-points {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
  color: var(--ink-soft);
  font-size: 14.5px;
}
.hero-points li { display: flex; align-items: center; gap: 10px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(185, 138, 47, 0.15);
}

@media (max-width: 700px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-points { order: 2; }
}

/* ============== CARDS ============== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px 28px 24px;
  margin-bottom: 22px;
  position: relative;
}
.card::before {
  /* Decorative gold rule across the top edge */
  content: "";
  position: absolute;
  inset: 0 18px auto 18px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg,
    transparent, var(--gold-soft) 20%, var(--gold) 50%, var(--gold-soft) 80%, transparent);
  opacity: 0.55;
}

.card-head { margin-bottom: 16px; }
.card-head h2 {
  font-family: var(--r-amiri);
  font-size: 28px;
  margin: 0 0 4px;
  color: var(--lapis-deep);
  letter-spacing: -0.3px;
}
.card-sub { color: var(--muted); font-size: 14.5px; }

/* ============== FIELDS ============== */
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.field > label, .field > legend {
  font-weight: 500;
  font-size: 14.5px;
  color: var(--ink);
}
.field > legend { padding: 0; }
.field small {
  color: var(--muted);
  font-size: 12.5px;
}

textarea, input[type="text"], input[type="password"], input:not([type]), select {
  width: 100%;
  font-family: inherit;
  font-size: 15.5px;
  color: var(--ink);
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: #B8AC92; }

textarea:focus, input:focus, select:focus {
  border-color: var(--lapis);
  box-shadow: 0 0 0 3px rgba(31, 78, 140, 0.15);
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 13px) calc(50% - 3px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 36px;
}
[dir="rtl"] select {
  background-position:
    18px calc(50% - 3px),
    13px calc(50% - 3px);
  padding-inline-end: 14px;
  padding-inline-start: 36px;
}

/* ============== OPTIONS PANEL ============== */
.options {
  margin: 18px 0 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 252, 240, 0.5);
}
.options summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 700;
  color: var(--lapis-deep);
}
.options summary::-webkit-details-marker { display: none; }
.summary-chev { transition: transform 200ms ease; color: var(--muted); }
.options[open] .summary-chev { transform: rotate(180deg); }
.opt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  padding: 4px 16px 18px;
}
.opt-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .opt-grid { grid-template-columns: 1fr; } }

/* ============== CHECK GROUPS ============== */
.check-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px 6px;
  margin: 0;
  background: #FFFFFF;
}
.check-group legend {
  font-size: 12.5px;
  color: var(--muted);
  padding: 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 6px 8px 8px 0;
  font-size: 14.5px;
  cursor: pointer;
}
[dir="rtl"] .chk { margin: 6px 0 8px 8px; }
.chk input {
  width: 18px; height: 18px;
  accent-color: var(--lapis);
  margin: 0;
  cursor: pointer;
}

/* ============== ACTIONS ============== */
.actions {
  display: flex; align-items: center; gap: 16px;
  margin-top: 12px;
}
.primary {
  position: relative;
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  color: #FFF7E1;
  background: linear-gradient(180deg, #285CA3, var(--lapis) 60%, var(--lapis-deep));
  border: none;
  border-radius: 12px;
  padding: 13px 22px;
  cursor: pointer;
  letter-spacing: 0.01em;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.2),
    inset 0 -2px 0 rgba(0,0,0,0.18),
    0 14px 24px -10px rgba(31, 78, 140, 0.55);
  transition: transform 100ms ease, box-shadow 200ms ease, filter 120ms ease;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.65; cursor: progress; }

.btn-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #FFF;
  border-radius: 50%;
  margin-inline-start: 8px;
  animation: spin 700ms linear infinite;
  vertical-align: -2px;
}
.primary[data-loading="1"] .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-error {
  color: var(--rose);
  font-size: 14px;
  font-weight: 500;
  min-height: 1em;
}

/* ============== JOB CARDS ============== */
.jobs { display: flex; flex-direction: column; gap: 18px; }

.job { padding: 22px 24px; }
.job-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; margin-bottom: 16px;
}
.job-title { display: flex; align-items: flex-start; gap: 12px; }
.job-state-icon {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  flex-shrink: 0;
  background: rgba(31, 78, 140, 0.08);
  color: var(--lapis);
  font-weight: 700;
  font-size: 16px;
  margin-top: 2px;
}
.job[data-state="queued"]   .job-state-icon::before { content: "⏳"; }
.job[data-state="running"]  .job-state-icon { background: rgba(185, 138, 47, 0.15); color: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
.job[data-state="running"]  .job-state-icon::before { content: "✺"; }
.job[data-state="done"]     .job-state-icon { background: rgba(46, 125, 79, 0.15); color: var(--ok); }
.job[data-state="done"]     .job-state-icon::before { content: "✓"; }
.job[data-state="error"]    .job-state-icon { background: rgba(178, 58, 72, 0.15); color: var(--rose); }
.job[data-state="error"]    .job-state-icon::before { content: "!"; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185, 138, 47, 0.35); }
  50%      { box-shadow: 0 0 0 10px rgba(185, 138, 47, 0); }
}

.job-name {
  margin: 0 0 4px;
  font-family: var(--r-amiri);
  font-size: 20px;
  font-weight: 700;
  color: var(--lapis-deep);
  line-height: 1.25;
}
.job-urls {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  word-break: break-all;
}
.job-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11.5px;
  color: var(--muted);
  background: rgba(20, 35, 58, 0.04);
  padding: 3px 8px;
  border-radius: 6px;
  user-select: all;
  white-space: nowrap;
}

.job-progress { margin-bottom: 12px; }
.progress {
  height: 6px;
  border-radius: 6px;
  background: rgba(20, 35, 58, 0.06);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 5%;
  background: linear-gradient(90deg, var(--gold-soft), var(--gold));
  border-radius: 6px;
  transition: width 350ms ease;
}
.job[data-state="running"] .progress-bar {
  width: 35%;
  background: linear-gradient(90deg,
    var(--gold-soft) 0%, var(--gold) 50%, var(--gold-soft) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
.job[data-state="done"]   .progress-bar { width: 100%; background: var(--ok); }
.job[data-state="error"]  .progress-bar { width: 100%; background: var(--rose); }
@keyframes shimmer { to { background-position: -200% 0; } }

.job-msg {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ============== DOWNLOADS ============== */
.job-downloads {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.dl-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, #FFFCF2, #FBF5E2);
  border: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
  transition: transform 100ms ease, box-shadow 200ms ease, border-color 120ms ease;
}
.dl-card:hover {
  transform: translateY(-1px);
  border-color: var(--gold-soft);
  box-shadow: 0 14px 24px -16px rgba(184, 138, 47, 0.5);
}
.dl-ico {
  width: 38px; height: 44px;
  border-radius: 5px;
  background: var(--lapis);
  color: #FFF7E1;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  position: relative;
  flex-shrink: 0;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18);
}
.dl-ico::after {
  /* folded-corner */
  content: "";
  position: absolute; top: 0; left: 0;
  border-style: solid;
  border-width: 0 8px 8px 0;
  border-color: transparent var(--paper) transparent transparent;
}
.dl-ico[data-fmt="markdown"] { background: var(--ok); }
.dl-ico[data-fmt="json"]     { background: var(--gold); color: #2A1F08; }
.dl-meta { display: flex; flex-direction: column; min-width: 0; }
.dl-title { font-size: 14px; font-weight: 500; line-height: 1.2; }
.dl-fmt   { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ============== FOOTER ============== */
.footer {
  margin-top: 36px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.footer p { margin: 0; }
