<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>کارنامه دانش‌آموز</title>
<style>
  @font-face {
    font-family: 'Vazirmatn';
    src: url('{{ public_path("assets/fonts/vazirmatn/Vazirmatn-Regular.woff2") }}') format('woff2');
    font-weight: 400;
  }
  @font-face {
    font-family: 'Vazirmatn';
    src: url('{{ public_path("assets/fonts/vazirmatn/Vazirmatn-Bold.woff2") }}') format('woff2');
    font-weight: 700;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    background: #fff;
    color: #111827;
    direction: rtl;
    font-family: 'Vazirmatn', 'Tahoma', sans-serif;
    font-size: 12px;
    line-height: 1.7;
    padding: 32px;
  }
  .header {
    align-items: center;
    border-bottom: 3px solid #0EA678;
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
  }
  .school-name {
    color: #0EA678;
    font-size: 20px;
    font-weight: 700;
  }
  .report-title {
    color: #64748B;
    font-size: 13px;
    margin-top: 4px;
  }
  .logo-area {
    align-items: center;
    background: #DFF8EF;
    border-radius: 12px;
    display: flex;
    height: 56px;
    justify-content: center;
    width: 56px;
  }
  .logo-letter {
    color: #0EA678;
    font-size: 24px;
    font-weight: 700;
  }
  .student-info {
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin-bottom: 24px;
    padding: 14px 18px;
  }
  .info-item {
    min-width: 180px;
  }
  .info-label {
    color: #64748B;
    font-size: 10px;
  }
  .info-value {
    font-size: 13px;
    font-weight: 700;
  }
  table {
    border-collapse: collapse;
    width: 100%;
  }
  th {
    background: #0EA678;
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 9px 10px;
    text-align: right;
  }
  td {
    border-bottom: 1px solid #E2E8F0;
    font-size: 12px;
    padding: 8px 10px;
    text-align: right;
  }
  tr:nth-child(even) td {
    background: #F8FAFC;
  }
  .score-cell {
    font-weight: 700;
    text-align: center;
  }
  .status-approved { color: #16A34A; }
  .status-pending { color: #F59E0B; }
  .status-rejected { color: #DC2626; }
  .avg-row td {
    background: #DFF8EF;
    border-top: 2px solid #0EA678;
    font-size: 13px;
    font-weight: 700;
  }
  .footer {
    border-top: 1px solid #E2E8F0;
    color: #94A3B8;
    font-size: 10px;
    margin-top: 24px;
    padding-top: 10px;
    text-align: center;
  }
  .no-grades {
    color: #64748B;
    padding: 24px;
    text-align: center;
  }
</style>
</head>
<body>
  <div class="header">
    <div>
      <div class="school-name">{{ $school?->name ?? 'مدرسه' }}</div>
      <div class="report-title">کارنامه تحصیلی</div>
    </div>
    <div class="logo-area">
      <span class="logo-letter">د</span>
    </div>
  </div>

  <div class="student-info">
    <div class="info-item">
      <div class="info-label">نام دانش‌آموز</div>
      <div class="info-value">{{ $student->first_name }} {{ $student->last_name }}</div>
    </div>
    <div class="info-item">
      <div class="info-label">کد دانش‌آموزی</div>
      <div class="info-value">{{ $student->student_code ?? '—' }}</div>
    </div>
    <div class="info-item">
      <div class="info-label">تاریخ صدور</div>
      <div class="info-value">{{ $jalaliDate(now()) }}</div>
    </div>
  </div>

  @if($grades->isEmpty())
    <div class="no-grades">هنوز هیچ نمره‌ای برای این دانش‌آموز ثبت نشده است.</div>
  @else
    <table>
      <thead>
        <tr>
          <th>درس</th>
          <th>کلاس</th>
          <th style="text-align:center">نمره</th>
          <th style="text-align:center">از</th>
          <th style="text-align:center">وضعیت</th>
          <th>توضیح</th>
        </tr>
      </thead>
      <tbody>
        @foreach($grades as $grade)
        <tr>
          <td>{{ $grade->subject_name ?? '—' }}</td>
          <td>{{ $grade->classroom_name ?? '—' }}</td>
          <td class="score-cell">{{ number_format($grade->score, 2) }}</td>
          <td class="score-cell">{{ number_format($grade->max_score, 0) }}</td>
          <td style="text-align:center">
            @if($grade->status === 'approved')
              <span class="status-approved">تایید شده</span>
            @elseif($grade->status === 'rejected')
              <span class="status-rejected">رد شده</span>
            @else
              <span class="status-pending">در انتظار</span>
            @endif
          </td>
          <td style="color:#64748B;font-size:11px">{{ $grade->description ?? '' }}</td>
        </tr>
        @endforeach
        @if($average !== null)
        <tr class="avg-row">
          <td colspan="2">معدل کل (از ۲۰)</td>
          <td class="score-cell" colspan="4">{{ $average }}</td>
        </tr>
        @endif
      </tbody>
    </table>
  @endif

  <div class="footer">
    دانشیار من — اتوماسیون هوشمند مدارس &bull; mydaneshyar.ir
  </div>
</body>
</html>
