/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f8fafc; color: #111; font-size: 15px; }

/* ===== TOPBAR ===== */
.topbar { background: white; border-bottom: 1px solid #e5e7eb; padding: 0 32px; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.top-brand { display: flex; align-items: center; gap: 10px; }
.top-logo { width: 36px; height: 36px; background: #1a3a6b; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: white; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.top-logo-img { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; flex-shrink: 0; }
.top-name { font-size: 14px; font-weight: 500; color: #111; }
.steps-bar { display: flex; align-items: center; }
.step-dot { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; border: 2px solid #d1d5db; color: #9ca3af; background: white; flex-shrink: 0; transition: all .2s; }
.step-dot.done { background: #2563eb; border-color: #2563eb; color: white; }
.step-dot.active { background: #2563eb; border-color: #2563eb; color: white; }
.step-line { width: 40px; height: 2px; background: #e5e7eb; transition: background .2s; }
.step-line.done { background: #2563eb; }

/* ===== LAYOUT ===== */
.portal-body { display: flex; gap: 24px; padding: 28px 32px; max-width: 1100px; margin: 0 auto; align-items: flex-start; }
.main-col { flex: 1; min-width: 0; }
.side-col { width: 280px; flex-shrink: 0; position: sticky; top: 72px; }
.page { display: none; }
.page.active { display: block; }

/* ===== TABS ===== */
.tabs { display: flex; border-bottom: 2px solid #e5e7eb; margin-bottom: 20px; }
.tab { padding: 10px 18px; font-size: 14px; cursor: pointer; color: #6b7280; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 500; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== SERVIZI ===== */
.service-item { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 16px 18px; display: flex; align-items: center; gap: 14px; cursor: pointer; margin-bottom: 10px; transition: border-color .15s, box-shadow .15s; }
.service-item:hover { border-color: #2563eb; box-shadow: 0 2px 8px rgba(37,99,235,.08); }
.svc-icon { width: 44px; height: 44px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.svc-info { flex: 1; min-width: 0; }
.svc-name { font-size: 14px; font-weight: 500; color: #111; }
.svc-meta { font-size: 12px; color: #6b7280; margin-top: 2px; }
.svc-desc { font-size: 12px; color: #6b7280; margin-top: 5px; line-height: 1.45; }
.prenota-btn { padding: 9px 20px; background: #2563eb; color: white; border: none; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; flex-shrink: 0; letter-spacing: .03em; transition: background .15s; }
.prenota-btn:hover { background: #1d4ed8; }

/* ===== INFO ===== */
.info-section { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 18px; margin-bottom: 12px; }
.info-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.info-section p { font-size: 13px; color: #374151; }
.info-section p.link { color: #2563eb; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-row { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0; border-bottom: 1px solid #f3f4f6; color: #374151; }
.info-row:last-child { border-bottom: none; }

/* ===== INDIRIZZO + MAPPA ===== */
.address-wrap { display: flex; gap: 14px; align-items: flex-start; }
.address-left { flex: 1; min-width: 0; }
.address-nav-link {
  display: inline-flex; align-items: flex-start; gap: 7px;
  color: #2563eb; text-decoration: none; font-size: 13px; font-weight: 500;
  line-height: 1.45; transition: color .15s;
}
.address-nav-link:hover { color: #1d4ed8; text-decoration: underline; }
.address-pin { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.address-nav-hint { font-size: 11px; color: #9ca3af; margin-top: 5px; margin-left: 22px; }
.address-map-wrap {
  position: relative; width: 180px; height: 130px;
  flex-shrink: 0; border-radius: 10px; overflow: hidden;
  border: 1px solid #e5e7eb;
}
.address-map-frame { width: 100%; height: 100%; border: none; display: block; }
.address-map-consent {
  width: 100%; height: 100%; padding: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; background: #f8fafc; text-align: center;
}
.address-map-icon { font-size: 18px; line-height: 1; }
.address-map-consent p { margin: 0; color: #64748b; font-size: 10px; line-height: 1.25; }
.address-map-load {
  border: 0; border-radius: 6px; padding: 5px 9px;
  background: #1a3a6b; color: white; font-size: 10px; font-weight: 600;
  cursor: pointer;
}
.address-map-load:hover { background: #10294f; }
.address-map-load:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.address-map-external {
  color: #2563eb; font-size: 10px; line-height: 1.2; text-decoration: none;
}
.address-map-external:hover { text-decoration: underline; }
.address-map-unload {
  position: absolute; top: 5px; right: 5px; z-index: 2;
  width: 24px; height: 24px; border: 1px solid #cbd5e1; border-radius: 50%;
  background: rgba(255,255,255,.95); color: #334155; line-height: 20px;
  font-size: 16px; cursor: pointer;
}
.address-map-unload:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

/* ===== SELETTORE OPERATORE ===== */
.staff-selector-wrap {
  background: white; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 14px 16px; margin-bottom: 14px;
}
.staff-selector-label { font-size: 12px; font-weight: 500; color: #6b7280; margin-bottom: 10px; }
.staff-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.staff-chip {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 13px 6px 6px;
  border: 1.5px solid #e5e7eb; border-radius: 24px;
  cursor: pointer; font-size: 13px; color: #374151;
  transition: border-color .15s, background .15s;
  user-select: none; white-space: nowrap;
}
.staff-chip:hover { border-color: #2563eb; }
.staff-chip.active { border-color: #2563eb; background: #eff6ff; color: #1d4ed8; font-weight: 500; }
.staff-chip-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 10px; flex-shrink: 0;
}

/* ===== NAVIGAZIONE ===== */
.back-link { font-size: 13px; color: #6b7280; cursor: pointer; margin-bottom: 16px; display: inline-flex; align-items: center; gap: 4px; }
.back-link:hover { color: #2563eb; }
.page-title { font-size: 22px; font-weight: 600; color: #111; margin-bottom: 20px; }

/* ===== CALENDARIO ===== */
.cal-box { background: white; border: 1px solid #e5e7eb; border-radius: 10px; overflow: hidden; }
.cal-split { display: flex; }
.cal-left { flex: 1; padding: 18px; border-right: 1px solid #e5e7eb; }
.cal-right { width: 230px; padding: 18px; }
.cal-nav-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-nav-btn { background: none; border: 1px solid #e5e7eb; border-radius: 6px; width: 28px; height: 28px; cursor: pointer; font-size: 16px; color: #374151; line-height: 1; }
.cal-nav-btn:hover { background: #f9fafb; }
.cal-month-lbl { font-size: 14px; font-weight: 500; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-lbl { text-align: center; font-size: 11px; color: #9ca3af; padding: 4px 0; font-weight: 500; }
.cal-d { text-align: center; padding: 7px 2px; font-size: 13px; border-radius: 50%; cursor: pointer; color: #111; transition: background .1s; }
.cal-d:hover:not(.other):not(.disabled) { background: #f3f4f6; }
.cal-d.other { color: #d1d5db; cursor: default; pointer-events: none; }
.cal-d.today { border: 1.5px solid #2563eb; color: #2563eb; }
.cal-d.selected { background: #2563eb !important; color: white !important; border: none; }
.cal-d.disabled { color: #d1d5db; cursor: default; pointer-events: none; }
.time-title { font-size: 13px; font-weight: 500; margin-bottom: 12px; color: #374151; }
.time-pill { display: inline-block; padding: 7px 13px; border: 1px solid #e5e7eb; border-radius: 20px; font-size: 13px; cursor: pointer; margin: 0 5px 8px 0; color: #111; background: white; transition: all .15s; }
.time-pill:hover { border-color: #2563eb; color: #2563eb; }
.time-pill.selected { background: #2563eb; color: white; border-color: #2563eb; }
.no-slots { font-size: 13px; color: #9ca3af; margin-top: 8px; }

/* ===== FORM ===== */
.form-card { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 20px; margin-bottom: 12px; }
.form-card-title { font-size: 15px; font-weight: 600; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #f3f4f6; display: flex; justify-content: space-between; align-items: center; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-row.single { grid-template-columns: 1fr; }
.fgrp { display: flex; flex-direction: column; gap: 4px; }
.fgrp label { font-size: 12px; color: #6b7280; }
.fgrp input, .fgrp textarea { width: 100%; padding: 9px 11px; border: 1px solid #e5e7eb; border-radius: 7px; font-size: 14px; color: #111; background: white; font-family: inherit; transition: border-color .15s; }
.fgrp input:focus, .fgrp textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.fgrp textarea { resize: vertical; min-height: 80px; }
.hp-field { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.note-toggle { font-size: 13px; color: #2563eb; cursor: pointer; font-weight: 400; }
.policy-text { font-size: 13px; color: #374151; line-height: 1.6; }
.form-error { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; border-radius: 7px; padding: 10px 14px; font-size: 13px; margin-top: 10px; }

/* ===== SIDEBAR ===== */
.summary-box { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 18px; }
.sum-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f3f4f6; }
.sum-icon { width: 40px; height: 40px; border-radius: 8px; background: #e0e7ff; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.org-icon { background: #1a3a6b; color: white; font-size: 11px; font-weight: 700; }
.svc-icon-sm { background: #e0e7ff; }
.sum-text { font-size: 13px; font-weight: 500; color: #111; }
.sum-sub { font-size: 12px; color: #6b7280; margin-top: 2px; line-height: 1.4; }
.sum-total { display: flex; justify-content: space-between; padding: 14px 0 12px; }
.sum-total-lbl { font-size: 14px; font-weight: 600; }
.sum-total-val { font-size: 14px; font-weight: 600; color: #6b7280; }
.confirm-btn { width: 100%; padding: 12px; background: #2563eb; color: white; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; text-transform: uppercase; letter-spacing: .06em; transition: background .15s; }
.confirm-btn:hover:not(:disabled) { background: #1d4ed8; }
.confirm-btn:disabled { background: #93c5fd; cursor: not-allowed; }

/* ===== CONFERMA ===== */
.success-box, .error-box { background: white; border: 1px solid #e5e7eb; border-radius: 10px; padding: 40px; text-align: center; }
.success-icon { width: 64px; height: 64px; background: #dcfce7; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 0 auto 16px; color: #16a34a; }
.error-icon { width: 64px; height: 64px; background: #fef2f2; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 0 auto 16px; color: #dc2626; }
.success-title { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.success-sub { font-size: 14px; color: #6b7280; line-height: 1.6; margin-bottom: 20px; }
.success-detail { background: #f8fafc; border-radius: 8px; padding: 14px 18px; text-align: left; margin-bottom: 20px; }
.success-detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid #f3f4f6; font-size: 13px; }
.success-detail-row:last-child { border-bottom: none; }
.success-detail-row span:first-child { color: #6b7280; flex-shrink: 0; }
.success-detail-row span:last-child { font-weight: 500; text-align: right; }
.new-btn { padding: 10px 22px; background: #2563eb; color: white; border: none; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; }
.new-btn:hover { background: #1d4ed8; }
.loading-box { text-align: center; padding: 60px 20px; }
.spinner { width: 40px; height: 40px; border: 3px solid #e5e7eb; border-top-color: #2563eb; border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { color: #6b7280; font-size: 14px; }

/* ===== MOBILE BAR (barra fissa in basso su smartphone) ===== */
.mobile-bar {
  display: none; /* controllato via JS */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: 12px 16px;
  z-index: 300;
  align-items: center;
  gap: 12px;
  box-shadow: 0 -2px 16px rgba(0,0,0,.09);
}
.mobile-bar-text {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}
.mobile-bar-text strong { color: #111; font-weight: 600; }
.mobile-confirm-btn {
  flex-shrink: 0;
  padding: 12px 22px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.mobile-confirm-btn:not(:disabled):active { background: #1d4ed8; }
.mobile-confirm-btn:disabled { background: #93c5fd; cursor: not-allowed; }

/* ===== RESPONSIVE 768px ===== */
@media (max-width: 768px) {

  /* Topbar */
  .topbar { padding: 0 14px; height: 52px; }
  .top-name { font-size: 12px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .steps-bar { gap: 0; }
  .step-dot { width: 28px; height: 28px; font-size: 12px; }
  .step-line { width: 22px; }

  /* Layout principale */
  .portal-body {
    flex-direction: column;
    padding: 16px 14px 84px; /* spazio per barra fissa in basso */
    gap: 0;
    max-width: 100%;
  }
  .main-col { width: 100%; }

  /* Sidebar nascosta: rimpiazzata dalla barra mobile */
  .side-col { display: none !important; }

  /* Titoli pagina */
  .page-title { font-size: 18px; margin-bottom: 16px; }
  .back-link { min-height: 40px; padding: 8px 0; align-items: center; }

  /* ── Card servizi ── */
  .service-item { flex-wrap: wrap; gap: 10px; padding: 14px; align-items: flex-start; }
  .svc-info { flex: 1 1 calc(100% - 58px); }
  .prenota-btn {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    text-align: center;
    border-radius: 8px;
  }

  /* ── Calendario ── */
  .cal-box { border-radius: 10px; }
  .cal-split { flex-direction: column; }
  .cal-left { padding: 14px 10px; border-right: none; }
  .cal-right { width: 100%; border-top: 1px solid #e5e7eb; border-right: none; padding: 14px 10px; }

  /* Celle del calendario: touch target adeguato */
  .cal-grid { gap: 3px; }
  .cal-d {
    padding: 0;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border-radius: 8px;
  }
  .cal-lbl { padding: 4px 0 6px; font-size: 11px; }

  /* Pulsanti navigazione calendario */
  .cal-nav-btn { width: 38px; height: 38px; font-size: 18px; }
  .cal-month-lbl { font-size: 15px; }

  /* ── Slot orari: griglia 3 colonne ── */
  #time-slots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 4px;
  }
  .time-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 4px;
    margin: 0;
    text-align: center;
    border-radius: 10px;
    font-size: 14px;
  }

  /* ── Form ── */
  .form-card { padding: 16px; }
  .form-row { grid-template-columns: 1fr; gap: 10px; }
  .fgrp input, .fgrp textarea { font-size: 16px; /* evita zoom automatico su iOS */ padding: 11px; }

  /* ── Sezione info ── */
  .info-grid { grid-template-columns: 1fr; }

  /* ── Indirizzo + mappa ── */
  .address-wrap { flex-direction: column; }
  .address-map-wrap { width: 100%; height: 180px; }

  /* ── Riquadro conferma ── */
  .success-box, .error-box { padding: 28px 20px; }
  .success-icon, .error-icon { width: 56px; height: 56px; font-size: 24px; }
  .success-title { font-size: 18px; }
}

/* ===== RESPONSIVE 420px (schermi molto piccoli) ===== */
@media (max-width: 420px) {
  .top-name { display: none; } /* solo logo + steps su schermi mini */
  .step-dot { width: 26px; height: 26px; font-size: 11px; }
  .step-line { width: 14px; }
  #time-slots { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .time-pill { font-size: 13px; min-height: 42px; }
  .portal-body { padding: 12px 10px 84px; }
  .form-card { padding: 14px; }
}
