/**
 * Print-Optimized Styles for Sophia STARS
 * Professional, clean layouts for printing reports
 * Date: October 31, 2025
 */

@media print {
  /* ========================================
     RESET & BASICS
     ======================================== */
  
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    background: white !important;
    color: black !important;
    font-size: 10pt;
    line-height: 1.4;
    margin: 0;
    padding: 20px;
  }

  /* ========================================
     HIDE NON-PRINTABLE ELEMENTS
     ======================================== */
  
  /* Navigation & Controls */
  nav,
  .navbar,
  .sidebar,
  header,
  footer,
  .navigation,
  .menu,
  button:not(.print-keep),
  .btn:not(.print-keep),
  .export-btn,
  .print-btn,
  .filters-accordion,
  .search-container,
  .unified-student-search,
  .form-actions,
  .modal-overlay,
  .toast-container,
  .back-button,
  .filter-section,
  .analytics-controls,
  .refresh-indicator,
  .loading-indicator,
  .dropdown-menu,
  .tooltip,
  input[type="button"],
  input[type="submit"],
  input[type="reset"] {
    display: none !important;
  }

  /* Interactive Elements */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  .editable,
  .draggable {
    display: none !important;
  }

  /* ========================================
     PAGE SETUP
     ======================================== */
  
  @page {
    size: A4;
    margin: 1.5cm 1cm 1.5cm 1cm;
  }

  /* ========================================
     HEADER WITH SCHOOL BRANDING
     ======================================== */
  
  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 3px solid #2c3e50;
    position: relative;
  }
  
  .print-header-logo {
    display: inline-block !important;
    width: 80px;
    height: auto;
    margin-bottom: 10px;
    vertical-align: middle;
  }
  
  .print-header-content {
    display: inline-block !important;
    vertical-align: middle;
  }

  .print-header h1 {
    font-size: 20pt;
    font-weight: bold;
    margin: 0 0 5px 0;
    color: #2c3e50;
  }

  .print-header h2 {
    font-size: 14pt;
    font-weight: normal;
    margin: 0 0 10px 0;
    color: #555;
  }

  .print-header .print-meta {
    font-size: 9pt;
    color: #777;
    margin-top: 8px;
  }

  /* ========================================
     TABLES - PRIMARY DATA DISPLAY
     ======================================== */
  
  table {
    width: 100% !important;
    border-collapse: collapse;
    margin: 15px 0;
    page-break-inside: auto;
    font-size: 9pt;
  }

  thead {
    display: table-header-group; /* Repeat on each page */
  }

  tbody {
    display: table-row-group;
  }

  tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  th {
    background: #2c3e50 !important;
    color: white !important;
    font-weight: bold;
    padding: 8px 6px !important;
    text-align: left;
    border: 1px solid #222 !important;
    font-size: 9pt;
  }

  td {
    padding: 6px 6px !important;
    border: 1px solid #ddd !important;
    color: black !important;
    background: white !important;
    vertical-align: top;
  }

  /* Zebra striping for readability */
  tbody tr:nth-child(even) {
    background: #f9f9f9 !important;
  }

  tbody tr:nth-child(odd) {
    background: white !important;
  }

  /* ========================================
     ANALYTICS CARDS
     ======================================== */
  
  .analytics-card,
  .stat-card,
  .summary-card {
    display: inline-block !important;
    width: 23% !important;
    margin: 0 1% 15px 0 !important;
    padding: 10px !important;
    border: 2px solid #2c3e50 !important;
    background: white !important;
    page-break-inside: avoid;
    vertical-align: top;
  }

  .analytics-card h3,
  .stat-card h3,
  .summary-card h3 {
    font-size: 10pt;
    margin: 0 0 5px 0;
    color: #2c3e50;
  }

  .analytics-card .value,
  .stat-card .value,
  .summary-card .value {
    font-size: 18pt;
    font-weight: bold;
    color: black !important;
  }

  /* ========================================
     STUDENT CARDS
     ======================================== */
  
  .student-card,
  .profile-card {
    page-break-inside: avoid;
    margin: 10px 0;
    padding: 10px !important;
    border: 1px solid #333 !important;
    background: white !important;
  }

  .student-card h4,
  .profile-card h4 {
    font-size: 11pt;
    font-weight: bold;
    margin: 0 0 8px 0;
    color: #2c3e50;
  }

  .student-card .student-details,
  .profile-card .details {
    font-size: 9pt;
    line-height: 1.6;
  }

  /* ========================================
     CHARTS & VISUALIZATIONS
     ======================================== */
  
  canvas,
  .chart-container {
    page-break-inside: avoid;
    max-width: 100% !important;
    height: auto !important;
  }

  .chart-title {
    font-size: 11pt;
    font-weight: bold;
    margin: 15px 0 8px 0;
    color: #2c3e50;
  }

  /* ========================================
     SECTIONS & HEADINGS
     ======================================== */
  
  h1 {
    font-size: 18pt;
    color: #2c3e50;
    margin: 20px 0 10px 0;
    page-break-after: avoid;
  }

  h2 {
    font-size: 14pt;
    color: #2c3e50;
    margin: 15px 0 8px 0;
    page-break-after: avoid;
  }

  h3 {
    font-size: 12pt;
    color: #2c3e50;
    margin: 12px 0 6px 0;
    page-break-after: avoid;
  }

  .section-title {
    font-size: 14pt;
    font-weight: bold;
    color: #2c3e50;
    margin: 15px 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 2px solid #2c3e50;
    page-break-after: avoid;
  }

  /* ========================================
     PAGE BREAKS
     ======================================== */
  
  .page-break {
    page-break-after: always;
  }

  .avoid-break {
    page-break-inside: avoid;
  }

  .print-section {
    page-break-inside: avoid;
    margin-bottom: 20px;
  }

  /* ========================================
     FOOTER WITH PAGE NUMBERS
     ======================================== */
  
  .print-footer {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 8pt;
    color: #777;
    padding: 10px 0;
    border-top: 1px solid #ddd;
  }

  /* ========================================
     LINKS & REFERENCES
     ======================================== */
  
  a {
    color: black !important;
    text-decoration: none !important;
  }

  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #555;
  }

  /* Don't show URLs for anchor links */
  a[href^="#"]:after,
  a[href^="javascript:"]:after {
    content: "";
  }

  /* ========================================
     UTILITY CLASSES
     ======================================== */
  
  .print-only {
    display: block !important;
  }

  .no-print {
    display: none !important;
  }

  .print-landscape {
    /* For pages that need landscape orientation */
    width: 100%;
    page-break-before: always;
  }

  /* ========================================
     RESPONSIVE TABLE FOR NARROW COLUMNS
     ======================================== */
  
  .responsive-table {
    font-size: 8pt;
  }

  .responsive-table th,
  .responsive-table td {
    padding: 4px 3px !important;
  }

  /* ========================================
     SUMMARY BOXES
     ======================================== */
  
  .summary-box {
    border: 2px solid #2c3e50;
    padding: 12px;
    margin: 15px 0;
    background: #f9f9f9 !important;
    page-break-inside: avoid;
  }

  .summary-box h3 {
    margin-top: 0;
    color: #2c3e50;
  }

  /* ========================================
     INFRINGEMENTS SPECIFIC
     ======================================== */
  
  .infringement-details {
    margin: 8px 0;
    padding: 8px;
    border-left: 3px solid #e74c3c;
    background: #fff !important;
  }

  /* ========================================
     OUT OF CLASS SPECIFIC
     ======================================== */
  
  .movement-entry {
    margin: 6px 0;
    padding: 6px;
    border-left: 3px solid #3498db;
    background: #fff !important;
  }

  /* ========================================
     POSITIVE AFFIRMATIONS SPECIFIC
     ======================================== */
  
  .affirmation-entry {
    margin: 6px 0;
    padding: 6px;
    border-left: 3px solid #27ae60;
    background: #fff !important;
  }

  /* ========================================
     REENGAGEMENT SPECIFIC
     ======================================== */
  
  .referral-entry {
    margin: 8px 0;
    padding: 8px;
    border-left: 3px solid #f39c12;
    background: #fff !important;
  }

  /* ========================================
     DATA QUALITY
     ======================================== */
  
  /* Ensure emojis print properly */
  .emoji {
    font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  }

  /* Ensure proper text wrapping */
  .wrap-text {
    word-wrap: break-word;
    word-break: break-word;
  }

  /* ========================================
     ACCESSIBILITY
     ======================================== */
  
  /* High contrast for important elements */
  .highlight,
  .important {
    font-weight: bold;
    color: black !important;
    background: #ffeb3b !important;
  }

  .warning {
    border-left: 4px solid #ff9800;
    padding-left: 8px;
  }

  .critical {
    border-left: 4px solid #f44336;
    padding-left: 8px;
    font-weight: bold;
  }
}

/* ========================================
   PRINT PREVIEW MODE (OPTIONAL)
   Show what will print without actually printing
   ======================================== */

body.print-preview {
  background: #eee !important;
  padding: 20px;
}

body.print-preview main,
body.print-preview .container {
  background: white;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  padding: 40px;
  max-width: 210mm; /* A4 width */
  margin: 0 auto;
}

/* ========================================
   EXPORT MODAL STYLES (FOR SCREEN)
   ======================================== */

.export-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s ease;
}

.export-modal-content {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.export-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid #e0e0e0;
}

.export-modal-header h3 {
  margin: 0;
  font-size: 1.4rem;
  color: #2c3e50;
}

.export-modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.export-modal-close:hover {
  background: #f0f0f0;
}

.export-modal-body {
  padding: 24px;
}

.export-section {
  margin-bottom: 24px;
}

.export-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.export-select-all {
  background: none;
  border: 1px solid #3498db;
  color: #3498db;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.export-select-all:hover {
  background: #3498db;
  color: white;
}

.export-format-buttons {
  display: flex;
  gap: 12px;
}

.export-format-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid #ddd;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
  text-align: center;
}

.export-format-btn:hover {
  border-color: #3498db;
  background: #f8f9fa;
}

.export-format-btn.active {
  border-color: #3498db;
  background: #e3f2fd;
  font-weight: 600;
}

.export-date-range {
  display: flex;
  align-items: center;
  gap: 12px;
}

.export-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.95rem;
}

.export-columns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
}

.export-column-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
}

.export-column-checkbox:hover {
  background: white;
}

.export-column-checkbox input[type="checkbox"] {
  cursor: pointer;
}

.export-info {
  padding: 12px;
  background: #e8f5e9;
  border-left: 4px solid #4caf50;
  border-radius: 4px;
  color: #2e7d32;
  font-size: 0.95rem;
}

.export-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid #e0e0e0;
  background: #f8f9fa;
}

.export-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.export-btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.export-btn-secondary:hover {
  background: #d0d0d0;
}

.export-btn-primary {
  background: #3498db;
  color: white;
}

.export-btn-primary:hover {
  background: #2980b9;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
