/**
 * Dual Calendar Date Picker Styles
 * Material Design 3 themed date picker with Hijri/Gregorian support
 */

/* Main container */
.dual-calendar-picker {
  position: fixed !important;
  z-index: 501 !important;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-large);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.24), 0 4px 16px rgba(0, 0, 0, 0.16);
  padding: var(--md-sys-spacing-3);
  min-width: 320px;
  max-width: 400px;
  width: max-content;
  direction: rtl;
  font-family: var(--md-sys-typescale-body-medium-font);
}

/* When the picker is open (especially on mobile), prevent background scroll */
html.dcp-open, html.dcp-open body {
  overflow: hidden;
}

/* Backdrop for mobile modal */
.dcp-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Center the picker on small screens */
.dual-calendar-picker.is-centered {
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  transform: translate(-50%, -50%) !important;
  max-width: min(92vw, 420px) !important;
  width: min(92vw, 420px) !important;
  max-height: 84vh;
  overflow: auto;
}

/* Header with calendar toggle and close button */
.dcp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--md-sys-spacing-3);
  padding-bottom: var(--md-sys-spacing-2);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

/* Calendar toggle buttons */
.dcp-calendar-toggle {
  display: flex;
  gap: var(--md-sys-spacing-2);
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 4px;
}

.dcp-toggle-btn {
  padding: 8px 20px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-family: var(--md-sys-typescale-label-large-font);
  font-size: var(--md-sys-typescale-label-large-size);
  font-weight: var(--md-sys-typescale-label-large-weight);
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

.dcp-toggle-btn:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.dcp-toggle-btn.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 600;
}

/* Close button */
.dcp-close {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 24px;
  line-height: 1;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  transition: background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dcp-close:hover {
  background: var(--md-sys-color-surface-container-high);
}

/* Calendar body */
.dcp-body {
  margin-bottom: var(--md-sys-spacing-3);
  position: relative;
}

.dcp-calendar {
  width: 100%;
  animation: calendarSlideIn 0.2s ease-out;
}

/* Smooth transition when switching calendars */
@keyframes calendarSlideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Calendar navigation */
.dcp-calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--md-sys-spacing-3);
  gap: var(--md-sys-spacing-2);
}

.dcp-nav-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  font-size: 18px;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dcp-nav-btn:hover {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.dcp-current-month {
  flex: 1;
  text-align: center;
  font-size: var(--md-sys-typescale-title-medium-size);
  font-weight: var(--md-sys-typescale-title-medium-weight);
  color: var(--md-sys-color-on-surface);
}

/* Weekdays header */
.dcp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: var(--md-sys-spacing-2);
}

.dcp-weekdays > div {
  text-align: center;
  font-size: var(--md-sys-typescale-label-small-size);
  font-weight: 600;
  color: var(--md-sys-color-primary);
  padding: 8px 4px;
}

/* Days grid */
.dcp-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dcp-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--md-sys-typescale-body-medium-size);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  transition: all var(--md-sys-motion-duration-short2) var(--md-sys-motion-easing-standard);
  position: relative;
  min-height: 40px;
}

.dcp-day:not(.dcp-day-empty):hover {
  background: var(--md-sys-color-surface-container-highest);
}

.dcp-day-empty {
  cursor: default;
}

/* Today indicator */
.dcp-day-today {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-weight: 600;
}

.dcp-day-today:hover {
  background: var(--md-sys-color-primary-container);
  opacity: 0.9;
}

/* Selected day */
.dcp-day-selected {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-weight: 600;
}

.dcp-day-selected:hover {
  background: var(--md-sys-color-primary);
  opacity: 0.9;
}

/* Selected dates display */
.dcp-selected-dates {
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: var(--md-sys-spacing-3);
  font-size: var(--md-sys-typescale-body-small-size);
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
}

.dcp-date-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--md-sys-spacing-1) 0;
}

.dcp-date-row:not(:last-child) {
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding-bottom: var(--md-sys-spacing-2);
  margin-bottom: var(--md-sys-spacing-2);
}

.dcp-date-label {
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.dcp-date-value {
  color: var(--md-sys-color-primary);
  font-weight: 500;
}

/* Input field enhancement for dual calendar */
.md3-text-field__input--date {
  cursor: pointer !important;
  caret-color: transparent !important;
  color: var(--md-sys-color-on-surface) !important;
  font-size: var(--md-sys-typescale-body-medium-size) !important;
  background: transparent !important;
  user-select: none;
  -webkit-user-select: none;
  padding-inline-start: var(--md-sys-spacing-4) !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: left 10px center !important;
  padding-inline-end: 36px !important;
}

/* Ensure value is always visible */
.md3-text-field__input--date:focus,
.md3-text-field__input--date:active {
  color: var(--md-sys-color-on-surface) !important;
  opacity: 1 !important;
}

/* Position wrapper for custom display */
.md3-text-field--date .md3-text-field__container {
  position: relative;
}

/* Make sure label floats when date has value */
.md3-text-field__input--date:not(:placeholder-shown) ~ .md3-text-field__label,
.md3-text-field__input--date:focus ~ .md3-text-field__label,
.md3-text-field__input--date[value]:not([value=""]) ~ .md3-text-field__label {
  top: 0 !important;
  transform: translateY(-50%) !important;
  font-size: var(--md-sys-typescale-body-small-size) !important;
  color: var(--md-sys-color-primary) !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .dual-calendar-picker {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    margin: 0;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
  }

  .dcp-current-month {
    font-size: var(--md-sys-typescale-title-small-size);
  }

  .dcp-day {
    min-height: 36px;
    font-size: var(--md-sys-typescale-body-small-size);
  }

  /* Prevent iOS Safari from zooming inputs (<16px) */
  .md3-text-field__input--date {
    font-size: 16px !important;
  }
}

/* Animation */
@keyframes dcpFadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dual-calendar-picker {
  animation: dcpFadeIn var(--md-sys-motion-duration-medium2) var(--md-sys-motion-easing-emphasized);
}

/* Dark mode support */
[data-theme="dark"] .dual-calendar-picker {
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

/* Accessibility */
.dcp-day:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.dcp-toggle-btn:focus,
.dcp-nav-btn:focus,
.dcp-close:focus {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Print styles - hide picker */
@media print {
  .dual-calendar-picker {
    display: none !important;
  }
}
