/* ---------------------------------------------------------
   Theme Variables & Reset
   --------------------------------------------------------- */
:root {
  --font-main: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Color Palette */
  --color-primary: #1e40af;
  --color-primary-dark: #1e3a8a;
  --color-primary-light: #eff6ff;
  
  --color-success: #047857;
  --color-success-bg: #ecfdf5;
  
  --color-warning: #b45309;
  --color-warning-bg: #fffbeb;
  
  --color-danger: #b91c1c;
  --color-danger-bg: #fef2f2;
  
  --color-text-main: #0f172a;
  --color-text-muted: #475569;
  --color-text-light: #64748b;
  
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --border-color: #cbd5e1;
  --border-radius-sm: 8px;
  --border-radius-md: 12px;
  --border-radius-lg: 18px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--color-text-main);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Accessibility: Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus styles for keyboard accessibility */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

.container {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------
   Header (Search Page)
   --------------------------------------------------------- */
.app-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  color: #ffffff;
  padding: 1.75rem 0;
  box-shadow: var(--shadow-md);
  margin-bottom: 2rem;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.school-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #ffffff;
  border-radius: var(--border-radius-md);
  padding: 3px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.school-tag {
  display: inline-block;
  font-size: 0.88rem;
  font-weight: 700;
  color: #93c5fd;
  margin-bottom: 0.15rem;
}

.site-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.site-subtitle {
  font-size: 0.95rem;
  color: #dbeafe;
  margin-top: 0.3rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid #6ee7b7;
}

.badge-absent {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid #fca5a5;
}

/* ---------------------------------------------------------
   Main Layout & Cards
   --------------------------------------------------------- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  padding-bottom: 3rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

/* ---------------------------------------------------------
   Search Section
   --------------------------------------------------------- */
.search-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-md);
  margin-top: 1rem;
}

.card-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.search-hint {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin: 0.6rem 0 1.5rem;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-label {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: var(--color-text-main);
}

.input-wrapper {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.text-input {
  flex: 1;
  min-width: 240px;
  font-family: var(--font-main);
  font-size: 1.2rem;
  padding: 0.8rem 1.2rem;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-md);
  background: #ffffff;
  color: var(--color-text-main);
  transition: all 0.2s ease;
  letter-spacing: 0.08em;
}

.text-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(30, 64, 175, 0.15);
  outline: none;
}

.help-text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
  line-height: 1.6;
}

/* Buttons */
.btn {
  font-family: var(--font-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 1.6rem;
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--border-radius-md);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-search {
  background: var(--color-primary);
  color: #ffffff;
  min-width: 160px;
}

.btn-search:hover {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 12px rgba(30, 64, 175, 0.25);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--color-text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Alerts */
.alert {
  padding: 1.1rem 1.25rem;
  border-radius: var(--border-radius-md);
  margin-top: 1.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  line-height: 1.6;
}

.alert-error {
  background: var(--color-danger-bg);
  border: 1px solid #fca5a5;
  color: var(--color-danger);
}

/* ---------------------------------------------------------
   Report Section
   --------------------------------------------------------- */
.report-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1rem;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mini Header on report view */
.report-header-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.school-brand-mini {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.school-logo-mini {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #bfdbfe;
  padding: 2px;
}

.mini-school-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--color-primary-dark);
}

.mini-exam-sub {
  font-size: 0.88rem;
  color: var(--color-text-muted);
}

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

.school-logo-print {
  width: 52px;
  height: 52px;
  object-fit: contain;
  margin-bottom: 0.3rem;
}

/* Student Profile Card */
.student-profile-card {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #ffffff;
  border-radius: var(--border-radius-lg);
  padding: 1.5rem 1.75rem;
  box-shadow: var(--shadow-md);
}

.profile-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.25rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.info-label {
  font-size: 0.85rem;
  color: #94a3b8;
}

.info-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f8fafc;
}

/* Absent Notice */
.absent-box {
  background: var(--color-danger-bg);
  border: 2px dashed #f87171;
  border-radius: var(--border-radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  color: #991b1b;
}

.absent-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.absent-box h3 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  font-weight: 800;
}

.absent-box p {
  font-size: 1rem;
  color: #b91c1c;
}

/* ---------------------------------------------------------
   Section 1: Summary of Total Exam
   --------------------------------------------------------- */
.summary-section-card {
  margin-top: 0.5rem;
}

.card-header-clean {
  padding: 1.25rem 1.75rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.section-title {
  font-size: 1.2rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-main);
}

.summary-grid {
  padding: 1.5rem 1.75rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: #f8fafc;
  padding: 1rem;
  border-radius: var(--border-radius-md);
  border: 1px solid var(--border-color);
}

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

.summary-val {
  font-size: 1.2rem;
  font-weight: 800;
}

.text-highlight {
  color: #b45309 !important;
}

.grade-label {
  display: inline-block;
  width: fit-content;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 6px;
}

.grade-excellent { background: #dcfce7; color: #15803d; }
.grade-good { background: #dbeafe; color: #1d4ed8; }
.grade-medium { background: #fef3c7; color: #b45309; }
.grade-low { background: #fee2e2; color: #b91c1c; }

/* ---------------------------------------------------------
   Section 2: Subject Table
   --------------------------------------------------------- */
.subject-table-card {
  margin-top: 1.25rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.report-table th, .report-table td {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
}

.report-table thead th {
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  font-size: 0.9rem;
  border-top: none;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

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

.text-center { text-align: center !important; }
.font-bold { font-weight: 700 !important; }
.text-success { color: var(--color-success) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-primary { color: var(--color-primary) !important; }

.subject-name-cell {
  font-weight: 700;
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rank-badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
}

.rank-top {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.diff-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}

.diff-positive {
  background: #ecfdf5;
  color: #047857;
}

.diff-negative {
  background: #fef2f2;
  color: #b91c1c;
}

.diff-equal {
  background: #f1f5f9;
  color: #64748b;
}

/* ---------------------------------------------------------
   Section 3: Comparison List & Progress Bars
   --------------------------------------------------------- */
.chart-card {
  margin-top: 1.25rem;
}

.comparison-list {
  list-style: none;
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.comparison-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comp-text-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 600;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.comp-subject-title {
  font-weight: 800;
  color: var(--color-primary-dark);
}

.comp-details {
  color: var(--color-text-main);
}

.bar-track {
  height: 20px;
  background: #e2e8f0;
  border-radius: 9999px;
  position: relative;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s ease;
}

.bar-fill-student {
  background: linear-gradient(90deg, #3b82f6, #1d4ed8);
}

.bar-avg-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #0f172a;
  z-index: 2;
}

.bar-avg-indicator::after {
  content: 'میانگین کل';
  position: absolute;
  bottom: -20px;
  transform: translateX(50%);
  font-size: 0.72rem;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
}

/* ---------------------------------------------------------
   Action Buttons Area
   --------------------------------------------------------- */
.action-buttons-area {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* Print Signatures (hidden on screen) */
.print-signatures-area {
  display: none;
}

/* ---------------------------------------------------------
   Footer
   --------------------------------------------------------- */
.app-footer {
  margin-top: auto;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  text-align: center;
}

.security-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f0fdf4;
  color: #166534;
  padding: 0.35rem 0.95rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #bbf7d0;
}

.footer-copy {
  font-weight: 700;
  color: var(--color-text-main);
}

/* ---------------------------------------------------------
   Print Stylesheet (@media print)
   --------------------------------------------------------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 1.2cm 1.5cm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  .no-print {
    display: none !important;
  }

  .container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .report-section {
    display: block !important;
    gap: 0 !important;
    margin-top: 0 !important;
  }

  /* Formal Print Header */
  .official-print-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #000000;
    padding-bottom: 1rem;
    margin-bottom: 1.2rem;
  }

  .print-meta-right h3 {
    font-size: 12pt;
    font-weight: bold;
  }
  .print-meta-right p {
    font-size: 10pt;
  }

  .print-meta-center {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .report-badge {
    display: inline-block;
    border: 2px solid #000;
    padding: 0.2rem 0.8rem;
    font-weight: bold;
    font-size: 12pt;
    border-radius: 4px;
    margin-bottom: 0.3rem;
  }

  .exam-title-print {
    font-size: 10pt;
    font-weight: 600;
  }

  .print-meta-left p {
    font-size: 9.5pt;
    text-align: left;
  }

  /* Student Profile */
  .student-profile-card {
    background: #f8fafc !important;
    color: #000000 !important;
    border: 1px solid #000000 !important;
    box-shadow: none !important;
    padding: 0.8rem 1rem !important;
    margin-bottom: 1rem !important;
  }

  .info-label {
    color: #334155 !important;
    font-size: 9.5pt !important;
  }

  .info-val {
    color: #000000 !important;
    font-size: 11pt !important;
  }

  /* Summary Section Print */
  .summary-section-card {
    border: 1px solid #000000 !important;
    box-shadow: none !important;
    margin-bottom: 1rem !important;
  }

  .summary-grid {
    padding: 0.8rem !important;
    gap: 0.5rem !important;
  }

  .summary-item {
    border: 1px solid #cbd5e1 !important;
    padding: 0.5rem !important;
  }

  /* Table styling for print */
  .card {
    border: none !important;
    box-shadow: none !important;
  }

  .report-table {
    border: 1px solid #000000 !important;
    font-size: 10pt !important;
  }

  .report-table th, .report-table td {
    border: 1px solid #000000 !important;
    padding: 0.5rem 0.6rem !important;
  }

  .report-table thead th {
    background: #e2e8f0 !important;
    color: #000000 !important;
  }

  .chart-card {
    display: none !important;
  }

  /* Signatures */
  .print-signatures-area {
    display: flex !important;
    justify-content: space-between;
    margin-top: 3rem;
    padding-top: 1rem;
  }

  .signature-box {
    text-align: center;
    width: 28%;
    font-size: 9.5pt;
    font-weight: bold;
  }

  .sig-line {
    margin-top: 3.5rem;
    border-bottom: 1px dashed #64748b;
  }
}

/* ---------------------------------------------------------
   Responsive Tweaks
   --------------------------------------------------------- */
@media (max-width: 640px) {
  .site-title { font-size: 1.2rem; }
  .header-content { flex-direction: column; align-items: flex-start; }
  .input-wrapper { flex-direction: column; }
  .btn-search { width: 100%; }
  .report-table th, .report-table td { padding: 0.6rem 0.5rem; font-size: 0.85rem; }
}
