/* مُفرِّغ — 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;
}

/* ============== TOPBAR ============== */
.topbar { margin-bottom: 28px; }
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-brand {
  font-family: var(--r-amiri);
  font-weight: 700;
  font-size: 20px;
  color: var(--lapis-deep);
  letter-spacing: -0.3px;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.donate-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 9px;
  background: linear-gradient(180deg, #FFF1C8, #F1D580 60%, #D9B86A);
  border: 1px solid rgba(184, 138, 47, 0.5);
  color: #4E370B;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.55),
    inset 0 -2px 0 rgba(120,80,10,0.18),
    0 2px 6px -2px rgba(185, 138, 47, 0.5);
  transition: transform 80ms ease, filter 120ms ease, box-shadow 200ms ease;
}
.donate-btn:hover {
  filter: brightness(1.04);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.55),
    inset 0 -2px 0 rgba(120,80,10,0.18),
    0 6px 14px -4px rgba(185, 138, 47, 0.55);
}
.donate-btn:active { transform: translateY(1px); }
.donate-ico { font-size: 14px; line-height: 1; }
@media (max-width: 640px) {
  /* Pill collapses to icon-only on narrow screens to save room next to
     the language switch and sign-in chip. */
  .donate-text { display: none; }
  .donate-btn { padding: 7px 9px; }
}

.lang-switch {
  display: inline-flex;
  background: rgba(20, 35, 58, 0.04);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.lang-opt {
  min-width: 30px;
  padding: 4px 10px;
  border: none;
  background: transparent;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.lang-opt:hover { color: var(--ink); }
.lang-opt.is-active {
  background: var(--card);
  color: var(--lapis-deep);
  box-shadow: 0 1px 2px rgba(20, 35, 58, 0.08);
}

.auth-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--lapis-deep);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 120ms ease, transform 80ms ease;
}
.auth-btn:hover { border-color: var(--lapis); }
.auth-btn:active { transform: translateY(1px); }

.auth-user { position: relative; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 5px 5px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 120ms ease;
}
.user-chip:hover { border-color: var(--lapis); }
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--gold), #8C661F);
  color: var(--paper);
  display: grid; place-items: center;
  font-family: var(--r-amiri);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
}
.user-name { font-weight: 500; }
.user-chev { color: var(--muted); font-size: 11px; margin-inline-start: 2px; }

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  min-width: 220px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 50;
}
.user-menu-item {
  display: block;
  width: 100%;
  text-align: start;
  padding: 9px 12px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  border: none;
  text-decoration: none;
  cursor: pointer;
}
.user-menu-item:hover { background: rgba(31, 78, 140, 0.06); }
.user-menu-item.is-danger { color: var(--rose); }
.user-menu-item.is-danger:hover { background: rgba(178, 58, 72, 0.08); }

/* ============== MODAL ============== */
.modal {
  position: fixed; inset: 0;
  z-index: 100;
  display: grid; place-items: center;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(20, 35, 58, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 22px 24px 24px;
  width: min(440px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 {
  margin: 0;
  font-family: var(--r-amiri);
  font-size: 22px;
  color: var(--lapis-deep);
}
.modal-close {
  width: 30px; height: 30px;
  border: none; background: transparent;
  font-size: 22px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
}
.modal-close:hover { background: rgba(20, 35, 58, 0.06); color: var(--ink); }

.auth-tabs {
  display: flex;
  gap: 6px;
  background: rgba(20, 35, 58, 0.04);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.is-active {
  background: var(--card);
  color: var(--lapis-deep);
  box-shadow: 0 1px 2px rgba(20, 35, 58, 0.08);
}

.auth-form {
  display: flex; flex-direction: column; gap: 10px;
}
.auth-form .primary { margin-top: 4px; }

.form-info {
  color: var(--ok);
  font-size: 14px;
  margin: 8px 0 0;
  min-height: 1em;
}

/* ============== HISTORY ============== */
.modal-card--wide { width: min(720px, 94vw); }
.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 0;
  margin: 0;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.history-main { min-width: 0; }
.history-title {
  margin: 0 0 4px;
  font-family: var(--r-amiri);
  font-size: 16px;
  color: var(--lapis-deep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-meta {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.history-state {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(31, 78, 140, 0.10);
  color: var(--lapis);
}
.history-state.is-running { background: rgba(185, 138, 47, 0.16); color: var(--gold); }
.history-state.is-done    { background: rgba(46, 125, 79, 0.14); color: var(--ok); }
.history-state.is-error   { background: rgba(178, 58, 72, 0.14); color: var(--rose); }
.history-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.dl-pill {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 6px;
  background: var(--lapis);
  color: #FFF7E1;
  text-decoration: none;
  transition: filter 100ms ease;
}
.dl-pill:hover { filter: brightness(1.1); }
.history-err {
  font-size: 12px;
  color: var(--rose);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .history-row { grid-template-columns: 1fr; }
  .history-actions { justify-content: flex-start; }
}

/* ============== SETTINGS / KEYS ============== */
.settings-intro {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--ink-soft);
  line-height: 1.7;
}
.keys-list {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.key-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.key-main { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.key-provider {
  font-size: 11.5px; font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(31, 78, 140, 0.10);
  color: var(--lapis);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.key-label { font-size: 14px; font-weight: 500; color: var(--ink); }
.key-masked {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--muted);
}
.key-meta { font-size: 12px; color: var(--muted); }
.key-delete {
  width: 28px; height: 28px;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 50%;
  font-size: 16px; font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.key-delete:hover { background: var(--rose); color: #FFF7E1; border-color: var(--rose); }

.add-key-form h4 {
  margin: 0 0 10px;
  font-family: var(--r-amiri);
  font-size: 17px;
  color: var(--lapis-deep);
}
.key-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}
.key-grid .wide { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .key-grid { grid-template-columns: 1fr; }
  .key-row { grid-template-columns: 1fr auto; }
  .key-meta { grid-column: 1 / -1; }
}

/* ============== 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; }
}

.beta-note {
  margin: 16px 0 0;
  padding: 10px 14px;
  background: rgba(185, 138, 47, 0.10);
  border: 1px dashed rgba(185, 138, 47, 0.35);
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 13.5px;
}
.beta-note span { font-weight: 700; color: var(--ink); }

.beta-donate-line {
  display: block;
  margin-top: 6px;
  font-weight: 400 !important;
  color: var(--ink-soft) !important;
  font-size: 13px;
}
.beta-donate-link {
  color: var(--gold);
  text-decoration: none;
  font-weight: 700;
  border-bottom: 1px solid transparent;
  transition: border-color 150ms ease;
  margin-inline-start: 4px;
}
.beta-donate-link:hover { border-bottom-color: var(--gold); }

/* ============== USAGE BADGE ============== */
.usage-badge {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 700px) {
  .usage-badge { grid-template-columns: repeat(2, 1fr); }
}
.usage-item {
  padding: 8px 10px;
  background: rgba(31, 78, 140, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 200ms ease, border-color 200ms ease, color 200ms ease;
}
.usage-label {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.usage-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.usage-item.is-warn   { background: rgba(185, 138, 47, 0.14); border-color: rgba(185, 138, 47, 0.35); }
.usage-item.is-warn   .usage-val { color: var(--gold); }
.usage-item.is-danger { background: rgba(178, 58, 72, 0.14);  border-color: rgba(178, 58, 72, 0.4); }
.usage-item.is-danger .usage-val { color: var(--rose); }

/* ============== MODE TABS ============== */
.mode-tabs {
  display: inline-flex;
  background: rgba(20, 35, 58, 0.04);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
  gap: 4px;
}
.mode-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.mode-tab:hover { color: var(--ink); }
.mode-tab.is-active {
  background: var(--card);
  color: var(--lapis-deep);
  box-shadow: 0 1px 2px rgba(20, 35, 58, 0.08);
}

/* ============== DROP ZONE ============== */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.drop-zone {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 150px;
  padding: 22px;
  border: 2px dashed var(--line-strong);
  border-radius: 14px;
  background: linear-gradient(180deg, #FFFCF2, #FAF3DE);
  cursor: pointer;
  outline: none;
  transition: border-color 150ms ease, background 150ms ease, transform 100ms ease;
}
.drop-zone:hover, .drop-zone:focus-visible {
  border-color: var(--lapis);
  background: linear-gradient(180deg, #FFFDF6, #F4ECD4);
}
.drop-zone.is-drag {
  border-color: var(--gold);
  background: linear-gradient(180deg, #FFF8E0, #F3E2A6);
  transform: scale(1.005);
}

.drop-empty {
  text-align: center;
  color: var(--ink-soft);
}
.drop-ico {
  width: 34px; height: 34px;
  margin: 0 auto 8px;
  color: var(--lapis);
  display: block;
}
.drop-title {
  margin: 0;
  font-weight: 700;
  color: var(--ink);
  font-size: 16px;
}
.drop-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.drop-filled {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
}
.drop-file-ico {
  width: 36px; height: 36px;
  color: var(--lapis-deep);
  flex-shrink: 0;
}
.drop-meta { flex: 1; min-width: 0; }
.drop-fname {
  margin: 0;
  font-weight: 500;
  color: var(--ink);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drop-stats {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.dot-sep { margin: 0 6px; }
.drop-clear {
  width: 28px; height: 28px;
  border: 1px solid var(--line);
  background: #FFFCF2;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.drop-clear:hover {
  background: var(--rose);
  border-color: var(--rose);
  color: #FFF7E1;
}

/* ============== 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; }
.footer-donate { margin-top: 8px !important; }
.footer-donate a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(185, 138, 47, 0.10);
  transition: background 150ms ease;
}
.footer-donate a:hover { background: rgba(185, 138, 47, 0.18); }
