/**
 * Satya Calendar Grid - Core Styles
 * 
 * Enhanced grid calendar layout with responsive breakpoints
 * Following design documentation specifications
 */

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

.satya-calendar-grid {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 600px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ==========================================================================
   Calendar Header
   ========================================================================== */

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
}

.calendar-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #2d3748;
  margin: 0;
}

.calendar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.calendar-nav-btn {
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.875rem;
  color: #374151;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.calendar-nav-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.calendar-nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.calendar-nav-btn:disabled:hover {
  background: #ffffff;
  border-color: #d1d5db;
}

/* ==========================================================================
   Day Headers
   ========================================================================== */

.calendar-day-headers {
  display: grid;
  grid-template-columns: 60px 1fr; /* Match the calendar-body grid */
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
  align-items: stretch;
  /* Add padding-right to compensate for scrollbar */
  padding-right: 17px; /* Standard scrollbar width */
}

.day-headers-container {
  display: grid;
  /* Grid columns will be set by media queries to match slots container */
}

/* Compensate for browsers with overlay scrollbars */
@supports (scrollbar-width: thin) {
  .calendar-day-headers {
    padding-right: 16px;
  }
}

/* For Webkit browsers with overlay scrollbars */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  .calendar-day-headers::-webkit-scrollbar {
    width: 17px;
  }
}

.time-header-space {
  width: 60px;
  background: #f8f9fa;
  border-right: 1px solid #e9ecef;
  flex-shrink: 0;
}

.day-header {
  padding: 12px 8px;
  text-align: center;
  font-weight: 600;
  font-size: 0.875rem;
  color: #4b5563;
  border-right: 1px solid #e9ecef;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.day-header:last-child {
  border-right: none;
}

.day-header.weekend {
  background: #f1f3f5;
  color: #6b7280;
}

.day-header.today {
  background: #dbeafe;
  color: #1d4ed8;
}

.day-name {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.day-number {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* ==========================================================================
   Calendar Body
   ========================================================================== */

.calendar-body {
  display: grid;
  grid-template-columns: 60px 1fr;
  flex: 1;
  overflow-y: auto; /* Allow vertical scrolling */
  overflow-x: hidden;
  position: relative;
}

.calendar-time-column {
  background: #f8f9fa;
  border-right: 1px solid #e9ecef;
  flex-shrink: 0;
  position: sticky;
  left: 0;
  z-index: 10;
  overflow-y: auto;
  overflow-x: hidden;
}

.time-label {
  height: 60px; /* 4 slots * 15px each */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #6b7280;
  border-bottom: 1px solid #e9ecef;
  position: relative;
}

.time-label.hour-start {
  border-top: 1px solid #d1d5db;
  font-weight: 500;
}

/* ==========================================================================
   Calendar Grid
   ========================================================================== */

.calendar-slots-container {
  display: grid;
  position: relative;
  /* Grid columns will be set by media queries */
}

.day-column {
  border-right: 1px solid #e9ecef;
  position: relative;
  min-height: 100%;
}

.day-column:last-child {
  border-right: none;
}

.day-column.weekend {
  background: #fafafa;
}

.day-column.today {
  background: #f0f9ff;
}

/* ==========================================================================
   Time Slots
   ========================================================================== */

.time-slot {
  height: 15px;
  border-bottom: 1px solid #f3f4f6;
  position: relative;
  cursor: pointer;
  transition: all 0.15s ease;
}

.time-slot.hour-start {
  border-top: 1px solid #e5e7eb;
}

.time-slot.half-hour {
  border-top: 0.5px dashed #e5e7eb;
}

/* Time Slot States - Following Design Documentation */
.time-slot.free {
  background-color: #f5f5f5;
}

.time-slot.free:hover {
  background-color: #f0fdf4;
  box-shadow: inset 0 0 0 1px #22c55e;
  opacity: 0.8;
}

.time-slot.unavailable {
  background-color: #e5e7eb;
}

.time-slot.available {
  background-color: #ffffff;
  cursor: pointer;
  border: none;
}

.time-slot.available:hover {
  background-color: #f0fdf4;
  box-shadow: inset 0 0 0 1px #22c55e;
}

.time-slot.selected {
  background-color: #ffffff;
  border: none;
}

.time-slot.selected:hover {
  background-color: #f0fdf4;
  box-shadow: inset 0 0 0 1px #22c55e;
}

.time-slot.booked-by-me {
  background-color: #22c55e;
  color: white;
  cursor: not-allowed;
}

.time-slot.booked-with-me {
  background-color: #3b82f6;
  color: white;
  cursor: not-allowed;
}

.time-slot.tentative-by-me {
  background-color: #22c55e;
  opacity: 0.7;
  border: 1px dashed #ffffff;
  box-sizing: border-box;
  cursor: not-allowed;
}

.time-slot.tentative-with-me {
  background-color: #3b82f6;
  opacity: 0.7;
  border: 1px dashed #ffffff;
  box-sizing: border-box;
  cursor: not-allowed;
}

/* ==========================================================================
   Context-Aware Booking Styles (Identity-Regulated)
   ========================================================================== */

/* Own booking - user can see their own booking details */
.time-slot.booking-own {
  background-color: #10b981;
  color: white;
  cursor: pointer;
  position: relative;
  overflow: visible;
}

.time-slot.booking-own:hover {
  background-color: #059669;
}

/* First slot in booking shows the label */
.time-slot.booking-own .booking-label {
  background-color: #10b981;
  color: white;
}

.time-slot.booking-own:hover .booking-label {
  background-color: #059669;
}

/* Blocked booking - other people's bookings shown as unavailable */
.time-slot.booking-blocked {
  background-color: #e5e7eb;
  color: #9ca3af;
  cursor: not-allowed;
  position: relative;
}

.time-slot.booking-blocked::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60%;
  height: 2px;
  background-color: #d1d5db;
  opacity: 0.5;
}

/* Booking label inside slot */
.booking-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 4px;
  background: transparent;
  color: inherit;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 5;
}

/* Selectable slot (available for booking) */
.time-slot.selectable {
  cursor: pointer;
}

.time-slot.selectable:hover {
  background-color: #dbeafe;
  border-color: #3b82f6;
  box-shadow: inset 0 0 0 2px #3b82f6;
}

/* Selected slot for booking (customer has selected this slot) */
.time-slot.booking-selected {
  background-color: #3b82f6;
  color: white;
}

/* Hover preview for duration-aware booking */
.time-slot.hover-preview {
  background-color: #dbeafe;
}

/* Invalid hover preview (not enough contiguous slots) - disabled by default */
.time-slot.hover-preview-invalid {
  background-color: #fee2e2;
  cursor: not-allowed;
}

/* ==========================================================================
   Current Time Indicator
   ========================================================================== */

.current-time-indicator {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #ef4444;
  z-index: 20;
  pointer-events: none;
}

.current-time-indicator::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  background-color: #ef4444;
  border-radius: 50%;
}

/* ==========================================================================
   Selection Overlay
   ========================================================================== */

.selection-overlay {
  position: absolute;
  background: rgba(34, 197, 94, 0.2);
  border: 2px solid #22c55e;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.selection-overlay.active {
  opacity: 1;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Mobile: 1 column */
@media (max-width: 639px) {
  .calendar-day-headers {
    grid-template-columns: 50px 1fr;
  }
  
  .day-headers-container {
    grid-template-columns: 1fr;
  }
  
  .calendar-body {
    grid-template-columns: 50px 1fr;
  }
  
  .calendar-slots-container {
    grid-template-columns: 1fr;
  }
  
  .calendar-time-column,
  .time-header-space {
    width: 50px;
  }
  
  .time-label {
    font-size: 0.65rem;
    height: 30px; /* Larger touch targets */
  }
  
  .time-slot {
    height: 7.5px; /* Half height, but double when rendered */
    min-height: 30px; /* Ensure touch targets are large enough */
  }
  
  .calendar-title {
    font-size: 1.1rem;
  }
  
  .calendar-controls {
    gap: 4px;
  }
  
  .calendar-nav-btn {
    padding: 6px 8px;
    font-size: 0.75rem;
  }
}

/* Tablet: 3 columns */
@media (min-width: 640px) and (max-width: 1023px) {
  .day-headers-container {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .calendar-slots-container {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .time-slot {
    height: 20px; /* Slightly larger for tablet */
  }
  
  .time-label {
    height: 80px; /* 4 slots * 20px each */
  }
}

/* Desktop: 7 columns */
@media (min-width: 1024px) {
  .day-headers-container {
    grid-template-columns: repeat(7, 1fr);
  }
  
  .calendar-slots-container {
    grid-template-columns: repeat(7, 1fr);
  }
  
  .time-slot {
    height: 15px; /* Standard desktop height */
  }
  
  .time-label {
    height: 60px; /* 4 slots * 15px each */
  }
}

/* ==========================================================================
   Loading and Empty States
   ========================================================================== */

.calendar-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  color: #6b7280;
  flex-direction: column;
  gap: 12px;
  z-index: 100;
}

.calendar-loading.hidden {
  display: none !important;
}

.calendar-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top: 3px solid #22c55e;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.calendar-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: #9ca3af;
  flex-direction: column;
  gap: 8px;
}

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

.time-slot:focus {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
  z-index: 1;
}

.time-slot[aria-selected="true"] {
  background-color: #e8f5e8;
  box-shadow: inset 0 0 0 2px #22c55e;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .time-slot.available:hover {
    box-shadow: inset 0 0 0 2px #000000;
  }
  
  .time-slot.selected {
    box-shadow: inset 0 0 0 3px #000000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .time-slot,
  .calendar-nav-btn,
  .selection-overlay {
    transition: none;
  }
  
  .calendar-loading-spinner {
    animation: none;
  }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
