/* ==============================================================================
   Teacher Duty Scheduling Module Styles (תורנויות מורים)
   Design System: Or School Stitch Tokens (Rubik, Primary #006194, Slate, Glassmorphism)
   Special Highlighting: Soft Green for Approved Substitutes (#ecfdf5 / #10B981)
   ============================================================================== */

:root {
  --primary: #006194;
  --primary-hover: #007bb9;
  --primary-light: #eff4ff;
  --surface: #f8f9ff;
  --surface-card: #ffffff;
  --border: #e2e8f0;
  --text-main: #0b1c30;
  --text-muted: #64748b;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;
  --success-accent: #10b981;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;
  --purple-soft: #f5f3ff;
  --purple-border: #ddd6fe;
  --purple-text: #5b21b6;
}

body {
  font-family: 'Rubik', system-ui, -apple-system, sans-serif;
  background-color: #f8f9ff;
  color: var(--text-main);
  direction: rtl;
}

/* Duty Board Grid */
.duty-table-container {
  overflow-x: auto;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.duty-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 960px;
}

.duty-table th {
  background: #f1f5f9;
  color: #1e293b;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.85rem 1rem;
  border-bottom: 2px solid #cbd5e1;
  border-left: 1px solid var(--border);
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.duty-table th.col-today {
  background: #e0f2fe;
  color: #0369a1;
  border-bottom-color: #0284c7;
}

.duty-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
  vertical-align: top;
  height: 92px;
  transition: background-color 0.15s ease;
}

.duty-table td:hover {
  background-color: #f8fafc;
}

.duty-table tr:last-child td {
  border-bottom: none;
}

/* Duty Slot Cell Styles */
.duty-cell-card {
  height: 100%;
  min-height: 80px;
  border-radius: 0.75rem;
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--border);
  background: #ffffff;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.duty-cell-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.06);
  border-color: #cbd5e1;
}

/* Soft Green for Approved Substitutes (ירוק עדין) */
.duty-cell-substitute-approved {
  background-color: var(--success-soft) !important;
  border-color: var(--success-border) !important;
  color: var(--success-text) !important;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.12);
}

.duty-cell-substitute-approved .teacher-name {
  color: var(--success-text) !important;
  font-weight: 700;
}

/* Pending Substitute (ממתין לאישור מחליף) */
.duty-cell-substitute-pending {
  background-color: var(--warning-soft) !important;
  border-color: var(--warning-border) !important;
  color: var(--warning-text) !important;
}

/* Needs Substitute / Absence Alert (היעדרות מורה ללא מחליף) */
.duty-cell-needs-substitute {
  background-color: var(--danger-soft) !important;
  border-color: var(--danger-border) !important;
  color: var(--danger-text) !important;
  animation: pulse-soft 2s infinite ease-in-out;
}

@keyframes pulse-soft {
  0%, 100% { border-color: #fca5a5; }
  50% { border-color: #ef4444; }
}

/* Long Term Substitute (חופשת לידה / מחליף קבוע) */
.duty-cell-long-term {
  background-color: var(--purple-soft) !important;
  border-color: var(--purple-border) !important;
  color: var(--purple-text) !important;
}

/* Active Duty Now (הארת תורנות בזמן אמת - כמה דקות לפני ואחרי ההפסקה) */
@keyframes active-duty-glow {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.6), 0 0 14px 3px rgba(245, 158, 11, 0.45);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.95), 0 0 26px 8px rgba(245, 158, 11, 0.7);
  }
}

.duty-cell-card.duty-cell-active-now {
  animation: active-duty-glow 1.4s infinite ease-in-out;
  border-color: #f59e0b !important;
  background-color: #fffbeb !important;
  z-index: 5;
}

.duty-cell-card.duty-cell-active-now::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #f59e0b, #fbbf24, #f59e0b);
  border-radius: 0.75rem 0.75rem 0 0;
}

.duty-cell-active-now-td {
  background-color: #fef3c7 !important;
}

/* Slot Group Header Row */
.slot-group-header {
  background: #f8fafc;
  color: #0f172a;
  font-weight: 700;
  font-size: 0.925rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #cbd5e1;
  border-top: 2px solid #cbd5e1;
}

/* Layer Badges */
.badge-layer {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 9999px;
  background-color: #e2e8f0;
  color: #334155;
}

.badge-substitute {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background-color: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.badge-long-term {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background-color: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
}

.badge-alert {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* Recommendation Drawer / Modal */
.recommendation-item {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  transition: all 0.15s ease;
  background: white;
}

.recommendation-item:hover {
  border-color: var(--primary);
  background: #f8fbff;
}

.score-badge {
  font-weight: 800;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
  border-radius: 0.5rem;
}

.score-high {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.score-medium {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.score-low {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.score-ineligible {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* Custom Scrollbars */
.custom-scroll::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.custom-scroll::-webkit-scrollbar-track {
  background: #f1f5f9;
}
.custom-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}
.custom-scroll::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==========================================================================
   Export / print (PDF, image, Excel)
   ========================================================================== */
.export-header {
  display: none;
}

body.exporting .export-header {
  display: block;
}

.export-header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 6px 14px;
  border-bottom: 3px solid #006194;
  margin-bottom: 12px;
}

.export-logo {
  height: 56px;
  width: auto;
  object-fit: contain;
}

.export-titles {
  flex: 1;
  text-align: right;
}

.export-school {
  font-size: 13px;
  color: #475569;
  font-weight: 600;
}

.export-title {
  font-size: 24px;
  font-weight: 800;
  color: #006194;
  line-height: 1.2;
}

.export-subtitle {
  font-size: 12px;
  color: #64748b;
  margin-top: 3px;
}

body.exporting .duty-table-container {
  overflow: visible !important;
  max-height: none !important;
}

body.exporting .duty-table th {
  position: static !important;
}

body.exporting #boardExportArea {
  background: #ffffff;
  padding: 6px;
}

/* ==========================================================================
   Staff management table: sticky header + sticky first (name) column
   ========================================================================== */
#staffManagementTable {
  border-collapse: separate;
  border-spacing: 0;
}

#staffManagementTable thead th {
  position: sticky;
  top: 0;
  z-index: 30;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

#staffManagementTable thead th:first-child,
#staffManagementTable tbody td:first-child {
  position: sticky;
  right: 0;
  z-index: 20;
  background: #ffffff;
  box-shadow: -1px 0 0 0 #e2e8f0;
}

#staffManagementTable thead th:first-child {
  z-index: 40;
  background: #f8fafc;
}

#staffManagementTable tbody td {
  border-bottom: 1px solid #f1f5f9;
}

#staffManagementTable tbody tr:hover td {
  background: #f8fafc;
}

/* ==============================================================================
   Duty insights (manager highlight-by-condition panel)
   ============================================================================== */

.insight-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: #334155;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.insight-chip:hover {
  border-color: var(--chip-color, #94a3b8);
  background: #f8fafc;
}

.insight-chip.is-active {
  border-color: var(--chip-color, #0f172a);
  background: color-mix(in srgb, var(--chip-color, #0f172a) 12%, white);
  color: #0f172a;
  box-shadow: inset 0 0 0 1px var(--chip-color, #0f172a);
}

.insight-chip.is-active::after {
  content: "✓";
  font-size: 10px;
  color: var(--chip-color, #0f172a);
}

.insight-chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 9999px;
  background: var(--chip-color, #94a3b8);
  flex: 0 0 auto;
}

.insight-chip-count {
  min-width: 1.15rem;
  padding: 0 0.25rem;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
}

.insight-group {
  border: 1px solid #e2e8f0;
  border-right: 3px solid var(--group-color, #64748b);
  border-radius: 0.75rem;
  background: #ffffff;
  overflow: hidden;
}

.insight-group-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  background: #f8fafc;
  border-bottom: 1px solid #eef2f6;
  font-size: 11px;
  font-weight: 700;
  color: #0f172a;
}

.insight-group-head .insight-chip-dot {
  background: var(--group-color, #64748b);
}

.insight-group-title {
  flex: 1 1 auto;
}

.insight-group-count {
  padding: 0.05rem 0.45rem;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--group-color, #64748b) 14%, white);
  color: var(--group-color, #334155);
  font-size: 10px;
  font-weight: 800;
}

.insight-teacher-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.insight-teacher {
  padding: 0.3rem 0;
  border-bottom: 1px dashed #eef2f6;
}

.insight-teacher:last-child {
  border-bottom: 0;
}

.insight-teacher-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 12px;
  color: #0f172a;
}

.insight-quota {
  padding: 0.05rem 0.4rem;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
}

.insight-teacher-details {
  margin-top: 0.1rem;
  font-size: 11px;
  color: #64748b;
  line-height: 1.45;
}

.insight-empty,
.insight-hint {
  margin: 0;
  padding: 0.6rem 0.7rem;
  font-size: 11px;
  color: #64748b;
}

.insight-hint {
  padding: 0.25rem 0.1rem;
}

/* The ring is drawn on an inner wrapper, never on the card, so the existing
   status background/border and the active-duty ::before stripe stay intact. */
.teacher-insight-target {
  position: relative;
  border-radius: 6px;
}

.insight-ring {
  box-shadow: 0 0 0 2px var(--insight-first, #0f172a);
}

.insight-ring.insight-multi {
  border: 2px solid transparent !important;
  background: linear-gradient(transparent, transparent) padding-box,
              conic-gradient(var(--insight-segments)) border-box !important;
}

.insight-ring.insight-multi::after {
  content: attr(data-insight-count);
  position: absolute;
  top: -7px;
  left: -7px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 9999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
  pointer-events: none;
}

body.exporting .insight-ring,
body.exporting .insight-ring.insight-multi {
  box-shadow: none !important;
  border: 0 !important;
  background: none !important;
}

body.exporting .insight-ring.insight-multi::after {
  display: none !important;
}

/* Print Friendly */
@media print {
  @page {
    size: A4 landscape;
    margin: 9mm;
  }
  body {
    background: white !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .no-print {
    display: none !important;
  }
  .insight-ring,
  .insight-ring.insight-multi {
    box-shadow: none !important;
    border: 0 !important;
    background: none !important;
  }
  .insight-ring.insight-multi::after {
    display: none !important;
  }
  .export-header {
    display: block !important;
  }
  #dutiesViewSwitcher,
  #staffManagementView {
    display: none !important;
  }
  #boardView {
    display: block !important;
  }
  #boardExportArea {
    display: block !important;
  }
  .duty-table-container {
    overflow: visible !important;
    max-height: none !important;
    box-shadow: none !important;
    border: 1px solid #000 !important;
  }
  .duty-table {
    min-width: 0 !important;
    width: 100% !important;
  }
  .duty-table th {
    background: #eee !important;
    color: #000 !important;
    position: static !important;
  }
  .duty-cell-card {
    box-shadow: none !important;
    border: 1px solid #999 !important;
  }
  #weeklyChangesSection {
    display: none !important;
  }
}
