/**
 * Calendar Component Styles
 * Reference existing calendar styling from GitHub repo
 */

.calendar-component {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
  font-family: var(--body-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
  background-color: transparent;
  height: fit-content;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.calendar-header {
  width: 100%;
  max-width: 100%;
}

/* Loading State */
.calendar-component.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
}

.loading-message {
  color: var(--foreground, #ffffff);
  font-size: 16px;
  font-family: var(--body-font, inherit);
}

/* Error State */
.calendar-component.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px 20px;
}

.error-message {
  color: var(--destructive, #d32f2f);
  font-size: 16px;
  text-align: center;
  font-family: var(--body-font, inherit);
}

.retry-button {
  padding: 10px 20px;
  background-color: var(--primary, #1976d2);
  color: var(--primary-foreground, #ffffff);
  border: none;
  border-radius: var(--radius-md, 4px);
  cursor: pointer;
  font-size: 14px;
  font-family: var(--button-font, inherit);
  transition: background-color 0.2s;
}

.retry-button:hover {
  background-color: var(--primary, #1565c0);
  opacity: 0.9;
}

/* Calendar Header - Top section with state and stats */
.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 24px;
}

/* State Selector */
.state-selector {
  position: relative;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.state-selector label {
  display: none; /* Hide label, button shows "State" */
}

/* Custom Dropdown Component */
.custom-dropdown {
  position: relative;
  min-width: 200px;
  width: 100%;
  max-width: 300px;
}

.custom-dropdown-trigger {
  width: auto;
  padding: 8px 16px; /* Vertical: 8px, Horizontal: 16px */
  border: 1px solid var(--input, #e0e0e0);
  border-radius: var(--radius-md, 8px);
  font-size: 16px;
  font-weight: 600; /* Semibold */
  font-family: var(--body-font, inherit);
  background-color: var(--card, #ffffff);
  color: var(--foreground, #333333);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-align: left;
}

.custom-dropdown-trigger:hover {
  border-color: var(--border, #b0b0b0);
}

.custom-dropdown-trigger:focus {
  outline: none;
  border-color: var(--ring, #1976d2);
  box-shadow: 0 0 0 3px var(--ring, rgba(25, 118, 210, 0.1));
}

.custom-dropdown-trigger.open {
  border-color: #1976d2;
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.1);
}

.custom-dropdown-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-dropdown-text.placeholder {
  color: var(--muted-foreground, #999999);
}

.custom-dropdown-arrow {
  flex-shrink: 0;
  margin-left: 8px;
  transition: transform 0.2s;
}

.custom-dropdown-trigger.open .custom-dropdown-arrow {
  transform: rotate(180deg);
}

.custom-dropdown-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background-color: var(--popover, #ffffff);
  border: 1px solid var(--border, #e0e0e0);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
}

.custom-dropdown-option {
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 400;
  font-family: var(--body-font, inherit);
  color: var(--popover-foreground, #333333);
  transition: background-color 0.15s;
}

.custom-dropdown-option:hover {
  background-color: #cddcfc; /* Light blue highlight on hover */
}

.custom-dropdown-option.selected {
  background-color: transparent; /* No background for selected item */
  color: #1156F9; /* Blue text color for selected item */
  font-weight: 500;
}

.custom-dropdown-option-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Calendar Container */
.calendar-container {
  margin: 0 auto 24px;
  background-color: var(--card, #ffffff);
  border-radius: var(--radius-lg, 12px);
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: inline-block;
  width: fit-content;
  max-width: 100%;
}

/* Mantine DatePicker wrapper styling */
.mantine-DatePicker-root {
  background-color: transparent;
}

.mantine-DatePicker-calendar {
  background-color: transparent;
}

.calendar-date-picker {
  width: auto;
}

/* Holiday Highlighting */
.holiday-public {
  background-color: #ffebee !important;
  color: #c62828 !important;
  font-weight: 500;
}

.holiday-school {
  background-color: #e3f2fd !important;
  color: #1565c0 !important;
  font-weight: 500;
}

.weekend {
  color: var(--foreground, #333333) !important;
  opacity: 1;
}

/* Results Display - Summary Statistics */
.results-display {
  display: flex;
  gap: 32px;
  margin-bottom: 0;
  margin-top: 0;
  flex-wrap: wrap;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.metric-value {
  font-weight: 700;
  font-family: var(--heading-font, inherit);
  color: var(--foreground, #ffffff);
  font-size: 4rem; /* Desktop */
  line-height: 1;
}

/* Light theme - results text color */
.calendar-component.theme-light .metric-value,
.calendar-component[data-theme="light"] .metric-value {
  color: #171316;
}

.calendar-component.theme-light .metric-label,
.calendar-component[data-theme="light"] .metric-label {
  color: #171316;
}

.metric-label {
  font-weight: 400;
  font-family: var(--body-font, inherit);
  color: var(--foreground, #ffffff);
  font-size: 1.5rem; /* Desktop */
  text-transform: lowercase;
}

.metric-label-desktop {
  display: inline;
}

.metric-label-mobile {
  display: none;
}

/* Mobile Landscape */
@media (max-width: 767px) and (orientation: landscape) {
  .metric-value {
    font-size: 2.625rem; /* Mobile landscape */
  }

  .metric-label {
    font-size: 1rem; /* Mobile landscape */
    font-weight: 600; /* Semibold */
  }

  .metric-label-desktop {
    display: none;
  }

  .metric-label-mobile {
    display: inline;
  }
}

/* Responsive Design */
@media (max-width: 767px) {
  .metric-label-desktop {
    display: none;
  }

  .metric-label-mobile {
    display: inline;
  }

  .results-display {
    gap: 16px;
  }

  .calendar-component {
    padding: 0;
  }

  .state-selector {
    margin-bottom: 16px;
  }

  .custom-dropdown {
    min-width: 100%;
    max-width: 100%;
  }


  .metric-value {
    font-size: 9.3458vw; /* Mobile */
  }

  .metric-label {
    font-size: 3.7383vw; /* Mobile */
    font-weight: 600; /* Semibold */
  }

  /* Calendar mobile overflow fixes */
  .calendar-container {
    padding: 16px 8px;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
  }

  .mantine-DatePicker-root {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .mantine-DatePicker-levelsGroup {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 100%;
    justify-content: center;
    align-items: center;
  }

  .mantine-DatePicker-calendar {
    width: 100%;
    max-width: 100%;
  }

  .mantine-DatePicker-month {
    max-width: 100%;
    min-width: 0;
  }

  .mantine-DatePicker-monthCell {
    max-width: 100%;
    min-width: 0;
  }

  .mantine-DatePicker-weekdaysRow {
    max-width: 100%;
  }

  .mantine-DatePicker-weekday {
    font-size: 12px !important;
    padding: 4px 2px !important;
    min-width: 0;
    flex: 1;
  }

  .mantine-DatePicker-day {
    /* Use same sizing as desktop - let Mantine handle the width */
    min-width: 0;
    position: relative;
    overflow: hidden; /* Prevent highlights from overflowing */
  }


  .mantine-DatePicker-day .calendar-day-content {
    width: 100%;
    height: 100%;
    min-height: 32px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Make holiday highlight fit within the cell to prevent clipping */
  .mantine-DatePicker-day .holiday-highlight {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
  }

  /* Ensure selected date backgrounds span full cell on mobile */
  .mantine-DatePicker-day[data-selected],
  .mantine-DatePicker-day[data-first-in-range],
  .mantine-DatePicker-day[data-last-in-range],
  .mantine-DatePicker-day[data-in-range] {
    position: relative;
  }

  /* Make sure the background covers the full cell including padding */
  .mantine-DatePicker-day[data-in-range]:not([data-first-in-range]):not([data-last-in-range]) {
    background-color: #CDDCFC !important;
  }

  .mantine-DatePicker-day[data-selected],
  .mantine-DatePicker-day[data-first-in-range],
  .mantine-DatePicker-day[data-last-in-range] {
    background-color: #1156F9 !important;
  }
  
  /* Ensure calendar header stacks properly on mobile */
  .calendar-header {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  
  .state-selector {
    width: 100%;
  }
  
  .mantine-DatePicker-calendarHeaderControl {
    display: flex !important; /* Show navigation controls on mobile */
  }

  .mantine-DatePicker-calendarHeaderLevel {
    font-size: 16px !important;
  }

  /* Center the month heading when arrows are visible using grid layout */
  .mantine-DatePicker-calendarHeader {
    display: grid !important;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    position: relative;
  }

  .mantine-DatePicker-calendarHeaderLevel {
    grid-column: 2;
    justify-self: center;
    text-align: center;
  }

  /* For year/decade selection - heading on left, button on right */
  .mantine-DatePicker-level[data-mantine-datepicker-level="year"] .mantine-DatePicker-calendarHeader,
  .mantine-DatePicker-level[data-mantine-datepicker-level="decade"] .mantine-DatePicker-calendarHeader {
    grid-template-columns: auto 1fr !important;
  }

  .mantine-DatePicker-level[data-mantine-datepicker-level="year"] .mantine-DatePicker-calendarHeaderLevel,
  .mantine-DatePicker-level[data-mantine-datepicker-level="decade"] .mantine-DatePicker-calendarHeaderLevel {
    grid-column: 1 !important;
    justify-self: start !important;
    text-align: left !important;
  }

  .mantine-DatePicker-level[data-mantine-datepicker-level="year"] .mantine-DatePicker-calendarHeaderControl,
  .mantine-DatePicker-level[data-mantine-datepicker-level="decade"] .mantine-DatePicker-calendarHeaderControl {
    grid-column: 2 !important;
    justify-self: end !important;
  }

  /* For month selection - arrows on sides, heading centered */
  .mantine-DatePicker-calendarHeaderControl:first-child {
    grid-column: 1;
    justify-self: start;
  }

  .mantine-DatePicker-calendarHeaderControl:last-child {
    grid-column: 3;
    justify-self: end;
  }

  .calendar-date-picker {
    width: 100%;
    max-width: 100%;
  }
}

/* ----------------- DATE PICKER STYLES -------------- */

/* Hide holiday highlights when date is selected */
.mantine-DatePicker-day[data-selected] .holiday-highlight,
.mantine-DatePicker-day[data-first-in-range] .holiday-highlight,
.mantine-DatePicker-day[data-last-in-range] .holiday-highlight,
.mantine-DatePicker-day[data-in-range] .holiday-highlight {
  display: none !important;
}

/* Start and End dates - Selected with #1156F9 background */
.mantine-DatePicker-day[data-selected],
.mantine-DatePicker-day[data-first-in-range],
.mantine-DatePicker-day[data-last-in-range] {
  border-radius: 100px !important;
  background-color: #1156F9 !important;
}

/* Text color for start/end/single selected dates - #FDFEFD */
.mantine-DatePicker-day[data-selected],
.mantine-DatePicker-day[data-first-in-range],
.mantine-DatePicker-day[data-last-in-range] {
  color: #FDFEFD !important;
}

.mantine-DatePicker-day[data-selected] .day-number,
.mantine-DatePicker-day[data-first-in-range] .day-number,
.mantine-DatePicker-day[data-last-in-range] .day-number {
  color: #FDFEFD !important;
  font-weight: 600 !important;
  z-index: 2 !important;
  position: relative !important;
}

/* Dates in between - #CDDCFC background with 0 radius */
.mantine-DatePicker-day[data-in-range]:not([data-first-in-range]):not([data-last-in-range]) {
  border-radius: 0 !important;
  background-color: #CDDCFC !important;
}

/* Text color for in-range dates - keep original color */
.mantine-DatePicker-day[data-in-range]:not([data-first-in-range]):not([data-last-in-range]) .day-number {
  font-weight: 600 !important;
  z-index: 2 !important;
  position: relative !important;
}

/* Override for weekend text colors when selected */
.mantine-DatePicker-day[data-weekend][data-selected],
.mantine-DatePicker-day[data-weekend][data-first-in-range],
.mantine-DatePicker-day[data-weekend][data-last-in-range] {
  color: #FDFEFD !important;
}

.mantine-DatePicker-day[data-weekend][data-selected] .day-number,
.mantine-DatePicker-day[data-weekend][data-first-in-range] .day-number,
.mantine-DatePicker-day[data-weekend][data-last-in-range] .day-number {
  color: #FDFEFD !important;
}

/* Weekend in-range dates keep their original color */

/* Regular weekend styling - same color as weekday dates */
.mantine-DatePicker-day[data-weekend] {
  color: var(--foreground, #333333);
}

.mantine-DatePicker-weekday {
  color: var(--foreground, #333333) !important;
  font-family: var(--body-font, inherit) !important;
}

/* Previous/next month dates - faded */
.mantine-DatePicker-day[data-outside] {
  color: var(--muted-foreground, #999999) !important;
  opacity: 0.5;
}

/* Public holiday dates from previous/next months - text color #FDFEFD */
.mantine-DatePicker-day[data-outside] .day-number.public-holiday-day {
  color: #FDFEFD !important;
}

/* Selected dates from previous/next months - use specific color instead of opacity */
.mantine-DatePicker-day[data-outside][data-selected],
.mantine-DatePicker-day[data-outside][data-first-in-range],
.mantine-DatePicker-day[data-outside][data-last-in-range],
.mantine-DatePicker-day[data-outside][data-in-range] {
  opacity: 1 !important;
  background-color: #8DAAFD !important;
  color: var(--muted-foreground, #999999) !important;
}

.mantine-DatePicker-calendarHeaderLevel, 
.mantine-DatePicker-weekday {
  font-weight: 600 !important;
  font-family: var(--heading-font, inherit) !important;
}

.mantine-DatePicker-day {
  font-family: var(--body-font, inherit) !important;
}


/* Responsive layout for calendar months */
/* Desktop (1080px+): 3 months horizontal */
@media only screen and (min-width: 1080px) {
  .mantine-DatePicker-levelsGroup {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    justify-content: center;
    align-items: flex-start; /* Align to top */
  }

  .mantine-DatePicker-calendarHeaderControl {
    display: flex !important;
  }

  /* Desktop calendar text size */
  .mantine-DatePicker-calendarHeaderLevel,
  .mantine-DatePicker-weekday,
  .mantine-DatePicker-day,
  .day-number {
    font-size: 16px !important;
  }
}

/* Tablet (768px - 1079px): 2 months horizontal */
@media only screen and (min-width: 768px) and (max-width: 1079px) {
  .mantine-DatePicker-levelsGroup {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    justify-content: center;
    align-items: flex-start; /* Align to top */
  }

  .mantine-DatePicker-calendarHeaderControl {
    display: flex !important;
  }

  .metric-value {
    font-size: 2.875rem; /* Tablet */
  }

  .metric-label {
    font-size: 1.125rem; /* Tablet */
  }
}


/* ----------------- END DATE PICKER STYLES -------------- */

/* ----------------- COMBOBOX STYLES -------------- */
.mantine-Combobox-option {
  padding: 0 !important;
}

[data-combobox-selected] {
  background-color: #cddcfc !important;
  color: black !important;
}

.mantine-Combobox-option:hover {
  background-color: #cddcfc !important;
}

/* ----------------- END COMBOBOX STYLES -------------- */

.mantine-DatePicker-monthCell {
  position: relative;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.mantine-DatePicker-day {
  position: relative;
  z-index: 1;
  overflow: hidden; /* Prevent highlights and backgrounds from overflowing */
  border-radius: 0 !important; /* Remove border-radius from date picker buttons */
}

/* Override Mantine's default border-radius on date picker day buttons */
.m_396ce5cb {
  border-radius: 0 !important;
}

/* Extend data-in-range background that comes after data-first-in-range */
.mantine-DatePicker-monthCell:has([data-first-in-range]) + .mantine-DatePicker-monthCell:has([data-in-range]):not(:has([data-last-in-range])):not(:has(.mantine-DatePicker-day[style*="display: none"]))::after {
  content: '';
  position: absolute;
  top: 0.5px;
  left: -50%;
  right: 0;
  bottom: 0.5px;
  background-color: #CDDCFC;
  z-index: 0;
}

/* Extend data-in-range background that comes before data-last-in-range */
.mantine-DatePicker-monthCell:has([data-in-range]):not(:has([data-first-in-range])):has(+ .mantine-DatePicker-monthCell [data-last-in-range]):not(:has(.mantine-DatePicker-day[style*="display: none"]))::after {
  content: '';
  position: absolute;
  top: 0.5px;
  left: -50%; /* Extend backwards to connect with start date */
  right: -50%;
  bottom: 0.5px;
  background-color: #CDDCFC;
  z-index: 0;
}

/* ----------------- HOLIDAY HIGHLIGHTING -------------- */

/* Base styles for holiday highlights */
.calendar-day-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* Prevent highlights from overflowing */
  box-sizing: border-box;
}

.holiday-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-sizing: border-box;
}

.holiday-highlight.public-holiday {
  background-color: #FF7433;
  border-radius: 100px !important; /* Match start/end date highlight shape */
  z-index: 1;
}

.holiday-highlight.school-holiday {
  background-color: #FFE5D4;
  z-index: 1;
}

.day-number {
  position: relative;
  z-index: 2;
}

/* Public Holidays - Orange/Peach solid circles */
.mantine-DatePicker-day[data-public-holiday] {
  background-color: #FF8C42 !important;
  border-radius: 100px !important;
  color: white !important;
  font-weight: 600 !important;
  z-index: 3 !important;
  position: relative !important;
}

/* School Holiday Periods - Light orange/peach rectangular background */
.mantine-DatePicker-day[data-school-holiday] {
  background-color: #FFE5D4 !important;
  border-radius: 0 !important;
  color: #333 !important;
  z-index: 2 !important;
  position: relative !important;
}

/* School holiday range - first day */
.mantine-DatePicker-day[data-school-holiday][data-school-holiday-start] {
  border-top-left-radius: 100px !important;
  border-bottom-left-radius: 100px !important;
}

/* School holiday range - last day */
.mantine-DatePicker-day[data-school-holiday][data-school-holiday-end] {
  border-top-right-radius: 100px !important;
  border-bottom-right-radius: 100px !important;
}

/* Hide holiday highlights when date is selected (blue selection takes priority) */
.mantine-DatePicker-day[data-selected][data-public-holiday],
.mantine-DatePicker-day[data-first-in-range][data-public-holiday],
.mantine-DatePicker-day[data-last-in-range][data-public-holiday],
.mantine-DatePicker-day[data-in-range][data-public-holiday] {
  background-color: #1156F9 !important;
  color: #FDFEFD !important;
}

.mantine-DatePicker-day[data-selected][data-school-holiday],
.mantine-DatePicker-day[data-first-in-range][data-school-holiday],
.mantine-DatePicker-day[data-last-in-range][data-school-holiday],
.mantine-DatePicker-day[data-in-range][data-school-holiday] {
  background-color: #CDDCFC !important;
  color: #171316 !important;
  border-radius: 0 !important;
}

.mantine-DatePicker-day[data-first-in-range][data-school-holiday],
.mantine-DatePicker-day[data-last-in-range][data-school-holiday] {
  border-radius: 100px !important;
  background-color: #1156F9 !important;
  color: #FDFEFD !important;
}

/* ----------------- END HOLIDAY HIGHLIGHTING -------------- */


