:root{
  --navy:#16294F; --navy-light:#22396B; --ink:#1A1F2B; --muted:#6B7280;
  --bg:#F7F6F2; --card:#FFFFFF; --line:#E7E4DC; --coral:#C23F2F; --coral-soft:#F5E2DE;
  --sidebar-muted:#AEB9D6; --ok-bg:#E4F0E9; --ok-text:#1F6F4A; --warn-bg:#FBEFDD; --warn-text:#8A5A11;
}
*{ box-sizing:border-box; }
html,body{ margin:0; }
body{ font-family:'Poppins',sans-serif; color:var(--ink); background:var(--bg); -webkit-text-size-adjust:100%; }
a{ text-decoration:none; color:inherit; }
button{ font-family:inherit; }
.mono{ font-family:'IBM Plex Mono',monospace; }

/* Guscio dell'app: a tutto schermo su computer (le colonne scorrono ognuna per conto suo) */
.app{ width:100%; height:100vh; height:100dvh; background:var(--bg); display:flex; flex-direction:column; overflow:hidden; }

.titlebar{ height:40px; flex:0 0 auto; background:var(--navy); display:flex; align-items:center; justify-content:space-between; padding:0 8px 0 16px; }
.titlebar .name{ display:flex; align-items:center; gap:8px; color:#fff; font-size:12.5px; font-weight:500; letter-spacing:.2px; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.body{ flex:1 1 auto; display:flex; min-height:0; }

.sidebar{ width:220px; flex:0 0 auto; background:var(--navy); display:flex; flex-direction:column; padding:24px 16px; }
.sb-brand{ margin-bottom:26px; }
.sb-brand img{ width:132px; height:auto; display:block; }
.sb-brand .t2{ margin-top:9px !important; font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sb-nav{ display:flex; flex-direction:column; gap:4px; }
.brand{ display:flex; align-items:center; gap:10px; margin-bottom:28px; padding:0 4px; }
.brand .t1{ color:#fff; font-weight:700; font-size:16px; line-height:1.1; }
.brand .t2{ color:var(--sidebar-muted); font-size:10.5px; letter-spacing:.3px; }
.navbtn{ all:unset; box-sizing:border-box; display:flex; align-items:center; gap:10px; padding:9px 12px; border-radius:8px; font-size:13.5px; font-weight:500; cursor:pointer; width:100%; color:var(--sidebar-muted); }
.navbtn:hover{ background:rgba(255,255,255,.06); }
.navbtn.active{ background:var(--navy-light); color:#fff; }
.nav-dot{ margin-left:auto; width:9px; height:9px; border-radius:50%; background:#E5484D; box-shadow:0 0 0 2px var(--navy); flex:0 0 auto; }
.nav-n{ margin-left:auto; font-size:11px; font-weight:700; line-height:1; background:var(--coral); color:#fff; border-radius:20px; padding:3px 8px; }
.spacer{ flex:1 1 auto; }
.who{ display:flex; align-items:center; gap:10px; padding:12px 12px 0 12px; border-top:1px solid rgba(255,255,255,.14); }
.who{ flex-wrap:wrap; }
.who > div:nth-child(2){ min-width:0; flex:1 1 0; }
.who > div:nth-child(2) > div{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.gm-esci{ all:unset; box-sizing:border-box; cursor:pointer; flex:1 1 100%; display:flex; align-items:center; justify-content:center; gap:7px; margin-top:12px; padding:8px 10px; white-space:nowrap; border:1px solid rgba(255,255,255,.32); border-radius:8px; color:#fff; font-size:12.5px; font-weight:600; }
.gm-esci:hover{ background:rgba(255,255,255,.1); border-color:rgba(255,255,255,.55); }
.gm-esci:focus-visible{ outline:2px solid var(--coral); outline-offset:2px; }
.gm-esci:disabled{ opacity:.6; cursor:wait; }
.gm-esci svg{ width:15px; height:15px; flex:0 0 auto; }
.avatar{ width:28px; height:28px; border-radius:50%; background:var(--coral); color:#fff; font-size:11px; font-weight:600; display:flex; align-items:center; justify-content:center; flex:0 0 auto; }

/* Colonna principale di ogni pagina */
.pane{ flex:1 1 auto; min-width:0; overflow:auto; padding:40px 48px; }

.card{ background:var(--card); border:1px solid var(--line); border-radius:16px; padding:20px; box-shadow:0 1px 2px rgba(22,41,79,.05); }
.pill{ font-size:10.5px; font-weight:600; padding:4px 9px; border-radius:20px; white-space:nowrap; }
.pill-ok{ background:var(--ok-bg); color:var(--ok-text); }
.pill-warn{ background:var(--warn-bg); color:var(--warn-text); }
.pill-off{ background:#EEF0F3; color:var(--muted); }

.chip{ display:inline-flex; align-items:center; font-size:11.5px; font-weight:500; padding:6px 13px; border-radius:20px; margin:0 6px 6px 0; }
.chip-on{ background:var(--navy); color:#fff; }
.chip-off{ background:#fff; color:var(--muted); border:1px solid var(--line); }

.field label{ display:block; font-size:11.5px; font-weight:600; color:var(--navy); margin-bottom:5px; }
.field .hint{ font-weight:400; color:var(--muted); }
.field input, .field textarea{ width:100%; box-sizing:border-box; border:1px solid var(--line); border-radius:9px; padding:9px 11px; font-family:inherit; font-size:12.5px; color:var(--ink); outline:none; background:#fff; }
.field textarea{ resize:vertical; }
.field textarea.nota-grande{ min-height:140px; line-height:1.5; }
#f-altro.nota-grande{ min-height:210px; }
.frow{ display:flex; gap:14px; }

.sect{ background:var(--card); border:1px solid var(--line); border-radius:16px; padding:24px; display:flex; flex-direction:column; gap:16px; }
.sect h2{ margin:0; font-size:16px; font-weight:700; color:var(--navy); }
.sect .subtitle{ font-size:11.5px; color:var(--muted); margin-top:-10px; }
.subgroup{ display:flex; flex-direction:column; gap:16px; border-top:1px solid var(--line); padding-top:18px; }
.subgroup:first-of-type{ border-top:none; padding-top:0; }
.subgroup-label{ font-size:10px; font-weight:700; letter-spacing:.8px; text-transform:uppercase; color:var(--coral); }
.row-card{ border:1px solid var(--line); border-radius:11px; padding:12px 14px; display:flex; align-items:center; justify-content:space-between; gap:12px; }
.row-card > div:first-child{ min-width:0; overflow-wrap:anywhere; }
.addbtn{ all:unset; box-sizing:border-box; display:inline-flex; align-items:center; gap:7px; color:var(--navy); font-size:12px; font-weight:600; cursor:pointer; padding:8px 2px; }

.icon{ display:block; flex:0 0 auto; }

.visually-hidden{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }

/* Modali della scheda, select, suggerimenti */
.field select, .field input[type=date], .field input[type=datetime-local]{ width:100%; box-sizing:border-box; border:1px solid var(--line); border-radius:9px; padding:9px 11px; font-family:inherit; font-size:12.5px; color:var(--ink); background:#fff; outline:none; }
.gm-modal-box{ width:560px; max-width:100%; max-height:92vh; overflow:auto; background:var(--card); border-radius:16px; padding:24px; box-shadow:0 20px 60px rgba(22,41,79,.35); }
.field-grid{ display:grid; grid-template-columns:1fr 1fr; gap:12px 14px; }
.field-grid .field:first-child, .field-grid .field:nth-child(2):last-child{ grid-column:1 / -1; }
.gm-btn{ all:unset; box-sizing:border-box; cursor:pointer; border-radius:9px; padding:10px 20px; font-size:12.5px; font-weight:600; text-align:center; }
.gm-btn-on{ background:var(--navy); color:#fff; }
.gm-btn-off{ border:1px solid var(--line); color:var(--navy); background:#fff; }
.gm-btn-coral{ background:var(--coral); color:#fff; }
.gm-btn[disabled]{ opacity:.55; cursor:default; }
.gm-suggest{ position:absolute; left:0; right:0; top:100%; margin-top:4px; background:#fff; border:1px solid var(--line); border-radius:10px; box-shadow:0 10px 30px rgba(22,41,79,.18); z-index:9500; overflow:hidden; }
.gm-sug{ padding:9px 12px; cursor:pointer; font-size:12.5px; display:flex; flex-direction:column; gap:1px; }
.gm-sug:hover{ background:var(--coral-soft); }
.gm-sug span{ font-size:11px; color:var(--muted); }

/* Sottotitolo sotto il logo in sidebar: leggibile su navy */
.sidebar .t2{ color:var(--sidebar-muted); font-size:10.5px; letter-spacing:.3px; }

/* Avvisi a comparsa */
#gm-toasts{ position:fixed; left:50%; bottom:42px; transform:translateX(-50%); z-index:9999; display:flex; flex-direction:column; align-items:center; gap:8px; width:max-content; max-width:calc(100vw - 32px); pointer-events:none; }
.gm-toast{ pointer-events:auto; cursor:pointer; padding:10px 18px; border-radius:9px; font:500 12.5px Poppins,Arial,sans-serif; color:#fff; background:#16294F; box-shadow:0 6px 20px rgba(0,0,0,.25); max-width:560px; text-align:center; line-height:1.45; }
.gm-toast.ko{ background:#C23F2F; }

/* Profilo in sola lettura (sede centrale): niente comandi di modifica */
body.sola-lettura .solo-filiale{ display:none !important; }

/* Schermi medi: colonne laterali più strette */
@media (max-width:1180px){
  .sidebar{ width:190px; padding:20px 12px; }
  .pane{ padding:28px 28px; }
}

/* ---------- Smartphone e tablet in verticale ---------- */
@media (max-width:900px){
  .app{ height:auto; min-height:100vh; min-height:100dvh; overflow:visible; }
  .titlebar{ display:none; }
  .body{ flex-direction:column; min-height:0; }
  /* la barra laterale diventa una barra in alto (logo + utente) e il menu va in basso, sempre a portata di pollice */
  .sidebar{ width:100%; flex-direction:row; align-items:center; gap:12px; padding:10px 16px; position:sticky; top:0; z-index:60; }
  .sb-brand{ margin:0; display:flex; align-items:center; }
  .sb-brand img{ width:96px; }
  .sb-brand .t2{ display:none; }
  .sidebar > .navbtn{ display:none; }
  .who{ border-top:0; padding:0; gap:8px; flex-wrap:nowrap; }
  .gm-esci{ flex:0 0 auto; margin:0 0 0 4px; padding:7px 10px; font-size:12px; }
  .who > div:nth-child(2) > div:nth-child(2){ display:none; }
  .who > div:nth-child(2) > div:first-child{ max-width:42vw; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .sb-nav{ position:fixed; left:0; right:0; bottom:0; z-index:70; flex-direction:row; gap:2px; background:var(--navy); padding:6px 8px calc(6px + env(safe-area-inset-bottom)); box-shadow:0 -4px 18px rgba(22,41,79,.18); }
  .sb-nav .navbtn{ flex:1 1 0; flex-direction:column; justify-content:center; gap:3px; padding:7px 2px; font-size:10.5px; text-align:center; border-radius:9px; position:relative; }
  .sb-nav .nav-dot{ position:absolute; top:5px; left:calc(50% + 8px); margin:0; }
  .sb-nav .nav-n{ position:absolute; top:3px; left:calc(50% + 6px); margin:0; font-size:9.5px; padding:2px 5px; }
  body{ padding-bottom:calc(64px + env(safe-area-inset-bottom)); }
  .pane{ overflow:visible; padding:20px 16px 24px; }
  .frow{ flex-wrap:wrap; }
  .frow > *{ flex:1 1 100% !important; }
  .field-grid{ grid-template-columns:1fr; }
  .field input, .field textarea, .field select{ font-size:16px; }   /* sotto i 16px iOS ingrandisce la pagina a ogni tocco */
  .gm-modal-box{ padding:18px 16px; max-height:88vh; }
  #gm-toasts{ bottom:calc(84px + env(safe-area-inset-bottom)); }
}
