/* shared.css v2.1 ── تم التعديل لدعم التمرير الأفقي وإصلاح المظهر */

:root {
  --primary:  #0984e3;
  --secondary:#00cec9;
  --accent:   #6c5ce7;
  --dark:     #2d3436;
  --white:    #ffffff;
  --shadow:   0 10px 30px rgba(0,0,0,.10);
  --radius:   18px;
  /* المتغيرات التي يتم حقنها بواسطة JS */
  --pg:  #0984e3;
  --pab: #f0f7ff;
  --pas: rgba(9,132,227,.15);
  --phg: linear-gradient(135deg,rgba(9,132,227,.9),rgba(0,206,201,.8));
  --pbb: #eef2ff;
  --pds: rgba(9,132,227,.25);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #f1f3f6;
  color: var(--dark);
  font-family: 'Tajawal', sans-serif;
  overflow-x: hidden;
}

/* ── Header ── */
header {
  position: relative;
  height: 320px;
  background: url('https://img.freepik.com/free-vector/abstract-medical-wallpaper-design_23-2149116602.jpg') center/cover;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  padding: 20px;
  border-bottom-left-radius:  50px;
  border-bottom-right-radius: 50px;
  box-shadow: var(--shadow);
}

header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--phg);
  border-bottom-left-radius:  50px;
  border-bottom-right-radius: 50px;
}

.header-content { position: relative; z-index: 2; }

h1 {
  font-size: 2.3rem;
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(0,0,0,.2);
  margin-bottom: 10px;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  background: rgba(255,255,255,.15);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: 6px 18px;
  border-radius: 50px;
  font-size: .85rem;
  font-weight: 700;
  text-decoration: none;
  transition: background .25s, color .25s;
}
.back-link:hover { background: #fff; color: var(--pg); }

/* ── Main container ── */
.main-container {
  max-width: 1100px;
  margin: -50px auto 0;
  padding: 0 20px;
  position: relative;
  z-index: 5;
}

/* ── Search area ── */
.search-area {
  background: var(--white);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 15px;
  margin-bottom: 35px;
}
.search-box { flex: 1; }

#searchInput {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid #f1f3f6;
  border-radius: 12px;
  outline: none;
  font-family: inherit;
  font-size: 1rem;
}
#searchInput:focus { border-color: var(--pg); background: #fdfdfd; }

#refreshBtn {
  width: 55px;
  background: var(--pg);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}

#refreshBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px var(--pds);
}

#refreshBtn.is-clicked {
  transform: scale(.95);
}

#refreshBtn.is-loading {
  animation: refresh-spin .9s linear infinite;
  opacity: .9;
  cursor: wait;
}

#refreshBtn:disabled {
  pointer-events: none;
}

@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Categories (التحسين المطلوب) ── */
.cat-grid {
    display: flex;
    flex-wrap: nowrap;          /* الحفاظ على السحب الأفقي */
    overflow-x: auto;           /* تفعيل التمرير */
    -webkit-overflow-scrolling: touch;
    gap: 12px;
    padding: 15px 20px;         /* مسافة جانبية لضمان التوسط */
    margin-bottom: 25px;
    scrollbar-width: none;
    
    /* سر التوسط: نستخدم margin auto على الحاوية ونحدد justify-content */
    justify-content: flex-start; /* لضمان بداية السحب من اليمين في الموبايل */
}

/* إخفاء شريط التمرير في كروم وسفاري */
.cat-grid::-webkit-scrollbar {
    display: none;
}

@media (min-width: 768px) {
    .cat-grid {
        justify-content: center; /* يتوسط فقط في الشاشات الواسعة */
    }
}

.cat-card {
    /* الحل النهائي للعرض الموحد ومنع الانكماش */
    flex: 0 0 110px;           /* عرض ثابت لكل الكروت (110 بكسل) */
    width: 110px;               /* تأكيد العرض */
    
    background: #ffffff !important; 
    border: 1px solid rgba(0,0,0,0.08);
    padding: 12px 10px;        /* تقليل البادنج الجانبي ليناسب العرض الثابت */
    border-radius: 15px;
    text-align: center;
    font-weight: 700;
    color: #555;
    transition: 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.cat-card i {
    display: block;
    font-size: 1.4rem;
    margin-bottom: 5px;
}

.cat-card span {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.cat-card:hover {
    transform: translateY(-5px);
    border-color: var(--pg);
    color: var(--pg);
}

.cat-card.active {
    background: var(--pab) !important;
    border-color: var(--pg) !important;
    color: var(--pg) !important;
    box-shadow: 0 10px 20px var(--pas) !important;
}

/* ── File grid ── */
#fileList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  padding-bottom: 50px;
}

.file-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,.03);
  transition: transform .22s, border-color .22s;
}
.file-card:hover { transform: translateY(-7px); border-color: var(--pg); }

.file-type-icon {
  width: 42px; height: 42px;
  background: var(--pab);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.file-name { font-weight: 700; font-size: .93rem; margin-bottom: 11px; color: var(--dark); }

.file-badge {
  font-size: .68rem;
  padding: 3px 10px;
  background: var(--pbb);
  color: var(--pg);
  border-radius: 6px;
  font-weight: 800;
}

.file-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 18px; }

.btn {
  padding: 11px;
  border-radius: 9px;
  text-decoration: none;
  text-align: center;
  font-size: .83rem;
  font-weight: 800;
}

.btn-preview  { background: #f1f2f6; color: var(--dark); }
.btn-download { background: var(--pg); color: #fff; box-shadow: 0 4px 12px var(--pds); }

/* ── Mobile Optimization ── */
@media (max-width: 600px) {
  h1 { font-size: 1.65rem; }
  header { height: 275px; border-radius: 0 0 35px 35px; }
  header::after { border-radius: 0 0 35px 35px; }
  #fileList { grid-template-columns: 1fr; }
  .main-container { margin-top: -40px; }
  
  /* في الموبايل، نضمن بقاء الكروت في سطر واحد قابل للسحب */
  .cat-grid {
      justify-content: flex-start;
      padding-left: 15px; 
  }
}

/* ══════════════════════════════════════════════════════
   UPLOADER BADGE — يظهر على كروت ملفات الطلاب
══════════════════════════════════════════════════════ */
.uploader-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 11px;
  padding: 7px 10px;
  background: linear-gradient(135deg, rgba(0,0,0,.03), rgba(0,0,0,.02));
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 10px;
}
.uploader-av {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--pg);
  flex-shrink: 0;
  background: var(--pab);
}
.uploader-info {
  flex: 1;
  min-width: 0;
}
.uploader-name {
  font-size: .72rem;
  font-weight: 800;
  color: var(--dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.uploader-meta {
  font-size: .62rem;
  color: #94a3b8;
  margin-top: 1px;
}
.uploader-badge {
  font-size: .6rem;
  padding: 2px 7px;
  background: var(--pab);
  color: var(--pg);
  border-radius: 20px;
  font-weight: 800;
  white-space: nowrap;
  border: 1px solid rgba(0,0,0,.06);
}

/* ── Student-uploaded card distinction ── */
.file-card.student-upload {
  border-right: 3px solid var(--pg);
}

/* ══════════════════════════════════════════════════════
   UPLOAD FAB — زر رفع ملف عائم
══════════════════════════════════════════════════════ */
.upload-fab {
  position: fixed;
  left: 24px;
  bottom: 28px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 22px 0 16px;
  height: 52px;
  background: var(--pg);
  color: #fff;
  border: none;
  border-radius: 26px;
  font-family: 'Tajawal', sans-serif;
  font-size: .9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 24px var(--pds), 0 2px 8px rgba(0,0,0,.12);
  text-decoration: none;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  animation: fab-in .4s cubic-bezier(.34,1.56,.64,1) both;
}
.upload-fab:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 10px 32px var(--pds), 0 4px 12px rgba(0,0,0,.15);
}
.upload-fab:active { transform: scale(.97); }
.upload-fab .fab-ico {
  font-size: 1.2rem;
  line-height: 1;
}
.upload-fab .fab-pulse {
  position: absolute;
  inset: -3px;
  border-radius: 30px;
  background: var(--pg);
  opacity: 0;
  animation: fab-pulse 2.5s ease-out 1.2s infinite;
}

@keyframes fab-in {
  from { opacity: 0; transform: translateY(20px) scale(.85); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fab-pulse {
  0%   { opacity: .25; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* ── محاذاة FAB في الموبايل ── */
@media (max-width: 600px) {
  .upload-fab {
    left: 16px;
    bottom: 20px;
    height: 48px;
    font-size: .83rem;
    padding: 0 18px 0 13px;
  }
}

/* ── تحسين padding في الـ fileList لعدم تغطية الـ FAB ── */
#fileList { padding-bottom: 90px; }

/* ── Skeleton loader ── */
.skeleton-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  min-height: 155px;
  position: relative;
  overflow: hidden;
}
.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.6) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #f0f0f0 30px, #e8e8e8 30px, #e8e8e8 44px, #f0f0f0 44px, #f0f0f0 70px, #efefef 70px, #efefef 82px, #f0f0f0 82px);
  border-radius: var(--radius);
}
@keyframes skeleton-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* ── Empty state ── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
  font-weight: 700;
  font-size: .95rem;
}

/* ── file-meta flex ── */
.file-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.file-badge.secondary { background: #f1f3f6; color: #666; }
