:root {
  --brand: #2d6a4f;
  --brand-dark: #1b4332;
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #2b2b28;
  --muted: #767268;
  --border: #e5e1d8;
  --danger: #b23a48;
  --warn: #b8860b;
}
* { box-sizing: border-box; }
body { margin:0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; }
.success { color: var(--brand-dark); min-height: 1.2em; font-weight: 600; }

.login-screen { min-height: 100vh; display:flex; align-items:center; justify-content:center; }
.login-card { background: var(--card); border:1px solid var(--border); border-radius:12px; padding:32px; width: 320px; display:flex; flex-direction:column; gap:14px; }
.login-card h1 { margin:0 0 6px; font-size:1.3rem; }
.login-card label { display:flex; flex-direction:column; gap:6px; font-size:0.9rem; font-weight:600; }

input, select, textarea {
  font: inherit; padding: 9px 10px; border-radius: 7px; border: 1px solid var(--border); background:#fff;
}
button { font: inherit; cursor: pointer; }
button.primary { background: var(--brand); color:#fff; border:none; padding: 10px 18px; border-radius: 8px; }
button.primary:hover { background: var(--brand-dark); }
button.ghost { background: transparent; border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; }
.ghost-link { margin-right: 12px; color: var(--brand-dark); font-size: 0.9rem; }

.admin-header { display:flex; align-items:center; justify-content:space-between; padding: 20px 24px; background: var(--brand-dark); color:#fff; }
.admin-header h1 { margin:0; font-size:1.2rem; }
.admin-header .ghost { color:#fff; border-color: rgba(255,255,255,0.4); }

.tabs { display:flex; gap:4px; padding: 12px 24px 0; background: var(--card); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-btn { background:none; border:none; padding: 10px 16px; border-bottom: 3px solid transparent; color: var(--muted); font-weight:600; }
.tab-btn.active { color: var(--brand-dark); border-color: var(--brand); }

.tab-panel { padding: 24px; max-width: 1100px; margin: 0 auto; }
#tab-services, #tab-appointments { max-width: 1600px; }
.panel-toolbar { display:flex; align-items:flex-end; gap:16px; margin-bottom:16px; }
.panel-toolbar label { display:flex; flex-direction:column; gap:4px; font-size:0.85rem; font-weight:600; }

.table-wrap { overflow-x:auto; background: var(--card); border:1px solid var(--border); border-radius: 12px; }
table { width:auto; min-width:100%; border-collapse: collapse; font-size:0.9rem; }
th, td { text-align:left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.wrap-text { white-space: normal; max-width: 240px; }
#servicesTable td.wrap-text { max-width: 420px; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight:700; text-transform: capitalize; }
.badge.pending { background:#fff4e0; color: var(--warn); }
.badge.accepted { background:#e6f4ea; color: var(--brand-dark); }
.badge.declined { background:#fbe9eb; color: var(--danger); }
.badge.cancelled { background:#efefef; color: var(--muted); }
.badge.reschedule_pending { background:#eef1fb; color:#3949ab; }

.row-actions { display:flex; gap:6px; flex-wrap:nowrap; }
.row-actions button { padding: 6px 10px; border-radius:6px; border:1px solid var(--border); background:#fff; font-size:0.8rem; white-space:nowrap; }
.row-actions button.accept { border-color: var(--brand); color: var(--brand-dark); }
.row-actions button.decline, .row-actions button.cancel { border-color: var(--danger); color: var(--danger); }

.inline-form { display:flex; gap:10px; flex-wrap:wrap; margin-top:14px; align-items:center; }
.inline-form input { flex: 1 1 160px; }
.inline-form label { display:flex; flex-direction:column; gap:4px; font-size:0.8rem; font-weight:600; }
.inline-form input[type=color] { flex: 0 0 auto; width: 48px; height: 38px; padding: 2px; cursor: pointer; }
.contact-hint { flex: 1 1 100%; margin: 2px 0 0; font-size: 0.8rem; }

.settings-form { display:flex; flex-direction:column; gap:14px; max-width: 420px; }
.settings-form label { display:flex; flex-direction:column; gap:6px; font-size:0.9rem; font-weight:600; }

#scheduleGrid { display:flex; flex-direction:column; gap:16px; margin: 16px 0; }
.day-row { background: var(--card); border:1px solid var(--border); border-radius:10px; padding:14px; }
.day-row .day-title { font-weight:700; margin-bottom:8px; }
.range-row { display:flex; gap:8px; align-items:center; margin-bottom:6px; }
.range-row input[type=time] { width: 120px; }
.range-row button { background:none; border:none; color: var(--danger); cursor:pointer; font-size:1rem; }
.add-range { background:none; border:1px dashed var(--border); border-radius:6px; padding:6px 10px; font-size:0.85rem; color: var(--muted); margin-top:4px; }

/* Calendario appuntamenti */
.calendar-toolbar { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:12px; margin-bottom:16px; }
.calendar-nav { display:flex; align-items:center; gap:10px; font-weight:700; }
.calendar-nav button { width:32px; height:32px; border-radius:6px; padding:0; }
.calendar-month-label { min-width: 160px; text-align:center; text-transform: capitalize; }
.calendar-legend { display:flex; gap:14px; flex-wrap:wrap; font-size:0.8rem; color:var(--muted); }
.legend-item { display:flex; align-items:center; gap:6px; }
.legend-dot { width:10px; height:10px; border-radius:50%; display:inline-block; }
.legend-dot.pending { background: var(--warn); }
.legend-dot.accepted { background: var(--brand); }
.legend-dot.declined { background: var(--danger); }
.legend-dot.cancelled { background: #9c9891; }
.legend-dot.reschedule_pending { background: #3949ab; }

.admin-calendar-grid { display:grid; grid-template-columns: repeat(7, 1fr); gap:6px; background: var(--card); border:1px solid var(--border); border-radius:12px; padding:16px; }
.admin-calendar-grid .dow { text-align:center; font-size:0.75rem; color:var(--muted); padding-bottom:6px; font-weight:600; }
.admin-calendar-grid .cal-day { min-height: 92px; border-radius:8px; background: var(--bg); padding:6px; display:flex; flex-direction:column; gap:3px; cursor:pointer; border:1px solid transparent; }
.admin-calendar-grid .cal-day.empty { background:transparent; cursor:default; }
.admin-calendar-grid .cal-day.today { border-color: var(--brand); }
.admin-calendar-grid .cal-day.selected { background:#e6f2ec; border-color: var(--brand); }
.admin-calendar-grid .cal-day .day-num { font-size:0.85rem; font-weight:700; color: var(--text); }
.admin-calendar-grid .cal-day .chip { font-size:0.72rem; padding:2px 6px; border-radius:5px; color:#fff; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.admin-calendar-grid .cal-day .chip.pending { background: var(--warn); }
.admin-calendar-grid .cal-day .chip.accepted { background: var(--brand); }
.admin-calendar-grid .cal-day .chip.declined { background: var(--danger); }
.admin-calendar-grid .cal-day .chip.cancelled { background: #9c9891; }
.admin-calendar-grid .cal-day .chip.reschedule_pending { background: #3949ab; }
.admin-calendar-grid .cal-day .chip-more { font-size:0.7rem; color: var(--muted); }

.day-detail { margin-top:24px; }
.day-detail h3 { margin-top:0; font-size:1rem; }

/* Aspetto (logo + colore) */
.logo-preview-wrap { margin: 14px 0; display:flex; align-items:center; gap:14px; }
.logo-preview { max-height: 90px; max-width: 220px; border:1px solid var(--border); border-radius:8px; padding:8px; background:#fff; }
#tab-appearance h2:not(:first-child) { margin-top: 32px; }
#tab-appearance input[type=color] { width: 60px; height: 38px; padding: 2px; cursor: pointer; }

/* Pulizia appuntamenti vecchi */
.cleanup-box { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.cleanup-box h3 { margin-bottom: 4px; }
button.danger-btn { border-color: var(--danger); color: var(--danger); }
button.danger-btn:hover { background: var(--danger); color: #fff; }

/* Colore servizio */
.color-dot { display:inline-block; width:16px; height:16px; border-radius:50%; border:1px solid rgba(0,0,0,0.1); vertical-align:middle; }

/* Aggiungi appuntamento manualmente */
.manual-appt-box { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.manual-appt-box h3 { margin-bottom: 10px; }
.subtabs { display:flex; gap:6px; margin-bottom: 14px; }
.subtab-btn { background: var(--card); border:1px solid var(--border); border-radius: 999px; padding: 6px 16px; font-size: 0.85rem; font-weight:600; color: var(--muted); }
.subtab-btn.active { background: var(--brand); color:#fff; border-color: var(--brand); }
.manual-appt-panel textarea { width:100%; flex: 1 1 100%; font-family: inherit; resize: vertical; }
.manual-appt-panel .bulk-duration { max-width: 320px; }
#bulkApptResult { margin-top: 10px; font-size: 0.88rem; }
#bulkApptResult .bulk-summary { font-weight:700; color: var(--brand-dark); margin-bottom: 6px; }
#bulkApptResult ul { margin: 4px 0 0; padding-left: 20px; color: var(--danger); }
#bulkApptResult li { margin-bottom: 2px; }

/* Numerazione servizi (usata anche nell'aggiunta manuale) */
.service-legend { display:flex; flex-wrap:wrap; gap:8px 16px; margin-bottom:12px; font-size:0.85rem; color: var(--muted); background: var(--bg); border:1px solid var(--border); border-radius:8px; padding:10px 14px; width:100%; }
.service-legend-item { white-space:nowrap; }

/* Categorie di massaggio */
.categories-box { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.categories-box h3 { margin-bottom: 4px; }

/* Informativa privacy (GDPR) */
.privacy-box { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.privacy-box h3 { margin-bottom: 4px; }
.privacy-box textarea { font-family: inherit; resize: vertical; }

/* Promemoria appuntamento */
.reminder-box { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.reminder-box h3 { margin-bottom: 4px; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; }

/* Google Calendar */
.gcal-status { background: var(--card); border:1px solid var(--border); border-radius:10px; padding:6px 18px; margin: 16px 0; max-width: 560px; }
.gcal-row { display:flex; justify-content:space-between; align-items:center; gap:16px; padding:9px 0; border-bottom:1px solid var(--border); font-size:0.9rem; }
.gcal-row:last-child { border-bottom:none; }
.gcal-label { font-weight:600; color: var(--muted); flex-shrink:0; }
.gcal-value { text-align:right; }
.gcal-ok { color: var(--brand-dark); font-weight:600; }
.gcal-bad { color: var(--danger); font-weight:600; }

/* Avviso BASE_URL non configurato */
.base-url-warning { background:#fff4e0; color:#7a4a00; border-bottom:1px solid #f0d9a6; padding:10px 24px; font-size:0.88rem; }
.base-url-warning code { background:rgba(0,0,0,0.06); padding:1px 5px; border-radius:4px; }

/* Modelli email */
#tab-email-templates code { background: var(--bg); padding:1px 5px; border-radius:4px; font-size:0.85em; }
.email-tpl-card { background: var(--card); border:1px solid var(--border); border-radius:12px; padding:16px 18px; margin-bottom:14px; }
.email-tpl-header { display:flex; justify-content:space-between; align-items:flex-start; gap:14px; }
.tpl-custom-badge { display:inline-block; background:#e6f4ea; color: var(--brand-dark); font-size:0.72rem; font-weight:700; padding:2px 8px; border-radius:999px; margin-left:6px; vertical-align:middle; }
.email-tpl-body { margin-top:14px; padding-top:14px; border-top:1px solid var(--border); display:flex; flex-direction:column; gap:12px; }
.email-tpl-body label { display:flex; flex-direction:column; gap:6px; font-size:0.9rem; font-weight:600; }
.email-tpl-body textarea { font-family: inherit; resize: vertical; }
.tpl-placeholders { font-size:0.82rem; color: var(--muted); line-height:1.8; }
.tpl-preview-box { margin-top:10px; padding:12px 14px; background: var(--bg); border:1px solid var(--border); border-radius:8px; font-size:0.88rem; }
.tpl-preview-html { background:#fff; border:1px solid var(--border); border-radius:8px; padding:12px; margin-top:8px; }
