* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: #f4f6f8;
  margin: 0;
  padding: 0;
  color: #1f2937;
}

header {
  background: #1e3a5f;
  color: white;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

header h1 {
  font-size: 1.1rem;
  margin: 0;
}

#user-info {
  /* عناصره (الاسم والأزرار) تشارك الشريط العلوي: اسم المعهد مقابل اسم المستخدم بسطر واحد */
  display: contents;
  font-size: 0.9rem;
}

#user-info.hidden {
  display: none;
}

main {
  padding: 20px;
  padding-bottom: 100px;
  max-width: 480px;
  margin: 0 auto;
}

section.hidden {
  display: none;
}

section {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.hint {
  color: #6b7280;
  font-size: 0.85rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

input,
select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  background: white;
}

button {
  padding: 12px;
  background: #1e3a5f;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
}

button:hover {
  background: #16304d;
}

#logout-btn {
  background: transparent;
  border: 1px solid white;
  border-radius: 6px;
}

.error {
  color: #b91c1c;
  background: #fee2e2;
  padding: 10px;
  border-radius: 6px;
  margin-top: 14px;
  font-size: 0.9rem;
}

.error.hidden {
  display: none;
}

.success {
  color: #065f46;
  background: #d1fae5;
  padding: 10px;
  border-radius: 6px;
  margin-top: 14px;
  font-size: 0.9rem;
}

.success.hidden {
  display: none;
}

.grade-inputs-row {
  display: flex;
  gap: 12px;
  min-width: 0;
}

.grade-inputs-row label {
  flex: 1;
  min-width: 0;
}

.grade-inputs-row input {
  width: 100%;
  min-width: 0;
}

#grades-staff-view select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 14px;
  width: 100%;
}

#grade-entry-form {
  margin-top: 4px;
  margin-bottom: 10px;
}

#grade-entry-form.hidden {
  display: none;
}

#attendance-view select,
#attendance-view input[type="date"] {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  margin-bottom: 14px;
}

#att-load-btn {
  margin-bottom: 16px;
}

.att-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f3f5;
}

.att-name {
  font-size: 0.82rem;
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-status-options {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.att-status-option {
  flex-direction: row !important;
  align-items: center;
  gap: 3px !important;
  padding: 5px 7px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.att-status-option input[type="radio"] {
  width: auto;
  margin: 0;
}

.att-status-option:has(input:checked) {
  background: #1e3a5f;
  border-color: #1e3a5f;
  color: #fff;
}

#att-save-btn {
  margin-top: 16px;
}

#att-save-btn.hidden {
  display: none;
}

#ranking-competitions-view select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  margin-bottom: 14px;
}

.tab-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab-btn {
  flex: 1;
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.tab-btn.active {
  background: #1e3a5f;
  color: white;
}

#rank-load-btn {
  margin-bottom: 16px;
}

.comp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f1f3f5;
}

.comp-open-btn {
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
}

#comp-detail-wrap {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

#comp-detail-wrap.hidden {
  display: none;
}

#comp-detail-title {
  color: #1e3a5f;
}

h4 {
  font-size: 0.95rem;
  margin: 16px 0 8px;
  color: #1e3a5f;
}

#comp-add-participant-btn {
  margin-bottom: 8px;
}

.comp-participant-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f1f3f5;
  gap: 10px;
}

.comp-participant-name {
  font-size: 0.9rem;
  flex: 1;
}

.comp-result-inputs {
  display: flex;
  gap: 6px;
  align-items: center;
}

.comp-score-input,
.comp-rank-input {
  width: 60px;
  padding: 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

.comp-save-result-btn {
  padding: 6px 10px;
  background: #1e3a5f;
  color: white;
  border: none;
  border-radius: 6px;
}

#users-view select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
}

.user-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #f1f3f5;
}

.user-row-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-row-sub {
  font-size: 0.8rem;
  color: #6b7280;
}

/* الأزرار الثلاثة (تعطيل، تصفير كلمة السر، حذف) جنب بعض بصف واحد أفقي
   عشان تختصر طول القائمة عند وجود عدد كبير من المستخدمين. */
.user-row-actions {
  display: flex;
  flex-direction: row;
  gap: 6px;
}

.user-toggle-btn,
.user-reset-btn,
.user-delete-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 4px;
  font-size: 0.72rem;
  line-height: 1.25;
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  border-radius: 6px;
  white-space: normal;
  text-align: center;
}

.reset-password-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}

.reset-password-input {
  font-size: 0.8rem;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid #d1d9e0;
  font-family: inherit;
}

.reset-confirm-btn,
.reset-cancel-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
  border: 1px solid #d1d9e0;
  white-space: nowrap;
}

.reset-confirm-btn {
  background: #1e3a5f;
  color: #fff;
  border-color: #1e3a5f;
}

.reset-cancel-btn {
  background: #f0f4f8;
  color: #1e3a5f;
}

#nav-users-btn.hidden {
  display: none;
}

.grade-edit-score {
  width: 55px;
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

.grade-row-actions {
  white-space: nowrap;
}

.grade-save-btn,
.grade-delete-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  background: #f0f4f8;
  margin-inline-start: 4px;
}

.show-pw-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-size: 0.85rem;
  color: #6b7280;
  cursor: pointer;
}

.show-pw-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* أيقونة إظهار/إخفاء كلمة السر داخل الخانة نفسها، على اليسار */
.pw-wrap {
  position: relative;
}

.pw-wrap input {
  padding-left: 40px;
}

.pw-eye-btn {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.15rem;
  padding: 6px;
  line-height: 1;
}

/* شاشة الترحيب */
.home-header {
  text-align: center;
  margin-bottom: 4px;
}

.home-logo {
  display: block;
  width: 150px;
  height: 150px;
  margin: 4px auto 8px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(6, 71, 12, 0.35);
}

.home-header h2 {
  font-size: 1.2rem;
  margin: 0;
}

.home-welcome-text {
  color: #6b7280;
  font-size: 1rem;
  margin: 4px 0 0;
}

/* الواجهة الرئيسية: الطلاب / الإدارة */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 8px;
}

.home-big-btn {
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  padding: 8px 12px;
  font-size: 1.15rem;
  font-weight: 700;
  border-radius: 10px;
  line-height: 1.2;
}

.home-sub-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.home-role-btn {
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  padding: 16px 12px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 10px;
}

.nav-grid {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 4px;
  padding: 6px;
  background: white;
  border-top: 1px solid #e5e7eb;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.07);
  z-index: 100;
}

.nav-grid.hidden {
  display: none;
}

.nav-grid button {
  flex: 1 1 0;
  min-width: 0;
  background: #f0f4f8;
  color: #1e3a5f;
  border: 1px solid #d1d9e0;
  padding: 6px 2px;
  font-size: 0.65rem;
  line-height: 1.35;
  border-radius: 8px;
}

.nav-grid button:hover {
  background: #e2e9f0;
}

.nav-grid button[data-soon] {
  color: #9ca3af;
  cursor: default;
}

.back-btn {
  background: transparent;
  color: #1e3a5f;
  border: none;
  padding: 0 0 14px 0;
  font-size: 0.9rem;
  text-align: right;
  align-self: flex-start;
}

#schedule-grade-select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 16px;
}

.day-heading {
  margin: 18px 0 8px;
  font-size: 1rem;
  color: #1e3a5f;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 4px;
}

.day-heading:first-child {
  margin-top: 0;
}

.users-list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.users-list-header .day-heading {
  margin: 18px 0 8px;
  border-bottom: none;
  padding-bottom: 0;
  flex: 1 1 auto;
}

.users-grade-filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: #6b7280;
  white-space: nowrap;
}

.users-grade-filter-label select {
  width: auto;
  margin-bottom: 0;
  padding: 6px 8px;
  font-size: 0.85rem;
}

.day-checkbox-group {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 0;
}

.day-checkbox-group legend {
  padding: 0 6px;
  font-size: 0.85rem;
  color: #6b7280;
}

#schedule-add-day-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.day-checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  font-size: 0.9rem;
  cursor: pointer;
  flex: 0 0 calc(33.333% - 7px);
}

.day-checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}

.attendance-summary {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.attendance-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 6px;
  border-radius: 10px;
  background: #f0f4f8;
}

.attendance-stat strong {
  font-size: 1.4rem;
}

.attendance-stat span {
  font-size: 0.8rem;
  color: #6b7280;
}

.attendance-stat-present {
  background: #d1fae5;
}

.attendance-stat-present strong {
  color: #065f46;
}

.attendance-stat-absent {
  background: #fee2e2;
}

.attendance-stat-absent strong {
  color: #b91c1c;
}

.attendance-stat-excused {
  background: #fef3c7;
}

.attendance-stat-excused strong {
  color: #92400e;
}

.schedule-table td {
  padding: 8px 6px;
  border-bottom: 1px solid #f1f3f5;
  font-size: 0.9rem;
}

.schedule-table td:first-child {
  color: #6b7280;
  white-space: nowrap;
  width: 30%;
}

.schedule-table th {
  padding: 6px;
  text-align: start;
  font-size: 0.8rem;
  color: #6b7280;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
}

#schedule-add-wrap {
  margin: 16px 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
}

.danger-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  background: #fee2e2;
  color: #b91c1c;
  margin-inline-start: 4px;
}

#enroll-grade-select,
#enroll-student-select {
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  margin-bottom: 14px;
}

#enroll-btn {
  margin-bottom: 8px;
}

/* سطر تأكيد يوم وتاريخ الحصة بشاشة الحضور */
.att-date-confirm {
  margin: 4px 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #e8f5e9;
  color: #1b5e20;
  font-weight: bold;
}
.att-date-confirm.mismatch {
  background: #fdecea;
  color: #b71c1c;
}

/* الأزرار الفاتحة (نص داكن): القاعدة العامة button:hover تعطي خلفية داكنة،
   فيصير النص الداكن غير مقروء — وعلى الجوال يبقى أثر hover بعد اللمس.
   نعطيها خلفية فاتحة أغمق قليلاً بدل ذلك. */
.home-big-btn:hover,
.home-role-btn:hover,
.tab-btn:not(.active):hover,
.comp-open-btn:hover,
.user-delete-btn:hover,
.reset-cancel-btn:hover,
.back-btn:hover {
  background: #e1e8ef;
}


/* أزرار الحساب بأعلى الشاشة (تغيير كلمة السر + الخروج) */
#user-name {
  order: 2;
  font-size: 0.95rem;
  font-weight: bold;
}

header h1 {
  order: 1;
}

/* الأزرار (نسخة احتياطية، تغيير كلمة السر، الخروج) بسطر واحد تحت الاسم */
.user-info-actions {
  order: 3;
  flex: 1 1 100%;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.user-info-actions button {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 4px;
  font-size: 0.75rem;
  line-height: 1.3;
  text-align: center;
}

#change-pw-btn,
#backup-btn {
  background: transparent;
  border: 1px solid white;
  border-radius: 6px;
}

#change-pw-btn.hidden,
#backup-btn.hidden {
  display: none;
}

#user-info {
  flex-wrap: wrap;
}

/* طلبات التسجيل: تنبيه التكرار وخيارات الحظر */
.dup-warning {
  display: block;
  margin-top: 4px;
  color: #9a5b00;
  font-size: 0.85rem;
}

.block-picker {
  flex-basis: 100%;
  margin-top: 8px;
  padding: 10px;
  border: 1px dashed #c0392b;
  border-radius: 8px;
  background: #fff7f6;
}

.block-picker .block-option {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-weight: normal;
}

.block-picker .block-option input {
  width: auto;
  margin: 0;
}

/* النسخة الاحتياطية: تنبيه النسخة الدورية + شاشة النسخ */
.backup-due-banner {
  background: #e8f4ea;
  color: #1b5e20;
  border-bottom: 2px solid #66bb6a;
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.backup-due-banner.hidden {
  display: none;
}

.backup-due-banner button {
  padding: 6px 12px;
  font-size: 0.9rem;
}

.backup-due-banner .secondary-btn {
  background: white;
  color: #1b5e20;
  border: 1px solid #66bb6a;
}

.backup-due-banner .secondary-btn:hover {
  background: #d7eed9;
}

#backup-view > button:not(.back-btn) {
  width: 100%;
  margin-bottom: 10px;
}

/* قبول المنتسبات: بطاقة صغيرة لكل صف/حلقة */
.grade-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 8px 0 12px;
}

.grade-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 4px;
  background: #f0f4f8;
  color: #1e3a5f;
  border: 2px solid #d1d9e0;
  border-radius: 10px;
  font-family: inherit;
  cursor: pointer;
}

.grade-tile:hover {
  background: #e1e8ef;
}

.grade-tile.active {
  border-color: #1e3a5f;
  background: #e3ecf7;
}

.grade-tile-name {
  font-weight: bold;
  font-size: 0.9rem;
  line-height: 1.25;
  text-align: center;
}

.grade-tile-line {
  font-size: 0.72rem;
  line-height: 1.3;
  color: #4b5563;
}

.grade-tile.has-pending .grade-tile-waiting {
  color: #c2410c;
  font-size: 0.85rem;
}
