/**
 * VRCC Availability Calendar Styles
 *
 * Flatpickr calendar customization with prm-inspired styling
 * Includes disabled dates, mobile drawer, and price overlay
 *
 * @since 2.2.0
 */

/* ==========================================================================
   Calendar Container
   ========================================================================== */

#vrcc-availability-calendar {
  max-width: 800px;
  margin: 20px auto;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.vrcc-calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.vrcc-calendar-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
}

.vrcc-refresh-availability {
  padding: 8px 16px;
  background: #007FAD;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.vrcc-refresh-availability:hover {
  background: #006994;
}

/* ==========================================================================
   Flatpickr Calendar Customization
   ========================================================================== */

.flatpickr-calendar {
  border: none !important;
  box-shadow: none !important;
  width: 100% !important;
  max-width: none !important;
}

.flatpickr-months {
  margin-bottom: 16px;
}

.flatpickr-month {
  color: #333;
}

.flatpickr-current-month {
  font-size: 18px;
  font-weight: 600;
}

/* Day Cells */
.flatpickr-day {
  border-radius: 4px;
  font-weight: 500;
  transition: all 0.2s;
}

/* Available Dates */
.vrcc-available-date {
  background: #e6f7e6;
  color: #006400;
  cursor: pointer;
}

.vrcc-available-date:hover {
  background: #c8efc8;
  transform: scale(1.05);
}

/* Disabled/Booked Dates */
.flatpickr-disabled {
  background: #ffebee !important;
  color: #d32f2f !important;
  cursor: not-allowed !important;
  position: relative;
}

.flatpickr-disabled::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 2px;
  background: #d32f2f;
  transform: rotate(-45deg);
}

/* Selected Range */
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: #007FAD !important;
  color: #fff !important;
  border-color: #007FAD !important;
}

.flatpickr-day.inRange {
  background: #e0f2f7 !important;
  border-color: #e0f2f7 !important;
  color: #333 !important;
}

/* Today */
.flatpickr-day.today {
  border: 2px solid #007FAD;
}

/* ==========================================================================
   Selected Dates Display
   ========================================================================== */

#vrcc-selected-dates {
  display: none;
  padding: 16px;
  background: #f5f5f5;
  border-radius: 4px;
  margin: 16px 0;
  font-size: 16px;
  color: #333;
}

#vrcc-selected-dates.show {
  display: block;
}

/* ==========================================================================
   Price Display
   ========================================================================== */

#vrcc-price-display {
  display: none;
  padding: 20px;
  background: #fff3e0;
  border: 2px solid #ff9800;
  border-radius: 8px;
  margin: 16px 0;
  text-align: center;
}

#vrcc-price-display.show {
  display: block;
}

.vrcc-price-amount {
  font-size: 32px;
  font-weight: 700;
  color: #ff6f00;
}

.vrcc-price-nights {
  font-size: 16px;
  color: #666;
  margin-left: 8px;
}

/* ==========================================================================
   Check Availability Button
   ========================================================================== */

#vrcc-check-availability {
  display: block;
  width: 100%;
  padding: 16px;
  background: #007FAD;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 16px;
}

#vrcc-check-availability:hover {
  background: #006994;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 127, 173, 0.3);
}

#vrcc-check-availability:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

/* ==========================================================================
   Mobile Drawer Mode (< 768px)
   ========================================================================== */

@media (max-width: 767px) {
  /* Toggle Button - Always Visible on Mobile */
  #vrcc-calendar-toggle {
    display: block;
    width: 100%;
    max-width: none;
    padding: 14px 16px;
    background: #007FAD;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 12px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
    min-height: 44px;
    position: relative;
  }

  #vrcc-calendar-toggle:active {
    background: #006994;
    transform: scale(0.98);
  }

  #vrcc-calendar-toggle::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    opacity: 0.7;
  }

  #vrcc-calendar-toggle[aria-expanded="true"]::after {
    transform: translateY(-50%) rotate(180deg);
  }

  /* Drawer Container (Full Screen) */
  #vrcc-calendar-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: auto;
    max-height: 90vh;
    background: #fff;
    border-radius: 16px 16px 0 0;
    z-index: 9998;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: 32px;
  }

  #vrcc-calendar-drawer[hidden] {
    display: none;
  }

  #vrcc-calendar-drawer:not([hidden]) {
    transform: translateY(0);
  }

  /* Drawer Handle (Visual Indicator) */
  #vrcc-calendar-drawer::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
  }

  /* Overlay Backdrop */
  .vrcc-calendar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9997;
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
  }

  .vrcc-calendar-overlay[hidden] {
    display: none;
  }

  .vrcc-calendar-overlay:not([hidden]) {
    opacity: 1;
  }

  /* Calendar Container Inside Drawer */
  #vrcc-availability-calendar {
    max-width: none;
    margin: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  .vrcc-calendar-header {
    padding: 16px 0 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
  }

  .vrcc-calendar-title {
    font-size: 18px;
  }

  /* Flatpickr Responsive */
  .flatpickr-calendar {
    max-width: 100% !important;
    width: 100% !important;
  }

  .flatpickr-months {
    padding: 8px 0;
  }

  .flatpickr-month {
    height: auto;
  }

  .flatpickr-monthSelect-months {
    width: 100%;
  }

  .flatpickr-innerContainer {
    display: block;
    width: 100%;
  }

  .flatpickr-weekday {
    width: calc(100% / 7);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 0;
  }

  .flatpickr-weeks {
    padding: 0;
  }

  .flatpickr-week {
    display: flex;
    width: 100%;
  }

  .flatpickr-day {
    width: calc(100% / 7);
    max-width: none;
    padding: 8px;
    font-size: 14px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .flatpickr-day:active {
    background: #007FAD !important;
    color: #fff !important;
  }

  /* Hide navigation arrows on mobile, use buttons instead */
  .flatpickr-prev-month,
  .flatpickr-next-month {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  /* Date Input Hidden on Mobile */
  #vrcc-date-picker {
    display: none;
  }

  /* Selected Dates Display */
  .vrcc-selected-dates {
    margin-top: 16px;
    padding: 12px;
    background: #f9f9f9;
    border-left: 4px solid #007FAD;
  }

  .vrcc-selected-dates.show {
    display: block;
  }

  /* Price Display */
  #vrcc-price-display {
    margin: 12px 0;
    padding: 12px;
  }

  /* Buttons Responsive */
  .vrcc-check-availability,
  .vrcc-refresh-availability {
    width: 100%;
    padding: 12px 16px;
    min-height: 44px;
    margin-bottom: 8px;
    margin-right: 0;
    font-size: 16px;
  }

  .vrcc-check-availability:active,
  .vrcc-refresh-availability:active {
    transform: scale(0.98);
  }

  /* Legend - Stack Vertically */
  .vrcc-calendar-legend {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
  }

  .vrcc-legend-item {
    font-size: 13px;
    padding: 6px 0;
  }

  /* Loading Indicator */
  .vrcc-calendar-loading {
    padding: 20px;
  }

  /* Pricing Tooltip - Adjust Position */
  #vrcc-pricing-tooltip {
    max-width: 180px;
    font-size: 12px;
    padding: 8px;
  }

  /* Prevent zoom on input focus */
  input[type="date"],
  input[type="text"],
  select {
    font-size: 16px;
  }
}

/* ==========================================================================
   Tablet Layout (768px - 1024px)
   ========================================================================== */

@media (min-width: 768px) and (max-width: 1024px) {
  #vrcc-calendar-toggle {
    display: none;
  }

  .vrcc-calendar-overlay {
    display: none !important;
  }

  #vrcc-calendar-drawer {
    position: static;
    transform: none;
    max-height: none;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 16px;
  }

  #vrcc-availability-calendar {
    max-width: 100%;
  }

  .flatpickr-calendar {
    max-width: 100% !important;
  }

  .flatpickr-day {
    font-size: 15px;
    min-height: 40px;
  }
}

/* ==========================================================================
   Desktop Layout (> 1024px)
   ========================================================================== */

@media (min-width: 1025px) {
  #vrcc-calendar-toggle {
    display: none;
  }

  .vrcc-calendar-overlay {
    display: none !important;
  }

  #vrcc-calendar-drawer {
    position: static;
    transform: none;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    background: transparent;
  }

  #vrcc-availability-calendar {
    max-width: 800px;
  }

  .flatpickr-calendar {
    max-width: 100% !important;
  }

  .flatpickr-day {
    min-height: 36px;
  }
}

/* ==========================================================================
   Sync Indicator
   ========================================================================== */

.vrcc-sync-indicator {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 12px;
}

.vrcc-sync-indicator.syncing {
  background: #fff3e0;
  color: #ff9800;
}

.vrcc-sync-indicator.syncing::before {
  content: '⟳ ';
  animation: spin 1s linear infinite;
}

.vrcc-sync-indicator.success {
  background: #e6f7e6;
  color: #006400;
}

.vrcc-sync-indicator.error {
  background: #ffebee;
  color: #d32f2f;
}

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

/* ==========================================================================
   Legend
   ========================================================================== */

.vrcc-calendar-legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e0e0e0;
}

.vrcc-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
}

.vrcc-legend-box {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.vrcc-legend-box.available {
  background: #e6f7e6;
  border-color: #006400;
}

.vrcc-legend-box.booked {
  background: #ffebee;
  border-color: #d32f2f;
}

.vrcc-legend-box.selected {
  background: #007FAD;
  border-color: #007FAD;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.vrcc-calendar-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.vrcc-calendar-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #007FAD;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

.flatpickr-day:focus {
  outline: 2px solid #007FAD;
  outline-offset: 2px;
}

.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;
}
