/* Shared components: filters, progress, save status, tables, buttons, forms, history, loader, toast, mobile layout, modals, protected-tab icon. Ported unchanged from the old styles.html lines 82-634. */
/* Filter Section */
.filter-section {
  background: linear-gradient(135deg, #f8faf9, #f0f5f2);
  border-radius: var(--radius); padding: 24px; margin-bottom: 24px;
  border: 1px solid var(--border-color);
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
.filter-group { display: flex; flex-direction: column; gap: 10px; }
.filter-label {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; color: var(--text-secondary); font-size: 0.9rem;
}
.step-badge {
  width: 26px; height: 26px; background: var(--primary); color: white;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}
.custom-select {
  width: 100%; padding: 14px 18px; font-size: 1rem; font-weight: 500; font-family: inherit;
  border: 2px solid var(--border-color); border-radius: 12px; background: white;
  color: var(--text-primary); appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%235a6b62' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 16px center;
  cursor: pointer; transition: all 0.2s ease;
}
.custom-select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(26,93,58,0.1); }

/* ========== شريط التقدم (جديد) ========== */
.progress-container {
  background: linear-gradient(135deg, #f8faf9, #f0f5f2);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 20px;
  border: 1px solid var(--border-color);
  animation: fadeIn 0.3s ease;
}
.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.progress-text {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}
.progress-text i {
  font-size: 1.2rem;
  color: var(--primary);
}
.progress-text strong {
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 1.05rem;
}
.progress-percent {
  font-weight: 800;
  font-size: 1rem;
  color: var(--primary);
  background: rgba(26,93,58,0.1);
  padding: 6px 14px;
  border-radius: 20px;
}
.progress-bar-wrap {
  width: 100%;
  height: 10px;
  background: rgba(26,93,58,0.1);
  border-radius: 10px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: progressShine 2s ease-in-out infinite;
}
@keyframes progressShine {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ========== مؤشر حالة الحفظ (جديد) ========== */
.save-status-wrap {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s ease;
}
.save-status i { font-size: 1rem; }
.save-status-idle {
  background: rgba(26,93,58,0.08);
  color: var(--primary);
}
.save-status-dirty {
  background: rgba(245,158,11,0.12);
  color: #b45309;
}
.save-status-saving {
  background: rgba(59,130,246,0.12);
  color: #1d4ed8;
}
.save-status-saving i {
  animation: spin 1s linear infinite;
}
.save-status-saved {
  background: rgba(34,197,94,0.12);
  color: #15803d;
}
.save-status-error {
  background: rgba(239,68,68,0.12);
  color: #b91c1c;
}

/* ========== تمييز الصفوف غير المرصودة (جديد) ========== */
.data-table tbody tr.ungraded {
  background: rgba(245, 158, 11, 0.06) !important;
}
.data-table tbody tr.ungraded:hover {
  background: rgba(245, 158, 11, 0.12) !important;
}
.data-table tbody tr.ungraded td:first-child::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 24px;
  background: #f59e0b;
  border-radius: 2px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Data Table */
.table-wrapper {
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border-color); background: white;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.data-table thead th {
  color: white; font-weight: 600; padding: 16px 12px;
  text-align: center; font-size: 0.9rem; white-space: nowrap;
}
.data-table tbody tr { border-bottom: 1px solid var(--border-color); transition: background 0.2s; }
.data-table tbody tr:hover { background: rgba(26,93,58,0.03); }
.data-table tbody td { padding: 14px 12px; text-align: center; vertical-align: middle; }
.student-name { text-align: right !important; font-weight: 600; }
.empty-state { padding: 50px 20px; text-align: center; color: var(--text-muted); }
.empty-state i { font-size: 3.5rem; margin-bottom: 16px; opacity: 0.4; display: block; }

.grade-input {
  width: 65px; height: 42px; padding: 0; text-align: center;
  font-weight: 700; font-size: 1.05rem; font-family: inherit;
  border: 2px solid var(--border-color); border-radius: 10px;
  background: #fafbfa; color: var(--text-primary); transition: all 0.2s ease;
}
.grade-input:focus { outline: none; border-color: var(--primary); background: white; box-shadow: 0 0 0 3px rgba(26,93,58,0.12); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }

.notes-input {
  width: 100px !important;
  font-size: 0.85rem !important;
  font-weight: 500 !important;
}

.fill-btn {
  margin-top: 8px; padding: 5px 14px; font-size: 0.7rem; font-family: inherit;
  background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3);
  color: white; border-radius: 20px; cursor: pointer; transition: all 0.2s;
}
.fill-btn:hover { background: rgba(255,255,255,0.35); }

.avg-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 50px; padding: 8px 14px; font-weight: 800; font-size: 0.95rem;
  border-radius: 25px; color: white;
}
.avg-badge.high { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.avg-badge.low { background: linear-gradient(135deg, #ef4444, #dc2626); }
.avg-badge.none { background: linear-gradient(135deg, #9ca3af, #6b7280); }
.avg-badge.success { background: linear-gradient(135deg, var(--primary-light), var(--primary)); }

.btn-primary {
  width: 100%; padding: 16px 28px; font-size: 1.05rem; font-weight: 700; font-family: inherit;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white; border: none; border-radius: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 4px 20px rgba(26,93,58,0.3); transition: all 0.25s ease; margin-top: 16px;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(26,93,58,0.35); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary i { font-size: 1.2rem; }

/* Students Section */
.students-container { max-width: 650px; margin: 0 auto; }
.mode-toggle {
  display: flex; background: #f0f3f1; border-radius: 14px; padding: 5px; margin-bottom: 24px;
}
.mode-toggle input { display: none; }
.mode-toggle label {
  flex: 1; padding: 14px 20px; text-align: center; font-weight: 600; font-size: 0.95rem;
  color: var(--text-secondary); border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.2s;
}
.mode-toggle input:checked + label { background: var(--primary); color: white; box-shadow: 0 3px 12px rgba(26,93,58,0.3); }
.student-section { background: #f8faf9; border-radius: var(--radius); padding: 24px; border: 1px solid var(--border-color); }
.info-box {
  background: linear-gradient(135deg, #e0f2fe, #bae6fd); border-radius: 12px;
  padding: 16px 18px; color: #0369a1; font-weight: 500; font-size: 0.95rem;
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px;
}
.info-box i { font-size: 1.3rem; }
.form-input {
  width: 100%; padding: 14px 18px; font-size: 1rem; font-family: inherit;
  border: 2px solid var(--border-color); border-radius: 12px; background: white;
  transition: all 0.2s; margin-bottom: 14px;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(26,93,58,0.1); }
textarea.form-input { resize: vertical; min-height: 140px; }
.btn-secondary {
  width: 100%; padding: 14px 24px; font-size: 1rem; font-weight: 600; font-family: inherit;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white; border: none; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.2s;
}
.btn-secondary:hover { transform: translateY(-2px); box-shadow: 0 4px 15px rgba(59,130,246,0.4); }

/* History Section */
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 16px; }
.history-title { font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.history-title i { color: var(--primary); }
.history-actions { display: flex; gap: 12px; }
.btn-outline {
  padding: 10px 20px; background: white; border: 2px solid var(--primary);
  color: var(--primary); font-weight: 600; font-family: inherit; font-size: 0.9rem;
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: all 0.2s;
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-danger {
  padding: 10px 20px; background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none; color: white; font-weight: 600; font-family: inherit; font-size: 0.9rem;
  border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: all 0.2s;
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(239,68,68,0.4); }

.history-table-wrapper { max-height: 500px; overflow-y: auto; border-radius: var(--radius); border: 1px solid var(--border-color); }
.history-table { width: 100%; border-collapse: collapse; }
.history-table thead { background: linear-gradient(135deg, #374151, #1f2937); position: sticky; top: 0; z-index: 10; }
.history-table thead th { color: white; font-weight: 600; padding: 14px 12px; text-align: center; font-size: 0.85rem; }
.history-table tbody tr { border-bottom: 1px solid var(--border-color); transition: background 0.2s; }
.history-table tbody tr:hover { background: #f8faf9; }
.history-table tbody td { padding: 12px; text-align: center; font-size: 0.9rem; }
.del-btn {
  width: 34px; height: 34px; border-radius: 50%; background: #fef2f2; color: #ef4444;
  border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.del-btn:hover { background: #ef4444; color: white; }

.pagination { display: flex; justify-content: center; gap: 8px; margin-top: 20px; }
.page-btn {
  min-width: 42px; height: 42px; border: 2px solid var(--border-color); background: white;
  color: var(--text-secondary); font-weight: 600; font-size: 0.95rem; font-family: inherit;
  border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.page-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.page-btn.active, .page-btn.active:hover:not(:disabled) { background: var(--primary); border-color: var(--primary); color: white; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Loader & Toast */
#loader {
  position: fixed; inset: 0; background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 20px;
}
.loader-spinner { width: 60px; height: 60px; border: 4px solid rgba(255,255,255,0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: white; font-size: 1.3rem; font-weight: 600; }
#errorArea { background: white; padding: 35px; border-radius: var(--radius); text-align: center; }
#errorArea h5 { color: #ef4444; margin-bottom: 12px; font-size: 1.1rem; }

.toast {
  position: fixed; bottom: 30px; left: 30px; padding: 16px 24px; border-radius: 14px;
  color: white; font-weight: 600; font-size: 1rem;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.2);
  transform: translateY(100px); opacity: 0; transition: all 0.3s ease; z-index: 9999;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
.toast.danger { background: linear-gradient(135deg, #ef4444, #dc2626); }
.toast.warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.toast.info { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.toast-close { margin-right: auto; background: none; border: none; color: white; opacity: 0.8; cursor: pointer; }

/* Mobile Bottom Nav - Hidden on Desktop */
.bottom-nav { display: none; }
.app-header-mobile { display: none; }

/* ========== MOBILE STYLES ========== */
@media (max-width: 768px) {
  body {
    padding-top: calc(60px + var(--safe-top));
    padding-bottom: calc(65px + var(--safe-bottom));
  }
  .app-container { padding: 16px; }
  .main-card { border-radius: 0; box-shadow: none; background: transparent; }
  .app-header-desktop, .nav-tabs-desktop { display: none; }
  .card-body-main { padding: 0; background: transparent; }

  /* Mobile Header */
  .app-header-mobile {
    display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: var(--safe-top) 0 0 0; box-shadow: 0 2px 20px rgba(0,0,0,0.15);
    height: calc(60px + var(--safe-top)); align-items: center; justify-content: center; gap: 12px;
  }
  .header-icon-mobile {
    width: 38px; height: 38px; background: linear-gradient(135deg, var(--accent), #f4e4a6);
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; color: var(--primary-dark);
  }
  .header-title-mobile { color: white; font-size: 1.15rem; font-weight: 700; }

  /* Mobile Bottom Nav */
  .bottom-nav {
    display: block; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    background: var(--bg-card); border-top: 1px solid var(--border-color);
    padding-bottom: var(--safe-bottom); box-shadow: 0 -2px 20px rgba(0,0,0,0.08);
  }
  .nav-items { display: flex; justify-content: space-around; align-items: center; height: 65px; }
  .nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; padding: 8px 0; cursor: pointer; transition: all 0.2s;
    border: none; background: none; color: var(--text-muted); -webkit-user-select: none;
  }
  .nav-item i { font-size: 1.5rem; }
  .nav-item span { font-size: 0.75rem; font-weight: 600; }
  .nav-item.active { color: var(--primary); }
  .nav-item.active i { transform: scale(1.1); }
  .nav-item:active { transform: scale(0.95); }

  /* Mobile Cards */
  .filter-section { grid-template-columns: 1fr; gap: 16px; padding: 20px; margin-bottom: 16px; }
  .progress-container { padding: 14px 16px; margin-bottom: 16px; }
  .progress-info { flex-wrap: wrap; gap: 8px; }
  .progress-text { font-size: 0.85rem; }
  .progress-percent { font-size: 0.85rem; padding: 4px 10px; }
  .table-wrapper { border-radius: 14px; }
  .data-table { min-width: 480px; }
  .data-table thead th { padding: 12px 8px; font-size: 0.8rem; }
  .data-table tbody td { padding: 10px 6px; font-size: 0.85rem; }
  .grade-input { width: 52px; height: 40px; font-size: 1rem; }
  .notes-input { width: 85px !important; }
  .fill-btn { padding: 3px 10px; font-size: 0.6rem; margin-top: 6px; }
  .avg-badge { min-width: 42px; padding: 6px 10px; font-size: 0.85rem; }
  .btn-primary { padding: 14px 20px; font-size: 1rem; border-radius: 12px; }

  .students-container { max-width: 100%; }
  .mode-toggle { border-radius: 12px; padding: 4px; margin-bottom: 20px; }
  .mode-toggle label { padding: 12px 16px; font-size: 0.9rem; }
  .student-section { padding: 20px; border-radius: 14px; }

  .history-header { margin-bottom: 16px; }
  .history-title { font-size: 1.05rem; }
  .history-actions { gap: 8px; }
  .btn-outline, .btn-danger { padding: 10px 14px; font-size: 0.85rem; }
  .btn-outline span, .btn-danger span { display: none; }
  .history-table-wrapper { max-height: 380px; border-radius: 14px; }
  .history-table { min-width: 550px; }

  .toast { bottom: calc(65px + var(--safe-bottom) + 16px); left: 16px; right: 16px; padding: 14px 18px; font-size: 0.95rem; }
}

/* ========== نافذة كلمة المرور (PIN Modal) ========== */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
  padding: 20px;
}
.pin-modal-box {
  background: white;
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUpModal 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes slideUpModal {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.pin-modal-header {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: white;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.pin-modal-header i { font-size: 1.7rem; }
.pin-modal-header h3 {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}
.pin-modal-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  font-size: 0.9rem;
}
.pin-modal-close:hover { background: rgba(255,255,255,0.3); }
.pin-modal-body {
  padding: 24px;
}
.pin-description {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-bottom: 18px;
  line-height: 1.7;
  background: #f8faf9;
  padding: 14px 16px;
  border-radius: 12px;
  border-right: 3px solid var(--primary);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.pin-description i { font-size: 1.1rem; margin-top: 2px; flex-shrink: 0; }
.pin-input {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.3rem;
  text-align: center;
  letter-spacing: 6px;
  font-family: inherit;
  font-weight: 700;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  background: #fafbfa;
  margin-bottom: 10px;
  transition: all 0.2s;
  direction: ltr;
}
.pin-input:focus {
  outline: none;
  border-color: #ef4444;
  background: white;
  box-shadow: 0 0 0 4px rgba(239,68,68,0.12);
}
.pin-input::placeholder {
  letter-spacing: 2px;
  font-weight: 500;
  font-size: 0.95rem;
}
.pin-error {
  color: #b91c1c;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 14px;
  background: #fef2f2;
  border-radius: 10px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}
.pin-error i { font-size: 1rem; flex-shrink: 0; }
.pin-modal-footer {
  padding: 0 24px 24px;
  display: flex;
  gap: 10px;
}
.pin-modal-footer button {
  flex: 1;
  padding: 13px 18px;
  font-size: 0.95rem;
  font-family: inherit;
  border-radius: 11px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
}
.pin-modal-footer .btn-outline {
  background: white;
  border: 2px solid;
}
.pin-modal-footer .btn-danger { border: none; }
.pin-modal-footer button:disabled { opacity: 0.6; cursor: not-allowed; }

@media (max-width: 768px) {
  .pin-modal-box { max-width: 100%; }
  .pin-modal-header { padding: 18px 20px; }
  .pin-modal-header h3 { font-size: 1.05rem; }
  .pin-modal-body { padding: 20px; }
  .pin-input { font-size: 1.15rem; letter-spacing: 4px; padding: 12px 16px; }
  .pin-modal-footer { padding: 0 20px 20px; }
  .pin-modal-footer button { padding: 12px 14px; font-size: 0.9rem; }
}

/* ========== أيقونة القفل للتبويبات المحمية ========== */
.protected-icon {
  font-size: 0.65rem !important;
  opacity: 0.55;
  margin-right: 4px;
  vertical-align: middle;
}
.nav-tab-desktop.active .protected-icon { opacity: 0.8; }
