/* Custom date-range picker popover / bottom sheet (replaces native <input type="date">) */

.date-picker-field {
  position: relative;
  display: flex;
  flex-direction: column;
}

.date-picker-trigger-btn {
  background: var(--editor-bg-high);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--border-radius-sm);
  outline: none;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-smooth);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.date-picker-trigger-btn:hover,
.date-picker-trigger-btn:focus {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-focus);
}

.btn-empty-cta.date-picker-trigger-btn {
  /* First-run CTA reuses the same trigger button but should keep the empty-state CTA look */
  width: auto;
}

/* Popover / sheet chrome */
.date-picker-popover {
  position: fixed;
  z-index: 2000;
  /* 7 columns x 44px min-width (touch target) + 6x2px gaps + 24px padding = 344px min */
  width: 348px;
  max-width: calc(100vw - 16px);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 12px;
  font-family: var(--font-sans);
  color: var(--text-primary);
}

.dp-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
}

.dp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.dp-header-text {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dp-close-x {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
  min-width: 28px;
  min-height: 28px;
  border-radius: var(--border-radius-sm);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dp-close-x:hover {
  color: var(--text-primary);
  background: var(--dp-btn-hover-bg, rgba(125, 125, 125, 0.12));
}

.dp-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dp-month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.dp-nav-prev,
.dp-nav-next {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  width: 32px;
  height: 32px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dp-nav-prev:hover,
.dp-nav-next:hover {
  border-color: var(--border-focus);
  background: var(--dp-btn-hover-bg, rgba(125, 125, 125, 0.08));
}

.dp-weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 4px;
}

.dp-weekday-row span {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 0;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.dp-day {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

.dp-day:not(.dp-disabled):not(.dp-empty):hover {
  background: var(--dp-hover-bg, var(--accent-green-glow));
  color: var(--dp-hover-text, var(--text-primary));
  font-weight: 800;
}

.dp-day.dp-today {
  border: 1px solid var(--border-focus);
}

.dp-day.dp-disabled {
  color: var(--text-muted);
  opacity: 0.3;
  cursor: not-allowed;
}

.dp-day.dp-existing {
  color: var(--text-muted);
  opacity: 0.4;
  cursor: not-allowed;
  position: relative;
}

.dp-day.dp-existing::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent-activity);
}

.dp-day.dp-selected,
.dp-day.dp-range-start,
.dp-day.dp-range-end {
  background: var(--dp-selected-bg, var(--accent-activity));
  color: var(--dp-selected-text, #0b0f19);
  font-weight: 700;
}

.dp-day.dp-in-range {
  background: var(--dp-in-range-bg, var(--accent-activity-glow));
  color: var(--dp-in-range-text, var(--text-primary));
  border-radius: 0;
}

.dp-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.dp-footer .btn {
  min-height: 36px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dp-footer .dp-done {
  background: var(--dp-selected-bg, var(--accent-activity));
  color: var(--dp-selected-text, #0b0f19);
  border: 1px solid var(--dp-selected-bg, var(--accent-activity));
  font-weight: 700;
}

.dp-footer .dp-done:hover:not(:disabled) {
  opacity: 0.9;
}

.dp-footer .dp-done:disabled {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
  opacity: 0.4;
  cursor: not-allowed;
}

.picker-trigger-error {
  border-color: var(--accent-dining, #ff3d00) !important;
}

/* Time picker: single scrollable list of times, desktop-only (non-touch) */
.time-picker-field {
  position: relative;
  display: flex;
  flex-direction: column;
}

.time-picker-popover {
  width: 176px;
  padding: 6px;
  max-height: 275px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tp-shortcuts {
  display: flex;
  gap: 4px;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  flex-shrink: 0;
}

.tp-shortcut-btn {
  flex: 1;
  background: var(--bg-tertiary, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: var(--border-radius-sm, 4px);
  color: var(--text-muted, #94a3b8);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 0;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tp-shortcut-btn:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.12));
  color: var(--text-primary, #ffffff);
  border-color: var(--border-hover, rgba(255, 255, 255, 0.25));
}

.tp-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.tp-row {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tp-row:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tp-row.tp-selected {
  background: var(--dp-selected-bg, var(--accent-activity));
  color: var(--dp-selected-text, #0b0f19);
  font-weight: 700;
}

/* Mobile / iOS-iPadOS: bottom sheet instead of anchored popover */
@media (max-width: 768px) {
  .date-picker-popover.dp-sheet {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    /* Kept tight: 7 x 48px cells + 6x1px gaps + 2x12px padding = 350px, must fit a 375px viewport */
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .date-picker-popover.dp-sheet.dp-open {
    transform: translateY(0);
  }

  .dp-weekday-row,
  .dp-grid {
    gap: 1px;
  }

  .dp-day {
    min-width: 48px;
    min-height: 48px;
    font-size: 14px;
  }

  .dp-nav-prev,
  .dp-nav-next,
  .dp-close-x {
    min-width: 48px;
    min-height: 48px;
  }

  .dp-footer {
    flex-direction: row-reverse;
  }

  .dp-footer .btn {
    flex: 1;
    min-height: 48px;
  }
}