/*
 * Kwalee BI — Custom date range picker styles
 *
 * No react-dates. The calendar is pure HTML buttons rendered by Python.
 * All colour references use only theme tokens from theme.css.
 *
 * Story 3.2: Date Picker Filter
 */

/* ─── Wrapper ─── */
.date-picker__wrapper {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

/* ─── Icon in chip ─── */
.date-picker__icon {
  font-size: 0.875rem;
  margin-right: 4px;
  line-height: 1;
}

/* ─── Panel ─── */
.date-picker__panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: row;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  /* Height anchor: presets sidebar is capped to this so it never
     drives the panel taller than the month calendar. */
  --preset-cap: 290px;
}

.date-picker__panel--closed {
  display: none;
}

.date-picker__panel--open {
  display: flex;
}

/* ─── Calendar section (left) ─── */
.date-picker__calendar {
  padding: 16px 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  flex: 1;
  /* Ensure the calendar is always at least as tall as the preset cap so the
     panel height is never driven by the preset sidebar. */
  min-height: var(--preset-cap);
}

/* ─── Navigation bar ─── */
.cal-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 8px;
}

.cal-nav-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s ease;
}

.cal-nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ─── Two-month grid container ─── */
.cal-grid {
  display: flex;
  flex-direction: row;
  gap: 24px;
}

/* ─── Single month ─── */
.cal-month {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}

.cal-month__title {
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  padding: 4px 0 8px;
}

/* ─── Day-of-week headers ─── */
.cal-day-header-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 2px;
}

.cal-day-header {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0;
}

/* ─── Day cells grid ─── */
.cal-grid__cells {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px 0;
}

/* Base day cell */
.cal-day {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease;
  padding: 0;
  margin: 0 auto;
}

button.cal-day:hover {
  background: var(--bg-hover);
}

/* Empty leading cell */
.cal-day--empty {
  visibility: hidden;
  pointer-events: none;
}

/* Today */
.cal-day--today {
  font-weight: 700;
  color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Disabled / out of range */
.cal-day--disabled {
  color: var(--text-muted);
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
  border-radius: 50%;
}

/* Selected start: filled accent circle */
.cal-day--start {
  background: var(--accent) !important;
  color: var(--accent-text) !important;
  border-radius: 50% 0 0 50%;
  font-weight: 600;
}

/* No end yet: full circle */
.cal-day--start:only-of-type,
.cal-day--start.cal-day--end {
  border-radius: 50% !important;
}

/* Selected end */
.cal-day--end {
  background: var(--accent) !important;
  color: var(--accent-text) !important;
  border-radius: 0 50% 50% 0;
  font-weight: 600;
}

/* Days in range */
.cal-day--in-range {
  background: var(--accent-muted);
  color: var(--text-primary);
  border-radius: 0;
}

/* ─── Preset sidebar (right) ─── */
.date-picker__presets {
  display: flex;
  flex-direction: column;
  padding: 16px 16px 12px;
  min-width: 160px;
  flex-shrink: 0;
  border-left: 1px solid var(--border-color);
  /* Cap the sidebar to the panel height anchor so it does not expand the
     picker beyond the month calendar height. */
  max-height: var(--preset-cap);
  overflow-y: hidden;
}

/* Scrollable preset button list — sits between heading and footer */
.date-picker__presets-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Thin custom scrollbar so it doesn't widen the sidebar */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.date-picker__presets-heading {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px 0;
  padding: 0 4px;
  letter-spacing: 0.01em;
}

.date-picker__preset-btn {
  display: block;
  width: 100%;
  padding: 7px 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition:
    background-color 0.12s ease,
    color 0.12s ease;
}

.date-picker__preset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.date-picker__preset-btn--active {
  font-weight: 600;
  color: var(--text-primary);
}

/* ─── Footer: Close + Apply ─── */
.date-picker__presets-footer {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.date-picker__close-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.date-picker__close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.date-picker__apply-btn {
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  transition: opacity 0.12s ease;
}

.date-picker__apply-btn:hover {
  opacity: 0.88;
}

/* ─── Responsive: stack on mobile ─── */
@media (max-width: 767px) {
  .date-picker__panel {
    flex-direction: column;
    left: 0;
    right: 0;
    min-width: 280px;
    max-width: 100vw;
  }

  .cal-grid {
    flex-direction: column;
    gap: 16px;
  }

  .date-picker__presets {
    flex-direction: row;
    flex-wrap: wrap;
    min-width: unset;
    max-height: unset;
    overflow-y: visible;
    border-left: none;
    border-top: 1px solid var(--border-color);
    padding: 8px 12px;
  }

  .date-picker__presets-list {
    flex-direction: row;
    flex-wrap: wrap;
    overflow-y: visible;
    max-height: unset;
  }

  .date-picker__presets-heading,
  .date-picker__presets-footer {
    display: none;
  }

  .date-picker__preset-btn {
    flex: 0 0 auto;
    width: auto;
  }
}
