/* styles/calendar.css */
/* DayPilot Theme: ksp_calendar - Earth Tone Design */

/* Tailwind Compatibility - Ensure Prompt font is used for calendar */
#calendar-card,
#calendar-card * {
  font-family: 'Prompt', 'Noto Sans Thai', sans-serif;
}

/* 1. Calendar Card Container - Warm Beige Theme */
#calendar-card {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 25px -5px rgba(141, 110, 99, 0.05), 0 10px 10px -5px rgba(141, 110, 99, 0.04);
  border: 1px solid rgba(141, 110, 99, 0.1);
  padding: 32px;
  position: relative;
  overflow: visible;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  /* Changed from hidden to allow Tailwind grid to work */
}

/* Decorative gradient blur */
#calendar-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 384px;
  height: 384px;
  background: linear-gradient(to bottom right, rgba(141, 110, 99, 0.15), transparent);
  border-radius: 50%;
  filter: blur(80px);
  z-index: 0;
  transform: translate(33%, -33%);
  pointer-events: none;
}

.calendar-card-header {
  margin-bottom: 24px;
  position: relative;
  z-index: 10;
}

.calendar-card-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #5d4037;
  /* Updated to match Tailwind color */
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Remove emoji when using Lucide icons */
.calendar-card-title::before {
  content: none;
}

/* Navigation Buttons */
.calendar-top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  background: transparent;
  padding: 0;
  position: relative;
  z-index: 10;
}

.calendar-month-label {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #6d4c41;
  text-align: center;
  min-width: 180px;
}

.calendar-nav-btn {
  background-color: transparent;
  color: #8d6e63;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  user-select: none;
}

.calendar-nav-btn:hover {
  background-color: rgba(141, 110, 99, 0.1);
  color: #6d4c41;
}

.calendar-nav-btn:active {
  transform: scale(0.95);
}

/* 2. DayPilot Container Styles */
#calendar-container {
  transition: opacity 0.3s ease, transform 0.3s ease;
  will-change: opacity, transform;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(141, 110, 99, 0.15);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Animation classes for swipe transitions */
#calendar-container.slide-left {
  animation: slideInFromRight 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

#calendar-container.slide-right {
  animation: slideInFromLeft 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideInFromRight {
  0% {
    opacity: 0;
    transform: translateX(50px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes slideInFromLeft {
  0% {
    opacity: 0;
    transform: translateX(-50px) scale(0.98);
  }

  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

#calendar-latest-events {
  border-radius: 12px;
  border: 1px solid rgba(141, 110, 99, 0.15);
  overflow: hidden;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* 3. Hide DayPilot default generic header/nav elements if they appear */
.ksp_calendar_nav,
.month_default_nav {
  display: none !important;
}

/* 4. Custom Theme Styles */
.ksp_calendar_main {
  font-family: inherit;
  border: none;
}

/* Grid Lines */
.ksp_calendar_cell_inner {
  border-right: 1px solid rgba(141, 110, 99, 0.15);
  border-bottom: 1px solid rgba(141, 110, 99, 0.15);
  background-color: #faf5ef;
  /* Slightly darker/warmer cream */
  color: #4a4a4a;
  transition: all 0.2s ease;
  height: 100%;
  position: relative;
}

.ksp_calendar_cell_inner:hover {
  background-color: rgba(141, 110, 99, 0.03);
}

/* Past Event Styling - Gray out and disable interaction */
.calendar-event.event-past .ksp_calendar_event_inner,
.event-past .ksp_calendar_event_inner {
  opacity: 0.4 !important;
  background-color: #E5E7EB !important;
  color: #6B7280 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

/* Pending Event Styling - Striped background to indicate pending status */
.calendar-event.status-pending .ksp_calendar_event_inner {
  background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.4) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.4) 50%, rgba(255, 255, 255, 0.4) 75%, transparent 75%, transparent);
  background-size: 10px 10px;
  border: 1px dashed rgba(0, 0, 0, 0.2) !important;
  opacity: 0.85;
}

.calendar-event.event-past,
.event-past {
  opacity: 0.5;
  filter: grayscale(50%);
}

/* Not-Owned Event Styling - Disable interaction */
.calendar-event.event-not-owned .ksp_calendar_event_inner,
.event-not-owned .ksp_calendar_event_inner {
  cursor: not-allowed !important;
}

/* Headers (Days of Week) */
.ksp_calendar_header {
  background: #e2d5cc;
  /* Darker warm brown */
  color: #5d4037;
  cursor: default;
  border-bottom: 1px solid #d7ccc8;
  /* Removed individual rounding */
}

.ksp_calendar_header_inner {
  border-right: 1px solid rgba(141, 110, 99, 0.1);
  border-bottom: 1px solid rgba(141, 110, 99, 0.15);
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  padding: 14px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
  /* Increased font size */
  letter-spacing: 0.5px;
}

/* Highlight Sunday in Header (Red) */
.ksp_calendar_header>div>div:first-child .ksp_calendar_header_inner {
  color: #D32F2F;
}

/* Day Numbers */
.ksp_calendar_cell_header {
  color: #6d4c41;
  font-size: 14px;
  padding: 6px 8px;
  font-weight: 500;
  text-align: center;
}

/* Event Styling */
/* Event Styling - Image 2 & 3 Style */
.ksp_calendar_event {
  cursor: pointer;
  font-size: 11px;
  border-radius: 4px;
  /* Slightly rounded like Image 2 */
  box-shadow: none;
  transition: all 0.2s ease;
  border: none;
  overflow: visible;
}

.ksp_calendar_event:hover {
  transform: translateY(-1px);
  filter: brightness(0.97);
  z-index: 20 !important;
}

.ksp_calendar_event_inner {
  display: flex !important;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  color: #333;
  /* Default text color */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 4px;
  height: 100%;
}

/* Leave Type Backgrounds */
/* Leave Type Backgrounds */
/* Vacation - Soft Yellow/Amber */
.event-type-vacation .ksp_calendar_event_inner,
.event-type-leave .ksp_calendar_event_inner {
  background: #FFF9C4 !important; /* Soft Solid */
  border-left: 4px solid #FBC02D;  /* Strong Accent */
  color: #5D4037 !important;
  border-radius: 6px;
}

/* Personal Leave - Soft Green/Mint */
.event-type-personal .ksp_calendar_event_inner {
  background: #C8E6C9 !important;
  border-left: 4px solid #43A047;
  color: #1B5E20 !important;
  border-radius: 6px;
}

/* Festival/Public Holiday - Soft Blue */
.event-type-festival .ksp_calendar_event_inner {
  background: #BBDEFB !important;
  border-left: 4px solid #1E88E5;
  color: #0D47A1 !important;
  border-radius: 6px;
}

/* Sick Leave - Soft Red/Pink */
.event-type-sick .ksp_calendar_event_inner {
  background: #FFCDD2 !important;
  border-left: 4px solid #E53935;
  color: #B71C1C !important;
  border-radius: 6px;
}

/* Weekly Off - Soft Teal/Cyan */
.event-type-weeklyoff .ksp_calendar_event_inner {
  background: #B2DFDB !important;
  border-left: 4px solid #00897B;
  color: #004D40 !important;
  border-radius: 6px;
}

/* Special Holiday - Soft Purple */
.event-type-holiday .ksp_calendar_event_inner {
  background: #E1BEE7 !important;
  border-left: 4px solid #8E24AA;
  color: #4A148C !important;
  border-radius: 6px;
}

/* Meeting - Soft Blue */
.event-type-meeting .ksp_calendar_event_inner {
  background: #BBDEFB !important;
  border-left: 4px solid #1E88E5;
  color: #0D47A1 !important;
  border-radius: 6px;
}

/* Work from Home / Other - Soft Green */
.event-type-other .ksp_calendar_event_inner,
.event-type-wfh .ksp_calendar_event_inner {
  background: #C8E6C9 !important;
  border-left: 4px solid #43A047;
  color: #33691E !important;
  border-radius: 6px;
}

/* Inner Elements (Dot + Name) */
.calendar-event-content {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.calendar-event-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.calendar-event-label {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: normal;
  /* Fix vertical alignment */
}

/* Shadow helper override */
.ksp_calendar_shadow_inner {
  background-color: rgba(141, 110, 99, 0.1) !important;
}

/* Empty State Styling */
.calendar-empty-state {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.8);
  color: #999;
  font-style: italic;
  z-index: 10;
  text-align: center;
  padding: 16px;
  border-radius: 12px;
}


/* 5. Legend and Filter Styles - Earth Tone */
.calendar-legend-filter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: linear-gradient(to right, #faf7f4, #fdfbf9);
  border-radius: 12px;
  border: 1px solid rgba(141, 110, 99, 0.15);
  box-shadow: 0 2px 4px rgba(107, 74, 51, 0.06);
  position: relative;
  z-index: 10;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px;
}

.calendar-legend--employees {
  flex: 1;
}

.calendar-legend--leavetypes {
  margin-top: 12px;
  font-size: 0.8rem;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: white;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid rgba(141, 110, 99, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Employee Legend Item Styles (for palette-based colors) */
.employee-legend-item {
  display: inline-flex;
  align-items: center;
  margin: 4px 6px 4px 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: white;
  font-size: 12px;
  border: 1px solid rgba(141, 110, 99, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  color: #666;
}

.employee-legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  font-size: 0;
  color: transparent;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.employee-legend-label {
  white-space: nowrap;
}

/* Month Details Section (bottom event list) */
.month-detail-row {
  display: flex;
  align-items: center;
  margin: 4px 0;
  padding: 4px 8px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
}

.month-detail-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
  font-size: 0;
  color: transparent;
}

.month-detail-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* Employee Events Modal */
.employee-events-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
  z-index: 900;
}

.employee-events-modal-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.employee-events-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
  width: min(640px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out;
  z-index: 901;
}

.employee-events-modal.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.employee-events-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #f0e6dd;
  font-size: 14px;
  font-weight: 600;
}

.employee-events-modal-close {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  color: #666;
  transition: color 0.15s ease;
}

.employee-events-modal-close:hover {
  color: #000;
}

.employee-events-modal-body {
  padding: 8px 14px 12px;
  overflow-y: auto;
}

.employee-events-modal-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.employee-events-row {
  display: flex;
  align-items: center;
  font-size: 12px;
  padding: 4px 0;
}

.employee-events-badge {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

.employee-events-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.employee-events-empty {
  font-size: 12px;
  color: #999;
  padding: 20px;
  text-align: center;
}

.filter select {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid rgba(141, 110, 99, 0.2);
  background-color: #fdfbf9;
  font-size: 13px;
  color: #6d4c41;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  font-weight: 500;
}

.filter select:hover {
  border-color: rgba(141, 110, 99, 0.4);
  background-color: #fff;
}

.filter select:focus {
  border-color: #8d6e63;
  box-shadow: 0 0 0 3px rgba(141, 110, 99, 0.1);
  background-color: #fff;
}

/* === MOBILE RESPONSIVENESS (600px and below) === */
@media (max-width: 600px) {
  #calendar-card {
    padding: 16px;
    border-radius: 12px;
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  .calendar-card-title {
    font-size: 1.25rem;
  }

  .calendar-top-nav {
    margin-bottom: 12px;
  }

  .calendar-nav-btn {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .calendar-month-label {
    font-size: 1.125rem;
    min-width: auto;
    flex: 1;
  }

  /* Legend - make scrollable horizontally */
  .calendar-legend-filter {
    padding: 8px;
    margin-bottom: 12px;
    flex-direction: column;
    gap: 8px;
  }

  .calendar-legend {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .calendar-legend::-webkit-scrollbar {
    display: none;
  }

  .filter {
    width: 100%;
  }

  .filter select {
    width: 100%;
    padding: 8px 12px;
  }

  /* Calendar grid cells - better height */
  .ksp_calendar_header_inner {
    font-size: 12px;
    padding: 8px 0;
  }

  .ksp_calendar_cell_header {
    font-size: 12px;
    padding: 4px;
  }

  .ksp_calendar_event {
    font-size: 10px;
  }

  .ksp_calendar_event_inner {
    padding: 2px 4px;
    line-height: 1.3;
  }

  /* Sidebar cards - better spacing on mobile */
  .ksp-calendar-sidebar {
    gap: 12px;
  }

  .ksp-sidebar-card {
    padding: 16px;
    border-radius: 12px;
  }

  .requests-recent-leave-title {
    font-size: 13px;
    margin-bottom: 12px;
  }

  .recent-leave-row {
    gap: 8px;
  }

  .leave-balance-row {
    padding: 10px;
  }
}

/* === MOBILE CALENDAR REDESIGN (768px and below) === */
@media (max-width: 768px) {

  /* 📱 MOBILE EVENT RENDERING: FORCE hide all bars and text */
  .ksp_calendar_event,
  .dp_month_event,
  .dp_event {
    background: none !important;
    border: none !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    line-height: 1 !important;
  }

  /* 📱 Show DayPilot event inner wrapper but remove styling (to show dots inside) */
  .ksp_calendar_event_inner,
  .dp_event_inner {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  /* 📱 MOBILE PILL EVENT (Small Text Bar) */
  .mobile-pill-event .mobile-event-inner {
    display: block !important;
    width: 100% !important;
    padding: 1px 4px !important;
    border-radius: 4px !important;
    font-size: 9px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    line-height: 1.3 !important;
    font-weight: 500 !important;
    text-align: left !important;
    margin: 1px 0 !important;
    box-shadow: none !important;
  }

  /* Force background to be transparent on the wrapper so inner pill shows */
  .mobile-pill-event {
    background: transparent !important;
    padding: 0 1px !important;
    height: auto !important;
  }

  /* Override specific Leave Type Styles for MOBILE PILL only */
  /* Because the wrapper .mobile-pill-event has the class, we target the inner div based on wrapper class */

  /* Sick Leave (Red/Pink) */
  .mobile-pill-event.event-type-sick .mobile-event-inner {
    background-color: #FFEBEE !important;
    color: #B71C1C !important;
    border: none !important;
  }

  /* Personal Leave (Green/Mint) */
  .mobile-pill-event.event-type-personal .mobile-event-inner {
    background-color: #E8F5E9 !important;
    color: #1B5E20 !important;
    border: none !important;
  }

  /* Vacation (Yellow/Amber) */
  .mobile-pill-event.event-type-vacation .mobile-event-inner {
    background-color: #FFFDE7 !important;
    /* Lighter yellow */
    color: #F57F17 !important;
    /* Darker amber text */
    border: none !important;
  }

  /* Weekly Off (Teal/Blue-ish) */
  .mobile-pill-event.event-type-weeklyoff .mobile-event-inner {
    background-color: #E0F2F1 !important;
    color: #006064 !important;
    border: none !important;
  }

  /* Festival/Holiday (Blue) */
  .mobile-pill-event.event-type-festival .mobile-event-inner,
  .mobile-pill-event.event-type-holiday .mobile-event-inner {
    background-color: #E3F2FD !important;
    color: #0D47A1 !important;
    border: none !important;
  }

  /* Meeting (Blue) */
  .mobile-pill-event.event-type-meeting .mobile-event-inner {
    background-color: #E1F5FE !important;
    color: #01579B !important;
    border: none !important;
  }

  /* Generic / Other */
  .mobile-pill-event.event-type-leave .mobile-event-inner {
    background-color: #F5F5F5 !important;
    color: #616161 !important;
  }

  /* 📱 Dots Container in Cell: Reset for generic content flow */
  .mobile-dot-container {
    display: block !important;
    /* Changed from flex to block to stack events */
    width: 100%;
    position: relative;
    z-index: 5;
    pointer-events: none;
  }

  /* 📱 Individual mobile dot styling */
  .mobile-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }

  /* Selected Cell Highlight */
  .mobile-selected-cell {
    background: linear-gradient(to bottom right, rgba(141, 110, 99, 0.08), rgba(255, 255, 255, 0.5)) !important;
    box-shadow: inset 0 0 0 2px rgba(141, 110, 99, 0.3);
  }

  /* Latest Events List (Bottom) */
  .latest-events-list {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100px;
  }

  .latest-event-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: linear-gradient(to right, #fdfbf9, white);
    border: 1px solid rgba(141, 110, 99, 0.12);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }

  .latest-event-item-empty {
    text-align: center;
    color: #999;
    padding: 24px;
    font-size: 0.9rem;
    background: rgba(141, 110, 99, 0.03);
    border-radius: 12px;
    font-style: italic;
  }

  .latest-event-dot-large {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 4px;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }

  .latest-event-content {
    flex: 1;
  }

  .latest-event-main {
    font-weight: 600;
    border: none;
    color: #4a4a4a;
    font-size: 13px;
  }

  .latest-event-sub {
    font-size: 12px;
    color: #999;
    line-height: 1.4;
    margin-top: 2px;
  }
}

/* === DRAG AND DROP STYLES === */

/* Event being dragged (Source) */
.calendar-event.draggable {
  cursor: grab;
  touch-action: pan-y;
  /* ✅ FIX: เปลี่ยนจาก none เป็น pan-y เพื่อให้ drag ได้ */
}

.calendar-event.draggable:active {
  cursor: grabbing;
}

/* Ghost Preview: State during drag */
.calendar-event.dragging {
  opacity: 0.4;
  transform: scale(1.05);
  transform-origin: center center;
  /* ✅ PATCH 4: ระบุ origin */
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
  z-index: 1050 !important;
  /* ✅ PATCH 4: สูงกว่า modal backdrop (900-901) */
  /* ✅ FIX: ลบ pointer-events: none เพื่อให้จับ event ได้ขณะ drag */
  will-change: transform, opacity;
  /* ✅ PATCH 4: Optimize performance */
  transition: transform 0.15s ease, opacity 0.15s ease;
  /* ✅ PATCH 4: Smooth animation */
}

/* ✅ PATCH 6: ป้องกัน :hover override .dragging */
.calendar-event.dragging:hover,
.ksp_calendar_event.dragging:hover {
  opacity: 0.4 !important;
  transform: scale(1.05) !important;
  filter: none !important;
  cursor: grabbing !important;
}

/* ✅ PATCH 4: Shake animation for failed drag & drop */
@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}


/* Drop Zone (Calendar Cell) */
.dropzone {
  /* ✅ PATCH 8: Explicit transitions สำหรับ properties ที่เปลี่ยน */
  transition: background-color 0.15s ease,
    border 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
  position: relative;
}

/* ✅ Past Cell Styling - Visual indicator for non-droppable past dates */
.dropzone.past-cell,
.ksp_calendar_cell.past-cell {
  background-color: rgba(229, 231, 235, 0.5) !important;
  cursor: not-allowed !important;
}

.dropzone.past-cell::before,
.ksp_calendar_cell.past-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg,
      transparent,
      transparent 10px,
      rgba(107, 114, 128, 0.05) 10px,
      rgba(107, 114, 128, 0.05) 20px);
  pointer-events: none;
  z-index: 1;
}

/* Drag Over State for Drop Zone */
/* ✅ Earth Tone Theme - ใช้ ::after overlay เพื่อหลีกเลี่ยง inline style override */
.dropzone.drop-hover,
.ksp_calendar_cell_inner.drop-hover,
.ksp_calendar_cell.drop-hover {
  position: relative !important;
}

/* ✅ FIX: ใช้ ::after เป็น overlay ทับทั้งช่อง (หลีกเลี่ยง DayPilot inline styles) */
.dropzone.drop-hover::after,
.ksp_calendar_cell_inner.drop-hover::after,
.ksp_calendar_cell.drop-hover::after {
  content: '' !important;
  position: absolute !important;
  inset: 0 !important;
  background: linear-gradient(135deg,
      rgba(205, 180, 150, 0.35) 0%,
      rgba(139, 115, 85, 0.25) 100%) !important;
  border: 4px dashed #8B7355 !important;
  border-radius: 8px !important;
  box-shadow:
    inset 0 0 0 3px rgba(139, 115, 85, 0.5),
    0 0 0 2px rgba(139, 115, 85, 0.5),
    0 4px 12px rgba(139, 115, 85, 0.3) !important;
  z-index: 999 !important;
  pointer-events: none !important;
  animation: dropZonePulse 1.5s ease-in-out infinite !important;
}

/* ✅ Pulse animation for visibility */
@keyframes dropZonePulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.85;
    transform: scale(0.98);
  }
}

/* ✅ FIX: ป้องกัน dragenter ซ้ำบน child elements (ทำให้กระพริบ) */
.dropzone.drop-hover *,
.ksp_calendar_cell_inner.drop-hover * {
  pointer-events: none !important;
}

/* ❌ Drop Zone Pulse Animation - REMOVED (static border instead) */

/* Ensure the drop target container covers the whole cell */
.day-drop-target {
  width: 100%;
  height: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.calendar-container {
  position: relative;
  min-height: 600px;
}

/* Requests Layout - Updated for Tailwind Grid */
.requests-layout {
  display: flex;
  gap: 24px;
  width: 100%;
  max-width: 100%;
}

.requests-left-panel {
  flex: 0 0 20%;
  max-width: 22%;
}

.requests-right-panel {
  flex: 1 1 80%;
  max-width: 80%;
}

/* Activity Body: Calendar + Sidebar - Now handled by Tailwind grid */
.requests-activity-body {
  display: block;
  /* Let Tailwind grid handle layout */
  position: relative;
  z-index: 10;
}

.requests-calendar-wrapper {
  width: 100%;
  min-height: 620px;
  position: relative;
  z-index: 10;
}

/* Sidebar Cards - Earth Tone Design */
.ksp-calendar-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.ksp-sidebar-card {
  background: linear-gradient(135deg, #fdfbf9 0%, #f9f5f1 100%);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(107, 74, 51, 0.08);
  border: 1px solid rgba(141, 110, 99, 0.15);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.ksp-sidebar-card:hover {
  box-shadow: 0 4px 12px rgba(107, 74, 51, 0.12);
  transform: translateY(-2px);
}

/* Decorative corner accent */
.ksp-sidebar-card::before {
  content: '';
  position: absolute;
  top: -16px;
  right: -16px;
  width: 96px;
  height: 96px;
  background: radial-gradient(circle at center, rgba(141, 110, 99, 0.12), transparent 70%);
  border-radius: 50%;
  z-index: 0;
}

.ksp-sidebar-leave-log {
  flex: 1;
  /* 50% */
}

.ksp-sidebar-leave-balance {
  flex: 1;
  /* 50% */
}

.requests-recent-leave-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 20px 0;
  color: #6d4c41;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 10;
}

/* Remove emoji icons - now using Lucide icons in HTML */
.requests-recent-leave-title::before {
  content: none;
}

.ksp-sidebar-leave-balance .requests-recent-leave-title::before {
  content: none;
}

.requests-recent-leave-list,
.leave-balance-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 10;
  max-height: 320px;
  padding-right: 8px;
}

/* Custom scrollbar styling */
.requests-recent-leave-list::-webkit-scrollbar,
.leave-balance-list::-webkit-scrollbar {
  width: 6px;
}

.requests-recent-leave-list::-webkit-scrollbar-track,
.leave-balance-list::-webkit-scrollbar-track {
  background: rgba(141, 110, 99, 0.05);
  border-radius: 10px;
}

.requests-recent-leave-list::-webkit-scrollbar-thumb,
.leave-balance-list::-webkit-scrollbar-thumb {
  background: rgba(141, 110, 99, 0.3);
  border-radius: 10px;
  transition: background 0.2s ease;
}

.requests-recent-leave-list::-webkit-scrollbar-thumb:hover,
.leave-balance-list::-webkit-scrollbar-thumb:hover {
  background: rgba(141, 110, 99, 0.5);
}

.leave-balance-list {
  gap: 16px;
  font-size: 12px;
}

/* Recent Leave Row Styling */
.recent-leave-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 12px;
  line-height: 1.4;
  padding: 0;
  transition: transform 0.2s ease;
}

.recent-leave-row:hover {
  background-color: rgba(141, 110, 99, 0.05);
}

/* Style for past leave rows */
.recent-leave-row.past {
  opacity: 0.5;
  filter: grayscale(50%);
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.recent-leave-row.past:hover {
  opacity: 0.8;
  filter: grayscale(20%);
}

.recent-leave-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.recent-leave-text {
  flex: 1;
  overflow: hidden;
}

.recent-leave-text strong {
  display: block;
  color: #4a4a4a;
  font-weight: 600;
  margin-bottom: 2px;
}

.recent-leave-text small {
  display: block;
  color: #999;
  font-size: 11px;
}

.recent-leave-date {
  font-size: 10px;
  color: #999;
  background: white;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(141, 110, 99, 0.1);
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.recent-leave-empty {
  font-size: 12px;
  color: #999;
  text-align: center;
  padding: 20px 10px;
  font-style: italic;
}

/* Leave Balance Styling - Progress Bars with Gradients */
.leave-balance-row {
  background: linear-gradient(to right, rgba(255, 255, 255, 0.9), white);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid rgba(141, 110, 99, 0.1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
}

.leave-balance-row:hover {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.leave-balance-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.leave-balance-label {
  color: #4a4a4a;
  font-weight: 700;
  font-size: 13px;
}

.leave-balance-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid;
  transition: all 0.3s ease;
}

/* Feedback Badge - Updated state (green highlight) */
.leave-balance-badge.balance-updated {
  background: linear-gradient(to right, #C8E6C9, #A5D6A7);
  border-color: #66BB6A;
  color: #1B5E20;
  animation: fadeInPulse 0.5s ease;
}

.leave-balance-badge .feedback-badge {
  font-size: 9px;
  background: #4CAF50;
  color: white;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: 4px;
}

/* Pending days indicator (orange/amber) */
.leave-balance-badge .pending-days {
  color: #F57C00;
  font-weight: 700;
  font-style: italic;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes fadeInPulse {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }

  50% {
    opacity: 1;
    transform: scale(1.05);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* Vacation Leave - Amber */
/* Vacation Leave - Amber */
/* Vacation Leave - Yellow/Amber Scheme */
.leave-balance-row.vacation {
  background: #FFF9C4; /* Matching solid bg */
  border-color: #FBC02D;
}
.leave-balance-row.vacation .leave-balance-label {
  color: #AF861E;
}
.leave-balance-row.vacation .leave-balance-fill {
  background: #FBC02D; /* Matching border color for bar fill */
}

/* Sick Leave - Red/Pink Scheme */
.leave-balance-row.sick {
  background: #FFCDD2;
  border-color: #E53935;
}
.leave-balance-row.sick .leave-balance-label {
  color: #C62828;
}
.leave-balance-row.sick .leave-balance-fill {
  background: #E53935;
}

/* Personal Leave - Green/Mint Scheme (ตามภาพตัวอย่าง - โทนเขียวมิ้นต์อ่อน) */
.leave-balance-row.personal {
  background: #C8E6C9;
  border-color: #43A047;
}
.leave-balance-row.personal .leave-balance-label {
  color: #2E7D32;
}
.leave-balance-row.personal .leave-balance-fill {
  background: #43A047;
}

/* Weekly Off - Teal/Cyan Scheme */
.leave-balance-row.weeklyoff {
  background: linear-gradient(to right, #E0F2F1, #ffffff);
  /* Teal 50 -> White */
  border-color: #B2DFDB;
  /* Teal 100 */
}

.leave-balance-row.weeklyoff .leave-balance-label {
  color: #00695C;
  /* Teal 800 */
}

.leave-balance-row.weeklyoff .leave-balance-badge {
  color: #004D40;
  background: #B2DFDB;
  border-color: #80CBC4;
}

.leave-balance-row.weeklyoff .leave-balance-bar-container {
  background: #E0F2F1;
  border: 1px solid #B2DFDB;
}

.leave-balance-row.weeklyoff .leave-balance-fill {
  background: linear-gradient(to right, #26A69A, #d5f0ed);
  /* Soft Teal Gradient */
}

/* Holiday (Special) - Purple Scheme */
.leave-balance-row.holiday {
  background: linear-gradient(to right, #F3E5F5, #ffffff);
  /* Purple 50 -> White */
  border-color: #E1BEE7;
  /* Purple 100 */
}

.leave-balance-row.holiday .leave-balance-label {
  color: #6A1B9A;
  /* Purple 800 */
}

.leave-balance-row.holiday .leave-balance-badge {
  color: #4A148C;
  background: #E1BEE7;
  border-color: #CE93D8;
}

.leave-balance-row.holiday .leave-balance-bar-container {
  background: #F3E5F5;
  border: 1px solid #E1BEE7;
}

.leave-balance-row.holiday .leave-balance-fill {
  background: linear-gradient(to right, #AB47BC, #f1dcf6);
  /* Soft Purple Gradient */
}

/* Festival (Public Holiday) - Blue Scheme */
.leave-balance-row.festival {
  background: linear-gradient(to right, #E3F2FD, #ffffff);
  /* Blue 50 -> White */
  border-color: #BBDEFB;
  /* Blue 100 */
}

.leave-balance-row.festival .leave-balance-label {
  color: #1565C0;
  /* Blue 800 */
}

.leave-balance-row.festival .leave-balance-badge {
  color: #0D47A1;
  background: #BBDEFB;
  border-color: #90CAF9;
}

.leave-balance-row.festival .leave-balance-bar-container {
  background: #E3F2FD;
  /* Light blue track */
  border: 1px solid #BBDEFB;
}

.leave-balance-row.festival .leave-balance-fill {
  background: linear-gradient(to right, #59a9f7, #eaf4fe);
  /* Soft Blue Gradient - ไล่เฉดอ่อนกว่าเดิม */
}


.leave-balance-bar-container {
  width: 100%;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 999px;
  height: 10px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-bottom: 6px;
}

.leave-balance-bar {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  position: relative;
}

.leave-balance-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.leave-balance-stats {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(0, 0, 0, 0.5);
  font-weight: 500;
}

.leave-balance-empty {
  color: #999;
  text-align: center;
  padding: 15px 10px;
  font-style: italic;
  font-size: 12px;
}

/* === TABLET/MOBILE LAYOUT (992px and below) === */
@media (max-width: 992px) {
  .requests-layout {
    flex-direction: column;
  }

  .requests-left-panel,
  .requests-right-panel {
    max-width: 100%;
    flex: 1 1 auto;
  }

  .requests-activity-body {
    display: block;
  }

  .requests-calendar-wrapper,
  .ksp-calendar-sidebar {
    max-width: 100%;
    width: 100%;
    min-height: auto !important;
    /* ✅ Fix: Remove fixed height on mobile to reduce gap */
  }

  .ksp-calendar-sidebar {
    gap: 16px;
    margin-top: 20px;
  }

  .ksp-sidebar-card {
    min-height: auto;
  }

  .ksp-sidebar-leave-log {
    flex: 1;
  }

  .ksp-sidebar-leave-balance {
    flex: 1;
  }

  /* Ensure Tailwind grid stacks on mobile */
  #calendar-card .grid {
    grid-template-columns: 1fr !important;
  }
}

/* === DRAG & DROP ANIMATIONS === */
.ksp_calendar_shadow {
  background-color: rgba(245, 158, 11, 0.15) !important;
  border: 2px dashed #d97706 !important;
  /* Amber-600 */
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  z-index: 10000 !important;
  animation: ksp-vibrant-pulse 1.5s infinite ease-in-out;
  backdrop-filter: blur(2px);
  /* Make it slightly larger to feel "lifted" */
  transform-origin: center center;
}

@keyframes ksp-vibrant-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.4);
    border-color: rgba(217, 119, 6, 0.6);
    transform: scale(1);
  }

  50% {
    box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.1);
    border-color: rgba(217, 119, 6, 1);
    transform: scale(1.02);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.4);
    border-color: rgba(217, 119, 6, 0.6);
    transform: scale(1);
  }
}

/* Hover effects for event moving */
.ksp_calendar_event {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ksp_calendar_event:hover {
  cursor: grab;
  filter: brightness(1.02);
  transform: translateY(-1px);
  z-index: 50;
  /* Ensure hovered event is on top */
}

.ksp_calendar_event:active {
  cursor: grabbing;
  transform: scale(0.98);
}

/* Today's Date Circle Highlight */
/* Today's Date Circle Highlight */
.calendar-today-circle {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 26px;
  height: 26px;
  background-color: #5d4037;
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 4px rgba(93, 64, 55, 0.3);
  margin-top: -2px;
  margin-bottom: 8px !important;
  /* Spacing key to prevent event overlap */
  position: relative;
  z-index: 2;
}

/* === MOBILE CALENDAR TWEAKS === */
@media (max-width: 768px) {

  /* ปรับขนาดตัวอักษรใน Event ให้เล็กลง */
  .ksp_calendar_event_inner {
    font-size: 11px !important;
    padding: 1px 4px !important;
    line-height: 1.2 !important;
  }

  /* ลดความสูงของ Header วัน (อา, จ, อ...) */
  .ksp_calendar_header {
    height: 30px !important;
    line-height: 30px !important;
    font-size: 12px !important;
  }

  /* ปรับขนาดเลขวันที่ */
  .ksp_calendar_cell_header {
    font-size: 12px !important;
    padding-right: 4px !important;
    padding-top: 4px !important;
  }

  /* ซ่อน Avatar/Icon ใน Event บนมือถือเพื่อประหยัดที่ */
  .ksp_calendar_event_inner .event-icon,
  .ksp_calendar_event_inner img {
    display: none !important;
  }

  /* 🔧 FORCE SHOW EVENTS ON MOBILE */
  .calendar_default_event,
  .ksp_calendar_event {
    visibility: visible !important;
    display: flex !important;
    opacity: 1 !important;
  }
}

/* === DRAG AND DROP POINTER FIX === */
/* When .dragging-active is added to a parent container (like #calendar-card or document.body), 
   we ignore pointer events on existing calendar bars/events/labels so that the underlying dropzone (cell) can receive the drop.
*/
.dragging-active .ksp_calendar_event,
.dragging-active .calendar-event,
.dragging-active .calendar-event-content,
.dragging-active .calendar-event-label,
.dragging-active .calendar-event-dot,
.dragging-active .ksp_calendar_event_inner {
  pointer-events: none !important;
}

/* Ensure the dropzone itself REMAINS interactive */
.dragging-active .dropzone,
.dragging-active .ksp_calendar_cell,
.dragging-active .ksp_calendar_cell_inner,
.dragging-active .day-drop-target {
  pointer-events: auto !important;
}

/* ✅ Loading Overlay (แสดงหลัง Drop) */
.calendar-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.calendar-loading-overlay.active {
  display: flex;
  opacity: 1;
}

/* Loading Ring Animation */
.loading-ring {
  width: 64px;
  height: 64px;
  position: relative;
}

.loading-ring div {
  box-sizing: border-box;
  display: block;
  position: absolute;
  width: 51px;
  height: 51px;
  margin: 6px;
  border: 6px solid #8B7355;
  border-radius: 50%;
  animation: loading-ring-spin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
  border-color: #8B7355 transparent transparent transparent;
}

.loading-ring div:nth-child(1) {
  animation-delay: -0.45s;
}

.loading-ring div:nth-child(2) {
  animation-delay: -0.3s;
}

.loading-ring div:nth-child(3) {
  animation-delay: -0.15s;
}

@keyframes loading-ring-spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 50px));
  font-size: 14px;
  color: #6B5D52;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ✅ Drop hover styles defined earlier in file using ::after overlay approach (lines ~927-960) */

/* Absence / No Show - Dark Grey/Red Scheme */
.leave-balance-row.absence {
  background: linear-gradient(to right, #eceff1, #ffffff);
  border-color: #cfd8dc;
}

.leave-balance-row.absence .leave-balance-label {
  color: #37474f;
  /* Blue Grey 800 */
}

.leave-balance-row.absence .leave-balance-badge {
  color: #263238;
  background: #cfd8dc;
  border-color: #b0bec5;
}

.leave-balance-row.absence .leave-balance-bar-container {
  background: #eceff1;
  border: 1px solid #cfd8dc;
}

.leave-balance-row.absence .leave-balance-fill {
  background: linear-gradient(to right, #ef5350, #b71c1c);
  /* Red for Absence! */
}