:root {
  --font: 'Cairo', sans-serif;
  --bg: #0c0e14;
  --bg-elevated: #12151e;
  --surface: #181c27;
  --surface-hover: #1e2433;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --primary: #e11d48;
  --primary-hover: #be123c;
  --primary-soft: rgba(225, 29, 72, 0.12);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-soft: rgba(59, 130, 246, 0.12);
  --purple: #8b5cf6;
  --purple-soft: rgba(139, 92, 246, 0.12);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --sidebar-w: 280px;
  --topbar-h: 72px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* ─── Login ─── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(225, 29, 72, 0.15), transparent),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(59, 130, 246, 0.08), transparent),
    var(--bg);
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.login-brand p {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.brand-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #9f1239);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
  color: white;
  flex-shrink: 0;
}

.brand-icon.sm { width: 40px; height: 40px; font-size: 1.1rem; border-radius: 10px; }

.login-form { display: flex; flex-direction: column; gap: 1.25rem; }

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.form-error {
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
}

/* ─── Layout ─── */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-text strong {
  display: block;
  font-size: 0.9375rem;
  font-weight: 700;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.75rem;
}

.nav-group { margin-bottom: 1.25rem; }

.nav-label {
  display: block;
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: right;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: #fda4af;
  border: 1px solid rgba(225, 29, 72, 0.25);
}

.nav-item.active svg { opacity: 1; color: var(--primary); }

.sidebar-foot {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.main-wrap {
  flex: 1;
  margin-right: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 14, 20, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-start {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar h1 {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 0.1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--surface);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-pill.ready { border-color: rgba(16, 185, 129, 0.3); background: var(--success-soft); color: #6ee7b7; }
.status-pill.ready .status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-pill.qr { border-color: rgba(245, 158, 11, 0.3); background: var(--warning-soft); color: #fcd34d; }
.status-pill.qr .status-dot { background: var(--warning); }
.status-pill.disconnected { border-color: rgba(239, 68, 68, 0.3); background: var(--danger-soft); color: #fca5a5; }
.status-pill.disconnected .status-dot { background: var(--danger); }

.main-content {
  flex: 1;
  padding: 1.75rem 2rem 2.5rem;
}

.page { display: none; animation: fadeIn 0.25s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Stats ─── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--border-strong); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--info-soft); color: var(--info); }
.stat-icon.amber { background: var(--warning-soft); color: var(--warning); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-icon.purple { background: var(--purple-soft); color: var(--purple); }

.stat-body span {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.stat-body strong {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

/* ─── Panels ─── */
.page-grid { display: grid; gap: 1.25rem; }
.page-grid.two-col { grid-template-columns: 1.4fr 1fr; }
.page-grid.narrow { max-width: 560px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.panel-center { max-width: 480px; margin: 0 auto; text-align: center; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.panel-head h3 {
  font-size: 1.0625rem;
  font-weight: 700;
}

.panel-desc {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1.25rem;
  line-height: 1.7;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.45rem;
  margin-right: 0.35rem;
  background: var(--primary-soft);
  color: #fda4af;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ─── Quick actions ─── */
.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.quick-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 1rem 1.15rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font);
  text-align: right;
  transition: all 0.18s;
  width: 100%;
}

.quick-card:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.quick-card strong { font-size: 0.9375rem; font-weight: 700; color: var(--text); }
.quick-card small { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.quick-icon { font-size: 1.25rem; margin-bottom: 0.25rem; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
}

.link-btn:hover { text-decoration: underline; }

/* ─── QR ─── */
.qr-box {
  background: white;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  min-height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.qr-box img { max-width: 240px; border-radius: 8px; }

.btn-row { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

/* ─── Filters ─── */
.filters-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.chip {
  padding: 0.45rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
}

.chip:hover { color: var(--text); border-color: var(--text-muted); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ─── Table ─── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: right;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  vertical-align: middle;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.data-table tbody tr:hover { background: var(--surface-hover); }

.data-table tbody tr:last-child td { border-bottom: none; }

.cell-title { font-weight: 700; color: var(--text); }
.cell-sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.1rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  font-weight: 600;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  opacity: 0.35;
}

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.badge.pending { background: var(--warning-soft); color: #fcd34d; }
.badge.submitted { background: var(--success-soft); color: #6ee7b7; }
.badge.failed { background: var(--danger-soft); color: #fca5a5; }
.badge.processing { background: var(--info-soft); color: #93c5fd; }

.muted { color: var(--text-muted); font-weight: 500; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.btn svg { width: 18px; height: 18px; }

.btn-block { width: 100%; }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.8125rem; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { filter: brightness(1.08); }

.btn-outline-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.btn-outline-danger:hover { background: var(--danger-soft); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--danger); border-color: rgba(239, 68, 68, 0.4); background: var(--danger-soft); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ─── Forms ─── */
.form-stack { display: flex; flex-direction: column; gap: 1.15rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 500;
}

.form-group textarea { min-height: 88px; resize: vertical; }
.form-group.full { grid-column: 1 / -1; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.checkbox-row input { width: auto; accent-color: var(--primary); }

/* ─── Modal ─── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 760px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1.35rem 1.5rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
}

.modal-header h3 { font-size: 1.125rem; font-weight: 800; }
.modal-sub { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; margin-top: 0.15rem; }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.result-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-top: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.7;
}

.result-box.success { border-color: rgba(16, 185, 129, 0.3); background: var(--success-soft); }
.result-box a { color: #93c5fd; font-weight: 700; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 1.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius);
  z-index: 300;
  font-size: 0.875rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}

.toast.success { border-color: rgba(16, 185, 129, 0.4); color: #6ee7b7; }
.toast.error { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
}

/* ─── Responsive ─── */
@media (max-width: 1200px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .page-grid.two-col { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .mobile-only { display: inline-flex; }

  .sidebar {
    transform: translateX(100%);
    transition: transform 0.28s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .main-wrap { margin-right: 0; }

  .topbar { padding: 0 1rem; }

  .main-content { padding: 1.25rem 1rem 2rem; }

  .stats-row { grid-template-columns: repeat(2, 1fr); }

  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .stats-row { grid-template-columns: 1fr; }
}
