@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Cairo:ital,wght@0,400;0,600;0,700;0,800&display=swap');

/* ═══════════════════════════════════════════
   DESIGN TOKENS — LIGHT (default)
   ═══════════════════════════════════════════ */
:root {
  color-scheme: light;

  /* Brand greens */
  --accent:        #2d6a4f;   /* solid fills / primary buttons (white text-safe) */
  --accent-hover:  #1f5a40;
  --accent-2:      #52b788;   /* bright accent: text, borders, glows */
  --accent-3:      #40c97a;   /* gradient highlight */
  --accent-light:  #d8f3dc;   /* icon chips */
  --accent-soft:   #effaf2;   /* hover tints / soft surfaces */
  --accent-soft-2: #d6f0de;   /* stronger hover tint */
  --accent-border: var(--accent-border);   /* success-ish borders */
  --accent-glow:   rgba(45, 106, 79, 0.18);

  /* Surfaces & background */
  --bg:            #f5f8f7;
  --bg-2:          #eef4f1;
  --surface:       #ffffff;
  --surface-2:     #f4f7f6;   /* subtle panels, table headers */
  --surface-3:     #eef2f1;
  --surface-hover: #e9efed;
  --nav-bg:        rgba(255, 255, 255, 0.78);
  --thumb-bg:      #eef2f1;

  /* Text */
  --text:        #0f1b16;
  --text-muted:  #5b6b66;
  --text-faint:  #9aa6a2;

  /* Borders */
  --border:        #e3e9e7;
  --border-strong: #d3dcd9;

  /* Glass */
  --glass-bg:     rgba(255, 255, 255, 0.62);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-blur:   16px;

  /* Feedback */
  --error-bg:    rgba(220, 38, 38, 0.07);
  --error-text:  #dc2626;
  --error-soft:  #fee2e2;
  --success:     #16a34a;
  --success-bg:  #effdf4;
  --warn:        #b45309;
  --warn-bg:     #fef3c7;
  --warn-border: #fcd34d;

  /* Type badges (json/full tree) */
  --t-string:  #1d4ed8; --t-string-bg:  rgba(29,78,216,0.07);  --t-string-bd:  rgba(29,78,216,0.18);
  --t-number:  #059669; --t-number-bg:  rgba(5,150,105,0.07);  --t-number-bd:  rgba(5,150,105,0.18);
  --t-bool:    #d97706; --t-bool-bg:    rgba(217,119,6,0.07);  --t-bool-bd:    rgba(217,119,6,0.18);
  --t-null:    #64748b; --t-null-bg:    rgba(100,116,139,0.07);--t-null-bd:    rgba(100,116,139,0.18);
  --t-object:  #2d6a4f; --t-object-bg:  rgba(45,106,79,0.07);  --t-object-bd:  rgba(45,106,79,0.18);
  --t-array:   #16a34a; --t-array-bg:   rgba(22,163,74,0.07);  --t-array-bd:   rgba(22,163,74,0.18);
  --code-text: #1e40af;
  --rv-key:    #64748b;

  /* Gradients */
  --grad-accent: linear-gradient(135deg, var(--accent) 0%, var(--accent-3) 100%);

  /* Geometry & elevation */
  --radius:    14px;
  --radius-lg: 20px;
  --shadow:        0 1px 3px rgba(16, 32, 26, 0.04), 0 6px 18px rgba(16, 32, 26, 0.05);
  --shadow-lg:     0 10px 40px rgba(16, 32, 26, 0.10);
  --shadow-glow:   0 12px 36px rgba(45, 106, 79, 0.20);
  --scrollbar:     #cbd5d1;
  --scrollbar-hov: #9aa6a2;
}

/* ═══════════════════════════════════════════
   DESIGN TOKENS — DARK
   ═══════════════════════════════════════════ */
[data-theme="dark"] {
  color-scheme: dark;

  --accent:        #2f9e6a;   /* brighter deep green so white text stays readable */
  --accent-hover:  #38b67b;
  --accent-2:      #34d399;
  --accent-3:      #6ee7b7;
  --accent-light:  rgba(52, 211, 153, 0.15);
  --accent-soft:   rgba(52, 211, 153, 0.08);
  --accent-soft-2: rgba(52, 211, 153, 0.16);
  --accent-border: rgba(52, 211, 153, 0.38);
  --accent-glow:   rgba(52, 211, 153, 0.28);

  --bg:            #07100c;
  --bg-2:          #0a1611;
  --surface:       #101a15;
  --surface-2:     #0d1612;
  --surface-3:     #16231d;
  --surface-hover: #1b2a23;
  --nav-bg:        rgba(13, 22, 18, 0.72);
  --thumb-bg:      #0d1612;

  --text:        #e9f1ed;
  --text-muted:  #9bada6;
  --text-faint:  #5f6f68;

  --border:        #21302a;
  --border-strong: #2c3f37;

  --glass-bg:     rgba(18, 28, 23, 0.55);
  --glass-border: rgba(82, 183, 136, 0.16);
  --glass-blur:   16px;

  --error-bg:    rgba(248, 113, 113, 0.12);
  --error-text:  #f87171;
  --error-soft:  rgba(248, 113, 113, 0.16);
  --success:     #4ade80;
  --success-bg:  rgba(74, 222, 128, 0.12);
  --warn:        #fbbf24;
  --warn-bg:     rgba(251, 191, 36, 0.12);
  --warn-border: rgba(251, 191, 36, 0.4);

  --t-string:  #93c5fd; --t-string-bg:  rgba(59,130,246,0.14);  --t-string-bd:  rgba(59,130,246,0.32);
  --t-number:  #6ee7b7; --t-number-bg:  rgba(16,185,129,0.14);  --t-number-bd:  rgba(16,185,129,0.32);
  --t-bool:    #fbbf24; --t-bool-bg:    rgba(217,119,6,0.16);   --t-bool-bd:    rgba(217,119,6,0.34);
  --t-null:    #94a3b8; --t-null-bg:    rgba(148,163,184,0.12); --t-null-bd:    rgba(148,163,184,0.28);
  --t-object:  #6ee7b7; --t-object-bg:  rgba(52,211,153,0.12);  --t-object-bd:  rgba(52,211,153,0.3);
  --t-array:   var(--accent-border); --t-array-bg:   rgba(34,197,94,0.12);   --t-array-bd:   rgba(34,197,94,0.3);
  --code-text: #93c5fd;
  --rv-key:    #8fa39b;

  --grad-accent: linear-gradient(135deg, var(--accent-2) 0%, var(--accent-3) 100%);

  --shadow:        0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg:     0 16px 48px rgba(0, 0, 0, 0.6);
  --shadow-glow:   0 14px 44px rgba(52, 211, 153, 0.22);
  --scrollbar:     #25342d;
  --scrollbar-hov: #36493f;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 620px at 12% -8%, var(--accent-soft) 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, var(--accent-soft) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background 0.4s ease, color 0.3s ease;
}

[dir="rtl"] body,
[dir="rtl"] {
  font-family: 'Cairo', 'Plus Jakarta Sans', sans-serif;
}

#stars-canvas { display: none; }

::selection { background: var(--accent-2); color: #04140d; }

/* ── Navbar ── */
.navbar {
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 2rem;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--border), 0 6px 24px -16px rgba(0, 0, 0, 0.4);
}

.navbar .logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.navbar .logo .logo-dash { color: var(--accent-2); }

.navbar .logo .logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--grad-accent);
  color: #fff;
  font-size: 0.72rem;
  box-shadow: 0 4px 12px -2px var(--accent-glow);
  transition: transform 0.25s ease;
}

.navbar .logo:hover .logo-mark { transform: rotate(-12deg) scale(1.06); }

/* ── Theme toggle ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s, background 0.18s, transform 0.18s;
}

.theme-toggle:hover {
  color: var(--accent-2);
  border-color: var(--accent-border);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.theme-toggle svg { display: block; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }

.nav-links {
  display: flex;
  gap: 0;
  flex: 1;
}

.nav-link {
  position: relative;
  padding: 0 1rem;
  height: 60px;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: color 0.15s;
  text-decoration: none;
}

.nav-link::after {
  content: "";
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 12px;
  height: 2px;
  border-radius: 2px;
  background: var(--grad-accent);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.22s ease;
}

.nav-link:hover { color: var(--text); }
.nav-link:hover::after { transform: scaleX(0.4); }

.nav-link.active { color: var(--text); }
.nav-link.active::after { transform: scaleX(1); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-lang {
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

/* ── Page panels ── */
.page-panel { display: none; }
.page-panel.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.4rem;
  /* subtle top sheen layered over the accent fill (painted behind text) */
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 55%), var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px -4px var(--accent-glow);
  transition: box-shadow 0.2s, transform 0.12s, filter 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
  filter: brightness(1.05);
}

.btn:active { transform: translateY(0) scale(0.98); }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  filter: none;
}

.btn-outline {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}

.btn-outline:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  box-shadow: 0 6px 18px -10px var(--accent-glow);
}

[data-theme="dark"] .btn-outline:hover { color: var(--accent-2); }

/* Saved-confirmation state */
.btn-saved {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 55%), var(--success);
  animation: btn-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes btn-pop {
  0%   { transform: scale(0.94); }
  60%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

/* ── Spinner ── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.btn.loading .spinner { display: block; }
.btn.loading .btn-text { opacity: 0.8; }
.btn-outline .spinner { border-color: rgba(0,0,0,0.15); border-top-color: var(--text-muted); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ── */
.alert {
  display: none;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.alert.show { display: block; }

.alert-error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid rgba(220, 38, 38, 0.18);
}

/* ═══════════════════════════════════════════
   HOME PAGE
   ═══════════════════════════════════════════ */

/* ── Hero ── */
.home-hero {
  position: relative;
  overflow: hidden;
  padding: 1.5rem 1.5rem 5rem;
  text-align: center;
  isolation: isolate;
  min-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* accent glow rising from the bottom so the lower half doesn't go flat-dark */
  background:
    radial-gradient(620px 300px at 50% 118%, var(--accent-glow) 0%, transparent 62%),
    radial-gradient(1100px 520px at 50% 114%, var(--accent-soft) 0%, transparent 60%);
}

/* animated gradient-mesh blobs */
.home-hero::before,
.home-hero::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  z-index: -1;
  pointer-events: none;
  opacity: 0.7;
}

.home-hero::before {
  width: 46vw;
  height: 46vw;
  max-width: 620px;
  max-height: 620px;
  top: -16%;
  left: -8%;
  background: radial-gradient(circle, var(--accent-2) 0%, transparent 70%);
  animation: hero-float-a 16s ease-in-out infinite;
}

.home-hero::after {
  width: 40vw;
  height: 40vw;
  max-width: 540px;
  max-height: 540px;
  top: -10%;
  right: -10%;
  background: radial-gradient(circle, var(--accent-3) 0%, transparent 70%);
  animation: hero-float-b 20s ease-in-out infinite;
}

[data-theme="dark"] .home-hero::before,
[data-theme="dark"] .home-hero::after { opacity: 0.45; }

/* fine dotted grid for depth */
.home-hero-grid {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(circle at center, var(--border-strong) 1px, transparent 1px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 35%, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 35%, #000 0%, transparent 75%);
  opacity: 0.55;
}

@keyframes hero-float-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(6%, 8%) scale(1.12); }
}

@keyframes hero-float-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-7%, 6%) scale(1.1); }
}

.home-hero-inner {
  position: relative;
  max-width: 1140px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 3.5rem;
  align-items: center;
}

.home-hero-copy { text-align: start; }


/* staggered entrance for copy children */
.home-hero-copy > * { animation: hero-rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both; }
.home-hero-copy > *:nth-child(2) { animation-delay: 0.07s; }
.home-hero-copy > *:nth-child(3) { animation-delay: 0.14s; }
.home-hero-copy > *:nth-child(4) { animation-delay: 0.21s; }
.home-hero-copy > *:nth-child(5) { animation-delay: 0.28s; }
.home-hero-copy > *:nth-child(6) { animation-delay: 0.35s; }

.home-hero-visual { animation: hero-rise 0.85s cubic-bezier(0.22, 1, 0.36, 1) 0.18s both; }

@keyframes hero-rise {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.home-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--glass-blur));
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--accent-border);
  border-radius: 100px;
  padding: 0.45rem 1.15rem;
  margin-bottom: 2rem;
  box-shadow: 0 6px 20px -10px var(--accent-glow);
  letter-spacing: 0.01em;
}

[data-theme="dark"] .home-badge { color: var(--accent-2); }

.home-title {
  font-size: clamp(2.4rem, 6vw, 4rem);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -0.045em;
  color: var(--text);
  margin-bottom: 1.35rem;
}

.home-title .green {
  background: linear-gradient(115deg, var(--accent-2) 0%, var(--accent-3) 55%, var(--accent-2) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-shimmer 6s linear infinite;
}

@keyframes title-shimmer {
  to { background-position: 200% center; }
}

.home-sub {
  font-size: 1.12rem;
  color: var(--text-muted);
  line-height: 1.75;
  max-width: 480px;
  margin: 0 0 2rem;
}

.home-actions {
  display: flex;
  flex-direction: row;
  gap: 0.85rem;
  justify-content: flex-start;
  flex-wrap: nowrap;
  margin-bottom: 1rem;
}

.home-text-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  padding: 0.2rem 0;
  margin-bottom: 2rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, gap 0.15s;
}

.home-text-link:hover { color: var(--accent-2); gap: 0.55rem; }

.home-cta-primary {
  padding: 0.9rem 2.2rem;
  font-size: 1.02rem;
  border-radius: 13px;
  box-shadow: var(--shadow-glow);
}

.home-actions .btn-outline {
  padding: 0.9rem 2.1rem;
  font-size: 1.02rem;
  border-radius: 13px;
}

.home-doc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-start;
}

.doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.36rem 0.95rem;
  border-radius: 100px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow);
  transition: border-color 0.18s, color 0.18s, background 0.18s, transform 0.18s;
  cursor: default;
}

.doc-chip:hover {
  border-color: var(--accent-border);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}

[data-theme="dark"] .doc-chip:hover { color: var(--accent-2); }

/* ── Hero extraction-preview visual ── */
.home-hero-visual {
  position: relative;
  direction: ltr;               /* keep the product mock consistent under RTL */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

/* faux source document */
.hv-doc {
  position: relative;
  flex: 0 0 auto;
  width: 40%;
  max-width: 188px;
  aspect-ratio: 8.5 / 11;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 16px 15px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow: hidden;
  animation: hv-bob 6s ease-in-out infinite;
}

.hv-doc-tag {
  position: absolute;
  top: 9px;
  right: 9px;
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 5px;
  padding: 1px 5px;
}

.hv-line { height: 7px; border-radius: 4px; background: var(--surface-3); width: 100%; }
.hv-line-title { height: 11px; width: 55%; background: var(--border-strong); margin-bottom: 3px; }
.hv-line.w90 { width: 90%; }
.hv-line.w80 { width: 80%; }
.hv-line.w75 { width: 75%; }
.hv-line.w70 { width: 70%; }
.hv-line.w60 { width: 60%; }
.hv-block {
  height: 34px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  margin: 3px 0;
}

.hv-scan {
  position: absolute;
  left: 0;
  right: 0;
  top: -30px;
  height: 26px;
  background: linear-gradient(180deg, transparent, var(--accent-glow), transparent);
  box-shadow: 0 0 18px var(--accent-2);
  animation: hv-scan 3.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes hv-scan {
  0%   { top: -30px; opacity: 0; }
  12%  { opacity: 1; }
  88%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.hv-arrow {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--grad-accent);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 8px 18px -6px var(--accent-glow);
  animation: hv-pulse 2.4s ease-in-out infinite;
  z-index: 2;
}

@keyframes hv-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.09); }
}

.hv-fields {
  flex: 1 1 auto;
  max-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  animation: hv-bob 6s ease-in-out infinite 0.6s;
}

.hv-fields-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.hv-check {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-size: 0.62rem;
  flex-shrink: 0;
}

.hv-fields-title { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.04em; color: var(--text-muted); flex: 1; }

.hv-conf {
  font-size: 0.58rem;
  font-weight: 800;
  color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 100px;
  padding: 1px 6px;
}

.hv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  opacity: 0;
  animation: hv-row-in 0.5s ease forwards;
}
.hv-row:nth-child(2) { animation-delay: 0.25s; }
.hv-row:nth-child(3) { animation-delay: 0.5s; }
.hv-row:nth-child(4) { animation-delay: 0.75s; }
.hv-row:nth-child(5) { animation-delay: 1s; }

.hv-key { height: 7px; width: 42px; border-radius: 4px; background: var(--surface-3); flex-shrink: 0; }
.hv-val { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.72rem; font-weight: 600; color: var(--text); }
.hv-val.accent { color: var(--accent-2); }

@keyframes hv-row-in {
  from { opacity: 0; transform: translateX(6px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes hv-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

@media (prefers-reduced-motion: reduce) {
  .home-hero::before,
  .home-hero::after,
  .home-title .green,
  .home-hero-copy > *,
  .home-hero-visual,
  .hv-doc,
  .hv-fields,
  .hv-arrow,
  .hv-scan,
  .hv-row { animation: none !important; opacity: 1 !important; }
}

/* ── How it works ── */
.home-steps-section {
  position: relative;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, transparent, var(--surface-2));
  padding: 1.85rem 1.5rem 2rem;
}

.home-steps-inner {
  max-width: 1040px;
  margin: 0 auto;
}

.home-section-eyebrow {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-2);
  margin-bottom: 0.65rem;
}

.home-section-title {
  text-align: center;
  font-size: clamp(1.3rem, 2.4vw, 1.7rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 0.9rem;
}

.step-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  counter-reset: step;
}

.step-card {
  counter-increment: step;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.5rem 0.4rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  text-align: start;
}

/* glow wash that reveals on hover */
.step-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 0% 0%, var(--accent-soft) 0%, transparent 55%);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

/* faint step number watermark */
.step-card::after {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  top: 0.6rem;
  inset-inline-end: 1rem;
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent-2);
  opacity: 0.14;
  transition: opacity 0.25s ease;
}

[dir="rtl"] .step-card:nth-child(1)::after { content: "١"; }
[dir="rtl"] .step-card:nth-child(2)::after { content: "٢"; }
[dir="rtl"] .step-card:nth-child(3)::after { content: "٣"; }

.step-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent-border);
  box-shadow: var(--shadow-lg);
}

.step-card:hover::before { opacity: 1; }
.step-card:hover::after  { opacity: 0.28; }

.step-icon-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  background: var(--grad-accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 8px 18px -8px var(--accent-glow);
}

.step-name {
  font-family: 'Plus Jakarta Sans', 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.4rem;
}

.step-desc {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.65;
  font-weight: 400;
}

/* ═══════════════════════════════════════════
   EXTRACT PAGE
   ═══════════════════════════════════════════ */

.extract-wrap {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}

.extract-wrap .card {
  padding: 1.4rem 1.5rem;
  margin-bottom: 0.85rem;
}

.extract-wrap h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.extract-wrap .page-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.85rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Dropzone ── */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.2s;
  position: relative;
  background: var(--surface-2);
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent-2);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-border), 0 12px 30px -18px var(--accent-glow);
}

.dropzone.drag-over { transform: scale(1.01); }

.dropzone .drop-icon { transition: transform 0.25s ease; }
.dropzone:hover .drop-icon,
.dropzone.drag-over .drop-icon { transform: translateY(-3px) scale(1.06); }

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.dropzone .drop-icon {
  font-size: 1.9rem;
  margin-bottom: 0.45rem;
  display: block;
}

.dropzone .drop-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.dropzone .drop-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.dropzone .file-preview {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  margin-top: 0.5rem;
  text-align: left;
}

.dropzone.has-file .file-preview { display: flex; }
.dropzone.has-file .drop-icon,
.dropzone.has-file .drop-label,
.dropzone.has-file .drop-sub { display: none; }

.file-preview-icon { font-size: 1.6rem; flex-shrink: 0; }

.file-preview-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.file-preview-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-preview-clear {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.25rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.file-preview-clear:hover { color: var(--error-text); background: var(--error-soft); }

/* ── Extract progress ── */
/* ── Epic progress ── */
.extract-progress {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: row;
  gap: 1.5rem;
  align-items: center;
}

.ep-status-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ep-phases {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ep-phase {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  transition: all 0.25s;
  letter-spacing: 0.03em;
}

.ep-phase.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.ep-phase.done {
  background: var(--success-bg, #f0fdf4);
  border-color: var(--success);
  color: var(--success);
}

.ep-phase-arrow {
  color: var(--border);
  font-size: 0.8rem;
}

.ep-msg-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 1.5rem;
}

.ep-spinner {
  font-size: 0.85rem;
  color: var(--accent);
  width: 1rem;
  text-align: center;
  flex-shrink: 0;
  transition: color 0.2s;
}

.ep-msg {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  transition: opacity 0.15s ease;
}

.ep-pulse-bar {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.ep-pulse-fill {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), #22d3a0, transparent);
  border-radius: 4px;
  animation: ep-pulse-slide 1.6s ease-in-out infinite;
}

@keyframes ep-pulse-slide {
  0%   { transform: translateX(-150%); }
  100% { transform: translateX(350%); }
}

.ep-log {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ep-log-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  animation: ep-fadein 0.35s ease;
}

.ep-log-check {
  color: var(--success);
  font-size: 0.75rem;
  flex-shrink: 0;
}

@keyframes ep-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Cycle spinner block ── */
#ep-cycle-block,
#tmpl-cycle-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem 2.5rem;
  gap: 2rem;
}

.ep-cycle-rings {
  position: relative;
  width: 88px;
  height: 88px;
}

.ep-ring {
  position: absolute;
  border-radius: 50%;
  border: 3px solid transparent;
}

.ep-ring-outer {
  inset: 0;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation: ep-spin 1.5s linear infinite;
}

.ep-ring-mid {
  inset: 14px;
  border-bottom-color: var(--accent-2);
  border-left-color: var(--accent-2);
  animation: ep-spin 1s linear infinite reverse;
}

.ep-ring-inner {
  inset: 28px;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  animation: ep-spin 0.65s linear infinite;
}

.ep-ring-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px var(--accent-2);
}

@keyframes ep-spin {
  to { transform: rotate(360deg); }
}

.ep-cycle-msg {
  font-family: 'Plus Jakarta Sans', 'Cairo', sans-serif;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: opacity 0.25s ease;
  text-align: center;
}

/* ── Upload progress bar ── */
.ep-upload-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  animation: ep-fadein 0.25s ease;
}

.ep-upload-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.ep-upload-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 3px;
  transition: width 0.18s ease;
}

.ep-upload-pct {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 2.8rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Slideshow solo block ── */
#ep-slideshow-block,
#tmpl-slideshow-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 0;
  animation: ep-fadein 0.5s ease;
}

.ep-pages-viewer-solo {
  width: 300px !important;
  margin: 0 auto;
}

.ep-ai-status {
  font-family: 'Plus Jakarta Sans', 'Cairo', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  transition: opacity 0.25s ease;
  letter-spacing: -0.01em;
}

/* ── Epic progress page viewer ── */
.ep-pages-viewer {
  width: 200px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 28px rgba(0,0,0,0.22);
  background: #12141a;
  border: 1px solid rgba(82,183,136,0.25);
  animation: ep-fadein 0.5s ease;
}

.ep-pages-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 8.5 / 11;
  overflow: hidden;
  background: #0d0f14;
}

.ep-pages-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.7s ease;
}

.ep-pages-frame img.ep-page-active {
  opacity: 1;
}

.ep-scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent-2), transparent);
  box-shadow: 0 0 14px var(--accent-2), 0 0 4px #fff;
  animation: ep-scan 2.8s linear infinite;
  z-index: 10;
  pointer-events: none;
}

@keyframes ep-scan {
  0%   { top: -2%;  opacity: 0; }
  4%   { opacity: 1; }
  96%  { opacity: 1; }
  100% { top: 102%; opacity: 0; }
}

.ep-pages-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.65rem;
  background: rgba(0,0,0,0.55);
}

.ep-pages-counter {
  font-size: 0.68rem;
  color: var(--accent-2);
  font-family: monospace;
  letter-spacing: 0.05em;
}

.ep-pages-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.ep-pages-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  transition: background 0.3s, transform 0.3s;
  flex-shrink: 0;
}

.ep-pages-dot.ep-dot-active {
  background: var(--accent-2);
  transform: scale(1.35);
}

/* ── Template row ── */
.tmpl-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 0.75rem 0;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

.tmpl-row-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.tmpl-row select {
  flex: 1;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
}

.tmpl-row select:focus { outline: none; border-color: var(--accent); }

.tmpl-status {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-muted);
}

.tmpl-status.ok { color: var(--success); }
.tmpl-status.err { color: var(--error-text); }

/* ── Run button ── */
.run-row {
  margin-top: 0.9rem;
}

.run-row .btn {
  width: 100%;
  justify-content: center;
  padding: 0.85rem;
  font-size: 0.95rem;
}

/* ── Config form ── */
.cfg-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
  align-items: start;
}


.cfg-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.cfg-field label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.cfg-field input,
.cfg-field select,
.cfg-field textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: textfield;
  -webkit-appearance: textfield;
}

.cfg-field textarea {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  resize: vertical;
  min-height: 52px;
}

.cfg-field input:focus,
.cfg-field select:focus,
.cfg-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.cfg-wide { grid-column: span 2; }

.cfg-subsection {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
  margin: 1rem 0 0.6rem;
}

.opt { font-weight: 400; text-transform: none; font-size: 0.8em; color: var(--text-muted); }

.cfg-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.cfg-card > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  background: var(--surface-2);
  border-bottom: 1px solid transparent;
  transition: background 0.15s;
}

.cfg-card > summary::-webkit-details-marker { display: none; }

.cfg-card > summary::before {
  content: "▶";
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  display: inline-block;
}

.cfg-card[open] > summary::before { transform: rotate(90deg); }
.cfg-card[open] > summary { border-bottom-color: var(--border); }
.cfg-card > summary:hover { background: var(--surface-hover); }

.cfg-body { padding: 1.25rem; }

/* hidden fields still used by JS */
textarea#j-schema,
textarea#j-prompt,
textarea#m-prompt,
input#m-model,
select#m-provider,
input#m-base-url,
input#m-api-key,
input#m-temperature,
input#m-max-tokens,
input#j-model,
select#j-provider,
input#j-base-url,
input#j-api-key,
input#j-temperature,
input#j-max-tokens {
  display: none !important;
}

/* ═══════════════════════════════════════════
   DOCUMENTS PAGE
   ═══════════════════════════════════════════ */

.docs-wrap {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}

/* ── Document grid ── */
.docs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}

.doc-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.doc-card-thumb {
  width: 100%;
  aspect-ratio: 8.5 / 11;
  background: var(--thumb-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

.doc-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  display: block;
}

.doc-card-thumb-empty {
  font-size: 2.5rem;
  color: var(--text-faint);
}

.doc-card-body {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.doc-card-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-card-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.doc-card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

/* ── Examples ────────────────────────────────────────────────────────────── */

.examples-wrap {
  max-width: 960px;
  margin: 2.5rem auto;
  padding: 0 1.5rem 3rem;
}

.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}

.example-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: pointer;
}

.example-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.example-card-thumb {
  width: 100%;
  height: 110px;
  background: linear-gradient(135deg, var(--accent-soft-2) 0%, var(--accent-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

.example-card-icon { font-size: 2.4rem; }

.example-card-body {
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
}

.example-card-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.example-card-vendor {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}

.example-card-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.example-card-actions { margin-top: 0.6rem; }

.example-card-actions .btn {
  width: 100%;
  font-size: 0.82rem;
  padding: 0.45rem 0.9rem;
}

.home-cta-examples { color: var(--accent); border-color: var(--accent); }
.home-cta-examples:hover { background: var(--accent-light); }

.btn-sm {
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
}

.btn-danger {
  background: none;
  border: 1.5px solid var(--error-text);
  color: var(--error-text);
}

.btn-danger:hover {
  background: var(--error-text);
  color: #fff;
}

.doc-view-btn {
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.page-header p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 5rem 2rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.35;
  display: block;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.empty-state p { font-size: 0.875rem; line-height: 1.6; }

/* ═══════════════════════════════════════════
   TEMPLATES PAGE
   ═══════════════════════════════════════════ */

.tmpl-wrap {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}

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

.tmpl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  position: relative;
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.2s;
}

.tmpl-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); }

.tmpl-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.35rem;
  padding-right: 2rem;
}

.tmpl-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
}

.tmpl-card-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tmpl-card-actions .btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
}

.tmpl-edit-link {
  background: none;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.tmpl-edit-link:hover {
  background: var(--accent);
  color: #fff;
}

.tmpl-card-del {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: color 0.15s;
  padding: 0.2rem;
}

.tmpl-card-del:hover { color: var(--error-text); }

/* ── New template flow ── */
.tmpl-new-wrap {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.breadcrumb-link {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s;
}

.breadcrumb-link:hover { color: var(--text); }

.breadcrumb-sep { color: var(--text-faint); }

.breadcrumb-current { color: var(--text); font-weight: 600; }

.tmpl-new-wrap h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 1.5rem;
}

/* Upload area for new template */
.upload-area {
  border: 2px dashed var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-soft);
  padding: 4rem 2rem;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover {
  border-color: var(--accent-2);
  background: var(--accent-soft-2);
}

.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-area-icon { font-size: 2rem; margin-bottom: 0.85rem; display: block; color: var(--accent); }
.upload-area-title { font-size: 1rem; font-weight: 600; color: var(--text); margin-bottom: 0.4rem; }
.upload-area-sub { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1.25rem; }
.upload-area-footer { font-size: 0.78rem; color: var(--text-muted); margin-top: 1.25rem; }

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Template editor (section-based) ── */
.tmpl-editor-wrap {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}

.tmpl-ref-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tmpl-ref-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.tmpl-ref-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.tmpl-ref-upload-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.65rem;
  border: 1px solid var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.tmpl-ref-upload-btn:hover { background: var(--accent-soft-2); }

.tmpl-ref-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  padding: 3rem 0.5rem;
  flex: 1;
}

/* ── Page viewer ── */
.page-viewer {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
  min-height: 0;
}

.page-viewer-img-wrap {
  width: 100%;
  overflow-y: auto;
  border-radius: 6px;
  background: var(--bg);
  cursor: grab;
}
.page-viewer-img-wrap:active { cursor: grabbing; }

.tmpl-ref-img {
  width: 100%;
  display: block;
  border-radius: 6px;
  user-select: none;
  -webkit-user-drag: none;
}

.page-viewer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.page-nav-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  padding: 0;
}
.page-nav-btn:hover:not(:disabled) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.page-nav-btn:disabled { opacity: 0.3; cursor: default; }

.page-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 3.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tmpl-form-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  min-width: 0;        /* grid item: prevent growth past 1fr allocation */
  overflow: visible;
}

.tmpl-name-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  margin-bottom: 1.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tmpl-name-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.tmpl-name-input::placeholder { color: var(--text-faint); }

.sections-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  position: sticky;
  top: 58px;
  background: var(--surface);
  z-index: 20;
  padding: 0.5rem 0;
  margin-top: -0.5rem;
}

.sections-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.add-section-btn, .add-field-btn {
  padding: 0.4rem 0.85rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.add-section-btn:hover, .add-field-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* ── Section card ── */
.section-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.85rem;
  overflow: clip;   /* clips visually but does NOT create a scroll container */
  background: var(--surface);
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.section-name-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  font-weight: 500;
  transition: border-color 0.15s;
}

.section-name-input:focus { outline: none; border-color: var(--accent); }

.section-type-select {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
}

.section-del-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.25rem;
  transition: color 0.15s;
  line-height: 1;
}

.section-del-btn:hover { color: var(--error-text); }

.section-fields {
  padding: 0.85rem 1rem;
  min-width: 0;
  overflow-x: auto;   /* scroll within section; never expand the page */
}

/* ── Array column table layout ── */
.section-field-list.array-mode {
  display: flex;
  flex-direction: row;
  gap: 0;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 0.5rem;
  width: 100%;        /* explicit width so overflow-x: auto clips rather than grows */
  min-width: 0;
  box-sizing: border-box;
}

.section-field-list.array-mode .field-entry {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 150px;
  max-width: 220px;
  flex-shrink: 0;
  margin-bottom: 0;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 0.7rem 0.75rem;
  background: var(--surface);
}

.section-field-list.array-mode .field-entry:last-child { border-right: none; }

.section-field-list.array-mode .field-name-input {
  font-weight: 700;
  font-size: 0.82rem;
  width: 100%;
  box-sizing: border-box;
}

.section-field-list.array-mode .field-type-select {
  width: 100%;
  font-size: 0.78rem;
  box-sizing: border-box;
}

.section-field-list.array-mode .field-desc-input {
  width: 100%;
  font-size: 0.73rem;
  resize: none;
  box-sizing: border-box;
}

.section-field-list.array-mode .field-del-btn {
  align-self: flex-end;
  margin-top: auto;
}

/* ── Key-value field entries (existing) ── */
.field-entry {
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem 0.5rem;
  background: var(--surface-2);
}

.field-entry-inline-array {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.inline-array-wrap {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  background: var(--surface);
}

.inline-array-columns {
  display: flex;
  flex-direction: row;
  gap: 0;
  min-width: 0;
}

.add-array-col-btn {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.78rem;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
  border-radius: 0 0 6px 6px;
}

.add-array-col-btn:hover { background: var(--accent-light); }

.field-row-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.field-name-input {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s;
}

.field-name-input:focus { outline: none; border-color: var(--accent); }
.field-name-input::placeholder { color: var(--text-faint); }

.field-type-select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
}

.field-del-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem;
  transition: color 0.15s;
  line-height: 1;
  flex-shrink: 0;
}

.field-del-btn:hover { color: var(--error-text); }

.field-desc-input {
  width: 100%;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface);
  transition: border-color 0.15s, color 0.15s;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
  overflow-y: auto;
}

.field-desc-input:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.field-desc-input::placeholder { color: var(--text-faint); font-style: italic; }

/* Array column desc: fixed height, no vertical resize */
.section-field-list.array-mode .field-desc-input {
  resize: none;
  overflow-y: auto;
}

.add-field-link {
  background: none;
  border: none;
  padding: 0.35rem 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  display: block;
  margin-top: 0.25rem;
  text-decoration: none;
  transition: opacity 0.15s;
}

.add-field-link:hover { opacity: 0.7; }


.section-empty {
  font-size: 0.8rem;
  color: var(--text-faint);
  text-align: center;
  padding: 0.75rem 0 0.25rem;
  font-style: italic;
}

.tmpl-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.75rem;
  padding: 1rem 0 0.25rem;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: var(--surface);
  z-index: 20;
}

.tmpl-error {
  font-size: 0.82rem;
  color: var(--error-text);
  margin-top: 0.75rem;
  display: none;
}

.tmpl-error.show { display: block; }

/* ── Auto-extract schema row ── */
.auto-extract-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════
   SETTINGS PAGE
   ═══════════════════════════════════════════ */

.settings-wrap {
  max-width: 960px;
  margin: 2rem auto;
  padding: 0 1.5rem 3rem;
}


.settings-wrap h1 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.settings-wrap .page-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 1.75rem;
}

/* ═══════════════════════════════════════════
   DOCUMENT REVIEW PAGE (full.html)
   ═══════════════════════════════════════════ */

.review-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 58px);
}

.review-left {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
}

.review-doc-header {
  padding: 0 1.25rem;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
}

.review-doc-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.review-doc-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.review-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft-2);
  color: var(--success);
  border: 1px solid var(--accent-border);
  margin-bottom: 0.35rem;
}

.review-status-badge.pending {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.review-doc-img-wrap {
  flex: 1;
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.review-doc-img {
  max-width: 100%;
  border-radius: 6px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.10);
  cursor: zoom-in;
}

.review-page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.review-page-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
  padding: 0;
}

.review-page-btn:hover:not(:disabled) { background: var(--accent-bg); border-color: var(--accent); }
.review-page-btn:disabled { opacity: 0.35; cursor: default; }

.review-page-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 3rem;
  text-align: center;
}

.review-right {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.review-right-header {
  padding: 0 1.5rem;
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.review-back-link {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: color 0.15s;
  text-decoration: none;
}

.review-back-link:hover { color: var(--text); }

.review-right-header .spacer { flex: 1; }

.review-body {
  flex: 1;
  padding: 1.5rem;
}

.review-section {
  margin-bottom: 2rem;
}

.review-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.review-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.review-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.review-field-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.review-field-input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.review-field-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Array table in review */
.review-table-wrap {
  overflow-x: auto;
  margin-top: 0.25rem;
}

.review-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.review-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.review-table td {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

.review-table td input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  color: var(--text);
  padding: 0.2rem;
  min-width: 80px;
}

.review-table td input:focus { outline: none; background: var(--accent-soft); border-radius: 4px; }

.review-table-action {
  background: none;
  border: none;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  color: var(--error-text);
  cursor: pointer;
  transition: opacity 0.15s;
}

.review-table-action:hover { opacity: 0.7; }

.review-add-row {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: opacity 0.15s;
}

.review-add-row:hover { opacity: 0.7; }

.review-approve-bar {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  bottom: 0;
}

.review-approve-bar .btn {
  width: 100%;
  justify-content: center;
  padding: 0.85rem;
  font-size: 0.95rem;
}

/* ═══════════════════════════════════════════
   SHARED / MISC
   ═══════════════════════════════════════════ */

/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hov); }

/* stat chips (used in pages.html / markdown.html) */
.stats-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.stat-chip .stat-label { color: var(--text-muted); }
.stat-chip .stat-value { font-weight: 700; color: var(--text); }

/* image grid (pages.html) */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.page-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
}

.page-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.page-card .img-wrap {
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  height: 320px;
  cursor: zoom-in;
}

.page-card .img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.page-card .meta {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.page-card .meta .page-num {
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.meta-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.meta-tag { font-size: 0.75rem; color: var(--text-muted); }
.meta-tag span { color: var(--text); font-weight: 500; }

.card-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-top .page-label { font-size: 0.85rem; font-weight: 700; color: var(--text); flex: 1; }

.card-check { display: flex; align-items: center; cursor: pointer; }
.card-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.page-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.page-card.unselected { opacity: 0.4; }
.page-card.unselected:hover { opacity: 0.7; }

.grid-toolbar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1.25rem; }
.grid-toolbar .selection-count { font-size: 0.85rem; color: var(--text-muted); margin-left: auto; }


/* markdown panel (markdown.html) */
.md-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.md-card .img-wrap {
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
  cursor: zoom-in;
  border-bottom: 1px solid var(--border);
}

.md-card .img-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }

.md-card .page-heading {
  padding: 0.8rem 1.25rem;
  font-weight: 700;
  font-size: 0.92rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.md-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  user-select: none;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  transition: background 0.15s;
}

.md-header:hover { background: var(--surface-hover); }

.md-header .md-toggle { font-size: 0.7rem; color: var(--text-muted); transition: transform 0.2s; }
.md-header.open .md-toggle { transform: rotate(90deg); }
.md-header .md-title { font-weight: 600; font-size: 0.85rem; color: var(--text); flex: 1; }
.md-header .md-time { font-size: 0.75rem; color: var(--text-muted); }

.md-content { display: none; padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.md-content.open { display: block; }

.md-content pre {
  margin: 0;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.85rem 1rem;
  max-height: 450px;
  overflow-y: auto;
}

.md-editor {
  display: block;
  width: 100%;
  min-height: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.85rem 1rem;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.md-editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }

/* json card (json.html) */
.json-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.json-card pre {
  margin: 0;
  padding: 1.5rem;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 75vh;
  overflow-y: auto;
}

/* field-card / rv (used in json.html, full.html tree view) */
.field-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem 0.5rem;
  margin-bottom: 0.5rem;
}

.field-list { margin-top: 0.75rem; }

.field-row { display: flex; gap: 0.4rem; align-items: center; margin-bottom: 0.3rem; }

.rv-key {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--rv-key);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rv-val {
  display: block;
  font-size: 0.85rem;
  color: var(--text);
  padding: 0.35rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  word-break: break-word;
  white-space: pre-wrap;
}

.rv-type {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.rv-type-string  { background: var(--t-string-bg); color: var(--t-string); border: 1px solid var(--t-string-bd); }
.rv-type-number  { background: var(--t-number-bg); color: var(--t-number); border: 1px solid var(--t-number-bd); }
.rv-type-boolean { background: var(--t-bool-bg);   color: var(--t-bool);   border: 1px solid var(--t-bool-bd); }
.rv-type-null    { background: var(--t-null-bg);   color: var(--t-null);   border: 1px solid var(--t-null-bd); }
.rv-type-object  { background: var(--t-object-bg); color: var(--t-object); border: 1px solid var(--t-object-bd); }
.rv-type-array   { background: var(--t-array-bg);  color: var(--t-array);  border: 1px solid var(--t-array-bd); }

.rv-children { padding-left: 0; }
.rv-card { cursor: default; }
.rv-row  { align-items: center; margin-bottom: 0.3rem; }

.sub-collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.6rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  line-height: 1;
  padding: 0;
}

.sub-collapse-btn:hover { background: var(--surface-hover); }

/* page (upload.html legacy) */
.page {
  max-width: 760px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.page-wide {
  max-width: 1280px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.result-section-title {
  display: flex;
  align-items: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.85rem;
  gap: 0.75rem;
}

/* endpoint badge */
.endpoint-badge {
  font-size: 0.65rem;
  font-weight: 600;
  font-family: "SFMono-Regular", Consolas, monospace;
  color: #0891b2;
  background: rgba(8,145,178,0.08);
  border: 1px solid rgba(8,145,178,0.22);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
}

/* ── Page lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.lightbox.open {
  opacity: 1;
  pointer-events: all;
}
.lightbox-inner {
  position: relative;
  max-width: min(90vw, 860px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
.lightbox-img {
  max-width: 100%;
  max-height: calc(92vh - 3rem);
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  user-select: none;
  -webkit-user-drag: none;
}
.lightbox-close {
  position: absolute;
  top: -2.25rem;
  right: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.28); }
.lightbox-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.lightbox-nav-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 1.35rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  padding: 0;
}
.lightbox-nav-btn:hover:not(:disabled) { background: rgba(255,255,255,0.25); }
.lightbox-nav-btn:disabled { opacity: 0.25; cursor: default; }
.lightbox-counter {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.7);
  min-width: 4rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tmpl-ref-img { cursor: zoom-in; }

/* compat: pages.html / markdown.html use raw img + .lb-close inside .lightbox */
.lightbox img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-close {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.lightbox .lb-close:hover { opacity: 1; }

/* ── Confirm popup ── */
.confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  animation: ep-fadein 0.15s ease;
}

.confirm-modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: hero-rise 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.confirm-modal-msg {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.55;
  margin: 0 0 1.25rem;
}

.confirm-modal-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: flex-end;
}

.confirm-modal-ok {
  background: linear-gradient(180deg, rgba(255,255,255,0.12), transparent 55%), var(--error-text);
  box-shadow: 0 4px 14px -4px rgba(220, 38, 38, 0.35);
}

.confirm-modal-ok:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 20px -6px rgba(220, 38, 38, 0.5);
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .tmpl-editor-wrap { grid-template-columns: 1fr; }
  .tmpl-ref-panel { position: static; max-height: none; }
  .step-cards { grid-template-columns: 1fr; gap: 1rem; }
  .review-layout { grid-template-columns: 1fr; height: auto; }
  .review-left { height: 50vh; }
  .cfg-wide { grid-column: span 1; }
  .home-hero { padding: 3.5rem 1.25rem 3rem; }
  .home-hero-inner { grid-template-columns: 1fr; gap: 2.75rem; }
  .home-hero-copy { text-align: center; }
  .home-hero-copy .home-sub { margin-left: auto; margin-right: auto; }
  .home-actions,
  .home-doc-chips { justify-content: center; }
  .home-hero-visual { width: 100%; max-width: 440px; margin: 0 auto; }
  .home-steps-section { padding: 2.5rem 1.25rem 3rem; }
  .home-title { font-size: 2.2rem; }
  .home-section-title { font-size: 1.3rem; margin-bottom: 1rem; }
  .navbar { gap: 0.75rem; padding: 0 1rem; }
  .nav-links { overflow-x: auto; scrollbar-width: none; }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link { padding: 0 0.6rem; font-size: 0.82rem; }
}

/* Hide nav text labels on very small screens to keep the bar tidy */
@media (max-width: 560px) {
  .nav-lang-btn span { display: none; }
}

/* ── RTL overrides ── */
[dir="rtl"] .navbar {
  flex-direction: row-reverse;
}



[dir="rtl"] .nav-right {
  margin-right: auto;
  margin-left: 0;
}

[dir="rtl"] .home-actions {
  flex-direction: row-reverse;
  justify-content: flex-end;
}

[dir="rtl"] .home-actions button:nth-child(1) { order: 3; }
[dir="rtl"] .home-actions button:nth-child(2) { order: 2; }
[dir="rtl"] .home-actions button:nth-child(3) { order: 1; }

[dir="rtl"] .home-doc-chips {
  flex-direction: row-reverse;
  justify-content: flex-end;
}
[dir="rtl"] .home-doc-chips .doc-chip:nth-child(1) { order: 4; }
[dir="rtl"] .home-doc-chips .doc-chip:nth-child(2) { order: 3; }
[dir="rtl"] .home-doc-chips .doc-chip:nth-child(3) { order: 2; }
[dir="rtl"] .home-doc-chips .doc-chip:nth-child(4) { order: 1; }

[dir="rtl"] .step-cards {
  direction: rtl;
}

[dir="rtl"] .step-card::before {
  border-radius: 3px 0 0 3px;
}

[dir="rtl"] .step-name {
  letter-spacing: 0;
}

[dir="rtl"] .home-section-eyebrow {
  letter-spacing: 0;
}



[dir="rtl"] .tmpl-row {
  flex-direction: row-reverse;
}

[dir="rtl"] .ep-phases {
  flex-direction: row-reverse;
}

[dir="rtl"] .ep-msg-row {
  flex-direction: row-reverse;
}

[dir="rtl"] .tmpl-card-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .tmpl-form-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .sections-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .doc-card-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] .breadcrumb {
  flex-direction: row-reverse;
}

[dir="rtl"] .cfg-row label {
  text-align: right;
}

[dir="rtl"] .ep-pages-bar {
  flex-direction: row-reverse;
}

[dir="rtl"] .ep-log-item {
  flex-direction: row-reverse;
}

[dir="rtl"] .review-right-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .review-page-nav {
  flex-direction: row-reverse;
}

[dir="rtl"] .lightbox-nav {
  flex-direction: row-reverse;
}

.nav-lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 34px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 0 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s, background 0.18s, transform 0.18s;
  letter-spacing: 0.04em;
}

.nav-lang-btn svg { opacity: 0.8; }

.nav-lang-btn:hover {
  border-color: var(--accent-border);
  color: var(--accent-2);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* ═══════════════════════════════════════════
   PREMIUM ENHANCEMENTS
   ═══════════════════════════════════════════ */

/* Accent borders on card hover (both themes) */
.doc-card:hover,
.example-card:hover,
.tmpl-card:hover,
.page-card:hover { border-color: var(--accent-border); }

/* Accessible focus ring */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-link:focus-visible,
.theme-toggle:focus-visible,
.nav-lang-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-glow);
  border-radius: 8px;
}

/* Page-transition motion */
.page-panel.active { animation: panel-in 0.42s cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Section headings get an understated gradient accent on the page titles */
.page-header h1,
.extract-wrap h1,
.settings-wrap h1,
.tmpl-wrap > .page-header h1 { letter-spacing: -0.03em; }

@media (prefers-reduced-motion: reduce) {
  .page-panel.active,
  .btn,
  .doc-card,
  .example-card,
  .tmpl-card,
  .step-card { animation: none !important; transition: none !important; }
}
