/* === RESET & ROOT === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sabbia:       #EDE4D8;
  --sabbia-light: #FAF7F3;
  --terra:        #C18465;
  --terra-dark:   #A85D3A;
  --salvia:       #8A9A7B;
  --salvia-dark:  #5F6E50;
  --oro:          #B8923E;
  --dark:         #2D1F0F;
  --text:         #3A2A1A;
  --text-muted:   #9A8A7A;
  --white:        #FFFFFF;
  --border:       #E8DFD5;

  --sidebar-w:  240px;
  --topbar-h:   60px;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 1px 3px rgba(45,31,15,.07), 0 4px 16px rgba(45,31,15,.05);
  --shadow-lg:  0 8px 40px rgba(45,31,15,.18);
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  color: var(--text);
  background: var(--sabbia-light);
  line-height: 1.5;
}

/* === LAYOUT === */
#app { display: flex; height: 100vh; }

/* === SIDEBAR === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--dark);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo img { width: 34px; height: 34px; object-fit: contain; }
.sidebar-logo-text { display: flex; flex-direction: column; line-height: 1.3; }
.sidebar-logo-name { font-family: 'Fraunces', serif; font-size: 15px; color: var(--sabbia); }
.sidebar-logo-sub  { font-size: 10px; color: var(--terra); text-transform: uppercase; letter-spacing: .08em; }

.sidebar-nav {
  list-style: none;
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-nav .nav-sep {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.22);
  padding: 10px 10px 3px;
}
.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.58);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .13s, color .13s;
}
.sidebar-nav li a:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.88); }
.sidebar-nav li a.active { background: rgba(193,132,101,.18); color: var(--sabbia); }
.sidebar-nav li a .ti { font-size: 17px; flex-shrink: 0; color: var(--terra); opacity: .8; }
.sidebar-nav li a.active .ti { opacity: 1; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-clock { font-size: 19px; font-weight: 600; color: var(--sabbia); font-variant-numeric: tabular-nums; }
.sidebar-version { font-size: 10px; color: rgba(255,255,255,.18); }

/* === MAIN === */
.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 26px;
  flex-shrink: 0;
}
.topbar-title    { font-size: 17px; font-weight: 600; }
.topbar-subtitle { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.topbar-actions  { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.mobile-menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 34px; height: 34px; flex-shrink: 0;
  background: none; border: none; border-radius: var(--radius-sm);
  color: var(--text); font-size: 20px; cursor: pointer;
}
.mobile-menu-btn:hover { background: var(--sabbia-light); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 499;
  background: rgba(0,0,0,.4);
}
.sidebar-backdrop.open { display: block; }

.view-container { flex: 1; overflow-y: auto; padding: 24px; }

/* === CARDS === */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.card-title .ti { color: var(--terra); font-size: 17px; }

/* === STATS === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--terra); }
.stat-card.green::before  { background: var(--salvia); }
.stat-card.gold::before   { background: var(--oro); }
.stat-card.purple::before { background: #6366F1; }
.stat-label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--text); }
.stat-sub   { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-icon  { position: absolute; right: 14px; top: 14px; font-size: 26px; color: var(--sabbia); }

/* === GRID LAYOUTS === */
.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-21  { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-12  { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .14s;
  text-decoration: none;
  white-space: nowrap;
}
.btn .ti { font-size: 15px; }
.btn-primary   { background: var(--terra); color: #fff; }
.btn-primary:hover { background: var(--terra-dark); }
.btn-secondary { background: var(--sabbia); color: var(--text); }
.btn-secondary:hover { background: #E2D8CC; }
.btn-danger    { background: #FEE2E2; color: #B91C1C; }
.btn-danger:hover { background: #FECACA; }
.btn-success   { background: #D1FAE5; color: #065F46; }
.btn-success:hover { background: #A7F3D0; }
.btn-ghost     { background: transparent; color: var(--text-muted); padding: 6px 10px; }
.btn-ghost:hover { background: var(--sabbia); color: var(--text); }
.btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--terra); color: var(--terra); }
.btn-sm  { padding: 4px 10px; font-size: 12px; }
.btn-sm .ti { font-size: 13px; }
.btn-lg  { padding: 10px 20px; font-size: 14.5px; }
.btn-icon { padding: 6px; min-width: 28px; min-height: 28px; }
/* Sfondo/bordo sempre visibili sui pulsanti solo-icona: se il font delle
   icone (CDN esterno) non si carica in rete, restano comunque visibili e
   cliccabili invece di sparire come riquadri trasparenti invisibili. */
.btn-ghost.btn-icon { background: var(--sabbia-light); border: 1px solid var(--border); }
.btn-ghost.btn-icon:hover { background: var(--sabbia); border-color: var(--terra); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.w-full { width: 100%; justify-content: center; }

/* === BADGES === */
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-attesa    { background: #FEF3C7; color: #92400E; }
.badge-confermata{ background: #D1FAE5; color: #065F46; }
.badge-completata{ background: #EDE9FE; color: #4338CA; }
.badge-disdetta  { background: #FEE2E2; color: #B91C1C; }
.badge-modificata{ background: #DBEAFE; color: #1E40AF; }

/* === TABLE === */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--border); }
.data-table th {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  background: var(--sabbia-light); white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--sabbia-light); cursor: pointer; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .acts { display: flex; gap: 3px; }

/* === FORMS === */
.form-group { margin-bottom: 14px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=time], input[type=password], select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px; color: var(--text);
  background: var(--white);
  transition: border-color .14s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(193,132,101,.1);
}
textarea { resize: vertical; min-height: 76px; }
.input-hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check input[type=checkbox] { width: auto; accent-color: var(--terra); cursor: pointer; }
/* Checkbox di selezione multipla nelle liste (Clienti) */
input.cli-sel { width: auto; accent-color: var(--terra); cursor: pointer; flex-shrink: 0; }

/* === SEARCH BAR === */
.search-bar { position: relative; display: inline-flex; align-items: center; }
.search-bar input { padding-left: 34px; min-width: 240px; }
.search-bar .ti { position: absolute; left: 9px; color: var(--text-muted); font-size: 15px; pointer-events: none; }

/* === TOOLBAR === */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }

/* === EMPTY STATE === */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 50px 20px; color: var(--text-muted); text-align: center;
}
.empty-state .ti { font-size: 38px; margin-bottom: 10px; color: var(--sabbia); }
.empty-state h3  { font-size: 15px; margin-bottom: 5px; color: var(--text); }
.empty-state p   { font-size: 13px; }

/* === CALENDAR === */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.cal-month  { font-size: 17px; font-weight: 600; font-family: 'Fraunces', serif; }
.cal-grid   { width: 100%; border-collapse: collapse; }
.cal-grid th {
  font-size: 10.5px; font-weight: 700; text-align: center;
  padding: 5px 4px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.cal-grid td {
  border: 1px solid var(--border);
  padding: 5px 6px;
  vertical-align: top;
  cursor: pointer;
  transition: background .1s;
  height: 76px;
  width: calc(100%/7);
}
.cal-grid td:hover         { background: var(--sabbia-light); }
.cal-grid td.other-month .cal-day-num { color: #CCC; }
.cal-grid td.today .cal-day-num {
  background: var(--terra); color: #fff; border-radius: 50%;
  width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center;
}
.cal-grid td.selected { background: rgba(193,132,101,.07); outline: 2px solid var(--terra); outline-offset: -2px; }
.cal-day-num  { font-size: 12px; font-weight: 600; display: inline-block; min-width: 24px; text-align: center; }
.cal-dots     { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.cal-dot      { width: 7px; height: 7px; border-radius: 50%; }
.cal-pren-mini { font-size: 10px; background: rgba(193,132,101,.12); border-radius: 3px; padding: 1px 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === CAL DAY PANEL === */
.cal-day-panel { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.cal-day-panel-title {
  font-size: 15px; font-weight: 600; margin-bottom: 14px;
  padding-bottom: 11px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

/* === TIME SLOTS === */
.time-slot { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.time-slot:last-child { border-bottom: none; }
.time-slot-time { font-size: 12px; font-weight: 700; color: var(--terra); min-width: 38px; font-variant-numeric: tabular-nums; }
.time-slot-card {
  flex: 1; background: var(--sabbia-light); border-radius: var(--radius-sm);
  padding: 7px 9px; border-left: 3px solid var(--terra);
}
.time-slot-card.confermata { border-left-color: #10B981; }
.time-slot-card.completata { border-left-color: #6366F1; }
.time-slot-card.disdetta   { border-left-color: #EF4444; opacity: .55; }
.time-slot-client  { font-weight: 600; font-size: 12.5px; }
.time-slot-service { font-size: 11.5px; color: var(--text-muted); }
.time-slot-meta    { display: flex; gap: 6px; margin-top: 3px; align-items: center; flex-wrap: wrap; }
.op-pill { display: inline-flex; align-items: center; gap: 3px; background: var(--sabbia); border-radius: 10px; padding: 1px 6px; font-size: 11px; font-weight: 500; }
.op-dot  { width: 7px; height: 7px; border-radius: 50%; }

/* === MODAL === */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 200; backdrop-filter: blur(2px); }
.modal-container { position: fixed; inset: 0; z-index: 201; display: flex; align-items: center; justify-content: center; padding: 20px; pointer-events: none; }
.modal-container:not(.hidden) { pointer-events: auto; }
.modal-box {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-width: 600px; width: 100%;
  max-height: 92vh; overflow-y: auto;
  animation: modal-in .18s ease;
}
.modal-box.wide { max-width: 820px; }
@keyframes modal-in { from { transform: translateY(-16px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 21px; line-height: 1; padding: 2px; border-radius: 4px; }
.modal-close:hover { background: var(--sabbia-light); }
.modal-body   { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* === TOAST === */
.toast-container { position: fixed; bottom: 22px; right: 22px; z-index: 300; display: flex; flex-direction: column; gap: 7px; }
.toast {
  background: var(--dark); color: #fff; padding: 11px 15px;
  border-radius: var(--radius-sm); font-size: 13px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px;
  animation: toast-in .22s ease; min-width: 240px; max-width: 340px;
}
.toast.success { border-left: 3px solid #10B981; }
.toast.error   { border-left: 3px solid #EF4444; }
.toast.warning { border-left: 3px solid #F59E0B; }
.toast .ti     { font-size: 15px; flex-shrink: 0; }
.toast.success .ti { color: #10B981; }
.toast.error   .ti { color: #EF4444; }
.toast.warning .ti { color: #F59E0B; }
@keyframes toast-in { from { transform: translateX(36px); opacity: 0; } to { transform: none; opacity: 1; } }

/* === TABS === */
.tabs-header { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 18px; gap: 2px; }
.tab-btn { padding: 9px 16px; font-size: 13px; font-weight: 500; color: var(--text-muted); cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .14s; }
.tab-btn.active  { color: var(--terra); border-bottom-color: var(--terra); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-panel       { display: none; }
.tab-panel.active{ display: block; }

/* === AVATAR === */
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; color: #fff; flex-shrink: 0; }
.avatar-lg { width: 48px; height: 48px; font-size: 17px; }

/* === AGENDA === */
.agenda-item { display: flex; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.agenda-item:last-child { border-bottom: none; }
.agenda-time  { font-size: 13px; font-weight: 700; color: var(--terra); min-width: 42px; font-variant-numeric: tabular-nums; }
.agenda-info  { flex: 1; }
.agenda-client  { font-weight: 600; font-size: 13px; }
.agenda-service { font-size: 11.5px; color: var(--text-muted); }
.agenda-meta    { display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }

/* === RICHIESTE DAL SITO (Prenotazioni) === */
.richiesta-sito-row { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); }
.richiesta-sito-row + .richiesta-sito-row { margin-top: 8px; }
.rs-data-badge { flex-shrink: 0; width: 54px; text-align: center; background: var(--sabbia-light); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 4px; }
.rs-giorno { font-size: 20px; font-weight: 800; color: var(--terra-dark); line-height: 1.05; }
.rs-mese   { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin-top: 1px; }
.rs-ora-badge { flex-shrink: 0; font-size: 15px; font-weight: 800; color: #fff; background: var(--terra); border-radius: var(--radius-sm); padding: 7px 10px; font-variant-numeric: tabular-nums; min-width: 56px; text-align: center; }
.rs-info { flex: 1; min-width: 0; }

/* === CLIENT LIST === */
.client-row { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.client-meta { font-size: 12px; color: var(--text-muted); text-align: right; min-width: 120px; }
.client-row:last-child { border-bottom: none; }
.client-info  { flex: 1; min-width: 0; }
.client-name  { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-sub   { font-size: 11.5px; color: var(--text-muted); }
.client-acts  { display: flex; gap: 3px; flex-shrink: 0; }

/* === SERVICE ITEMS === */
.service-item { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.service-item:last-child { border-bottom: none; }
.service-name  { font-weight: 500; font-size: 13px; }
.service-meta  { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.service-price { font-weight: 700; font-size: 14px; color: var(--terra); white-space: nowrap; }
.service-acts  { display: flex; gap: 3px; flex-shrink: 0; }

.cat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 6px; border-bottom: 2px solid var(--sabbia); margin-bottom: 4px; margin-top: 18px; }
.cat-header:first-child { margin-top: 0; }
.cat-title { font-size: 13px; font-weight: 700; color: var(--terra); display: flex; align-items: center; gap: 6px; }

/* === OFFER CARDS === */
.offers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.offer-card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.offer-badge { background: var(--terra); color: #fff; font-size: 10.5px; font-weight: 700; padding: 5px 12px; display: flex; align-items: center; gap: 5px; }
.offer-badge.expired { background: var(--text-muted); }
.offer-body  { padding: 14px; flex: 1; }
.offer-title { font-size: 14.5px; font-weight: 600; margin-bottom: 4px; font-family: 'Fraunces', serif; }
.offer-desc  { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; }
.offer-prices { display: flex; align-items: baseline; gap: 7px; }
.offer-price-new { font-size: 22px; font-weight: 700; color: var(--terra-dark); }
.offer-price-old { font-size: 15px; color: var(--text-muted); text-decoration: line-through; }
.offer-save      { font-size: 11px; background: #D1FAE5; color: #065F46; padding: 2px 7px; border-radius: 10px; font-weight: 600; }
.offer-footer    { padding: 10px 14px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--text-muted); }
.offer-image     { width: 100%; height: 120px; object-fit: cover; display: block; background: var(--sabbia-light); }
.offer-bundle-list { font-size: 11.5px; color: var(--text-muted); margin: 2px 0 8px 16px; }
.offer-bundle-list li { margin-bottom: 2px; }
.img-upload-wrap { display: flex; align-items: center; gap: 10px; }
.img-upload-preview { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; background: var(--sabbia-light); border: 1px solid var(--border); flex-shrink: 0; }

/* === COMMUNICATIONS === */
.email-preview { border: 1.5px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.email-preview-header { background: var(--sabbia-light); padding: 10px 14px; font-size: 12px; border-bottom: 1px solid var(--border); }
.email-preview-body   { padding: 14px; font-size: 13px; line-height: 1.65; white-space: pre-wrap; min-height: 80px; }
.progress-wrap { background: var(--sabbia); border-radius: 8px; height: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--terra); border-radius: 8px; transition: width .3s; }
.send-log-row  { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.send-log-row:last-child { border-bottom: none; }

/* === BIRTHDAY === */
.bday-alert { background: linear-gradient(135deg,#FEF3C7,#FDE68A); border: 1px solid #F59E0B; border-radius: var(--radius-sm); padding: 9px 13px; display: flex; align-items: center; gap: 9px; font-size: 13px; margin-bottom: 8px; }
.bday-alert .ti { color: #B45309; font-size: 18px; flex-shrink: 0; }
.bday-pill { display: inline-flex; align-items: center; gap: 3px; background: linear-gradient(135deg,var(--oro),#D4A853); color: #fff; border-radius: 20px; padding: 2px 7px; font-size: 10.5px; font-weight: 700; }

/* === SETTINGS === */
.settings-section { margin-bottom: 26px; }
.settings-section h3 { font-size: 13.5px; font-weight: 700; margin-bottom: 14px; padding-bottom: 7px; border-bottom: 2px solid var(--sabbia); display: flex; align-items: center; gap: 6px; }
.settings-section h3 .ti { color: var(--terra); font-size: 16px; }
.op-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.op-item:last-child { border-bottom: none; }
.op-color { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(0,0,0,.1); cursor: pointer; flex-shrink: 0; }
.orario-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.orario-row:last-child { border-bottom: none; }
.orario-label { width: 40px; font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--text-muted); }

/* === SWITCH === */
.switch { position: relative; display: inline-block; width: 38px; height: 21px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; inset: 0; background: var(--border); border-radius: 21px; cursor: pointer; transition: background .18s; }
.switch-track::after { content: ''; position: absolute; left: 2px; top: 2px; width: 17px; height: 17px; background: #fff; border-radius: 50%; transition: transform .18s; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.switch input:checked + .switch-track { background: var(--terra); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }

/* === MISC === */
.divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 11.5px; }
.text-right  { text-align: right; }
.hidden      { display: none !important; }
.flex        { display: flex; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.fw-600 { font-weight: 600; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--sabbia); border-top-color: var(--terra); border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #DDD; border-radius: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); }

/* === AUTOCOMPLETE === */
.autocomplete-list { position: absolute; z-index: 100; background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 200px; overflow-y: auto; width: 100%; top: 100%; left: 0; }
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.autocomplete-item:hover { background: var(--sabbia-light); }
.autocomplete-wrap { position: relative; }

/* === TIME PICKER GRID === */
.time-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.time-btn { padding: 5px 2px; border: 1.5px solid var(--border); border-radius: 6px; background: #fff; font-size: 11.5px; cursor: pointer; text-align: center; transition: all .12s; color: var(--text); }
.time-btn:hover   { border-color: var(--terra); color: var(--terra); }
.time-btn.selected{ background: var(--terra); color: #fff; border-color: var(--terra); }
.time-btn.busy    { background: var(--sabbia-light); color: var(--text-muted); border-color: var(--border); cursor: not-allowed; text-decoration: line-through; }

/* Cliente detail */
.scheda-header { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.scheda-info h2 { font-size: 20px; font-weight: 600; font-family: 'Fraunces', serif; }
.scheda-info p  { font-size: 12.5px; color: var(--text-muted); }
.scheda-stats   { display: flex; gap: 20px; margin-top: 6px; }
.scheda-stat    { text-align: center; }
.scheda-stat strong { display: block; font-size: 18px; font-weight: 700; color: var(--terra); }
.scheda-stat span   { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; }
.tag { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; background: var(--sabbia); border-radius: 20px; font-size: 11.5px; color: var(--text-muted); }

/* === LOGIN / SETUP === */
#login-overlay, #setup-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(150deg, #2D1F0F 0%, #4A3020 60%, #3A2510 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  overflow-y: auto;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 36px 40px;
  max-width: 400px; width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.15);
}
.login-logo  { width: 62px; height: 62px; object-fit: contain; display: block; margin: 0 auto 12px; }
.login-title { font-family: 'Fraunces', serif; font-size: 23px; font-weight: 600; text-align: center; color: #2D1F0F; }
.login-sub   { font-size: 13px; color: #9A8A7A; text-align: center; margin: 4px 0 24px; }

/* === RESPONSIVE === */

/* Sidebar a scomparsa fino a 1024px: include l'iPad in verticale (820-1024px),
   dove una sidebar fissa da 240px lascerebbe ~580px di contenuto — troppo
   stretto per tabelle e form. In orizzontale (1180px+) resta sempre visibile. */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 500;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: flex; }
  /* Layout asimmetrici: su tablet le colonne strette diventano inutilizzabili */
  .grid-21, .grid-12 { grid-template-columns: 1fr; }
}

/* iPad verticale (stats-grid a 2 colonne è già gestito dalla regola a 1100px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .view-container { padding: 26px 30px; }
  .modal-box { max-width: 92vw; }
  .modal-box.wide { max-width: 92vw; }
}

/* Tablet piccoli e telefoni */
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* === TELEFONO (iPhone) === */
@media (max-width: 640px) {
  .view-container { padding: 16px 14px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .card { padding: 16px; }
  .modal-body { padding: 16px; }
  .modal-header, .modal-footer { padding-left: 16px; padding-right: 16px; }

  /* Riga cliente su due livelli: con visite + 3 pulsanti sulla stessa riga
     il nome/telefono restava schiacciato a 0px e diventava invisibile. */
  .client-row { flex-wrap: wrap; row-gap: 8px; }
  .client-info { flex: 1 1 150px; }
  .client-meta { flex: 1 1 auto; text-align: left; }
  .client-acts { margin-left: auto; }

  /* Ricerca a tutta larghezza, pulsanti che si dividono la riga sotto */
  .toolbar > .search-bar { flex: 1 1 100%; }
  .search-bar input { min-width: 0; width: 100%; }
  .toolbar-right { margin-left: 0; flex: 1 1 100%; }
  .toolbar-right .btn { flex: 1 1 auto; justify-content: center; }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  /* Le schede con molti tab (Comunicazioni ne ha 5) scorrono in orizzontale
     invece di accavallarsi su più righe */
  .tabs-header { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs-header::-webkit-scrollbar { display: none; }
  .tab-btn { flex: 0 0 auto; white-space: nowrap; }

  /* Campi affiancati: a ~130px una data non ci sta per intero */
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .time-grid { grid-template-columns: repeat(4, 1fr); }
  .scheda-header { flex-wrap: wrap; }

  /* Notifiche a tutta larghezza, sopra la barra home dell'iPhone */
  .toast-container { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; max-width: none; }
}

/* Barra home / notch: env() vale 0 dove non serve, quindi è innocuo altrove */
.sidebar { padding-bottom: env(safe-area-inset-bottom); }

/* === TOUCH (iPad / iPhone) ===
   Si attiva sui dispositivi senza mouse, a qualunque larghezza: un iPad in
   orizzontale è largo come un desktop ma si usa con le dita. */
@media (pointer: coarse) {
  /* CRITICO: sotto i 16px iOS Safari ingrandisce la pagina a ogni tap su un
     campo, e resta zoomata. Non toccare questo valore. */
  input[type=text], input[type=email], input[type=tel], input[type=number],
  input[type=date], input[type=time], input[type=password], select, textarea {
    font-size: 16px;
    padding: 11px 13px;
  }
  .search-bar input { padding-left: 38px; }
  .search-bar .ti { font-size: 17px; left: 12px; }

  /* Aree toccabili: minimo ~44px (linee guida Apple) */
  .btn { min-height: 44px; padding: 10px 18px; font-size: 14px; }
  .btn-sm { min-height: 38px; padding: 8px 13px; font-size: 13px; }
  .btn-icon, .btn-sm.btn-icon { min-width: 44px; min-height: 44px; padding: 8px; }
  .btn-icon .ti, .btn-sm.btn-icon .ti { font-size: 18px; }
  .tab-btn { min-height: 46px; padding: 12px 18px; font-size: 14px; }
  .sidebar-nav li a { padding: 13px 12px; font-size: 14.5px; }
  .modal-close { min-width: 44px; min-height: 44px; font-size: 24px; }
  .time-btn { min-height: 44px; font-size: 13.5px; padding: 10px 4px; }
  .cal-grid td { height: 92px; }
  .agenda-item, .client-row { padding: 13px 0; }

  /* Checkbox e switch: da 13px sono impossibili da centrare col dito */
  .form-check input[type=checkbox], input.cli-sel { width: 22px; height: 22px; }
  .form-check { gap: 11px; }
  .switch { width: 46px; height: 26px; }
  .switch-track::after { width: 22px; height: 22px; }
  .switch input:checked + .switch-track::after { transform: translateX(20px); }

  /* Il modal non deve trascinare la pagina sotto quando finisce lo scroll */
  .modal-box { overscroll-behavior: contain; }
}

/* === HOVER SOLO CON IL MOUSE ===
   Su touch il :hover resta "appiccicato" dopo il tap finché non si tocca
   altrove: righe e celle restano evidenziate a caso. */
@media (hover: none) {
  .data-table tbody tr:hover { background: transparent; }
  .cal-grid td:hover:not(.selected) { background: transparent; }
  .sidebar-nav li a:hover:not(.active) { background: transparent; color: rgba(255,255,255,.58); }
  .btn-ghost.btn-icon:hover { background: var(--sabbia-light); border-color: var(--border); }
  .modal-close:hover { background: none; }
}
