/*
 * Site-wide select and date/time styling (loaded after Tailwind in base.html).
 * `body select:not([multiple])` (0,1,2) beats per-template utility classes;
 * width and margins stay with the template. Pickers: static/js/form-controls.js.
 */

:root {
  --fc-border: #e2e8f0;      /* slate-200 */
  --fc-border-hover: #cbd5e1; /* slate-300 */
  --fc-text: #0f172a;        /* night */
  --fc-muted: #64748b;       /* slate-500 */
  --fc-focus: #5cbf3c;       /* brand-500 */
  --fc-focus-ring: rgba(92, 191, 60, 0.25);
  --fc-brand-50: #f1f9ea;
  --fc-brand-600: #4ba22f;
  --fc-disabled: #f8fafc;    /* slate-50 */
  --fc-radius: 0.75rem;
  --fc-height: 42px;
}

/* --- Shared base: select, native date/time and the flatpickr input ---------------- */
body select:not([multiple]),
body input[type="date"],
body input[type="datetime-local"],
body input[type="time"],
body input.fc-date {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-sizing: border-box;
  min-height: var(--fc-height);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background-color: #fff;
  color: var(--fc-text);
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s;
}

body select:not([multiple]):hover,
body input[type="date"]:hover,
body input[type="datetime-local"]:hover,
body input[type="time"]:hover,
body input.fc-date:hover {
  border-color: var(--fc-border-hover);
}

body select:not([multiple]):focus,
body input[type="date"]:focus,
body input[type="datetime-local"]:focus,
body input[type="time"]:focus,
body input.fc-date:focus,
body input.fc-date.active {
  outline: none;
  border-color: var(--fc-focus);
  box-shadow: 0 0 0 3px var(--fc-focus-ring);
}

body select:not([multiple]):disabled,
body input[type="date"]:disabled,
body input[type="datetime-local"]:disabled,
body input[type="time"]:disabled,
body input.fc-date:disabled {
  background-color: var(--fc-disabled);
  color: var(--fc-muted);
  cursor: not-allowed;
}

/* --- Select: custom arrow (appearance:none hides the native one) ------------------ */
body select:not([multiple]) {
  padding-right: 2.25rem;
  cursor: pointer;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1.1rem;
}
/* Firefox dotted focus outline on select text. */
body select:-moz-focusring {
  color: transparent;
  text-shadow: 0 0 0 var(--fc-text);
}

/* --- Date/time: calendar icon (clock for time-only) -------------------------------- */
body input[type="date"],
body input[type="datetime-local"],
body input.fc-date {
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
  cursor: pointer;
}
body input[type="time"],
body input.fc-date.fc-time {
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
}
/* Native inputs (mobile): hide the browser icon; the whole field opens the picker. */
body input[type="date"]::-webkit-calendar-picker-indicator,
body input[type="datetime-local"]::-webkit-calendar-picker-indicator,
body input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  cursor: pointer;
}
/* iOS Safari: empty date collapses and centers the text. */
body input[type="date"]::-webkit-date-and-time-value,
body input[type="datetime-local"]::-webkit-date-and-time-value,
body input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
  min-height: 1.25rem;
}
body input.fc-date::placeholder {
  color: #94a3b8; /* slate-400 */
}

/* --- flatpickr calendar in brand colors ---------------------------------------------- */
.flatpickr-calendar {
  font-family: inherit;
  border-radius: 1rem;
  border: 1px solid var(--fc-border);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
  z-index: 70; /* above panel modals (50) and the bell (60) */
}
.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowBottom::before {
  border-bottom-color: var(--fc-border);
}
.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  color: var(--fc-text);
  font-weight: 600;
}
.flatpickr-current-month {
  font-size: 1rem;
}
/* The month header is a select: undo the base field style. */
body .flatpickr-current-month select.flatpickr-monthDropdown-months {
  min-height: 0;
  padding: 0 0.25rem;
  border: 0;
  box-shadow: none;
  background-image: none;
  background-color: transparent;
  font-weight: 600;
}
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
  fill: var(--fc-focus);
}
span.flatpickr-weekday {
  color: var(--fc-muted);
  font-weight: 600;
}
.flatpickr-day {
  border-radius: 0.6rem;
  color: var(--fc-text);
}
.flatpickr-day:hover,
.flatpickr-day:focus {
  background: var(--fc-brand-50);
  border-color: var(--fc-brand-50);
}
.flatpickr-day.today {
  border-color: var(--fc-focus);
}
.flatpickr-day.today:hover,
.flatpickr-day.today:focus {
  background: var(--fc-brand-50);
  border-color: var(--fc-focus);
  color: var(--fc-text);
}
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover,
.flatpickr-day.selected:focus,
.flatpickr-day.startRange:focus,
.flatpickr-day.endRange:focus {
  background: var(--fc-focus);
  border-color: var(--fc-focus);
  color: #fff;
}
.flatpickr-day.inRange {
  background: var(--fc-brand-50);
  border-color: var(--fc-brand-50);
  box-shadow: -5px 0 0 var(--fc-brand-50), 5px 0 0 var(--fc-brand-50);
}
.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n + 1)),
.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n + 1)),
.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n + 1)) {
  box-shadow: -10px 0 0 var(--fc-focus);
}
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover,
.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
  color: #cbd5e1;
}
.flatpickr-time {
  border-top: 1px solid var(--fc-border);
}
.flatpickr-time input,
.flatpickr-time .flatpickr-time-separator,
.flatpickr-time .flatpickr-am-pm {
  color: var(--fc-text);
  font-weight: 600;
}
.flatpickr-time input:hover,
.flatpickr-time input:focus,
.flatpickr-time .flatpickr-am-pm:hover {
  background: var(--fc-brand-50);
}
/* "Today" / "Clear" footer shortcuts. */
.fc-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.65rem;
  border-top: 1px solid var(--fc-border);
}
.fc-actions button {
  border: 0;
  background: none;
  padding: 0.25rem 0.5rem;
  border-radius: 0.5rem;
  color: var(--fc-brand-600);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
}
.fc-actions button:hover {
  background: var(--fc-brand-50);
}
.fc-actions button[data-fc-clear] {
  color: var(--fc-muted);
}

@media (max-width: 1023px) {
  body select:not([multiple]),
  body input[type="date"],
  body input[type="datetime-local"],
  body input[type="time"],
  body input.fc-date {
    font-size: 1rem; /* no iOS zoom at 16px */
  }
}
