:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --bg-main: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Cairo', 'Tajawal', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  direction: rtl;
  text-align: right;
  line-height: 1.5;
  min-height: 100vh;
}

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: white;
  padding: 1.25rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

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

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.header-title h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-title p {
  font-size: 0.875rem;
  opacity: 0.85;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.meta-pill {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  backdrop-filter: blur(4px);
}

.live-clock {
  font-family: monospace;
  font-weight: 700;
  font-size: 1.1rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  direction: ltr;
}

/* Nav Links / Quick Bar */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.nav-classes-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.class-select-dropdown {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main);
  background-color: var(--bg-main);
  cursor: pointer;
  outline: none;
  min-width: 250px;
}

.nav-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

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

.btn-secondary {
  background-color: #f1f5f9;
  color: #334155;
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background-color: #e2e8f0;
}

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-main);
}
.btn-outline:hover {
  background: var(--bg-main);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

/* Main Grid Layout */
.attendance-grid {
  display: grid;
  grid-template-columns: 460px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1080px) {
  .attendance-grid {
    grid-template-columns: 1fr;
  }
}

/* Barcode Card / Hero Panel */
.barcode-panel {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: sticky;
  top: 1rem;
}

.barcode-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* Timer Circle Indicator */
.refresh-status-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  margin-bottom: 1.25rem;
  width: 100%;
  justify-content: space-between;
}

.timer-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pulse-indicator {
  width: 10px;
  height: 10px;
  background-color: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-ring 1.5s infinite;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

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

.timer-countdown {
  font-weight: 700;
  color: var(--primary);
  font-family: monospace;
  font-size: 1rem;
}

/* Progress bar */
.timer-progress-track {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}

.timer-progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  transition: width 0.1s linear;
}

/* Code Display Box */
.codes-container {
  background: white;
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 2px dashed #cbd5e1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.25rem;
  position: relative;
  transition: transform 0.15s ease;
}

.qr-box {
  width: 250px;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

.qr-box canvas, .qr-box img {
  border-radius: 8px;
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.barcode-box {
  width: 100%;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.barcode-box svg {
  max-width: 100%;
  height: 65px;
}

.dynamic-token-pill {
  font-family: monospace;
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: #475569;
  margin-top: 0.75rem;
  word-break: break-all;
  direction: ltr;
}

.scan-prompt {
  font-size: 0.95rem;
  color: var(--text-main);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.scan-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.barcode-controls {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

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

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

.stat-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 1.25rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-icon.total { background: #eff6ff; color: #2563eb; }
.stat-icon.present { background: #ecfdf5; color: #10b981; }
.stat-icon.absent { background: #fef2f2; color: #ef4444; }
.stat-icon.rate { background: #fef3c7; color: #d97706; }

.stat-info h3 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-info p {
  font-size: 0.825rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Roster Table Card */
.roster-card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
}

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

.roster-title h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.roster-title p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.table-toolbar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  outline: none;
  min-width: 220px;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-pills {
  display: flex;
  background: #f1f5f9;
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.filter-btn {
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  font-size: 0.825rem;
  font-weight: 600;
  border: none;
  background: transparent;
  cursor: pointer;
  color: #475569;
  transition: all 0.15s ease;
}

.filter-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Table Style */
.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.attendance-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.9rem;
}

.attendance-table th {
  background: #f8fafc;
  padding: 0.85rem 1rem;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.attendance-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.attendance-table tr:hover {
  background-color: #f8fafc;
}

.attendance-table tr.just-registered {
  animation: highlight-row 2s ease;
}

@keyframes highlight-row {
  0% { background-color: #d1fae5; }
  100% { background-color: transparent; }
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.badge-present {
  background-color: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-absent {
  background-color: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.badge-excused {
  background-color: var(--warning-bg);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Student Registration Page Style */
.student-portal-wrapper {
  max-width: 580px;
  margin: 2rem auto;
  padding: 1rem;
}

.student-portal-card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.student-card-header {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  padding: 1.75rem;
  text-align: center;
}

.student-card-header h2 {
  font-size: 1.4rem;
  margin-bottom: 0.25rem;
}

.student-card-body {
  padding: 2rem;
}

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

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #334155;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  background: #f8fafc;
}
.form-control:focus {
  background: white;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.student-autocomplete-results {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 200px;
  overflow-y: auto;
  margin-top: 0.35rem;
  box-shadow: var(--shadow-md);
}

.student-autocomplete-item {
  padding: 0.65rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}
.student-autocomplete-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.selected-student-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.selected-student-avatar {
  width: 48px;
  height: 48px;
  background: #10b981;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
}

.status-feedback-banner {
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  display: none;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.status-feedback-banner.success {
  display: flex;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.status-feedback-banner.error {
  display: flex;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #1e293b;
  color: white;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slide-in 0.3s ease;
  min-width: 280px;
}

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

/* Print Layout */
@media print {
  body {
    background: white;
    color: black;
  }
  .app-header, .top-nav, .barcode-panel, .table-toolbar, .btn, .nav-actions, .filter-pills {
    display: none !important;
  }
  .attendance-grid {
    display: block;
  }
  .roster-card {
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .print-official-header {
    display: block !important;
    text-align: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #000;
    padding-bottom: 1rem;
  }
  .attendance-table th, .attendance-table td {
    border: 1px solid #000 !important;
    color: #000 !important;
    padding: 6px 10px;
  }
}

.print-official-header {
  display: none;
}

.attendance-table th:last-child,
.attendance-table td:last-child {
  min-width: 180px !important;
  text-align: center;
  white-space: nowrap;
}

.btn-warning {
  background-color: #f59e0b;
  color: white;
}
.btn-warning:hover {
  background-color: #d97706;
}
