:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(79, 70, 229, .22);

  --success: #067647; --success-bg: #ecfdf3; --success-border: #abefc6;
  --warning: #b54708; --warning-bg: #fffaeb; --warning-border: #fedf89;
  --danger: #b42318;  --danger-bg: #fef3f2;  --danger-border: #fecdca;
  --info: #175cd3;    --info-bg: #eff8ff;    --info-border: #b2ddff;

  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(129, 140, 248, .16);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 40px -8px rgba(16, 24, 40, .22);

  --sidebar-w: 240px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
  --font-ar: "Noto Sans Arabic", "Segoe UI", "Geeza Pro", Tahoma, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.ar { font-family: var(--font-ar); }

.icon { display: inline-flex; flex: none; }
.icon svg, .nav svg, .api-status svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  padding: 20px 14px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: #fff; }
.brand:hover { color: #fff; }
.brand-mark svg { width: 32px; height: 32px; display: block; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { stroke: #fff; stroke-width: 2.4; stroke-linecap: round; fill: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 650; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--sidebar-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav a.active svg { color: #a5b4fc; }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .08); }
.api-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--sidebar-muted); }
.api-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sidebar-muted); }
.api-status[data-state="online"] .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.api-status[data-state="offline"] .dot { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }

.main { min-width: 0; }
.view { max-width: 1240px; margin: 0 auto; padding: 28px 32px 56px; }

/* ---------- Page header ---------- */
.page-header { margin-bottom: 24px; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumb-sep { color: var(--faint); }
.page-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 22px; line-height: 1.3; }
.page-subtitle { color: var(--muted); margin-top: 4px; }
.page-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-2);
  font-weight: 550; font-size: 13.5px; white-space: nowrap;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn:focus-visible, .seg button:focus-visible, .input:focus, .icon-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 4px var(--accent-ring);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: rgba(16, 24, 40, .05); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.loading .icon { animation: spin .8s linear infinite; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: rgba(16, 24, 40, .06); color: var(--text); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; }
.card-sub { font-size: 12.5px; color: var(--muted); }
.card-body { padding: 18px; }
.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.grid-detail { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; line-height: 18px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-done { color: var(--success); background: var(--success-bg); border-color: var(--success-border); }
.badge-partial { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.badge-error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-border); }
.badge-processing { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.badge-processing .badge-dot { animation: pulse 1.2s ease-in-out infinite; }
.pill {
  display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--muted); font-weight: 500;
}

/* ---------- Alerts ---------- */
.alert {
  display: flex; gap: 10px; padding: 12px 14px;
  border: 1px solid; border-radius: var(--radius);
  font-size: 13.5px;
}
.alert .icon { margin-top: 2px; }
.alert-title { font-weight: 600; }
.alert-body { margin-top: 2px; color: var(--text-2); word-break: break-word; }
.alert-body ul { margin: 4px 0 0; padding-left: 18px; }
.alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; line-height: 1.2; }
.stat-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-hint div { display: flex; justify-content: space-between; gap: 8px; }
a.stat { color: inherit; transition: border-color .12s, box-shadow .12s; }
a.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
a.stat.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---------- Upload sources ---------- */
.source-list {
  display: flex; flex-direction: column; gap: 12px;
  padding: 4px; margin: -4px; border-radius: var(--radius-lg);
  transition: background .15s, box-shadow .15s;
}
.source-list.dragging { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.source-list.dragging > * { pointer-events: none; }
.source-option {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  padding: 18px 20px; cursor: pointer; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.source-option:hover { background: var(--surface-2); border-color: var(--border-strong); }
.source-option:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.source-option:active { background: #f2f4f7; }
.source-option:disabled { opacity: .55; cursor: not-allowed; }
.source-icon {
  display: inline-flex; flex: none; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.source-option:hover .source-icon { background: var(--surface); }
.source-icon svg { width: 22px; height: 22px; }
.source-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.source-title { display: flex; align-items: center; flex-wrap: wrap; font-size: 16px; font-weight: 600; }
.source-sub { font-size: 13.5px; color: var(--muted); }
.source-chevron { color: var(--faint); transition: transform .15s; }
.source-chevron svg { width: 18px; height: 18px; }
.source-hint { text-align: center; font-size: 12.5px; color: var(--faint); padding-top: 2px; }
.source-badge {
  display: inline-flex; align-items: center; margin-left: 8px; padding: 1px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 650; vertical-align: middle;
}
.source-expand {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
}
.source-expand .source-option { border: 0; border-radius: 0; }
.source-expand.open { border-color: var(--border-strong); }
.source-expand.open .source-option { background: var(--surface-2); }
.source-expand.open .source-chevron { transform: rotate(90deg); }
.source-url-panel { padding: 0 20px 18px; background: var(--surface-2); }
.url-row { display: flex; gap: 8px; align-items: center; }
.url-row .input { height: 40px; padding-left: 12px; flex: 1; min-width: 0; }
.url-row .btn { flex: none; white-space: nowrap; }

.file-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 16px; }
.file-tile { position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.file-thumb {
  aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--faint);
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-thumb .icon svg { width: 28px; height: 28px; }
.file-meta { padding: 8px 10px; border-top: 1px solid var(--border); }
.file-name { font-size: 12.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 11.5px; color: var(--muted); }
.file-remove {
  position: absolute; top: 6px; right: 6px;
  background: rgba(255, 255, 255, .92); box-shadow: var(--shadow);
}

/* ---------- Steps ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.step { display: grid; grid-template-columns: 28px 1fr; gap: 12px; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.step-title { font-weight: 600; font-size: 13.5px; }
.step-text { color: var(--muted); font-size: 13px; }

/* ---------- Recent list ---------- */
.recent { list-style: none; margin: 0; padding: 6px; }
.recent a {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  padding: 8px; border-radius: var(--radius-sm); color: inherit;
}
.recent a:hover { background: var(--surface-2); }
.recent-title { font-weight: 550; font-size: 13px; }
.recent-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thumb {
  width: 36px; height: 36px; border-radius: var(--radius-sm); overflow: hidden; flex: none;
  background: var(--surface-2); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center; color: var(--faint);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Toolbar / inputs ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 550; color: var(--muted); cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg .count { margin-left: 6px; font-size: 11.5px; color: var(--faint); font-weight: 500; }

.search { position: relative; min-width: 240px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.input {
  width: 100%; height: 34px; padding: 0 12px 0 32px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus { border-color: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 12px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-history tbody tr { cursor: pointer; transition: background .1s; }
.table-history tbody tr:hover { background: var(--surface-2); }
.cell-menu { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-menu-id { font-family: var(--mono); font-size: 13px; font-weight: 550; color: var(--text); }
.cell-menu-sub { font-size: 12px; color: var(--muted); max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-chevron { width: 40px; color: var(--faint); }

/* ---------- Detail ---------- */
.id-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 4px 1px 8px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  font-family: var(--mono); font-size: 12px; color: var(--text-2);
}
.id-chip .icon-btn { width: 22px; height: 22px; }
.id-chip .icon-btn svg { width: 13px; height: 13px; }

.pages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 14px; }
.page-tile {
  position: relative; display: block; padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); cursor: zoom-in;
}
.page-tile img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; }
.page-tile .page-label {
  position: absolute; left: 6px; bottom: 6px; padding: 1px 7px; border-radius: 999px;
  background: rgba(15, 23, 42, .78); color: #fff; font-size: 11px; font-weight: 550;
}
.page-tile.missing { display: flex; align-items: center; justify-content: center; aspect-ratio: 3 / 4; color: var(--faint); font-size: 12px; cursor: default; }

.menu-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }

summary { list-style: none; cursor: pointer; user-select: none; }
summary::-webkit-details-marker { display: none; }
summary:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-ring); }
.disclosure { color: var(--faint); transition: transform .15s; }
details[open] > summary .disclosure { transform: rotate(90deg); }

.category { border-bottom: 1px solid var(--border); }
.category:last-child { border-bottom: 0; }
.category-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.category-head:hover { background: #f2f4f7; }
.category:not([open]) > .category-head { border-bottom: 0; }
.category-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; min-width: 0; flex-wrap: wrap; }
.category-index {
  font-family: var(--mono); font-size: 11.5px; color: var(--accent);
  background: var(--accent-soft); border-radius: 5px; padding: 1px 6px; font-weight: 600;
}
.title-ar { font-family: var(--font-ar); font-weight: 600; }
.title-sep { color: var(--faint); font-weight: 400; }
.subcategory + .subcategory, .table-wrap + .subcategory, .subcategory + .table-wrap { border-top: 1px solid var(--border); }
.subcategory-title {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 18px; font-size: 12.5px; font-weight: 600; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em;
}
.subcategory-title:hover { background: var(--surface-2); }
.subcategory[open] > .subcategory-title { border-bottom: 1px solid var(--border); }
.subcategory-title .title-ar { text-transform: none; letter-spacing: 0; font-size: 13.5px; }
.subcategory-title .pill { margin-left: auto; text-transform: none; letter-spacing: 0; }

.items th { background: transparent; padding-top: 8px; padding-bottom: 8px; }
.items td { padding-top: 10px; padding-bottom: 10px; }
.items tbody tr:hover { background: var(--surface-2); }
.item-name { font-weight: 550; }
.item-contents { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.items td[dir="rtl"], .items th[dir="rtl"] { text-align: right; font-family: var(--font-ar); }
.items .empty-cell { color: var(--faint); }
.price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.price .currency { margin-left: 4px; font-size: 12px; font-weight: 500; color: var(--muted); }

/* ---------- Processing ---------- */
.processing { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 18px; padding: 20px 22px; }
.processing-title { font-weight: 600; font-size: 15px; }
.processing-elapsed { text-align: right; }
.processing-elapsed .mono { display: block; font-size: 22px; font-weight: 600; color: var(--text); }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
.progress-steps { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.progress-step { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--faint); }
.progress-step::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.progress-step.done { color: var(--success); }
.progress-step.active { color: var(--info); }
.progress-step.active::before { animation: pulse 1.2s ease-in-out infinite; }
.progress-step + .progress-step::after { content: none; }

/* ---------- Empty / skeleton ---------- */
.empty { padding: 48px 24px; text-align: center; }
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 12px; margin-bottom: 12px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--faint);
}
.empty-icon svg { width: 22px; height: 22px; }
.empty-title { font-weight: 600; font-size: 15px; }
.empty-text { color: var(--muted); margin: 4px auto 16px; max-width: 380px; }

.skeleton { display: flex; flex-direction: column; gap: 14px; }
.sk {
  height: 14px; border-radius: 6px;
  background: linear-gradient(90deg, #eceef2 25%, #f5f6f8 50%, #eceef2 75%);
  background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite;
}
.sk-block { height: 120px; border-radius: var(--radius-lg); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  padding: 40px 24px 20px; gap: 16px; background: rgba(15, 23, 42, .88); backdrop-filter: blur(4px);
  animation: fade .15s ease-out;
}
.lightbox-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 16px; }
.lightbox figure { margin: 0; min-width: 0; max-width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lightbox figure img { max-width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: var(--radius); box-shadow: var(--shadow-lg); background: #fff; }
.lightbox.has-strip figure img { max-height: calc(100vh - 210px); }
.lightbox figcaption { display: flex; align-items: center; gap: 10px; color: #cbd5e1; font-size: 13px; text-align: center; }
.lightbox-counter {
  padding: 1px 9px; border-radius: 999px; background: rgba(255, 255, 255, .12);
  color: #fff; font-weight: 600; font-variant-numeric: tabular-nums;
}
.lightbox-close { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; color: #fff; background: rgba(255, 255, 255, .1); }
.lightbox-close:hover { background: rgba(255, 255, 255, .2); color: #fff; }
.lightbox-nav {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  color: #fff; background: rgba(255, 255, 255, .12); transition: background .12s, opacity .12s;
}
.lightbox-nav svg { width: 24px; height: 24px; }
.lightbox-nav:hover:not(:disabled) { background: rgba(255, 255, 255, .24); color: #fff; }
.lightbox-nav:disabled { opacity: .25; cursor: default; }
.lightbox-strip {
  flex: none; display: flex; justify-content: safe center; gap: 8px;
  overflow-x: auto; padding: 4px 2px;
}
.lightbox-thumb {
  flex: none; width: 52px; height: 68px; padding: 0; border-radius: var(--radius-sm); overflow: hidden;
  border: 2px solid transparent; background: rgba(255, 255, 255, .08); cursor: pointer;
  opacity: .55; transition: opacity .12s, border-color .12s;
}
.lightbox-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lightbox-thumb:hover { opacity: .85; }
.lightbox-thumb.active { opacity: 1; border-color: #a5b4fc; }

/* ---------- Toasts ---------- */
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 260px; max-width: 420px; padding: 10px 14px; border-radius: var(--radius);
  background: #0f172a; color: #f1f5f9; font-size: 13.5px; box-shadow: var(--shadow-lg);
  border-left: 3px solid #64748b; animation: slide-in .2s ease-out;
}
.toast-success { border-left-color: #22c55e; }
.toast-error { border-left-color: #ef4444; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-2, .grid-detail { grid-template-columns: 1fr; }
  .pages { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; align-items: center; gap: 12px; padding: 10px 14px;
  }
  .brand { padding: 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a span { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .view { padding: 20px 16px 40px; }
  .search { min-width: 0; flex: 1; }
  .processing { grid-template-columns: auto 1fr; }
  .lightbox { padding: 56px 8px 12px; }
  .lightbox-stage { gap: 6px; }
  .lightbox-nav { width: 38px; height: 38px; }
  .processing-elapsed { grid-column: 1 / -1; text-align: left; }
}
