/* DoctorSuite — selettore di date e ore (03 §7.7.2). Script: shared/assets/js/ds-datepicker.js.
 * Solo token --ds-*: il tema scuro (html.dark) e l'alto contrasto seguono da soli. */

/* input originale: resta nel form (name, valore nativo) ma non si vede */
input.dsdp-src { display: none !important; }

/* campo visibile: eredita le classi dell'originale (.ds-input, larghezze…) e aggiunge l'icona */
input.dsdp-field {
  padding-right: 2.35rem;
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 1rem 1rem;
  font-variant-numeric: tabular-nums;
  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='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4.5' width='18' height='16.5' rx='3'/%3E%3Cpath d='M3 9.5h18M8 2.5v4M16 2.5v4'/%3E%3C/svg%3E");
}
input.dsdp-field--time {
  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='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}
input.dsdp-field[aria-expanded="true"] {
  border-color: var(--ds-cyan);
  box-shadow: 0 0 0 3px rgba(41,171,226,.2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231676A9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4.5' width='18' height='16.5' rx='3'/%3E%3Cpath d='M3 9.5h18M8 2.5v4M16 2.5v4'/%3E%3C/svg%3E");
}
input.dsdp-field--time[aria-expanded="true"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231676A9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}
html.dark input.dsdp-field {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4.5' width='18' height='16.5' rx='3'/%3E%3Cpath d='M3 9.5h18M8 2.5v4M16 2.5v4'/%3E%3C/svg%3E");
}
html.dark input.dsdp-field--time {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}
html.dark input.dsdp-field[aria-expanded="true"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237DD3FC' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4.5' width='18' height='16.5' rx='3'/%3E%3Cpath d='M3 9.5h18M8 2.5v4M16 2.5v4'/%3E%3C/svg%3E");
}
html.dark input.dsdp-field--time[aria-expanded="true"] {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237DD3FC' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v5l3 2'/%3E%3C/svg%3E");
}
input.dsdp-field:disabled { cursor: not-allowed; opacity: .65; }
input.dsdp-field:read-only:not(:disabled) { background-image: none; padding-right: .8rem; }
input.dsdp-field[aria-invalid="true"] { border-color: var(--err-t); }

/* ── popup ───────────────────────────────────────────────────────────────────────────── */
.dsdp-pop {
  position: fixed; inset: auto; left: 0; top: 0; margin: 0; padding: 14px; box-sizing: border-box;
  width: max-content; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto;
  background: var(--ds-surface); color: var(--ds-ink);
  border: 1px solid var(--ds-line); border-radius: var(--ds-r-xl); box-shadow: var(--ds-shadow-modal);
  font-family: 'Plus Jakarta Sans Variable', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: .875rem; line-height: 1.4; letter-spacing: -0.015em; text-align: left;
  z-index: calc(var(--ds-z-spotlight, 1300) + 10); /* fallback senza top layer: sopra modali e spotlight, sotto i toast */
  user-select: none; -webkit-user-select: none;
}
.dsdp-pop[hidden] { display: none; }
html.dark .dsdp-pop { box-shadow: 0 25px 50px -12px rgba(0,0,0,.6); border-color: var(--ds-line); }
.dsdp-pop.is-in { animation: dsdp-in var(--ds-dur, 200ms) var(--ds-ease, cubic-bezier(.2,.8,.2,1)); }
.dsdp-pop.is-in[data-side="top"] { animation-name: dsdp-in-top; }
@keyframes dsdp-in { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes dsdp-in-top { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.dsdp-body { display: flex; gap: 14px; align-items: stretch; }
.dsdp-cal { width: 280px; }

.dsdp-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.dsdp-nav, .dsdp-title { border: 0; background: none; color: var(--ds-ink); font: inherit; cursor: pointer; border-radius: var(--ds-r-md); }
.dsdp-nav { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; background: var(--ds-surface-2); color: var(--ds-muted); font-size: .75rem; flex-shrink: 0;
  transition: background var(--ds-dur-fast, 120ms), color var(--ds-dur-fast, 120ms); }
.dsdp-nav:hover:not(:disabled) { background: rgba(41,171,226,.15); color: var(--ds-dark); }
.dsdp-nav:disabled { opacity: .35; cursor: not-allowed; }
.dsdp-title { flex: 1; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; font-size: .95rem; color: var(--ds-ink); }
.dsdp-title i { font-size: .6rem; color: var(--ds-muted-2); transition: transform var(--ds-dur-fast, 120ms); }
.dsdp-title:hover:not(:disabled) { background: var(--ds-surface-2); color: var(--ds-dark); }
.dsdp-title:disabled { cursor: default; }

.dsdp-grid { width: 100%; border-collapse: separate; border-spacing: 2px; table-layout: fixed; }
.dsdp-grid th { font-size: .6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--ds-muted-2); padding: 2px 0 6px; text-align: center; }
.dsdp-grid th.is-we { color: var(--ds-muted); }
.dsdp-grid td { padding: 0; text-align: center; }
.dsdp-day { position: relative; width: 100%; aspect-ratio: 1 / 1; min-height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px; background: none; color: var(--ds-ink); font: inherit; font-weight: 600; font-size: .85rem; font-variant-numeric: tabular-nums; cursor: pointer;
  transition: background var(--ds-dur-fast, 120ms), color var(--ds-dur-fast, 120ms), box-shadow var(--ds-dur-fast, 120ms); }
.dsdp-day.is-sat, .dsdp-day.is-sun { background: var(--ds-surface-2); }
.dsdp-day.is-sun { color: var(--err-t); }
.dsdp-day.is-fest { color: var(--err-t); background: var(--err-b); }
.dsdp-day.is-fest::after { content: ''; position: absolute; bottom: 4px; left: 50%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; }
.dsdp-day.is-out { opacity: .42; }
.dsdp-day:hover:not(.is-off):not(.is-sel) { background: rgba(41,171,226,.15); color: var(--ds-dark); }
.dsdp-day.is-today { box-shadow: inset 0 0 0 1.5px var(--ds-cyan); color: var(--ds-cyan-text); font-weight: 800; }
.dsdp-day.is-sel, .dsdp-cell.is-sel, .dsdp-opt.is-sel { background: var(--ds-grad-brand); color: #fff; font-weight: 800; box-shadow: 0 6px 14px -6px rgba(27,32,128,.55); opacity: 1; }
.dsdp-day.is-sel.is-today { box-shadow: 0 6px 14px -6px rgba(27,32,128,.55), inset 0 0 0 2px rgba(255,255,255,.75); }
.dsdp-day.is-off, .dsdp-cell.is-off, .dsdp-opt.is-off { color: var(--ds-disabled-ink); background: none; cursor: not-allowed; text-decoration: line-through; text-decoration-thickness: 1px; }
.dsdp-day.is-off.is-sel, .dsdp-cell.is-off.is-sel, .dsdp-opt.is-off.is-sel { background: var(--ds-grad-brand); color: #fff; opacity: .55; }
.dsdp-day:focus-visible, .dsdp-cell:focus-visible, .dsdp-opt:focus-visible, .dsdp-nav:focus-visible, .dsdp-title:focus-visible {
  outline: 3px solid var(--ds-focus); outline-offset: 1px; z-index: 1; }

.dsdp-mgrid { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }
.dsdp-mrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dsdp-cell { height: 52px; border: 0; border-radius: var(--ds-r-md); background: var(--ds-surface-2); color: var(--ds-ink); font: inherit; font-weight: 700; font-size: .875rem; cursor: pointer;
  font-variant-numeric: tabular-nums; transition: background var(--ds-dur-fast, 120ms), color var(--ds-dur-fast, 120ms); }
.dsdp-cell:hover:not(.is-off):not(.is-sel) { background: rgba(41,171,226,.15); color: var(--ds-dark); }
.dsdp-cell.is-today:not(.is-sel) { box-shadow: inset 0 0 0 1.5px var(--ds-cyan); color: var(--ds-cyan-text); }

/* orario */
.dsdp-time { display: flex; gap: 8px; }
.dsdp-pop--dt .dsdp-time { border-left: 1px solid var(--ds-line-soft); padding-left: 14px; }
.dsdp-tcol { display: flex; flex-direction: column; width: 64px; }
.dsdp-tlab { font-size: .6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--ds-muted-2); text-align: center; padding: 8px 0 8px; }
.dsdp-tlist { position: relative; height: 252px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding: 2px; scrollbar-width: thin; overscroll-behavior: contain; }
.dsdp-pop--time .dsdp-tlist { height: 220px; }
.dsdp-pop--time .dsdp-time { justify-content: center; }
.dsdp-opt { flex-shrink: 0; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
  color: var(--ds-ink); transition: background var(--ds-dur-fast, 120ms); }
.dsdp-opt:hover:not(.is-off):not(.is-sel) { background: rgba(41,171,226,.15); color: var(--ds-dark); }

.dsdp-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--ds-line-soft); }
.dsdp-foot__sp { flex: 1; }
.dsdp-foot .ds-btn { height: 32px; }

/* ── foglio dal basso (mobile) ───────────────────────────────────────────────────────── */
.dsdp-handle { width: 40px; height: 5px; border-radius: 9999px; background: var(--ds-line); margin: -4px auto 12px; }
.dsdp-pop--sheet {
  left: 0 !important; right: 0; top: auto !important; bottom: 0; width: 100%; max-width: 100%; max-height: 92vh;
  border-radius: var(--ds-r-xl) var(--ds-r-xl) 0 0; border-bottom: 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.dsdp-pop--sheet.is-in, .dsdp-pop--sheet.is-in[data-side="top"] { animation-name: dsdp-sheet; animation-duration: var(--ds-dur-slow, 300ms); }
@keyframes dsdp-sheet { from { transform: translateY(100%); } to { transform: none; } }
.dsdp-pop--sheet::backdrop { background: rgba(15,23,42,.55); }
.dsdp-back { position: fixed; inset: 0; background: var(--ds-overlay); z-index: calc(var(--ds-z-spotlight, 1300) + 9); }
.dsdp-pop--sheet .dsdp-body { flex-direction: column; }
.dsdp-pop--sheet .dsdp-cal { width: 100%; max-width: 420px; margin: 0 auto; }
.dsdp-pop--sheet .dsdp-day { min-height: 42px; font-size: .95rem; }
.dsdp-pop--sheet.dsdp-pop--dt .dsdp-time { border-left: 0; padding-left: 0; border-top: 1px solid var(--ds-line-soft); padding-top: 8px; }
.dsdp-pop--sheet .dsdp-time { justify-content: center; }
.dsdp-pop--sheet .dsdp-tcol { width: 50%; max-width: 160px; }
.dsdp-pop--sheet .dsdp-tlist { height: 168px; }
.dsdp-pop--sheet .dsdp-opt { height: 40px; }
.dsdp-pop--sheet .dsdp-foot .ds-btn { height: 44px; }

/* alto contrasto */
html.hc .dsdp-pop { border: 2px solid var(--ds-ink); }
html.hc .dsdp-day.is-today { box-shadow: inset 0 0 0 2px var(--ds-ink); }

@media (prefers-reduced-motion: reduce) {
  .dsdp-pop.is-in { animation: none; }
}
@media print { .dsdp-pop { display: none !important; } input.dsdp-field { background-image: none; padding-right: .8rem; } }
