/* ═════════════════════════════════════════════════════════════════
   SuperCat DS — Date picker  ·  .kf-date
   ─────────────────────────────────────────────────────────────────
   ▸ Class prefix: `.kf-*` = "kit form".
   ▸ Wraps a real <input type="date"> + a branded popover.
   ▸ Companion script (date.js) wires up nav/selection. Without it,
     the field still works as a plain typeable date input.
   ▸ Framework-agnostic. Native form semantics preserved.
   ─────────────────────────────────────────────────────────────────
   .kf-date — Custom date picker
   ─────────────────────────────────────────────────────────────────
   The native <input type="date"> calendar is browser chrome — we can
   restyle the trigger but not the popup. This primitive replaces the
   popup with a fully branded calendar.

   We still ship a real <input type="date"> underneath (form data,
   keyboard typing, validation). The popover is purely visual.

   Usage (canonical pattern):

     <div class="kf-date kf-md" data-kf-date>
       <input type="date" class="kf-input kf-md" value="2026-05-22" />
       <button type="button" class="kf-date-trigger" aria-label="Open calendar">
         <svg viewBox="0 0 16 16" width="16" height="16" fill="none"
              stroke="currentColor" stroke-width="1.5" stroke-linecap="round">
           <rect x="2" y="3" width="12" height="11" rx="1.5" />
           <path d="M2 6h12M5 1.5v3M11 1.5v3" />
         </svg>
       </button>
       <div class="kf-date-pop" role="dialog" aria-label="Pick a date" hidden></div>
     </div>

   The companion script (date.js) wires up nav/selection. Without it,
   the field still works as a plain typeable date input.
   ─────────────────────────────────────────────────────────────── */

.kf-date,
:where(.kf-date) {
  --kfd-cell:        36px;
  --kfd-bg-pop:      var(--surface-card);
  --kfd-border:      var(--border-default);
  --kfd-fg:          var(--text-primary);
  --kfd-fg-muted:    var(--text-faint);
  --kfd-active-bg:   var(--text-crimson);
  --kfd-active-fg:   var(--text-on-crimson);
  --kfd-hover-bg:    color-mix(in oklch, var(--text-crimson) 10%, transparent);
  --kfd-today-ring:  var(--text-crimson);

  position: relative;
  display: inline-block;
  width: 100%;
}

/* Hide the native calendar icon so our trigger is the only one shown */
.kf-date .kf-input[type="date"]::-webkit-calendar-picker-indicator {
  display: none;
  -webkit-appearance: none;
}
.kf-date .kf-input[type="date"] {
  padding-right: calc(var(--space-3) + 28px);
}

/* Trigger button (sits on top of the date input, right side) */
.kf-date-trigger {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0;
  transition: color var(--duration-fast), background var(--duration-fast);
}
.kf-date-trigger:hover {
  color: var(--text-primary);
  background: color-mix(in oklch, var(--text-primary) 6%, transparent);
}
.kf-date-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--text-crimson) 22%, transparent);
}

/* ── Popover ──────────────────────────────────────────────────── */
.kf-date-pop {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  z-index: 50;
  min-width: 280px;
  padding: var(--space-4);
  background: var(--kfd-bg-pop);
  border: 1px solid var(--kfd-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  font-family: var(--font-sans);
  color: var(--kfd-fg);
  /* Slight slide-down on open */
  animation: kfd-pop var(--duration-base) var(--ease-out);
}
.kf-date-pop[hidden] { display: none; }

@keyframes kfd-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Popover header (month + year + nav) */
.kf-date-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.kf-date-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--kfd-fg);
  /* Click for month/year switcher (handled in JS) */
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  margin: 0 calc(var(--space-2) * -1);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  transition: background var(--duration-fast);
}
.kf-date-title:hover {
  background: color-mix(in oklch, var(--text-primary) 6%, transparent);
}
.kf-date-title-chev {
  width: 9px; height: 9px;
  color: var(--text-muted);
  transition: transform var(--duration-base) var(--ease-out);
}
.kf-date-pop[data-view="months"] .kf-date-title-chev,
.kf-date-pop[data-view="years"]  .kf-date-title-chev {
  transform: rotate(180deg);
}

.kf-date-nav {
  display: inline-flex;
  gap: 2px;
}
.kf-date-nav-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 0;
  transition: color var(--duration-fast), background var(--duration-fast);
}
.kf-date-nav-btn:hover {
  color: var(--text-primary);
  background: color-mix(in oklch, var(--text-primary) 6%, transparent);
}
.kf-date-nav-btn svg { width: 12px; height: 12px; }

/* ── Day grid ─────────────────────────────────────────────────── */
.kf-date-grid {
  display: grid;
  grid-template-columns: repeat(7, var(--kfd-cell));
  gap: 2px;
}

/* Weekday header row */
.kf-date-dow {
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: var(--weight-semibold);
}

/* Day cell */
.kf-date-day {
  width: var(--kfd-cell);
  height: var(--kfd-cell);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-feature-settings: "tnum";
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--kfd-fg);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
  font-family: inherit;
}
.kf-date-day:hover:not(:disabled):not([data-selected]) {
  background: var(--kfd-hover-bg);
}
.kf-date-day:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--kfd-active-bg);
}

/* Days from prev/next month */
.kf-date-day[data-out] {
  color: var(--kfd-fg-muted);
}

/* Today — subtle ring underline */
.kf-date-day[data-today]:not([data-selected])::after {
  content: "";
  position: absolute;
  bottom: 5px;
  left: 50%;
  width: 12px;
  height: 2px;
  background: var(--kfd-today-ring);
  border-radius: 1px;
  transform: translateX(-50%);
}

/* Selected — crimson chip */
.kf-date-day[data-selected] {
  background: var(--kfd-active-bg);
  color: var(--kfd-active-fg);
  font-weight: var(--weight-semibold);
}

/* Disabled (out of min/max range) */
.kf-date-day:disabled {
  color: var(--kfd-fg-muted);
  cursor: not-allowed;
  opacity: 0.4;
}

/* ── Month / year picker views ────────────────────────────────── */
.kf-date-grid-months,
.kf-date-grid-years {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: var(--space-2) 0;
}
.kf-date-mo,
.kf-date-yr {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--kfd-fg);
  cursor: pointer;
  font-feature-settings: "tnum";
  transition: background var(--duration-fast), color var(--duration-fast);
  font-family: inherit;
}
.kf-date-mo:hover,
.kf-date-yr:hover {
  background: var(--kfd-hover-bg);
}
.kf-date-mo[data-selected],
.kf-date-yr[data-selected] {
  background: var(--kfd-active-bg);
  color: var(--kfd-active-fg);
  font-weight: var(--weight-semibold);
}
.kf-date-yr[data-out] {
  color: var(--kfd-fg-muted);
}

/* ── Footer (today / clear shortcuts) ─────────────────────────── */
.kf-date-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border-subtle);
}
.kf-date-shortcut {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast), background var(--duration-fast);
}
.kf-date-shortcut:hover {
  color: var(--text-crimson);
  background: var(--kfd-hover-bg);
}

/* ── Reduced motion ──────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .kf-date-pop { animation: none; }
  .kf-date-day,
  .kf-date-mo,
  .kf-date-yr,
  .kf-date-trigger,
  .kf-date-nav-btn { transition: none; }
}

/* ── Dark theme ──────────────────────────────────────────────── */
[data-theme="dark"] .kf-date {
  --kfd-active-bg:   var(--color-crimson);
  --kfd-today-ring:  var(--color-crimson);
  --kfd-hover-bg: color-mix(in oklch, var(--color-crimson) 18%, transparent);
}
