/* ═══════════════════════════════════════════════════════════════════════
 * NEXA v2 — shared frontend styles (RTL Arabic-first)
 * ═══════════════════════════════════════════════════════════════════════ */

/* Theme tokens. The default values are the existing light-mode palette;
 * dark mode is opt-in via [data-theme="dark"] on <html>. The toggle in
 * nx-nav writes the choice to localStorage. */
:root {
  --nx-bg: #fafaf8;
  --nx-fg: #1a1a1a;
  --nx-fg-muted: #666;
  --nx-fg-faint: #888;
  --nx-surface: #fff;
  --nx-surface-alt: #f9f9f7;
  --nx-border: #eee;
  --nx-border-strong: #ddd;
  --nx-input-bg: #fff;
  --nx-row-hover: #fafafa;
  --nx-shadow-card: 0 1px 3px rgba(0,0,0,0.04);
  --nx-shadow-strong: 0 4px 16px rgba(0,0,0,0.08);
  --nx-gold: #d4af37;
  --nx-nav-bg: #0a0a0a;
  --nx-nav-fg: #fff;
}
[data-theme="dark"] {
  --nx-bg: #0e0e10;
  --nx-fg: #f1f1ee;
  --nx-fg-muted: #aaa;
  --nx-fg-faint: #888;
  --nx-surface: #1a1a1c;
  --nx-surface-alt: #232326;
  --nx-border: #2a2a2d;
  --nx-border-strong: #3a3a3e;
  --nx-input-bg: #1a1a1c;
  --nx-row-hover: #232326;
  --nx-shadow-card: 0 1px 3px rgba(0,0,0,0.4);
  --nx-shadow-strong: 0 6px 20px rgba(0,0,0,0.5);
  --nx-nav-bg: #050507;
  --nx-nav-fg: #f1f1ee;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
html, body { height: 100%; }

body {
  font-family: 'Helvetica Neue', Arial, 'Segoe UI', Tahoma, sans-serif;
  background: var(--nx-bg);
  color: var(--nx-fg);
  line-height: 1.6;
  direction: rtl;
}

a { color: var(--nx-gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────────────────────── */
.nx-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.nx-nav {
  background: var(--nx-nav-bg);
  color: var(--nx-nav-fg);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.nx-nav-brand {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #d4af37 0%, #f5deb3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.nx-nav-menu {
  display: flex;
  gap: 24px;
  align-items: center;
}
.nx-nav-menu a { color: #fff; opacity: 0.8; font-size: 0.95rem; }
.nx-nav-menu a:hover { opacity: 1; text-decoration: none; }
.nx-nav-menu .nx-user { color: #d4af37; font-weight: 600; }

.nx-main {
  flex: 1;
  padding: 40px 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.nx-footer {
  text-align: center;
  padding: 24px;
  color: var(--nx-fg-faint);
  font-size: 0.85rem;
  border-top: 1px solid var(--nx-border);
}

/* ── Cards ────────────────────────────────────────────────────── */
.nx-card {
  background: var(--nx-surface);
  border: 1px solid var(--nx-border);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--nx-shadow-card);
}
.nx-card + .nx-card { margin-top: 20px; }
.nx-card-narrow { max-width: 480px; margin: 60px auto; }

.nx-card-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--nx-fg);
}
.nx-card-subtitle {
  color: var(--nx-fg-muted);
  margin-bottom: 24px;
}

/* ── Forms ────────────────────────────────────────────────────── */
.nx-field { margin-bottom: 18px; }
.nx-field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--nx-fg);
}
.nx-field input,
.nx-field textarea,
.nx-field select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--nx-border-strong);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--nx-input-bg);
  color: var(--nx-fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.nx-field input:focus,
.nx-field textarea:focus,
.nx-field select:focus {
  outline: none;
  border-color: #d4af37;
  box-shadow: 0 0 0 3px rgba(212,175,55,0.15);
}
.nx-field textarea { min-height: 100px; resize: vertical; }
.nx-field-hint { font-size: 0.8rem; color: var(--nx-fg-faint); margin-top: 4px; }
.nx-field-error { font-size: 0.85rem; color: #c00; margin-top: 4px; }

/* ── Buttons ──────────────────────────────────────────────────── */
.nx-btn {
  display: inline-block;
  padding: 11px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.nx-btn-primary {
  background: #1a1a1a;
  color: #fff;
}
.nx-btn-primary:hover { background: #333; }
.nx-btn-gold {
  background: #d4af37;
  color: #1a1a1a;
}
.nx-btn-gold:hover { background: #b8961f; }
.nx-btn-block { width: 100%; }
.nx-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Alerts ───────────────────────────────────────────────────── */
.nx-alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 18px;
  font-size: 0.9rem;
}
.nx-alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.nx-alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.nx-alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Tables / Lists ───────────────────────────────────────────── */
.nx-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--nx-surface);
}
.nx-table th, .nx-table td {
  padding: 12px 16px;
  text-align: right;
  border-bottom: 1px solid var(--nx-border);
  color: var(--nx-fg);
}
.nx-table th {
  background: var(--nx-surface-alt);
  font-weight: 700;
  color: var(--nx-fg-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.nx-table tr:hover td { background: var(--nx-row-hover); }

/* ── Status badges ────────────────────────────────────────────── */
.nx-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.nx-badge-queued { background: #fef3c7; color: #92400e; }
.nx-badge-processing { background: #dbeafe; color: #1e40af; }
.nx-badge-ready { background: #d1fae5; color: #065f46; }
.nx-badge-failed { background: #fee2e2; color: #991b1b; }

/* ── Loading skeletons ────────────────────────────────────────── */
.nx-skeleton {
  display: block;
  background: linear-gradient(90deg, #f0f0f0 25%, #e6e6e6 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: nx-skeleton 1.5s linear infinite;
  border-radius: 4px;
  height: 14px;
  margin-bottom: 8px;
}
.nx-skeleton-title { height: 24px; width: 60%; }
.nx-skeleton-line { height: 14px; width: 100%; }
.nx-skeleton-line.short { width: 40%; }
.nx-skeleton-card {
  background: linear-gradient(90deg, #f0f0f0 25%, #e6e6e6 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: nx-skeleton 1.5s linear infinite;
  border-radius: 8px;
  height: 200px;
  margin-bottom: 16px;
}
@keyframes nx-skeleton {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Empty state ──────────────────────────────────────────────── */
.nx-empty {
  text-align: center;
  padding: 60px 24px;
  color: #999;
}
.nx-empty h3 { font-size: 1.2rem; margin-bottom: 8px; color: #555; }

/* ── Command palette (Cmd/Ctrl+K) ─────────────────────────────── */
.nx-cmdk-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,10,0.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 80px 16px 16px;
  z-index: 1200;
  animation: nx-fade-in 0.15s ease-out;
}
.nx-cmdk {
  background: var(--nx-surface);
  color: var(--nx-fg);
  width: 100%; max-width: 540px;
  border-radius: 12px;
  box-shadow: var(--nx-shadow-strong), 0 16px 60px rgba(0,0,0,0.35);
  overflow: hidden;
  border: 1px solid var(--nx-border);
}
.nx-cmdk-input {
  width: 100%;
  border: none; outline: none;
  padding: 16px 20px;
  font-size: 1rem; font-family: inherit;
  background: transparent; color: var(--nx-fg);
  border-bottom: 1px solid var(--nx-border);
}
.nx-cmdk-list { max-height: 360px; overflow-y: auto; }
.nx-cmdk-item {
  padding: 11px 18px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
  font-size: 0.95rem;
}
.nx-cmdk-item.active,
.nx-cmdk-item:hover { background: var(--nx-surface-alt); }
.nx-cmdk-item-icon {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  color: var(--nx-gold);
}
.nx-cmdk-item-label { flex: 1; }
.nx-cmdk-item-hint { font-size: 0.75rem; color: var(--nx-fg-faint); }
.nx-cmdk-empty { padding: 24px; text-align: center; color: var(--nx-fg-faint); font-size: 0.9rem; }

/* ── Toast notifications ──────────────────────────────────────── */
.nx-toast-host {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-start: 24px;
  display: flex; flex-direction: column-reverse;
  gap: 10px;
  z-index: 1100;
  pointer-events: none;
}
.nx-toast {
  pointer-events: auto;
  min-width: 240px; max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  display: flex; align-items: flex-start; gap: 10px;
  animation: nx-toast-in 0.22s ease-out;
}
.nx-toast-icon { font-weight: 900; min-width: 18px; line-height: 1.4; }
.nx-toast-msg { flex: 1; line-height: 1.5; word-break: break-word; }
.nx-toast-close {
  background: none; border: none; color: inherit;
  cursor: pointer; padding: 0 0 0 4px; font-size: 1.1rem;
  opacity: 0.7; transition: opacity 0.15s;
}
.nx-toast-close:hover { opacity: 1; }
.nx-toast-success { background: #065f46; }
.nx-toast-error   { background: #991b1b; }
.nx-toast-info    { background: #1e40af; }
.nx-toast.exiting { animation: nx-toast-out 0.18s forwards; }
@keyframes nx-toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes nx-toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(12px); }
}

/* ── Onboarding wizard (first-visit overlay) ──────────────────── */
.nx-wizard-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, 0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 1000;
  animation: nx-fade-in 0.2s ease-out;
}
.nx-wizard {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  padding: 36px 32px 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
  position: relative;
}
.nx-wizard-step { display: none; }
.nx-wizard-step.active { display: block; animation: nx-fade-in 0.25s ease-out; }
.nx-wizard-icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #d4af37 0%, #f5deb3 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 900; color: #1a1a1a;
}
.nx-wizard h2 {
  font-size: 1.5rem; font-weight: 700;
  margin-bottom: 10px; color: #1a1a1a;
}
.nx-wizard p {
  color: #555; font-size: 0.98rem; line-height: 1.7;
  margin-bottom: 22px;
}
.nx-wizard-points {
  text-align: right;
  background: #fafaf8;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 22px;
  list-style: none;
}
.nx-wizard-points li {
  padding: 6px 0;
  display: flex; gap: 10px; align-items: flex-start;
  color: #333; font-size: 0.92rem;
}
.nx-wizard-points li::before {
  content: '✓';
  color: #d4af37; font-weight: 900;
  min-width: 18px;
}
.nx-wizard-dots {
  display: flex; justify-content: center; gap: 8px;
  margin-bottom: 18px;
}
.nx-wizard-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #e0e0d8; transition: background 0.2s;
}
.nx-wizard-dot.active { background: #d4af37; width: 24px; border-radius: 4px; }
.nx-wizard-actions {
  display: flex; gap: 12px; justify-content: center;
}
.nx-wizard-skip {
  position: absolute; top: 14px; left: 16px;
  background: none; border: none;
  color: #888; font-size: 0.85rem;
  cursor: pointer; padding: 6px 10px;
  font-family: inherit;
}
.nx-wizard-skip:hover { color: #333; }
@keyframes nx-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  .nx-nav { padding: 12px 16px; flex-direction: column; gap: 12px; }
  .nx-nav-menu { flex-wrap: wrap; gap: 16px; justify-content: center; }
  .nx-main { padding: 24px 16px; }
  .nx-card { padding: 20px; }
  .nx-card-narrow { margin: 24px auto; }
  .nx-wizard { padding: 28px 22px 22px; }
  .nx-wizard h2 { font-size: 1.25rem; }
}

/* ── Print stylesheet ─────────────────────────────────────────── */
/* Forces a print-friendly view: drop chrome (nav/footer/buttons), force
 * white background + black ink, expand cards, page-break sensibly. */
@media print {
  /* Force light theme regardless of toggle */
  :root, [data-theme="dark"] {
    --nx-bg: #fff !important;
    --nx-fg: #000 !important;
    --nx-fg-muted: #333 !important;
    --nx-fg-faint: #555 !important;
    --nx-surface: #fff !important;
    --nx-surface-alt: #f5f5f5 !important;
    --nx-border: #ddd !important;
    --nx-shadow-card: none !important;
  }
  body { background: #fff !important; color: #000 !important; }

  /* Hide everything that isn't content. */
  .nx-nav,
  .nx-footer,
  .nx-toast-host,
  .nx-cmdk-overlay,
  .nx-wizard-overlay,
  .bulk-bar,
  [data-nx-theme-toggle],
  .nx-btn,
  button,
  #logoutBtn,
  .filterClear,
  #filterQ, #filterStatus,
  #revokeAll {
    display: none !important;
  }

  /* Re-show inline content buttons that the user might want to keep. */
  .nx-print-keep { display: inline-block !important; }

  .nx-main {
    padding: 0 !important;
    max-width: 100% !important;
  }
  .nx-card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
    page-break-inside: avoid;
    padding: 16px !important;
    margin-bottom: 12px !important;
  }
  .nx-table th, .nx-table td {
    color: #000 !important;
    border-bottom: 1px solid #ccc !important;
    padding: 8px 10px !important;
  }
  .nx-table th { background: #f5f5f5 !important; }

  a { color: #000 !important; text-decoration: none !important; }
  a[href]::after { content: ''; }

  /* Page break helpers — pages can opt-in. */
  .nx-page-break { page-break-after: always; }
  .nx-no-break { page-break-inside: avoid; }

  /* Tighter line-height / font for print */
  html, body { font-size: 12pt; line-height: 1.45; }

  @page {
    size: A4;
    margin: 16mm 14mm;
  }
}
