// RDS Date Picker Component Styles
// Following BEM methodology with rds- prefix
// Uses design tokens for consistency across themes

.rds-date-picker {
  width: auto;
  min-width: 200px; // Base minimum width
  max-width: 600px; // Allow for wider range pickers
  // Global input styles for all variants
  .MuiInputBase-input {
    font-family: inherit;
    font-weight: 400;
    font-size: 1rem;
  }

  // Specific width adjustments based on content and variant
  &--datetimerange {
    min-width: 400px;
    max-width: 500px;
    
    .MuiFormControl-root {
      min-width: 400px;
      max-width: 500px;
    }
    
    .MuiInputBase-root {
      min-width: 400px;
      
      .MuiInputBase-input {
        min-width: 350px; // Leave space for icon
        padding-right: var(--rds-spacing-2xl-px); // Extra padding for icon
      }
    }
  }
  
  &--timerange {
    min-width: 460px;
    max-width: 460px;
    
    .MuiFormControl-root {
      min-width: 460px;
      max-width: 460px;
    }
    
    .MuiInputBase-root {
      min-width: 460px;
      
      .MuiInputBase-input {
        min-width: 460px; // Leave space for icon
        padding-right: var(--rds-spacing-2xl-px); // Extra padding for icon
      }
    }
  }
  
  &--daterange,
  &--multi-month {
    min-width: 300px;
    max-width: 300px;
    
    .MuiFormControl-root {
      min-width: 300px;
      max-width: 300px;
    }
    
    .MuiInputBase-root {
      min-width: 300px;
      
      .MuiInputBase-input {
        min-width: 250px; // Leave space for icon
        padding-right: var(--rds-spacing-2xl-px); // Extra padding for icon
      }
    }
  }

  // For daterange variant, show the calendar icon on the left side of the input
  &--daterange {
    .MuiOutlinedInput-root {
      .MuiInputAdornment-positionEnd {
        position: absolute;
        right: 8px; /* distance from input left edge */
        top: 50%;
        transform: translateY(-50%);
      }
    }
  }

  // Size variants
  &--small {
    .MuiInputBase-root,
    .MuiTextField-root .MuiInputBase-root {
      min-height: 40px;
      
      .MuiInputBase-input {
        padding: var(--rds-spacing-sm, 8.5px) var(--rds-spacing-sm, 14px);
        font-size: var(--rds-font-size-body2, 0.875rem);
      }
    }

    // Specific adjustments for TextField component used in daterange variant
    .MuiTextField-root {
      .MuiInputBase-root {
        min-height: 40px;
      }
      
      .MuiInputLabel-root {
        font-size: var(--rds-font-size-body2, 0.875rem);
        
        &.MuiInputLabel-shrink {
          font-size: var(--rds-font-size-caption, 0.75rem);
        }
      }
      
      .MuiInputAdornment-root {
        .MuiIconButton-root {
          padding: var(--rds-spacing-xs, 6px);
          
          .MuiSvgIcon-root {
            font-size: 1.25rem;
          }
        }
      }
    }
  }

  &--medium {
    .MuiInputBase-root,
    .MuiTextField-root .MuiInputBase-root {
      min-height: 56px;
      
      .MuiInputBase-input {
        padding: var(--rds-spacing-md, 16.5px) var(--rds-spacing-sm, 14px);
        font-size: var(--rds-font-size-body1, 1rem);
      }
    }
  }

  // State variants
  &--error {
    .MuiOutlinedInput-root {
      .MuiOutlinedInput-notchedOutline {
        border-color: var(--rds-color-error);
        border-width: 2px;
      }
    }
  }
  
  // Global override for all picker day elements to use square backgrounds
  .MuiPickersDay-root,
  .MuiDateRangePickerDay-root,
  .MuiPickersYear-root,
  .MuiPickersMonth-root {
    border-radius: var(--rds-border-radius, 4px) !important;
    
    &:hover {
      border-radius: var(--rds-border-radius, 4px) !important;
      background-color: var(--rds-color-primary-hover) !important;
      color: var(--rds-color-primary) !important;
    }
    
    &.Mui-selected {
      border-radius: var(--rds-border-radius, 4px) !important;
      background-color: var(--rds-color-primary) !important;
      color: var(--rds-color-on-primary, white) !important;
      
      &:hover {
        border-radius: var(--rds-border-radius, 4px) !important;
        background-color: var(--rds-color-primary-dark) !important;
      }
    }
    
    &.MuiPickersDay-today {
      border-radius: var(--rds-border-radius, 4px) !important;
      border: 2px solid var(--rds-color-primary) !important;
      color: var(--rds-color-primary) !important;
    }
  }
  
  // Custom Date Range Picker with Presets
  &__custom-layout {
    display: flex;
    min-height: 400px;
    min-width: 600px;
    border-radius: var(--rds-border-radius-lg);
    overflow: hidden;
    background-color: var(--rds-color-surface);
    box-shadow: var(--rds-elevation-3, 0 4px 6px rgba(0, 0, 0, 0.1));
  }

  &__preset-panel {
    width: 200px;
    border-right: 1px solid var(--rds-color-border);
    background-color: var(--rds-color-surface-variant);
    display: flex;
    flex-direction: column;
  }

  &__preset-list {
    list-style: none;
    padding: var(--rds-spacing-md, 16px);
    margin: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--rds-spacing-xs, 4px);
  }

  &__preset-item {
    margin: 0;
  }

  &__preset-button {
    width: 100%;
    padding: var(--rds-spacing-sm, 8px) var(--rds-spacing-md, 12px);
    border: none;
    border-radius: var(--rds-border-radius, 4px);
    background-color: transparent;
    color: var(--rds-color-on-surface);
    font-size: var(--rds-font-size-body2, 0.875rem);
    font-weight: 400;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      background-color: var(--rds-color-primary-hover);
      color: var(--rds-color-primary);
    }

    &--selected {
      background-color: var(--rds-color-primary);
      color: var(--rds-color-on-primary);
      font-weight: 600;

      &:hover {
        background-color: var(--rds-color-primary-dark);
      }
    }
  }

  &__calendar-panel {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--rds-spacing-md, 16px);
    background-color: var(--rds-color-surface, #ffffff);
  }

  &__range-input-container {
    display: inline-block;

    // Show beginning of text with ellipsis — prevents Chrome scrolling
    // to cursor-end in controlled readonly inputs
    .MuiInputBase-input {
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
  }

  // Open state for range/multi-month input (popover is open)
  &__input--open {
    .MuiOutlinedInput-root {
      .MuiOutlinedInput-notchedOutline {
        border-color: var(--rds-color-primary, #2196F3) !important;
        border-width: 2px !important;
      }
    }
  }

  // Input element styling
  &__input {
    cursor: pointer;
    
    &--disabled {
      cursor: not-allowed !important;
    }
    
    &--readonly {
      cursor: default !important;
    }

    &--required {
      .MuiInputLabel-root {
        // Hide Material-UI's default required asterisk since we're using custom one
        &::after {
          content: none !important;
          display: none !important;
        }
        
        &.MuiInputLabel-asterisk {
          &::after {
            content: none !important;
            display: none !important;
          }
        }
      }
      
      // Hide any MUI required indicator elements
      .MuiInputLabel-asterisk,
      .MuiFormLabel-asterisk {
        display: none !important;
      }
    }
  }

  // Label with required indicator
  &__label {
    display: inline-flex;
    align-items: center;
    gap: var(--rds-spacing-xs, 4px);
  }

  &__required-indicator {
    color: var(--rds-color-error);
    font-size: var(--rds-font-size-body1, 1rem);
    font-weight: var(--rds-font-weight-bold, 700);
    line-height: 1;
    margin-left: var(--rds-spacing-xs, 2px);
    
    // Ensure the asterisk is properly positioned
    display: inline-block;
    vertical-align: top;
  }

  // Required state styling
  &--required {
    .MuiInputLabel-root {
      // Add visual indication that field is required
      &.Mui-focused {
        color: var(--rds-color-primary);
      }
    }

    .MuiOutlinedInput-root {
      &.Mui-focused .MuiOutlinedInput-notchedOutline {
        border-color: var(--rds-color-primary);
      }
    }
    
    // Hide ALL Material-UI required indicators since we use custom ones
    .MuiInputLabel-root {
      &::after {
        content: "" !important;
        display: none !important;
      }
      
      &.MuiInputLabel-asterisk {
        &::after {
          content: "" !important;
          display: none !important;
        }
      }
    }
    
    .MuiInputLabel-asterisk,
    .MuiFormLabel-asterisk {
      display: none !important;
      
      &::after, &::before {
        content: "" !important;
        display: none !important;
      }
    }
    
    // Target any span that might contain just an asterisk
    .MuiFormLabel-root span {
      &[aria-hidden="true"] {
        display: none !important;
      }
    }
    
    // Hide MUI's built-in required asterisk
    .MuiFormLabel-root .MuiFormLabel-asterisk {
      display: none !important;
    }
  }

  // Day element styling
  &__day {
    border-radius: var(--rds-border-radius, 4px) !important;
  }

  // Demo component styling
  &__demo-title {
    margin: 0 0 var(--rds-spacing-md, 16px) 0;
    font-size: var(--rds-font-size-h6, 1.25rem);
    font-weight: var(--rds-font-weight-semibold, 600);
    color: var(--rds-color-text-primary);
  }

  &__field-wrapper {
    position: relative;
    width: 100%;
  }

  &__helper {
    margin-top: var(--rds-spacing-compact);
    padding-left: var(--rds-spacing-14);
    padding-right: var(--rds-spacing-14);
    font-size: var(--rds-font-size-caption, 0.75rem);
    line-height: 1.25;
    color: var(--rds-color-text-secondary, rgba(0,0,0,0.6));
    white-space: normal;
    word-break: break-word;
  }
  
  // Custom styling for Material-UI date picker components
  .MuiInputBase-root {
    border-radius: var(--rds-border-radius-lg, 8px);
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 56px; // Ensure consistent height
    display: flex;
    align-items: center;
    width: 100%; // Take full width of container
    
    &:hover {
      box-shadow: var(--rds-elevation-1, 0 2px 8px rgba(0, 0, 0, 0.1));
    }
    
    .MuiInputBase-input {
      cursor: pointer;
      padding: var(--rds-spacing-md, 16.5px) var(--rds-spacing-sm, 14px);
      line-height: 1.4375em; // Material-UI default line height
      font-size: var(--rds-font-size-body1, 1rem);
      flex: 1; // Take available space
      min-width: 0; // Allow shrinking
      
      &::placeholder {
        color: var(--rds-color-text-secondary, rgba(0, 0, 0, 0.6));
        opacity: 1;
        font-style: normal;
        transition: opacity 0.2s ease;
        white-space: nowrap; // Prevent wrapping
        overflow: visible; // Show full placeholder
        text-overflow: clip; // Don't truncate placeholder
      }
      
      &:placeholder-shown {
        color: var(--rds-color-text-secondary, rgba(0, 0, 0, 0.6));
      }
      
      // When label is present and field is empty, hide placeholder
      &:placeholder-shown + .MuiInputLabel-root:not(.MuiInputLabel-shrink) + .MuiInputBase-input {
        &::placeholder {
          opacity: 0;
        }
      }
    }
    
    // Ensure adequate space for end adornment (calendar icon)
    .MuiInputAdornment-positionEnd {
      margin-left: var(--rds-spacing-xs, 8px); // Space between text and icon
      
      .MuiSvgIcon-root {
        font-size: 1.50rem;
      }
    }
    
    &:not(.Mui-focused) {
      .MuiInputBase-input:placeholder-shown {
        color: var(--rds-color-text-secondary, rgba(0, 0, 0, 0.6));
        opacity: 1;
      }
    }
    
    // When focused or has value, ensure label shrinks
    &.Mui-focused,
    &:has(.MuiInputBase-input:not([value=""])) {
      .MuiInputLabel-root {
        transform: translate(14px, -9px) scale(0.75);
      }
    }
  }
  
  .MuiOutlinedInput-root {
    cursor: pointer;
    
    &:hover .MuiOutlinedInput-notchedOutline {
      border-width: 2px;
      border-color: var(--rds-color-primary);
      border-width: 2px !important;
      border-color: var(--rds-color-primary, #2196F3) !important;
    }
    
    &.Mui-focused .MuiOutlinedInput-notchedOutline {
      border-width: 2px;
      border-color: var(--rds-color-primary);
      border-width: 2px !important;
      border-color: var(--rds-color-primary, #2196F3) !important;
    }
    
    &.Mui-error .MuiOutlinedInput-notchedOutline {
      border-color: var(--rds-color-error);
    }
    
    .MuiInputAdornment-root {
      cursor: pointer;
      margin-left: var(--rds-spacing-xs, 8px); // Ensure space between text and icon
      
      &.MuiInputAdornment-positionEnd {
        margin-left: var(--rds-spacing-xs, 8px);
        margin-right: var(--rds-spacing-xs, 8px);
      }
      
      .MuiIconButton-root {
        padding: var(--rds-spacing-xs, 8px);
        margin-right: var(--rds-spacing-neg-8); // Adjust for proper alignment
      }
    }
    
    &.MuiInputBase-adornedEnd {
      .MuiInputBase-input {
        padding-right: var(--rds-spacing-xs, 8px);
      }
    }
  }
  
  .MuiFormControl-root {
    width: fit-content;
    min-width: 200px; // Base minimum width for usability
    max-width: 300px; // Increased to accommodate range pickers
    
    // Ensure proper label positioning relative to the input
    .MuiInputLabel-root {
      // Calculate vertical center based on input height
      // Default input height is 56px (16.5px top + 1.4375em line-height + 16.5px bottom)
      // Center the label within this space
      &:not(.MuiInputLabel-shrink) {
        top: 50%;
        transform: translate(14px, -50%) scale(1);
        line-height: 1;
      }
      
      &.MuiInputLabel-shrink {
        top: 0;
        transform: translate(14px, -9px) scale(0.75);
      }
    }
    
    // For different input sizes
    &.MuiFormControl-fullWidth {
      .MuiInputLabel-root:not(.MuiInputLabel-shrink) {
        transform: translate(14px, -50%) scale(1);
      }
    }
  }

  .MuiInputLabel-root {
    font-weight: var(--rds-font-weight-medium, 500);
    transform-origin: top left;
    transition: all 0.2s ease-in-out;
    pointer-events: none; // Prevent label from blocking clicks
    position: absolute;
    z-index: var(--rds-z-index-layer-1);
    
    &.Mui-focused {
      font-weight: var(--rds-font-weight-semibold, 600);
      color: var(--rds-color-primary);
    }
    
    &.Mui-error {
      color: var(--rds-color-error);
    }
    
    // Ensure label moves to top when input has value or is focused
    &.MuiInputLabel-shrink {
      top: 0;
      transform: translate(14px, -9px) scale(0.75);
    }
    
    // Position label correctly when not shrunk - center it vertically within the input
    &:not(.MuiInputLabel-shrink) {
      top: 50%;
      transform: translate(14px, -50%) scale(1);
      line-height: 1;
    }
  }
  
  .MuiFormHelperText-root {
    margin-top: var(--rds-spacing-xs, 6px);
    font-size: var(--rds-font-size-caption, 0.75rem);
    
    &.Mui-error {
      color: var(--rds-color-error);
    }
  }
  
  // Date picker popup/popper styles
  .MuiPickersPopper-root {
    z-index: var(--rds-z-index-modal, 1400);
    
    .MuiPaper-root {
      box-shadow: none !important;
      border: 1.5px solid var(--rds-color-border-light) !important;
      border-radius: var(--rds-border-radius-lg, 12px) !important;
    }
  }
  
  .MuiDateCalendar-root {
    background: var(--rds-color-surface, white);
    border-radius: var(--rds-border-radius-lg, 12px);
    box-shadow: none !important;
    border: 1.5px solid var(--rds-color-border-light) !important;
  }
  
  .MuiPickersCalendarHeader-root {
    padding: var(--rds-spacing-md, 16px);
    border-bottom: 1px solid var(--rds-color-border);
  }
  
  .MuiDayCalendar-weekDayLabel {
    font-weight: var(--rds-font-weight-semibold, 600);
    color: var(--rds-color-text-secondary);
    font-weight: 400;
    color: var(--rds-color-text-secondary, #666);
  }
  
  .MuiPickersDay-root {
    border-radius: var(--rds-border-radius-sm);
    font-weight: var(--rds-font-weight-medium, 500);
    background-color: var(--rds-color-surface);
    color: var(--rds-color-text-primary);

    &:hover {
      background-color: var(--rds-color-primary-hover);
      border-radius: var(--rds-border-radius-sm);
      color: var(--rds-color-primary);
    }

    &.Mui-selected {
      background-color: var(--rds-color-primary);
      font-weight: var(--rds-font-weight-semibold, 600);
      border-radius: var(--rds-border-radius-sm);
      color: var(--rds-color-on-primary);
      background-color: #2196F3;
      font-weight: 400;
      border-radius: 4px;
      color: #fff;
      &:hover {
        background-color: var(--rds-color-primary-dark);
        border-radius: var(--rds-border-radius-sm);
      }
    }

    &.MuiPickersDay-today {
      border: 2px solid var(--rds-color-primary);
      border-radius: var(--rds-border-radius-sm);
      background-color: var(--rds-color-surface);
      color: var(--rds-color-primary);
      font-weight: var(--rds-font-weight-semibold, 600);
      border: 2px solid #2196F3;
      border-radius: 4px;
      background-color: #fff;
      color: #2196F3;
      font-weight: 400;
      
      &:not(.Mui-selected) {
        background-color: var(--rds-color-surface);
        color: var(--rds-color-primary);
        border-radius: var(--rds-border-radius-sm);
        color: var(--rds-color-primary, #2196F3) !important;
      }
    }
  }

  // Disabled state
  &--disabled {
    .MuiInputBase-root {
      background-color: var(--rds-color-surface-disabled, #f5f5f5);
      color: var(--rds-color-text-disabled, rgba(0, 0, 0, 0.38));
      cursor: not-allowed !important;
      
      .MuiInputBase-input {
        cursor: not-allowed !important;
      }
      
      .MuiInputAdornment-root {
        cursor: not-allowed !important;
      }
    }
  }
  
  // Read-only state
  &--readonly {
    .MuiInputBase-root {
      background-color: var(--rds-color-surface-readonly, #fafafa);
      cursor: not-allowed !important;
      
      .MuiInputBase-input {
        cursor: not-allowed !important;
      }
      
      .MuiInputAdornment-root {
        cursor: not-allowed !important;
      }
    }
  }
}

// Dark theme support
@media (prefers-color-scheme: dark) {
  .rds-date-picker {
    .MuiDateCalendar-root {
      background: var(--rds-color-surface-dark, #1e1e1e);
      color: var(--rds-color-on-surface-dark, white);
    }
    
    .MuiPickersCalendarHeader-root {
      border-bottom-color: var(--rds-color-border-dark, #333);
    }
    
    .MuiDayCalendar-weekDayLabel {
      color: var(--rds-color-text-secondary-dark, #ccc);
    }
  }
}

// Utility layout classes

.rds-date-picker__range-calendar-row {
  display: flex;
  flex-direction: row;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
  box-sizing: border-box;

  .MuiDateCalendar-root {
    flex: 1;
    min-width: 0;
  }
}

.rds-date-picker__time-range-stack {
  display: flex;
  flex-direction: row;
  gap: 16px;
  width: 100%;
}

.rds-date-picker__time-range-item {
  flex: 1;
  min-width: 0;

  .MuiFormControl-root {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .MuiInputBase-root {
    width: 100%;
    min-width: 0;
  }
}

.rds-date-picker__range-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
  width: 100%;
}

// Responsive design

// Large mobile (up to 767px)
@media (max-width: 767px) {
  .rds-date-picker {
    width: 100%;
    min-width: 0;
    max-width: 100%;

    &--datetimerange,
    &--timerange,
    &--daterange,
    &--multi-month {
      min-width: 0;
      width: 100%;

      .MuiFormControl-root {
        min-width: 0;
        width: 100%;
        max-width: 100%;
      }

      .MuiInputBase-root {
        min-width: 0;
        width: 100%;

        .MuiInputBase-input {
          min-width: 0;
        }
      }
    }

    .MuiFormControl-root {
      min-width: 0;
      width: 100%;
      max-width: 100%;
    }

    .MuiDateCalendar-root {
      border-radius: 8px;
    }

    .MuiPickersDay-root {
      font-size: 0.875rem;
    }

    // Ensure input font size remains consistent on mobile
    .MuiInputBase-root {
      .MuiInputBase-input {
        font-size: var(--rds-font-size-body1, 1rem) !important;

        &::placeholder {
          font-size: var(--rds-font-size-body1, 1rem) !important;
        }
      }
    }

    &__range-input-container {
      display: block;
      width: 100%;

      .MuiTextField-root,
      .MuiFormControl-root {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
      }

      .MuiInputBase-root {
        width: 100% !important;
        min-width: 0 !important;

        .MuiInputBase-input {
          min-width: 0 !important;
          width: 100%;
          font-size: var(--rds-font-size-body1, 1rem) !important;

          &::placeholder {
            font-size: var(--rds-font-size-body1, 1rem) !important;
          }
        }
      }
    }
  }

  // Outer Popover paper — constrain to viewport width on mobile
  .rds-date-picker__popover-paper-gap {
    max-width: calc(100vw - 16px) !important;
    overflow: hidden;
  }

  // Popover paper adapts to viewport
  .rds-date-picker__range-paper {
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 12px;
    max-height: calc(100dvh - 80px);
    box-sizing: border-box;
    align-items: stretch;

    // Force DateCalendar to fit the available width inside the paper
    .MuiDateCalendar-root {
      width: 100% !important;
      max-width: 100% !important;
    }
  }

  // Range datetime stacks vertically on mobile
  .rds-date-picker__range-datetime {
    flex-direction: column;
    width: 100%;

    .rds-date-picker__range-datetime-divider {
      width: auto;
      height: 1px;
      margin: 8px 0;
    }

    .rds-date-picker__range-datetime-spacer {
      width: auto;
      height: 0;
      margin: 4px 0;
    }
  }

  // Calendar row stacks vertically on mobile
  .rds-date-picker__range-calendar-row {
    flex-direction: column;
    width: 100%;

    .MuiDateCalendar-root {
      width: 100% !important;
      max-width: 100% !important;
    }
  }

  // Time range stacks vertically on mobile
  .rds-date-picker__time-range-stack {
    flex-direction: column;
    width: 100%;
  }

  .rds-date-picker__time-range-item {
    flex: none;
    width: 100%;
  }

  // Custom date range layout becomes vertical on mobile
  .rds-date-picker__custom-layout {
    flex-direction: column;
    min-width: 0;
    width: calc(100vw - 32px);
    min-height: auto;

    .rds-date-picker__preset-panel {
      width: 100%;
      border-right: none;
      border-bottom: 1px solid var(--rds-color-border, #e0e0e0);
    }

    .rds-date-picker__preset-list {
      flex-direction: row;
      flex-wrap: wrap;
      gap: 8px;
      padding: 12px;
    }
  }
}

// Small mobile (up to 480px)
@media (max-width: 480px) {
  .rds-date-picker {
    &__custom-layout {
      width: calc(100vw - 16px);
    }

    // Ensure input font size remains consistent on small mobile
    .MuiInputBase-root {
      .MuiInputBase-input {
        font-size: var(--rds-font-size-body1, 1rem) !important;

        &::placeholder {
          font-size: var(--rds-font-size-body1, 1rem) !important;
        }
      }
    }

    &__range-input-container {
      .MuiInputBase-root {
        .MuiInputBase-input {
          font-size: var(--rds-font-size-body1, 1rem) !important;

          &::placeholder {
            font-size: var(--rds-font-size-body1, 1rem) !important;
          }
        }
      }
    }
  }

  .rds-date-picker__popover-paper-gap {
    max-width: calc(100vw - 8px) !important;
  }

  .rds-date-picker__range-paper {
    max-width: 100%;
    padding: 8px;
    max-height: calc(100dvh - 64px);
    align-items: stretch;

    // Force calendar to use full available width
    .MuiDateCalendar-root {
      width: 100% !important;
      max-width: 100% !important;
      min-width: 0 !important;
    }

    // Hide week-number column to recover horizontal space on tiny screens
    .MuiDayCalendar-weekNumberLabel,
    .MuiDayCalendar-weekNumber {
      display: none !important;
    }

    // Tighten day cells so 7 columns fit within ~280px content area
    .MuiDayCalendar-header,
    .MuiDayCalendar-weekContainer {
      justify-content: space-between;
    }

    .MuiPickersDay-root {
      width: 32px !important;
      height: 32px !important;
      font-size: 0.8rem !important;
      margin: 1px !important;
    }

    .MuiDayCalendar-weekDayLabel {
      width: 32px !important;
      font-size: 0.75rem !important;
    }

    // Scale calendar header navigation
    .MuiPickersCalendarHeader-root {
      padding-left: 8px;
      padding-right: 4px;
    }
  }

  .rds-date-picker__range-calendar-row {
    .MuiDateCalendar-root {
      width: 100% !important;
      max-width: 100% !important;
    }
  }
}

// Animation for picker opening
@keyframes rds-date-picker-fade-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.MuiPickersPopper-root {
  animation: rds-date-picker-fade-in 0.2s ease-out;
}


// Base picker paper (DatePicker, TimePicker, DateTimePicker dropdowns)
.rds-date-picker__picker-paper {
  box-shadow: none !important;
  border: 2px solid #2196F3 !important;
  border-radius: 4px !important;
}

// Year picker paper - adjusts internal calendar heights
.rds-date-picker__year-picker-paper {
  .MuiDateCalendar-root {
    height: auto;
  }

  .MuiPickersLayout-contentWrapper {
    height: auto;
  }

  .MuiYearCalendar-root {
    height: auto;
    max-height: 280px;
    overflow-y: auto;
  }
}

// Month picker paper - adjusts internal calendar heights
.rds-date-picker__month-picker-paper {
  .MuiDateCalendar-root {
    height: auto;
  }

  .MuiPickersLayout-contentWrapper {
    height: auto;
  }

  .MuiMonthCalendar-root {
    height: auto;
  }
}

// Range picker Popover paper
.rds-date-picker__range-paper {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 2px solid #2196F3 !important;
  border-radius: 4px !important;
  box-shadow: none !important;
  // Allow scrolling when content exceeds viewport height (datetime range on small screens)
  max-height: calc(100dvh - 100px);
  overflow-y: auto;
  overflow-x: hidden;
  // Take full width of parent popover paper to match input width
  width: 100%;
  box-sizing: border-box;
}

// Top margin gap between input and popover
.rds-date-picker__popover-paper-gap {
  margin-top: 4px;
  // Ensures popover respects inline width style set by component
  box-sizing: border-box;
}

// Custom range day state classes (applied via className in renderDaySlot)
.rds-date-picker__day--in-range {
  background-color: var(--rds-color-primary-hover, #E3F2FD) !important;
  color: var(--rds-color-primary, #1976d2) !important;
}

.rds-date-picker__day--range-end-point {
  background-color: var(--rds-color-primary, #2196F3) !important;
  color: var(--rds-color-on-primary, #fff) !important;
}

// RangeDateTime layout classes
.rds-date-picker__range-datetime {
  display: flex;
  align-items: flex-start;
  width: 100%;
  box-sizing: border-box;
}

.rds-date-picker__range-datetime-divider {
  width: 1px;
  background-color: #2196F3;
  align-self: stretch;
  margin: 8px;
}

.rds-date-picker__range-datetime-spacer {
  width: 0.5px;
  align-self: stretch;
  margin: 8px;
}

.rds-date-picker__range-datetime-time-label {
  font-size: 0.75rem;
  color: rgba(0, 0, 0, 0.6);
  margin-bottom: 4px;
  text-align: center;
}

// Global override to ensure all date picker elements use square borders
.MuiPickersPopper-root,
.MuiPickersLayout-root,
.MuiDateCalendar-root,
.MuiYearCalendar-root,
.MuiMonthCalendar-root {
  .MuiPickersDay-root,
  .MuiPickersYear-root,
  .MuiPickersMonth-root {
    border-radius: var(--rds-border-radius, 4px) !important;
    
    &:hover {
      border-radius: var(--rds-border-radius, 4px) !important;
      background-color: var(--rds-color-primary-hover) !important;
      color: var(--rds-color-primary) !important;
    }
    
    &.Mui-selected {
      border-radius: var(--rds-border-radius, 4px) !important;
      background-color: var(--rds-color-primary) !important;
      color: var(--rds-color-on-primary, white) !important;
      
      &:hover {
        border-radius: var(--rds-border-radius, 4px) !important;
        background-color: var(--rds-color-primary-dark) !important;
      }
    }
    
    &.MuiPickersDay-today {
      border-radius: var(--rds-border-radius, 4px) !important;
      border: 2px solid var(--rds-color-primary) !important;
      color: var(--rds-color-primary) !important;
      
      &:not(.Mui-selected) {
        color: var(--rds-color-primary, #2196F3) !important;
      }
      
      &.Mui-selected {
        background-color: var(--rds-color-primary, #2196F3) !important;
        color: var(--rds-color-on-primary, #fff) !important;
        border: 2px solid var(--rds-color-primary, #2196F3) !important;
        font-weight: 400 !important;
        
        &:hover {
          background-color: var(--rds-color-primary-dark) !important;
          color: var(--rds-color-on-primary) !important;
          border: 2px solid var(--rds-color-primary-dark) !important;
        }
      }
    }
  }
}

// Time picker dropdown font size reduction
.MuiMultiSectionDigitalClock-root {
  .MuiMultiSectionDigitalClockSection-root {
    .MuiMenuItem-root {
      font-size: 0.8rem !important; // Reduced font size
      min-height: var(--rds-size-xl) !important; // Reduced height
      padding: var(--rds-spacing-xs) var(--rds-spacing-sm) !important; // Reduced padding
    }
  }
}

// Specific styles for time range picker component
.rds-date-picker--timerange {
  // Layout for the two side-by-side time inputs
  .rds-date-picker__time-range-stack {
    width: 100%;
  }

  .rds-date-picker__time-range-item {
    .MuiFormControl-root {
      width: 100% !important;
      min-width: 0 !important;
      max-width: none !important;
      margin-left: 0 !important;
    }
  }

  // Ensure proper spacing and layout for time range inputs
  .MuiFormControl-root {
    margin-bottom: 0;
  }
  
  // Reduce font size in digital clock dropdowns
  .MuiPickersPopper-root {
    .MuiMultiSectionDigitalClock-root {
      .MuiMultiSectionDigitalClockSection-root {
        width: auto;
        min-width: 60px;
        
        .MuiMenuItem-root {
          font-size: 0.75rem !important;
          min-height: 28px !important;
          padding: calc(var(--rds-spacing-xs) / 2) calc(var(--rds-spacing-sm) - var(--rds-spacing-xs)) !important;
          line-height: 1.2;
        }
        
        .MuiList-root {
          padding: var(--rds-spacing-xs) 0;
        }
      }
    }
  }
}

// Global styles for all time pickers
.MuiPickersPopper-root {
  .MuiMultiSectionDigitalClock-root {
    .MuiMultiSectionDigitalClockSection-root {
      .MuiMenuItem-root {
        font-size: 0.8rem !important;
        min-height: 30px !important;
        padding: calc(var(--rds-spacing-xs) * 0.75) calc(var(--rds-spacing-sm) - 1px) !important;
        
        &:hover {
          background-color: var(--rds-color-primary-hover);
          color: var(--rds-color-primary);
        }
        
        &.Mui-selected {
          background-color: var(--rds-color-primary);
          color: var(--rds-color-on-primary, white);
          font-weight: 400;
        }
      }
      
      .MuiList-root {
        padding: calc(var(--rds-spacing-xs) / 2) 0;
      }
    }
  }
}

// Action bar button styling for all pickers
.MuiPickersLayout-actionBar {
  padding: 8px 16px !important;

  .MuiButton-root {
    text-transform: none !important;
    font-weight: 500 !important;
    border-radius: 6px !important;
  }

  // Cancel button — plain text
  .MuiButton-root:first-of-type {
    color: rgba(0, 0, 0, 0.6) !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  // OK button — filled blue
  .MuiButton-root:last-of-type {
    background-color: #2196F3 !important;
    color: #fff !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    box-shadow: none !important;

    &:hover {
      background-color: #1976d2 !important;
    }
  }
}
