* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: "Segoe UI", Tahoma, Arial, sans-serif; background:#f7f7fb; color:#222; }

.app-header { background: #2b6cb0; color: #fff; padding: 16px 20px; }
.app-header h1 { margin: 0 0 8px 0; font-size: 20px; }
.projects-bar { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.proj-label { font-weight:600; }
.proj-select { min-width: 220px; padding:6px; border-radius:6px; border:1px solid #cbd5e1; }

.container { max-width: 960px; margin: 20px auto; padding: 0 16px; }
.layout { display:flex; gap:16px; align-items:flex-start; }
.sidebar { width: 220px; position: sticky; top: 0; align-self: stretch; padding: 16px; }
.tabs-nav { display:flex; flex-direction:column; gap:8px; }
.tab-link { text-align:right; padding:10px; border:1px solid #e5e7eb; background:#fff; border-radius:8px; cursor:pointer; }
.tab-link.active, .tab-link:hover { background:#eef2ff; border-color:#c7d2fe; }

.card { background:#fff; border:1px solid #e5e7eb; border-radius: 10px; padding: 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.06); }
.card h2 { margin-top: 0; font-size: 18px; color:#1a202c; }
.tab-section.hidden { display:none; }

.form-row { margin-bottom: 12px; }
label { display:block; margin-bottom:6px; font-weight:600; }
input[type="text"], input[type="number"] { width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px; font-size:14px; }

.days-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.day-chip { display:flex; align-items:center; gap:8px; padding:8px 10px; border:1px solid #e2e8f0; border-radius:8px; background:#f8fafc; }

.actions { margin-top: 16px; }
.primary { background:#2b6cb0; color:#fff; border:none; border-radius:8px; padding:10px 16px; cursor:pointer; }
.primary:hover { background:#2c5282; }
.primary.saving { opacity: 0.8; }
.primary.saved { background:#047857; }

.save-feedback { margin-inline-start: 10px; color:#047857; font-weight:600; opacity:0; transition: opacity 0.2s ease; }
.save-feedback.show { opacity: 1; }

.preview { margin-top: 16px; background:#f9fafb; border:1px dashed #cbd5e1; border-radius:8px; padding:12px; }
.hint { color:#6b7280; }
.catalog-hint { margin-top:8px; }

.app-footer { margin: 24px 0; text-align:center; color:#4b5563; }

/* Print-only title (hidden on screen) */
.print-title { display:none; text-align:center; font-size: 20px; font-weight:700; margin: 8px 0 10px; }

@media (max-width: 520px) {
  .days-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Lists and forms */
.inline-form { display:flex; gap:8px; align-items:center; }
.list { margin-top:12px; display:flex; flex-direction:column; gap:8px; }
.list-item { display:flex; justify-content:space-between; align-items:center; border:1px solid #e5e7eb; border-radius:8px; padding:8px 10px; background:#fff; }
.btn { padding:6px 10px; border-radius:6px; border:1px solid #cbd5e1; background:#fff; cursor:pointer; }
.btn.danger { color:#b91c1c; border-color:#fecaca; background:#fff5f5; }
.btn.secondary { color:#1f2937; background:#f3f4f6; border-color:#e5e7eb; }
.btn:hover { background:#f8fafc; }
.hidden { display:none !important; }
.hidden-row { display:none; }

/* Flash highlight for attention */
.flash-highlight { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(255, 213, 0, 0.65); }
  50% { box-shadow: 0 0 0 6px rgba(255, 213, 0, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(255, 213, 0, 0); }
}

.checkbox-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:8px; }
.checkbox-grid label { display:flex; align-items:center; gap:6px; }
.class-scope-box { border:1px dashed #e5e7eb; border-radius:8px; padding:8px; margin-bottom:8px; }
.scope-controls { display:flex; flex-direction:column; gap:6px; margin-top:6px; }
.scope-option { display:flex; align-items:center; gap:6px; }
.sections-choices { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:8px; }
.subject-assignments { display:flex; flex-direction:column; gap:8px; }
.subject-row { display:flex; flex-direction:column; gap:6px; }
.subject-row .subject-title { font-weight:600; }
.subject-row .sections-grid { display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:8px; }
.subject-row .section-cell { display:flex; align-items:center; gap:6px; }

/* Slot times */
.slot-table { width:100%; border-collapse: collapse; margin-top: 8px; }
.slot-table th, .slot-table td { border:1px solid #e5e7eb; padding:8px; text-align:center; }
.slot-table th { background:#f3f4f6; }

/* Auto-calc fields for slot times */
.calc-fields { display:grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items:end; }
.calc-fields > div input[type="time"], .calc-fields > div input[type="number"] { width:100%; }
.calc-actions { display:flex; align-items:center; }

@media (max-width: 720px) {
  .calc-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Progress */
.toolbar { display:flex; gap:12px; align-items:center; margin: 12px 0; }
.toolbar .spacer { flex:1 1 auto; }
.export-group { display:flex; gap:8px; }
.visually-hidden { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }
.view-toggle .btn { border-color:#c7d2fe; }
.timetable { width:100%; border-collapse: collapse; margin: 8px 0 16px; }
.table-scroll { overflow: auto; max-height: 70vh; }

.timetable th, .timetable td { border:1px solid #e5e7eb; padding:6px; text-align:center; font-size:13px; }
.timetable th { background:#f9fafb; }
.timetable caption { caption-side: top; font-weight:700; margin-bottom:6px; }
.timetable-container { display:flex; flex-direction:column; gap:20px; }

@media print {
  .sidebar, .toolbar, .tabs-nav, .inline-form, .actions { display:none !important; }
  .app-header { display:none !important; }
  .container { max-width: 100%; margin:0; }
  .card { border:none; box-shadow:none; padding:0; }
  .timetable th, .timetable td { font-size:11px; padding:4px; }
  .print-title { display:block; }
  /* Hide progress headers and summary; keep only print header + tables */
  #progress-section h2, #progressSummary, .timetable caption { display:none !important; }
}

/* Landscape printing for combined view - optimized for A3 */
@media print {
  @page { 
    size: A3 landscape; 
    margin: 5mm; 
  }
  
  body.combined-print .timetable { 
    table-layout: auto; 
    width: 100%;
  }
  
  body.combined-print .timetable th, 
  body.combined-print .timetable td { 
    padding: 1px 2px; 
    border-width: 0.5px;
    vertical-align: middle;
  }
  
  body.combined-print .timetable thead th { 
    white-space: normal; 
    font-size: 9px;
    font-weight: 600;
  }
  
  /* الخلايا المدمجة (المادة/المدرس) */
  body.combined-print .compact-cell {
    line-height: 1.2;
  }
  
  body.combined-print .combined-cell {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }
  
  body.combined-print .table-scroll { 
    overflow: visible !important; 
  }
  
  body.combined-print .print-header { 
    margin-bottom: 3px; 
    font-size: 12px; 
  }
}

/* Compact cell styles for combined big table */
.timetable td > .hint { font-size: 11px; color:#6b7280; }
.timetable thead th { white-space: nowrap; }

/* Combined cell styles (subject / teacher) */
.combined-cell {
  line-height: 1.3;
  padding: 2px;
  word-wrap: break-word;
  hyphens: auto;
}

.compact-cell {
  padding: 3px !important;
  text-align: center;
}

/* Responsive text sizing for long content */
.combined-cell.long-text {
  font-size: 11px;
}

.combined-cell.very-long-text {
  font-size: 9px;
}

/* Per-day-per-slot matrix */
#teacherForbiddenDaySlots table { width:100%; border-collapse: collapse; }
#teacherForbiddenDaySlots th, #teacherForbiddenDaySlots td { border:1px solid #e5e7eb; padding:6px; text-align:center; }
#teacherForbiddenDaySlots thead th { background:#f9fafb; font-weight:600; }

/* ========== Unassigned Lessons & Drag-Drop ========== */
.unassigned-lessons-container {
  margin: 20px 0;
  padding: 15px;
  background: #fff8dc;
  border: 2px dashed #ff9800;
  border-radius: 8px;
}

.unassigned-lessons-container h3 {
  margin: 0 0 15px 0;
  color: #d32f2f;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.unassigned-count-badge {
  background: #d32f2f;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.9em;
}

.unassigned-lessons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.unassigned-lesson-card {
  background: #fff;
  border: 2px solid #ff9800;
  border-radius: 6px;
  padding: 10px;
  cursor: move;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  user-select: none;
}

.unassigned-lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  border-color: #f57c00;
  background: #fffbf0;
}

.unassigned-lesson-card.dragging {
  opacity: 0.4;
  transform: rotate(2deg);
}

.unassigned-lesson-subject {
  font-weight: bold;
  color: #1976d2;
  margin-bottom: 4px;
  font-size: 0.95em;
}

.unassigned-lesson-teacher {
  color: #666;
  font-size: 0.85em;
  margin-bottom: 2px;
}

.unassigned-lesson-section {
  color: #888;
  font-size: 0.8em;
}

/* Drag and Drop States for Table Cells */
.timetable td {
  position: relative;
  transition: all 0.2s;
}

.timetable td.drag-over-empty {
  background: #e3f2fd !important;
  border: 2px dashed #2196f3 !important;
  box-shadow: inset 0 0 8px rgba(33, 150, 243, 0.3);
}

.timetable td.drag-over-replace {
  background: #fff3e0 !important;
  border: 2px dashed #ff9800 !important;
  box-shadow: inset 0 0 8px rgba(255, 152, 0, 0.3);
}

.lesson-cell-content {
  cursor: move;
  user-select: none;
  padding: 2px;
  border-radius: 4px;
  transition: all 0.2s;
}

.lesson-cell-content:hover {
  background: rgba(33, 150, 243, 0.05);
}

.lesson-cell-content.dragging {
  opacity: 0.3;
}

/* Empty cell indicator */
.timetable td.empty-cell {
  background: #fafafa;
  color: #ccc;
}

/* ========== Unassigned Lesson Boxes in Stats Sidebar ========== */
.unassigned-lesson-box {
  display: inline-block;
  background: white;
  border: 2px solid #f59e0b;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: grab;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  font-size: 12px;
  text-align: center;
  min-width: 120px;
  user-select: none;
}

.unassigned-lesson-box:active {
  cursor: grabbing;
}

.unassigned-lesson-box.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.unassigned-boxes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ========== Floating Unassigned Box ========== */
.floating-unassigned-box {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 350px;
  max-height: 70vh;
  background: white;
  border: 3px solid #f59e0b;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
}

.floating-unassigned-box.collapsed {
  max-height: 50px;
}

.floating-unassigned-box.collapsed .floating-box-content,
.floating-unassigned-box.collapsed .floating-box-footer {
  display: none;
}

.floating-unassigned-box.collapsed .floating-box-toggle {
  transform: rotate(-90deg);
}

.floating-box-header {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  font-weight: 600;
}

.floating-box-header:hover {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
}

.floating-box-title {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.floating-box-toggle {
  transition: transform 0.3s ease;
  font-size: 12px;
}

.floating-box-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fffbf0;
}

.floating-box-content::-webkit-scrollbar {
  width: 6px;
}

.floating-box-content::-webkit-scrollbar-track {
  background: #fef3c7;
}

.floating-box-content::-webkit-scrollbar-thumb {
  background: #f59e0b;
  border-radius: 3px;
}

.teacher-group {
  margin-bottom: 16px;
  background: white;
  border-radius: 8px;
  padding: 10px;
  border: 1px solid #fde68a;
}

.teacher-group:last-child {
  margin-bottom: 0;
}

.teacher-name {
  font-weight: 600;
  color: #92400e;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.teacher-name .badge {
  background: #f59e0b;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.lessons-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.unassigned-lesson-card {
  background: white;
  border: 2px solid #f59e0b;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: grab;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  text-align: center;
}

.unassigned-lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
  border-color: #d97706;
  background: #fffbf0;
}

.unassigned-lesson-card:active {
  cursor: grabbing;
}

.unassigned-lesson-card.dragging {
  opacity: 0.4;
  transform: rotate(3deg);
}

.card-subject {
  font-weight: 700;
  color: #1f2937;
  font-size: 12px;
  margin-bottom: 2px;
}

.card-section {
  color: #6b7280;
  font-size: 10px;
}

.floating-box-footer {
  background: #fef3c7;
  padding: 8px 12px;
  border-top: 1px solid #fde68a;
  text-align: center;
}

.floating-box-footer small {
  color: #92400e;
  font-size: 11px;
  display: block;
  line-height: 1.4;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .floating-unassigned-box {
    width: 280px;
    left: 10px;
    bottom: 10px;
  }
  
  .lessons-grid {
    grid-template-columns: 1fr;
  }
}

/* ====== Copy-Paste Functionality Styles ====== */

/* Copy button on lessons */
.copy-lesson-btn {
  position: absolute;
  top: 2px;
  left: 2px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.lesson-cell-content {
  position: relative;
}

.lesson-cell-content:hover .copy-lesson-btn {
  opacity: 1;
}

.copy-lesson-btn:hover {
  background: #2563eb;
  transform: scale(1.1);
}

.copy-lesson-btn:active {
  transform: scale(0.95);
}

/* Copied lesson indicator */
.copied-lesson {
  outline: 3px solid #22c55e;
  outline-offset: 2px;
  animation: copiedPulse 0.6s ease-in-out;
}

@keyframes copiedPulse {
  0%, 100% { outline-color: #22c55e; }
  50% { outline-color: #86efac; }
}

/* Empty cell styling */
.empty-cell {
  cursor: default;
  transition: all 0.2s ease;
}

.empty-cell-indicator {
  color: #d1d5db;
  font-size: 18px;
}

/* Paste target highlighting */
.paste-target {
  background: #fef3c7 !important;
  cursor: pointer !important;
  animation: pulseGlow 1.5s ease-in-out infinite;
  border: 2px dashed #fbbf24 !important;
}

@keyframes pulseGlow {
  0%, 100% { 
    background: #fef3c7 !important;
    border-color: #fbbf24 !important;
  }
  50% { 
    background: #fde68a !important;
    border-color: #f59e0b !important;
  }
}

.paste-target:hover {
  background: #fde047 !important;
  transform: scale(1.02);
}

.paste-target .empty-cell-indicator {
  color: #92400e;
  font-weight: bold;
}

/* Paste animation */
.paste-animation {
  animation: pasteSuccess 0.6s ease-out;
}

@keyframes pasteSuccess {
  0% {
    transform: scale(1);
    background: #fef3c7;
  }
  50% {
    transform: scale(1.05);
    background: #86efac;
  }
  100% {
    transform: scale(1);
    background: transparent;
  }
}

/* Copy-Paste notification */
.copy-paste-notification {
  position: fixed;
  top: 80px;
  right: 20px;
  background: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  transform: translateX(100px);
  transition: all 0.3s ease;
  z-index: 9999;
  max-width: 300px;
  border-left: 4px solid #3b82f6;
}

.copy-paste-notification.success {
  border-left-color: #22c55e;
  color: #166534;
}

.copy-paste-notification.error {
  border-left-color: #ef4444;
  color: #991b1b;
}

.copy-paste-notification.show {
  opacity: 1;
  transform: translateX(0);
}

/* Responsive adjustments for copy-paste */
@media (max-width: 768px) {
  .copy-paste-notification {
    top: 60px;
    right: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
  }
  
  .copy-lesson-btn {
    opacity: 1; /* Always visible on mobile */
  }
}

/* Version History Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}

/* Constraint Warning Dialog Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideInScale {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
