/* CRM date picker — standard condiviso, coerente con il period selector Performance. */
.crm-date-field {
  position: relative;
  display: inline-grid;
  width: 100%;
  min-width: 0;
}

.crm-date-field > input {
  grid-area: 1 / 1;
  width: 100%;
  padding-right: 38px !important;
  cursor: pointer;
}

.crm-date-field > input::-webkit-calendar-picker-indicator {
  opacity: 0;
  pointer-events: none;
}

.crm-date-trigger {
  position: absolute;
  z-index: 1;
  top: 50%;
  right: 7px;
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: var(--radius-sm, 7px);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.crm-date-trigger:hover,
.crm-date-trigger:focus-visible {
  background: var(--muted);
  color: var(--foreground);
  outline: none;
}

.crm-date-trigger svg { width: 16px; height: 16px; }

.crm-date-backdrop {
  position: fixed;
  inset: 0;
  /* Il picker può nascere dentro un modal ma viene portato sul body: deve
     stare sopra il modal root senza superare toast e messaggi critici. */
  z-index: calc(var(--layer-modal-root, 2000) + 90);
  display: none;
}

.crm-date-backdrop.is-open { display: block; }

.crm-date-popover {
  position: fixed;
  z-index: calc(var(--layer-modal-root, 2000) + 100);
  display: none;
  width: min(336px, calc(100vw - 24px));
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--card);
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--foreground) 10%, transparent),
              0 18px 48px color-mix(in oklch, var(--foreground) 18%, transparent);
}

.crm-date-popover.is-open { display: block; }

.crm-date-header {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 32px;
  align-items: center;
  padding: 12px 12px 8px;
}

.crm-date-month {
  margin: 0;
  color: var(--foreground);
  font-size: .875rem;
  font-weight: 650;
  text-align: center;
}

.crm-date-nav {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
}

.crm-date-nav:hover,
.crm-date-nav:focus-visible {
  background: var(--muted);
  color: var(--foreground);
  outline: none;
}

.crm-date-nav svg { width: 16px; height: 16px; }

.crm-date-weekdays,
.crm-date-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  padding: 0 12px;
}

.crm-date-weekdays span {
  padding: 5px 0;
  color: var(--muted-foreground);
  font-size: .6875rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
}

.crm-date-day {
  display: inline-flex;
  aspect-ratio: 1;
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: .8125rem;
  cursor: pointer;
}

.crm-date-day:hover,
.crm-date-day:focus-visible { background: var(--muted); outline: none; }
.crm-date-day.is-outside { color: color-mix(in oklch, var(--muted-foreground) 55%, transparent); }
.crm-date-day.is-today { box-shadow: inset 0 0 0 1px var(--primary); }
.crm-date-day.is-selected {
  background: var(--primary);
  color: var(--primary-foreground, #162000);
  font-weight: 700;
  box-shadow: none;
}

.crm-date-time {
  display: none;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 12px 14px 0;
}

.crm-date-popover.has-time .crm-date-time { display: grid; }
.crm-date-time select { min-width: 0; width: 100%; }
.crm-date-time-separator { color: var(--muted-foreground); font-weight: 700; }

.crm-date-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
}

.crm-date-footer .sc-btn:first-child { margin-right: auto; }

@media (max-width: 640px) {
  .crm-date-backdrop.is-open {
    display: block;
    background: color-mix(in oklch, var(--foreground) 30%, transparent);
    backdrop-filter: blur(2px);
  }
  .crm-date-popover {
    top: auto !important;
    right: 8px !important;
    bottom: 8px !important;
    left: 8px !important;
    width: auto;
    border-radius: var(--radius-xl);
  }
  .crm-date-day { aspect-ratio: auto; min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .crm-date-popover, .crm-date-backdrop { scroll-behavior: auto; }
}
