/* ═══════════════════════════════════════════════════════════════════════════
   AGENDA STUDIO — Stylesheet
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --pri:      #2563eb;
  --pri-dark: #1d4ed8;
  --pri-bg:   #eff6ff;
  --surface:  #ffffff;
  --bg:       #f1f5f9;
  --border:   #e2e8f0;
  --text:     #1e293b;
  --muted:    #64748b;
  --danger:   #ef4444;
  --danger-bg:#fef2f2;
  --header-h: 56px;
  --sidebar-w:224px;
  --radius:   8px;
  --shadow:   0 1px 3px rgba(0,0,0,.1);
  --shadow-lg:0 8px 32px rgba(0,0,0,.18);
}

*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { height: 100%; height: -webkit-fill-available; height: 100dvh; }
body { font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  font-size:14px; color:var(--text); background:var(--bg);
  height:100%; height:-webkit-fill-available; height:100dvh; overflow:hidden; }
.hidden { display:none !important; }
button { font-family:inherit; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn-pri   { background:var(--pri); color:#fff; border:none; padding:8px 18px;
             border-radius:var(--radius); cursor:pointer; font-size:14px; font-weight:500; }
.btn-pri:hover { background:var(--pri-dark); }
.btn-sec   { background:var(--surface); color:var(--text); border:1px solid var(--border);
             padding:8px 16px; border-radius:var(--radius); cursor:pointer; font-size:14px; }
.btn-sec:hover { background:var(--bg); }
.btn-ghost { background:none; color:var(--muted); border:none;
             padding:8px 14px; border-radius:var(--radius); cursor:pointer; font-size:14px; }
.btn-ghost:hover { background:var(--bg); }
.btn-danger { background:var(--danger-bg); color:var(--danger);
              border:1px solid var(--danger); padding:8px 16px;
              border-radius:var(--radius); cursor:pointer; font-size:14px; }
.btn-danger:hover { background:var(--danger); color:#fff; }
.btn-icon  { background:none; border:none; cursor:pointer; padding:6px 10px;
             border-radius:var(--radius); font-size:18px; color:var(--muted); line-height:1; }
.btn-icon:hover  { background:var(--border); color:var(--text); }
.btn-text  { background:none; border:1px solid var(--border); padding:4px 12px;
             border-radius:var(--radius); cursor:pointer; font-size:13px; color:var(--text); }
.btn-text:hover { background:var(--bg); }
.btn-link  { background:none; border:none; color:var(--pri); cursor:pointer;
             font-size:13px; padding:0; text-decoration:underline; }
.btn-full  { width:100%; }

/* ─── Fields ─────────────────────────────────────────────────────────── */
.field { display:flex; flex-direction:column; gap:4px; flex:1; }
.chk-label { display:flex; align-items:center; gap:8px; cursor:pointer; font-size:13px; padding:6px 0; user-select:none; }
.chk-label input[type=checkbox] { width:16px; height:16px; cursor:pointer; accent-color:#4a7c2a; }
.field label { font-size:11px; font-weight:700; color:var(--muted);
               text-transform:uppercase; letter-spacing:.04em; }
.field input, .field select, .field textarea {
  border:1px solid var(--border); border-radius:var(--radius);
  padding:8px 10px; font-size:14px; color:var(--text); background:var(--surface); width:100%; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline:none; border-color:var(--pri); box-shadow:0 0 0 3px rgba(37,99,235,.1); }
.field textarea { resize:vertical; }
.field-row { display:flex; gap:12px; }

/* ─── LOGIN ───────────────────────────────────────────────────────────── */
.login-screen { position:fixed; inset:0; display:flex; align-items:center; justify-content:center;
  background:linear-gradient(135deg,#1e3a8a 0%,#0891b2 100%); }
.login-card { background:var(--surface); border-radius:16px; padding:40px;
  width:100%; max-width:380px; box-shadow:var(--shadow-lg); text-align:center; }
.login-logo { font-size:52px; margin-bottom:8px; }
.login-title { font-size:24px; font-weight:700; margin-bottom:4px; }
.login-sub { color:var(--muted); font-size:14px; margin-bottom:28px; }
.login-form { text-align:left; display:flex; flex-direction:column; gap:16px; }
.login-err { background:var(--danger-bg); color:var(--danger);
  border:1px solid #fca5a5; border-radius:var(--radius); padding:8px 12px; font-size:13px; }

/* ─── APP SHELL ───────────────────────────────────────────────────────── */
/* Shell ancorata al viewport: position:fixed in alto + height dinamica (dvh).
   Evita che, su iOS Safari, header e barra date "scorrano via" quando la
   barra indirizzi si mostra/nasconde. */
.app { position:fixed; top:0; left:0; right:0;
  height:100vh; height:-webkit-fill-available; height:100dvh;
  display:flex; flex-direction:column; overflow:hidden; }

/* Header — semplice flex item in cima alla shell (niente sticky: su iOS
   dentro un flex non scrollabile lo sticky si "stacca"). */
.app-header { height:var(--header-h); background:var(--surface);
  border-bottom:1px solid var(--border); display:flex; align-items:center;
  padding:0 14px; gap:10px; box-shadow:var(--shadow);
  position:relative; z-index:20; flex-shrink:0; }
.hdr-left  { display:flex; align-items:center; gap:8px; }
.app-title { font-size:16px; font-weight:700; white-space:nowrap; }
.hdr-nav   { display:flex; align-items:center; gap:6px; flex:1; justify-content:center; }
.hdr-period { font-size:15px; font-weight:600; min-width:200px; text-align:center; }
.hdr-right { display:flex; align-items:center; gap:8px; }
.user-badge { background:var(--pri-bg); color:var(--pri);
  border-radius:20px; padding:4px 12px; font-size:13px; font-weight:600; }

/* Body */
.app-body { display:flex; flex:1; overflow:hidden; }

/* Sidebar */
.app-sidebar { width:var(--sidebar-w); background:var(--surface);
  border-right:1px solid var(--border); display:flex; flex-direction:column;
  padding:14px; gap:16px; overflow-y:auto; flex-shrink:0; }
.sidebar-sec h3 { font-size:11px; font-weight:700; text-transform:uppercase;
  letter-spacing:.06em; color:var(--muted); margin-bottom:8px; }
.sidebar-list { display:flex; flex-direction:column; gap:4px; }
.sidebar-item { background:var(--bg); border-left:3px solid #94a3b8;
  border-radius:0 var(--radius) var(--radius) 0; padding:6px 8px; cursor:pointer; }
.sidebar-item:hover { background:var(--pri-bg); }
.sidebar-time  { font-size:11px; font-weight:700; color:var(--muted); }
.sidebar-nome  { font-size:13px; font-weight:600; }
.sidebar-esame { font-size:11px; color:var(--muted); }
.empty-msg { font-size:13px; color:var(--muted); font-style:italic; }

/* Main */
.app-main { flex:1; overflow:auto; }

/* ─── CALENDAR ────────────────────────────────────────────────────────── */
.cal-wrap { min-width:0; }   /* larghezza impostata via JS */

.cal-header { display:grid; /* grid-template-columns impostato via JS */
  background:var(--surface); border-bottom:2px solid var(--border);
  position:sticky; top:0; z-index:5; }
/* Angolo ore sticky a sinistra su desktop e mobile */
.cal-th-time {
  position:-webkit-sticky; position:sticky;
  left:0; z-index:7; background:var(--surface);
}
.cal-th-day  { padding:8px 4px; text-align:center; border-left:1px solid var(--border); }
.cal-th-dayname { display:block; font-size:10px; font-weight:700;
  text-transform:uppercase; letter-spacing:.05em; color:var(--muted); }
.cal-th-daynum  { display:inline-flex; align-items:center; justify-content:center;
  font-size:22px; font-weight:700; width:36px; height:36px; border-radius:50%;
  margin-top:2px; }
.cal-th-day.today .cal-th-daynum { background:var(--pri); color:#fff; }

.cal-body { display:grid; /* grid-template-columns impostato via JS */ }

/* Colonna ore sticky a sinistra su desktop e mobile */
.cal-time-col {
  position:-webkit-sticky; position:sticky;
  left:0; z-index:3; background:var(--surface);
}
.cal-lbl { position:absolute; right:6px; font-size:10px; color:var(--muted);
  transform:translateY(-7px); white-space:nowrap; }

.cal-day { position:relative; border-left:1px solid var(--border); }
.cal-day.today { background:#fffbeb; }

.cal-hline { position:absolute; left:0; right:0; border-top:1px solid #f0f4f8; }
.cal-hline.major { border-top-color:#cbd5e1; }

.cal-slot { position:absolute; left:0; right:0; cursor:pointer; }
.cal-slot:hover { background:rgba(37,99,235,.06); }

/* ─── BLOCCHI AGENDA (festività, impegni) ──────────────────────────────── */
.cal-day.festivo { background:repeating-linear-gradient(
  135deg, #fef2f2, #fef2f2 4px, #fff5f5 4px, #fff5f5 12px); }
.cal-slot-blocked { cursor:not-allowed !important; }
.cal-slot-blocked:hover { background:rgba(239,68,68,.06) !important; }

.cal-blocco-overlay {
  position:absolute; inset:0; z-index:1;
  display:flex; align-items:flex-start; justify-content:center;
  padding-top:8px; pointer-events:none;
}
.cal-blocco-label {
  background:rgba(239,68,68,.15); color:#b91c1c;
  font-size:9px; font-weight:700; text-transform:uppercase;
  letter-spacing:.04em; padding:2px 6px; border-radius:4px;
  white-space:nowrap; max-width:90%; overflow:hidden; text-overflow:ellipsis;
}

/* Header festivo */
.cal-th-day.festivo { background:#fef2f2; color:#b91c1c; }
.cal-th-festivo { display:block; font-size:9px; line-height:1; }

/* Appointment blocks */
.cal-app { position:absolute; left:2px; right:2px; border-radius:6px;
  padding:3px 6px; cursor:pointer; overflow:hidden; z-index:2;
  border-left:3px solid rgba(0,0,0,.15); box-shadow:var(--shadow);
  transition:box-shadow .15s; }
.cal-app:hover { box-shadow:0 3px 10px rgba(0,0,0,.2); }
.cal-app-time  { font-size:10px; font-weight:700; opacity:.85; }
.cal-app-nome  { font-size:12px; font-weight:600;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.cal-app-esame { font-size:10px; opacity:.75;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* Status colors — calendar blocks */
.stato-prenotato { background:#dbeafe; color:#1e40af; border-left-color:#3b82f6; }
.stato-arrivato  { background:#fef3c7; color:#92400e; border-left-color:#f59e0b; }
.stato-in_corso  { background:#d1fae5; color:#065f46; border-left-color:#10b981; }
.stato-refertato { background:#f1f5f9; color:#475569; border-left-color:#94a3b8; }
.stato-annullato { background:#fee2e2; color:#991b1b; border-left-color:#ef4444; opacity:.55; }
.stato-in_attesa { background:#fef3c7; color:#78350f; border-left-color:#f59e0b;
                   border-left-style:dashed; }

/* Sidebar border colors */
.sidebar-item.stato-prenotato  { border-left-color:#3b82f6; }
.sidebar-item.stato-arrivato   { border-left-color:#f59e0b; }
.sidebar-item.stato-in_corso   { border-left-color:#10b981; }
.sidebar-item.stato-refertato  { border-left-color:#94a3b8; }
.sidebar-item.stato-annullato  { border-left-color:#ef4444; opacity:.6; }
.sidebar-item.stato-in_attesa  { border-left-color:#f59e0b; }

/* ─── MODAL ───────────────────────────────────────────────────────────── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.5);
  display:flex; align-items:center; justify-content:center;
  z-index:10000; backdrop-filter:blur(2px); }
.modal { background:var(--surface); border-radius:14px; width:100%; max-width:540px;
  max-height:92vh; display:flex; flex-direction:column; box-shadow:var(--shadow-lg); }
.modal-hdr { display:flex; align-items:center; justify-content:space-between;
  padding:16px 20px; border-bottom:1px solid var(--border); flex-shrink:0; }
.modal-hdr h2 { font-size:18px; font-weight:700; }
.modal-body { padding:20px; overflow-y:auto; flex:1; display:flex;
  flex-direction:column; gap:14px; }
.modal-ftr { padding:12px 20px; border-top:1px solid var(--border);
  display:flex; justify-content:space-between; align-items:center; flex-shrink:0; }
.modal-ftr-r { display:flex; gap:8px; }

/* Patient search */
.paz-search-wrap { position:relative; }
.paz-results { position:absolute; top:100%; left:0; right:0;
  background:var(--surface); border:1px solid var(--border); border-top:none;
  border-radius:0 0 var(--radius) var(--radius); max-height:200px; overflow-y:auto;
  z-index:10; box-shadow:var(--shadow-lg); }
.paz-item { padding:8px 12px; cursor:pointer; border-bottom:1px solid var(--border); }
.paz-item:last-child { border-bottom:none; }
.paz-item:hover { background:var(--pri-bg); }
.paz-nome { font-weight:600; font-size:13px; }
.paz-info { font-size:11px; color:var(--muted); }
.paz-selezionato { background:var(--pri-bg); border:1px solid #bfdbfe;
  border-radius:var(--radius); padding:8px 12px; display:flex;
  align-items:center; justify-content:space-between; font-weight:600; }


/* Pannello read-only dati paziente selezionato */
.paz-info-panel {
  background:#f8fafc; border:1px solid var(--border);
  border-radius:var(--radius); padding:8px 12px; margin-top:4px;
  display:flex; flex-direction:column; gap:3px;
}
.paz-info-row { display:flex; gap:8px; font-size:12px; align-items:baseline; }
.paz-info-lbl { color:var(--muted); min-width:90px; font-size:11px; }
.paz-info-edit { margin-top:6px; font-size:12px; }

.nuovo-paz-form { background:var(--bg); border:1px solid var(--border);
  border-radius:var(--radius); padding:14px; display:flex; flex-direction:column; gap:10px; }

/* ─── PREP REMINDER ──────────────────────────────────────────────────── */
.prep-reminder {
  display:flex; align-items:flex-start; gap:10px;
  background:#fffbeb; border:1px solid #f59e0b;
  border-left:4px solid #f59e0b;
  border-radius:var(--radius); padding:12px 14px;
  animation:prepIn .2s ease;
}
@keyframes prepIn {
  from { opacity:0; transform:translateY(-6px); }
  to   { opacity:1; transform:none; }
}
.prep-icon { font-size:20px; line-height:1.2; flex-shrink:0; }
.prep-text { font-size:13px; color:#78350f; line-height:1.5; }
.prep-text strong { color:#92400e; }

/* Stato buttons */
.stato-btns { display:flex; gap:6px; flex-wrap:wrap; }
.stato-btn { padding:6px 14px; border-radius:20px; border:2px solid transparent;
  cursor:pointer; font-size:12px; font-weight:600; transition:box-shadow .15s; }
.stato-btn.active { box-shadow:0 0 0 2px var(--pri); }

/* ─── MENU DROPDOWN ──────────────────────────────────────────────────── */
.menu-wrap { position:relative; }
.menu-dropdown {
  position:absolute; top:calc(100% + 6px); left:0;
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); box-shadow:var(--shadow-lg);
  min-width:230px; z-index:200; padding:5px 0;
  animation:menuIn .12s ease;
}
@keyframes menuIn { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:none; } }
.menu-item {
  display:flex; align-items:center; gap:2px;
  width:100%; padding:10px 18px;
  background:none; border:none; cursor:pointer;
  font-size:14px; color:var(--text); text-align:left;
}
.menu-item:hover { background:var(--bg); }
.menu-item--danger { color:var(--danger); }
.menu-divider { border-top:1px solid var(--border); margin:5px 0; }

/* ─── ARCHIVIO PAZIENTI ───────────────────────────────────────────────── */
.arch-modal { max-width:720px; width:95%; }
.arch-table-wrap { max-height:420px; overflow-y:auto; border:1px solid var(--border); border-radius:var(--radius); }
.arch-table { width:100%; border-collapse:collapse; font-size:13px; }
.arch-table thead th {
  position:sticky; top:0; background:var(--bg);
  padding:8px 12px; text-align:left;
  font-size:11px; font-weight:700; text-transform:uppercase;
  letter-spacing:.05em; color:var(--muted);
  border-bottom:2px solid var(--border);
}
.arch-table tbody td { padding:9px 12px; border-bottom:1px solid var(--border); }
.arch-table tbody tr:last-child td { border-bottom:none; }
.arch-table tbody tr:hover td { background:var(--pri-bg); cursor:pointer; }
.arch-empty { padding:32px; text-align:center; color:var(--muted); font-style:italic; }
.arch-hint { font-size:12px; color:var(--muted); margin-top:10px; text-align:center; }

/* ─── DETTAGLIO PAZIENTE ──────────────────────────────────────────────────── */
.paz-detail-modal  { max-width:640px; width:95%; }
.paz-detail-body   { overflow-y:auto; max-height:calc(100vh - 220px); }
.paz-detail-grid   {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px 16px;
  margin-bottom:20px;
}
.paz-detail-full   { grid-column:1 / -1; }
.paz-detail-storico { border-top:1px solid var(--border); padding-top:14px; }
.paz-storico-title  { font-size:13px; font-weight:700; color:var(--muted);
                      text-transform:uppercase; letter-spacing:.05em; margin:0 0 10px; }
.paz-storico-list   { display:flex; flex-direction:column; gap:6px; max-height:180px; overflow-y:auto; }
.paz-storico-item   {
  display:flex; align-items:center; gap:10px;
  padding:8px 12px; border-radius:var(--radius);
  background:var(--pri-bg); font-size:13px;
}
.paz-storico-data   { font-weight:600; color:var(--pri); min-width:90px; }
.paz-storico-esame  { flex:1; color:var(--text); }
.paz-storico-stato  { font-size:11px; padding:2px 7px; border-radius:10px;
                      background:#e8f5e9; color:#2e7d32; }
.paz-storico-vuoto  { font-size:13px; color:var(--muted); font-style:italic; padding:8px 0; }

/* ─── MOBILE DAY NAV — nascosta su desktop, visibile su mobile via media query */
.mobile-day-nav {
  display:none;  /* default: nascosta */
  align-items:center; justify-content:space-between;
  background:var(--surface); border-bottom:2px solid var(--border);
  padding:0 4px; height:50px; flex-shrink:0;
}
#mobile-day-label {
  flex:1; text-align:center; font-size:14px; font-weight:700; color:var(--text);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; padding:0 4px;
}
.mobile-nav-btn {
  background:none; border:none; font-size:32px; color:var(--pri);
  cursor:pointer; padding:0 10px; line-height:1;
  min-width:52px; min-height:50px;
  display:flex; align-items:center; justify-content:center;
  -webkit-tap-highlight-color:transparent;
}
.mobile-nav-btn:active { background:var(--pri-bg); }

/* ─── MOBILE BOTTOM BAR — nascosta su desktop, visibile su mobile via media query */
.mobile-bottom-bar {
  display:none;  /* default: nascosta */
  position:fixed; bottom:0; left:0; right:0;
  background:var(--surface); border-top:1px solid var(--border);
  z-index:9999;
  padding-bottom:env(safe-area-inset-bottom, 0px);
  box-shadow:0 -2px 8px rgba(0,0,0,.08);
}
.mobile-bottom-bar button {
  flex:1; background:none; border:none; cursor:pointer;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:3px; color:var(--pri); padding:10px 0;
  -webkit-tap-highlight-color:transparent;
  font-family:inherit;
}
.mobile-bottom-bar button:active { background:var(--pri-bg); }
.mbb-icon { font-size:22px; line-height:1; }
.mbb-lbl  { font-size:11px; font-weight:600; }

/* ─── GIORNI FERIALI (prenotabili) — sfondo neutro bianco ───────────── */
.cal-th-day.ecografia { background: #fff; }
.cal-day.ecografia { background: #fff; }
.cal-day.ecografia.today { background: #fffbeb; }

/* ─── BLOCCO INDISPONIBILITÀ ─────────────────────────────────────────── */
.cal-blocco {
  position: absolute; left: 0; right: 0; z-index: 1;
  background: repeating-linear-gradient(-45deg,
    rgba(239,68,68,.07), rgba(239,68,68,.07) 10px,
    rgba(239,68,68,.02) 10px, rgba(239,68,68,.02) 20px);
  border-left: 3px solid rgba(239,68,68,.55);
  border-top: 1px dashed rgba(239,68,68,.4);
  cursor: pointer; overflow: hidden;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  transition: background .15s;
}
.cal-blocco:hover {
  background: repeating-linear-gradient(-45deg,
    rgba(239,68,68,.16), rgba(239,68,68,.16) 10px,
    rgba(239,68,68,.07) 10px, rgba(239,68,68,.07) 20px);
}
.cal-blocco-icon  { font-size: 18px; line-height: 1; }
.cal-blocco-label { font-size: 11px; font-weight: 700; color: rgba(153,27,27,.85);
  text-align: center; padding: 0 4px; }
.cal-blocco-motivo { font-size: 10px; color: rgba(153,27,27,.6); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 90%; padding: 0 4px; }

/* Impegno personale da Google Calendar — blocco grosso "non prenotabile" */
.cal-blocco-gcal {
  z-index: 3;
  background: repeating-linear-gradient(-45deg,
    rgba(120,53,15,.16), rgba(120,53,15,.16) 10px,
    rgba(120,53,15,.07) 10px, rgba(120,53,15,.07) 20px);
  border-left: 4px solid rgba(180,83,9,.85);
  border-top: 1px solid rgba(180,83,9,.45);
}
.cal-blocco-gcal:hover {
  background: repeating-linear-gradient(-45deg,
    rgba(120,53,15,.26), rgba(120,53,15,.26) 10px,
    rgba(120,53,15,.13) 10px, rgba(120,53,15,.13) 20px);
}
.cal-blocco-gcal .cal-blocco-label  { color: rgba(124,45,18,.95); }
.cal-blocco-gcal .cal-blocco-motivo { color: rgba(124,45,18,.7); }

/* Tipo selector nel modal blocco */
.blocco-tipo-btns { display: flex; gap: 8px; }
.blocco-tipo-btn {
  flex: 1; padding: 10px 6px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 12px; font-weight: 600;
  text-align: center; line-height: 1.5; color: var(--text);
  transition: border-color .15s, background .15s;
}
.blocco-tipo-btn small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.blocco-tipo-btn:hover { background: var(--bg); border-color: var(--muted); }
.blocco-tipo-btn.active { border-color: #ef4444; background: #fef2f2; color: #991b1b; }
.blocco-tipo-btn.active small { color: #b91c1c; }

/* ─── RESPONSIVE ──────────────────────────────────────────────────────── */
@media (max-width:768px) {
  /* Mostra elementi mobile */
  .mobile-day-nav    { display:flex !important; }
  .mobile-bottom-bar { display:flex !important; }

  /* Header semplificato */
  .hdr-period { display:none; }
  #btn-stampa { display:none; }
  .app-title  { font-size:15px; }
  .user-badge { display:none; }

  /* Sidebar nascosta — accessibile dal menu */
  .app-sidebar { display:none !important; }

  /* .app e .app-body restano overflow:hidden (contenitore 100vh).
     Il bottom bar e' fuori da #app quindi position:fixed funziona. */
  .app-main {
    flex:1; overflow:auto;
    -webkit-overflow-scrolling:touch;
    /* Spazio per la bottom bar fissa in fondo */
    padding-bottom:calc(62px + env(safe-area-inset-bottom, 0px));
  }

  /* Calendario: larghezza e grid-template-columns impostati via JS (multi-settimana) */
  .cal-wrap   { min-width:0; }

  /* Colonna ore sticky a sinistra (con prefisso webkit per iOS) */
  .cal-time-col {
    position:-webkit-sticky; position:sticky;
    left:0; z-index:3; background:var(--surface);
  }
  .cal-th-time {
    position:-webkit-sticky; position:sticky;
    left:0; z-index:7; background:var(--surface);
  }

  /* Intestazioni giorni compatte */
  .cal-th-day     { padding:5px 1px; }
  .cal-th-dayname { font-size:9px; }
  .cal-th-daynum  { font-size:15px; width:26px; height:26px; margin-top:1px; }

  /* Etichette ore compatte */
  .cal-lbl { font-size:9px; right:2px; }

  /* Appuntamenti compatti */
  .cal-app-nome  { font-size:11px; }
  .cal-app-time  { font-size:10px; }
  .cal-app-esame { display:none; }

  /* Dropdown non tagliato fuori schermo */
  /* Su mobile: menu fisso in basso sopra la bottom bar */
  .menu-dropdown {
    position: fixed !important;
    left: 0 !important; right: 0 !important;
    bottom: calc(62px + env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    width: 100% !important; min-width: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    z-index: 10000 !important;
    box-shadow: 0 -4px 24px rgba(0,0,0,.15) !important;
  }

  /* Modal: sale dal basso a schermo pieno */
  .modal-overlay { padding:0 !important; align-items:flex-end !important; }
  .modal         { border-radius:16px 16px 0 0; max-height:92vh; width:100% !important; max-width:100% !important; }
  .modal-body    { overflow-y:auto; max-height:60vh; }
  .arch-modal    { border-radius:16px 16px 0 0; }

  /* Safe area iPhone X+: evita che la barra home copra il footer */
  .modal-ftr { padding-bottom:calc(12px + env(safe-area-inset-bottom, 0px)) !important; }

  /* iOS fix: quando JS imposta l'altezza dell'overlay via visualViewport,
     il modal usa % invece di vh così il footer resta sempre visibile */
  .modal-overlay[data-vv] .modal      { max-height:98% !important; }
  .modal-overlay[data-vv] .modal-body { max-height:calc(100% - 140px) !important; }
}
