/* ============================================================
   RAPPORTINI APP — Design System v2 — Mobile First
   ============================================================ */

/* Font di sistema — nessuna CDN, funziona offline e nell'app */

/* ─── CSS VARIABLES ─────────────────────────────────────── */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #e2e5ea;
  --border-strong: #c8cdd5;

  --text-primary: #1a1d23;
  --text-secondary: #5a6270;
  --text-muted: #8d96a3;
  --text-inverse: #ffffff;

  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-dark: #1d4ed8;

  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;

  --topbar-h:    56px;
  --bottomnav-h: 60px;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12);

  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;

  --transition: .18s cubic-bezier(.4,0,.2,1);

  /* Safe area (iPhone notch / Dynamic Island / Android cutout) */
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}

/* ─── RESET ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
-webkit-tap-highlight-color: transparent;
* { -webkit-tap-highlight-color: transparent; }

/* ─── LOGIN PAGE ─────────────────────────────────────────── */
#login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  padding: calc(1rem + var(--safe-top)) 1rem calc(1rem + var(--safe-bottom));
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  animation: fadeUp .4s ease;
}

.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .app-icon {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: .75rem;
  font-size: 1.6rem; color: white;
  box-shadow: 0 4px 16px rgba(37,99,235,.35);
}
.login-logo h1 { font-size: 1.4rem; font-weight: 700; }
.login-logo p  { font-size: .85rem; color: var(--text-muted); }

/* ─── APP SHELL ──────────────────────────────────────────── */
#app-shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
#app-shell.hidden { display: none; }
#login-page.hidden { display: none; }

/* ─── TOPBAR ─────────────────────────────────────────────── */
.topbar {
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: #0f172a;
  color: white;
  display: flex;
  align-items: center;
  padding-left: calc(1rem + var(--safe-left));
  padding-right: calc(1rem + var(--safe-right));
  position: sticky; top: 0; z-index: 100;
  gap: .75rem;
  flex-shrink: 0;
}

.topbar-title { font-size: 1rem; font-weight: 700; flex: 1; color: white; }
.topbar-actions { display: flex; gap: .4rem; align-items: center; }
.topbar-actions .btn { padding: .4rem .75rem; font-size: .82rem; }

/* Avatar utente nella topbar */
.topbar-avatar {
  width: 32px; height: 32px;
  background: rgba(37,99,235,.5);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; color: white;
  cursor: pointer; flex-shrink: 0;
}

/* ─── MAIN CONTENT ───────────────────────────────────────── */
#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page-content {
  flex: 1;
  padding: 1rem;
  /* padding-bottom garantisce che l'ultimo elemento non finisca sotto la bottom nav */
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 1.5rem);
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* ─── LAYOUT RESPONSIVE — Sidebar vs Bottom Nav ─────────────
   Regola: landscape → sidebar desktop (anche su tablet)
            portrait  → bottom nav mobile (anche su tablet grande)
   Su desktop (min-width 1024px) sempre sidebar indipendente da orientamento
   ─────────────────────────────────────────────────────────── */

/* Layout desktop: sidebar sempre visibile su schermi grandi */
@media (min-width: 1024px) {
  #app-shell { flex-direction: row; }

  #sidebar-desktop {
    width: 260px;
    min-height: 100vh;
    background: #0f172a;
    display: flex !important;
    flex-direction: column;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
  }

  #main-content { padding-bottom: 0; flex: 1; min-width: 0; }
  .topbar { display: none; }
  #bottom-nav { display: none !important; }

  .page-content {
    padding: 1.75rem 2rem;
    max-width: 1200px;
    padding-bottom: 2rem;
  }
}

/* Tablet/telefono in LANDSCAPE → layout desktop (sidebar) */
@media (max-width: 1023px) and (orientation: landscape) {
  #app-shell { flex-direction: row; }

  #sidebar-desktop {
    width: 220px;
    min-height: 100vh;
    background: #0f172a;
    display: flex !important;
    flex-direction: column;
    position: sticky; top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
  }

  #main-content { padding-bottom: 0; flex: 1; min-width: 0; }
  .topbar { display: none; }
  #bottom-nav { display: none !important; }

  .page-content {
    padding: 1rem 1.5rem;
    padding-bottom: 1.5rem;
  }
}

/* Telefono/tablet in PORTRAIT → layout mobile (bottom nav) */
@media (max-width: 1023px) and (orientation: portrait) {
  #app-shell { flex-direction: column; }
  #sidebar-desktop { display: none !important; }
  #bottom-nav { display: flex !important; }
  .topbar { display: flex; }
  #main-content { padding-bottom: 70px; }
  .page-content { padding: 1rem; padding-bottom: 1.5rem; }
}

/* ─── SIDEBAR DESKTOP ────────────────────────────────────── */
#sidebar-desktop {
  display: none; /* nascosta su mobile, mostrata via media query */
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .65rem;
}
.sidebar-brand .icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; flex-shrink: 0;
}
.sidebar-brand .brand-name { font-weight: 700; font-size: .95rem; color: white; }
.sidebar-brand .brand-sub  { font-size: .68rem; color: rgba(255,255,255,.4); }

.sidebar-user {
  padding: .75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .6rem;
}
.sidebar-user .user-avatar {
  width: 32px; height: 32px;
  background: rgba(37,99,235,.4);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; color: white; flex-shrink: 0;
}
.sidebar-user .user-name { font-size: .82rem; font-weight: 600; color: white; }
.sidebar-user .user-role  { font-size: .68rem; color: rgba(255,255,255,.4); text-transform: uppercase; }

.sidebar-nav-desktop { flex: 1; padding: .5rem 0; overflow-y: auto; }

.sidebar-nav-desktop .nav-section-label {
  font-size: .65rem; color: rgba(255,255,255,.3);
  text-transform: uppercase; letter-spacing: .1em;
  padding: .75rem 1rem .2rem; font-weight: 600;
}

.sidebar-nav-desktop .nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1rem;
  color: rgba(255,255,255,.65);
  font-size: .85rem; font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  user-select: none;
}
.sidebar-nav-desktop .nav-item:hover { background: rgba(255,255,255,.07); color: white; }
.sidebar-nav-desktop .nav-item.active {
  background: rgba(37,99,235,.2); color: white;
  border-left-color: var(--accent);
}
.sidebar-nav-desktop .nav-icon { width: 16px; text-align: center; }

.sidebar-footer-desktop {
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.08);
}

.btn-logout {
  width: 100%;
  background: rgba(239,68,68,.15);
  color: #fca5a5;
  border: 1px solid rgba(239,68,68,.2);
  border-radius: 8px;
  padding: .5rem 1rem;
  font-size: .82rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn-logout:hover { background: rgba(239,68,68,.25); color: white; }

/* ─── BOTTOM NAVIGATION (mobile) ────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #0f172a;
  display: flex;
  align-items: stretch;
  z-index: 200;
  border-top: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 -4px 20px rgba(0,0,0,.2);
}

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: rgba(255,255,255,.45);
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .01em;
  transition: color var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: 6px 4px 0;
  position: relative;
}

.bn-item i {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform var(--transition);
}

.bn-item span {
  font-size: .62rem;
  line-height: 1;
}

.bn-item.active {
  color: white;
}

.bn-item.active i {
  transform: translateY(-1px);
}

/* Indicatore attivo */
.bn-item.active::before {
  content: '';
  position: absolute;
  top: 0; left: 20%; right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
}

/* Tasto "nuovo" centrale — evidenziato */
.bn-item.bn-primary {
  color: white;
}
.bn-item.bn-primary i {
  background: var(--accent);
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 2px;
  box-shadow: 0 2px 12px rgba(37,99,235,.5);
  transform: translateY(-6px);
}
.bn-item.bn-primary.active i {
  background: var(--accent-dark);
  transform: translateY(-8px);
}

/* ─── PAGE SECTIONS ──────────────────────────────────────── */
.page-section { display: none; }
.page-section.active { display: block; animation: fadeUp .22s ease; }

/* ─── CARDS ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem;
}
.card-title { font-size: .95rem; font-weight: 700; }
.card-body  { padding: 1.25rem; }

/* ─── STAT CARDS ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1.25rem;
}
@media (min-width: 600px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat-card .stat-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin-bottom: .4rem;
}
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: .75rem; color: var(--text-muted); font-weight: 500; }

/* ─── FORMS ──────────────────────────────────────────────── */
.form-group { margin-bottom: .9rem; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--text-secondary); }

.form-control, .form-select {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 16px; /* evita zoom iOS */
  color: var(--text-primary);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control.is-invalid { border-color: var(--danger); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-check { display: flex; align-items: center; gap: .5rem; }
.form-check-input { width: 18px; height: 18px; flex-shrink: 0; cursor: pointer; }
.form-check-label { font-size: .9rem; cursor: pointer; }

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .6rem 1rem;
  border-radius: 8px;
  font-family: var(--font);
  font-size: .88rem; font-weight: 600;
  border: none; cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
  min-height: 42px;
  user-select: none;
}
.btn-primary  { background: var(--accent); color: white; }
.btn-primary:hover  { background: var(--accent-dark); }
.btn-primary:active { opacity: .85; transform: scale(.97); }

.btn-secondary { background: var(--surface); color: var(--text-primary); border: 1.5px solid var(--border); }
.btn-secondary:hover  { background: var(--bg); }
.btn-secondary:active { opacity: .85; transform: scale(.97); }

.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger);  color: white; }
.btn-warning { background: var(--warning); color: white; }

.btn-sm { padding: .35rem .7rem; font-size: .8rem; min-height: 34px; }
.btn-lg { padding: .75rem 1.4rem; font-size: 1rem; min-height: 50px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ─── TABLES — scorrevoli su mobile ─────────────────────── */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  min-width: 500px; /* forza scroll orizzontale invece di comprimere */
  border-collapse: collapse;
  font-size: .85rem;
  background: var(--surface);
}

th {
  background: var(--surface-2);
  padding: .65rem .85rem;
  text-align: left;
  font-weight: 700;
  font-size: .75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: .75rem .85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
  /* impedisce che il testo lungo allargi la tabella */
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tr:active td { background: var(--bg); }

/* Colonna azioni: non troncare */
td:last-child { white-space: nowrap; max-width: none; overflow: visible; }

/* ─── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  white-space: nowrap;
}
.badge-bozza       { background: var(--warning-light); color: #92400e; }
.badge-finalizzato { background: var(--success-light); color: #065f46; }
.badge-approvato   { background: var(--accent-light);  color: #1e40af; }
.badge-admin       { background: rgba(139,92,246,.15); color: #6d28d9; }
.badge-tecnico     { background: var(--accent-light);  color: #1e40af; }

/* ─── FIRMA CANVAS ───────────────────────────────────────── */
.firma-container {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: .75rem;
  text-align: center;
  background: var(--surface-2);
}

#firma-canvas, #firma-rapportino-canvas, #firma-cliente-canvas {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: crosshair;
  background: white;
  display: block;
  margin: 0 auto;
  width: 100% !important;
  max-width: 100%;
  touch-action: none;
}

.firma-preview {
  max-width: 100%;
  max-height: 100px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: .5rem;
}

/* ─── TEMPLATE BUILDER ───────────────────────────────────── */
.campo-item {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: .65rem .85rem;
  margin-bottom: .4rem;
  display: flex; align-items: center; gap: .65rem;
  cursor: grab;
  transition: all var(--transition);
}
.campo-item:active { border-color: var(--accent); }
.campo-item.dragging { opacity: .5; }
.campo-handle { color: var(--text-muted); font-size: 1rem; }
.campo-info { flex: 1; min-width: 0; }
.campo-nome { font-weight: 600; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campo-tipo { font-size: .72rem; color: var(--text-muted); }
.campo-required { font-size: .68rem; color: var(--danger); font-weight: 700; }

/* ─── MODAL — full-screen su mobile ─────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: flex-end;       /* bottom sheet su mobile */
  justify-content: center;
  z-index: 1000;
  padding: 0;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 100%;
  /* Lascia spazio per topbar e safe area */
  max-height: calc(100dvh - var(--topbar-h) - var(--safe-top) - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
}
.modal-overlay.open .modal-box { transform: translateY(0); }

/* Handle drag per bottom sheet */
.modal-box::before {
  content: '';
  display: block;
  width: 36px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 10px auto 0;
}

.modal-header {
  padding: .85rem 1.25rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-size: .95rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--text-muted); padding: .3rem;
  border-radius: 6px; min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.modal-body   { padding: 1.25rem; }
.modal-footer {
  padding: .85rem 1.25rem;
  padding-bottom: calc(.85rem + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex; gap: .5rem; justify-content: flex-end;
  flex-wrap: wrap;
  position: sticky; bottom: 0; background: var(--surface);
}

/* Desktop: modal centrato come prima */
@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 1rem;
  }
  .modal-box {
    border-radius: var(--radius-lg);
    max-width: 560px;
    max-height: 90vh;
    transform: translateY(20px);
  }
  .modal-overlay.open .modal-box { transform: translateY(0); }
  .modal-box::before { display: none; }
  .modal-footer { padding-bottom: .85rem; position: static; }
}

/* Modal rapportino più largo */
#modal-rapportino .modal-box { max-width: 750px; }

/* ─── TOAST ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + .75rem);
  left: 1rem; right: 1rem;
  z-index: 9999;
  display: flex; flex-direction: column; gap: .4rem;
  pointer-events: none;
}
@media (min-width: 600px) {
  #toast-container {
    left: auto; right: 1.5rem;
    bottom: 1.5rem;
    width: 360px;
  }
}

.toast {
  background: var(--surface);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .8rem 1rem;
  display: flex; align-items: flex-start; gap: .65rem;
  animation: slideUp .3s ease;
  font-size: .88rem;
  pointer-events: all;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
.toast-icon    { font-size: .95rem; margin-top: .05rem; }
.toast-msg     { flex: 1; min-width: 0; }
.toast-title   { font-weight: 700; margin-bottom: .1rem; }
.toast-text    { color: var(--text-secondary); font-size: .8rem; }

/* ─── LOADING ────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(37,99,235,.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block; flex-shrink: 0;
}

/* ─── FILTER BAR ─────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filter-bar .form-control,
.filter-bar .form-select { flex: 1; min-width: 120px; }

/* ─── SECTION HEADER ─────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem; flex-wrap: wrap; gap: .65rem;
}
.section-title { font-size: 1.2rem; font-weight: 800; }
.section-sub   { font-size: .82rem; color: var(--text-muted); }

/* ─── EMPTY STATE ────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
.empty-state p { font-size: .9rem; }

/* ─── GRID ───────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* ─── PRINT ──────────────────────────────────────────────── */
@media print {
  #bottom-nav, #sidebar-desktop, .topbar,
  .btn, .filter-bar, .section-header .btn,
  #toast-container, .modal-overlay { display: none !important; }
  #main-content { padding-bottom: 0 !important; }
  body { background: white; }
}

/* ─── MISC ───────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1rem 0; }
.text-muted    { color: var(--text-muted); }
.text-success  { color: var(--success); }
.text-danger   { color: var(--danger); }
.fw-bold       { font-weight: 700; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.w-100  { width: 100%; }

/* Logo upload area */
.logo-upload-area {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface-2);
}
.logo-upload-area:active { border-color: var(--accent); background: var(--accent-light); }
.logo-upload-area input[type=file] { display: none; }
.logo-preview { max-height: 70px; max-width: 180px; border-radius: 6px; border: 1px solid var(--border); }

/* Colore picker row */
.color-row { display: flex; align-items: center; gap: .65rem; }
.color-row input[type=color] { width: 40px; height: 34px; border: 1.5px solid var(--border); border-radius: 6px; cursor: pointer; padding: 2px; }

/* Impostazioni grid */
.impostazioni-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 700px) { .impostazioni-grid { grid-template-columns: 1fr 1fr; } }

/* Template builder two-column layout */
@media (min-width: 900px) {
  .template-builder-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    align-items: start;
  }
}

/* ─── ANIMATIONS ─────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── PRINT OVERLAY ──────────────────────────────────────── */
/* Usato da stampaRapportino() — mostra solo il rapportino in stampa */
#print-overlay {
  display: none;        /* nascosto a schermo */
}

@media print {
  /* Nascondi tutto tranne il print overlay */
  body > *:not(#print-overlay) {
    display: none !important;
  }
  #print-overlay {
    display: block !important;
    position: fixed;
    inset: 0;
    background: white;
    z-index: 99999;
    padding: 0;
    margin: 0;
  }
  #print-overlay * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  @page {
    margin: 10mm;
    size: A4 portrait;
  }
}

/* Logout nella bottom nav — colore rosso tenue */
.bn-logout {
  color: rgba(252,165,165,.7) !important;
}
.bn-logout:active {
  color: #fca5a5 !important;
}

/* ─── CAMPO FOTO ─────────────────────────────────────────── */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: .5rem;
  margin-bottom: .5rem;
}

.foto-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

.foto-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
}

/* ─── FIRMA CANVAS — dimensioni aumentate ─────────────────── */
/* Desktop: area firma più alta */
@media (min-width: 900px) {
  #firma-rapportino-canvas,
  #firma-cliente-canvas,
  #firma-canvas {
    height: 200px !important;
  }
}

/* Canvas profilo impostazioni */
#firma-canvas {
  height: 160px;
}
@media (min-width: 900px) {
  #firma-canvas { height: 220px !important; }
}

/* ─── MENU MOBILE (bottom sheet "Altro") ─────────────────── */
#mobile-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(0,0,0,.5);
  animation: fadeIn .15s ease;
}

/* ─── TEMPLATE LAYOUT — responsive ───────────────────────── */
.template-layout {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Su schermi larghi: lista a sinistra fissa, builder a destra */
@media (min-width: 768px) {
  .template-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
    align-items: start;
  }
}

/* Su mobile: lista collassabile — mostra solo lista OPPURE builder */
@media (max-width: 767px) {
  /* Quando il builder è attivo (ha contenuto != empty-state),
     nascondi la lista e viceversa */
  .template-layout.builder-attivo .card:first-child {
    display: none;
  }
  .template-layout.lista-attiva #template-builder {
    display: none;
  }

  /* Bottone per tornare alla lista (solo mobile, nel builder) */
  .btn-torna-lista {
    display: inline-flex;
  }
}

@media (min-width: 768px) {
  .btn-torna-lista { display: none !important; }
}
