/* ============================================================
   Sagires UI — il sistema di stile comune a tutte le app Sagires
   ------------------------------------------------------------
   Colori, font, misure e componenti scritti una sola volta. Ogni app copia
   questo file (e la cartella fonts/) e usa SOLO queste classi: niente stili
   propri per pulsanti, schede, tabelle, moduli, etichette.

   Nomi delle classi: quelli di Interventi (btn btn-primary, card, badge,
   data-table, topbar...). Le app ereditate dalle altre convenzioni si
   allineano a questi.

   Indice: 1 base · 2 disposizione (barra in alto, menu laterale, pagina) ·
   3 pulsanti · 4 schede e misure · 5 etichette e avvisi · 6 tabelle ·
   7 moduli · 8 finestre e notifiche · 9 utilità · 10 stile moderno
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Inter servito dall'app stessa: le regole di sicurezza accettano solo font-src 'self' */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
}

/* ---------- 1. Base ---------- */
:root {
  /* Blu navy: struttura (barra in alto, titoli) */
  --brand-50:  #eaf0f8;
  --brand-100: #dbe5f2;
  --brand-600: #2f5480;
  --brand-700: #24466d;
  --brand-800: #1b3455;
  --brand-900: #14263d;

  /* Arancione: l'azione principale (un solo pulsante arancione per schermata, di norma) */
  --accent-100: #fdecd8;
  --accent-400: #f5ad63;
  --accent-500: #f39c4a;
  --accent-600: #e0863a;
  --accent-text: #9a4f0b;   /* l\'arancio come colore di testo (contrasto 5:1 su bianco e crema) */

  --text-on-navy: #eef1f6;
  --text-on-navy-dim: #b7c4d6;

  /* Significati: non sono colori di decorazione */
  --success: #2a8a68;  --success-100: #e3f4ec;  --success-900: #1d5e47;
  --warning: #9a6500;  --warning-100: #fdf1d3;  --warning-900: #6e4800;
  --danger:  #bf5136;  --danger-100:  #fbeae5;  --danger-900:  #8a3622;
  --info:    #3467a8;  --info-100:    #e6eef9;

  /* Fondo caldo e superfici */
  --bg:        #f5f3ec;
  --surface:   #ffffff;
  --surface-2: #faf8f2;
  --border:    #e7e2d3;
  --border-2:  #d9d2bd;
  --text:      #23293a;
  --text-2:    #5f594d;
  --text-3:    #716b5c;

  --shadow-xs: 0 1px 2px rgba(20, 38, 61, 0.05);
  --shadow-sm: 0 2px 6px rgba(20, 38, 61, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 38, 61, 0.1);
  --shadow-lg: 0 16px 40px rgba(20, 38, 61, 0.16);

  --radius:    8px;    /* campi, pulsanti piccoli, voci di menu */
  --radius-lg: 12px;   /* pulsanti */
  --radius-xl: 18px;   /* schede */

  --topbar-h: 56px;
  --sidebar-w: 240px;
  --font: "Segoe UI Variable Text", "Segoe UI", "SF Pro Text", Roboto, system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-100); color: var(--brand-900); }
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
[hidden], .hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--accent-400); outline-offset: 2px; }

/* ---------- 2. Disposizione ---------- */

/* Barra in alto, uguale in tutte le app: logo + «Sagires · NOME APP» a sinistra,
   eventuali schede, poi a destra azioni, pulsante Console, utente, uscita. */
.topbar {
  background: var(--brand-900);
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06), var(--shadow-sm);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 26px; height: 26px; display: block; flex-shrink: 0; }
.topbar-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-on-navy); white-space: nowrap; }
.topbar-title span { color: var(--accent-400); font-weight: 500; }
.topbar-nav { display: flex; gap: 4px; margin-left: 16px; }
.topbar-tab {
  background: transparent; border: none; cursor: pointer; font: inherit;
  color: var(--text-on-navy-dim); font-size: 13.5px; font-weight: 550;
  padding: 7px 12px; border-radius: var(--radius); text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.topbar-tab:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-on-navy); text-decoration: none; }
.topbar-tab.is-active { background: rgba(255, 255, 255, 0.12); color: #fff; box-shadow: inset 0 -2px 0 var(--accent-500); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-on-navy-dim); }
.topbar-divider { width: 1px; height: 22px; background: rgba(255, 255, 255, 0.16); }
/* Ritorno alla Sagires Console: in ogni app, sempre con target="sagires-console" */
.topbar-console {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 13px; font-weight: 550; color: var(--text-on-navy);
  padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.18);
  transition: background 0.12s, border-color 0.12s;
}
.topbar-console:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--accent-500); text-decoration: none; color: #fff; }
.topbar-console svg { width: 16px; height: 16px; color: var(--accent-400); }
.topbar-user { display: flex; align-items: center; gap: 8px; color: var(--text-on-navy); white-space: nowrap; }
.avatar {
  width: 28px; height: 28px; border-radius: 999px; flex-shrink: 0;
  background: var(--accent-500); color: var(--brand-900);
  font-size: 11.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.avatar:empty { display: none; }
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  width: 32px; height: 32px; border-radius: var(--radius);
  color: var(--text-on-navy-dim);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: var(--accent-400); }

/* Disposizione A: barra in alto + menu laterale (app complesse) */
.menu-toggle { display: none; }          /* il pulsante ☰ compare solo su telefono */
.sidebar-backdrop { display: none; }
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "topbar topbar" "sidebar content";
  min-height: 100vh;
}
.app-shell > .topbar { grid-area: topbar; }
.sidebar {
  grid-area: sidebar;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px; overflow-y: auto;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px; border-radius: var(--radius);
  color: var(--text-2); font-size: 13.5px; font-weight: 500; text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-100); color: var(--accent-text); font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-section { padding: 16px 11px 6px; font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; }
.content { grid-area: content; padding: 28px 32px 64px; min-width: 0; }

/* Disposizione B: barra in alto + pagina semplice (app piccole) */
.page { max-width: 1280px; margin: 0 auto; padding: 28px 32px 64px; min-width: 0; }
.page-narrow { max-width: 960px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; color: var(--brand-900); text-wrap: balance; }
.page-subtitle { color: var(--text-2); font-size: 13.5px; margin-top: 4px; max-width: 75ch; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- 3. Pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 9px 16px;
  border: 1px solid transparent; border-radius: var(--radius-lg);
  font: inherit; font-size: 13.5px; font-weight: 550; line-height: 1.2; white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary   { background: var(--accent-500); color: var(--brand-900); }
.btn-primary:hover:not(:disabled) { background: var(--accent-600); }
.btn-secondary { background: var(--surface); color: var(--brand-800); border-color: var(--border-2); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--brand-700); }
.btn-ghost     { background: transparent; color: var(--brand-700); }
.btn-ghost:hover:not(:disabled) { background: var(--brand-50); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #a3432c; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #22735a; }
.btn-sm    { min-height: 30px; padding: 5px 11px; font-size: 12.5px; border-radius: var(--radius); }
.btn-lg    { min-height: 46px; padding: 12px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 4. Schede e misure ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs); padding: 20px 22px; margin-bottom: 16px;
}
/* Scheda che contiene solo una tabella: senza margine interno, con gli angoli che ritagliano la tabella */
.card-flush { padding: 0; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card-title { font-size: 16px; font-weight: 600; color: var(--brand-800); }
.card-subtitle { font-size: 13px; color: var(--text-2); margin-top: 2px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs); padding: 16px 18px;
  --colore: var(--brand-700); border-left: 4px solid var(--colore);
}
.stat-card.is-success { --colore: var(--success); }
.stat-card.is-warning { --colore: var(--accent-600); }
.stat-card.is-danger  { --colore: var(--danger); }
.stat-label { font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; color: var(--brand-900); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-meta  { font-size: 12.5px; color: var(--text-2); margin-top: 6px; }

.progress { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--success); }
.progress.is-warning > span { background: var(--warning); }
.progress.is-danger > span { background: var(--danger); }

.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty strong { display: block; color: var(--brand-800); font-size: 15px; margin-bottom: 4px; }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand-600); border-radius: 50%; animation: gira 0.8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

/* ---------- 5. Etichette e avvisi ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 550; line-height: 1.4; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge-success { background: var(--success-100); color: var(--success-900); border-color: transparent; }
.badge-warning { background: var(--warning-100); color: var(--warning-900); border-color: transparent; }
.badge-danger  { background: var(--danger-100);  color: var(--danger-900);  border-color: transparent; }
.badge-info    { background: var(--info-100);    color: var(--brand-800);   border-color: transparent; }
.badge-accent  { background: var(--accent-100);  color: var(--brand-900);   border-color: transparent; }
.badge-dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.alert { padding: 11px 14px; border-radius: var(--radius-lg); border: 1px solid; font-size: 13.5px; margin-bottom: 14px; }
.alert-success { background: var(--success-100); border-color: var(--success); color: var(--success-900); }
.alert-danger  { background: var(--danger-100);  border-color: var(--danger);  color: var(--danger-900); }
.alert-warning { background: var(--warning-100); border-color: var(--warning); color: var(--warning-900); }
.alert-info    { background: var(--info-100);    border-color: var(--info);    color: var(--brand-800); }

/* ---------- 6. Tabelle ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left; padding: 10px 14px; background: var(--surface-2);
  font-size: 11px; font-weight: 550; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; }

/* ---------- 7. Moduli ---------- */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
label .required { color: var(--danger); }
/* :where() azzera la specificità: i campi hanno questo aspetto di base ma ogni app può ritoccarli con una regola normale */
:where(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file])), select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  font: inherit; font-size: 14px; background: var(--surface); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-500); box-shadow: 0 0 0 3px var(--accent-100); }
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--text-2); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); background: var(--danger-100); }
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand-700); width: 16px; height: 16px; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.input-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer; margin: 0; }

/* ---------- 8. Finestre e notifiche ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 38, 61, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000; }
.modal { background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; }
.modal-lg { max-width: 800px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 600; color: var(--brand-900); }
.modal-body { padding: 20px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); }

.toast-container { position: fixed; top: calc(var(--topbar-h) + 16px); right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand-700);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 12px 16px; font-size: 13px;
}
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--accent-500); }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 9px 13px; font: inherit; font-size: 13px; font-weight: 550; color: var(--text-2); cursor: pointer;
}
.tab:hover { color: var(--brand-800); }
.tab.is-active { color: var(--brand-800); border-bottom-color: var(--accent-500); }

/* ---------- 9. Utilità ---------- */
.text-muted { color: var(--text-2); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .wrap { flex-wrap: wrap; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }

/* ---------- Schermi stretti ---------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "topbar" "content"; }
  /* Menu laterale su telefono: nascosto, si apre con il pulsante ☰ (js/sagires-ui.js) sopra la pagina */
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: var(--topbar-h); bottom: 0; height: auto;
    width: min(280px, 85vw); z-index: 60; box-shadow: var(--shadow-lg);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0.2s;
  }
  .app-shell.menu-open .sidebar { transform: none; visibility: visible; }
  .sidebar-backdrop { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(20, 38, 61, 0.45); z-index: 55; }
  .app-shell.menu-open .sidebar-backdrop { display: block; }
  .content, .page { padding: 20px 16px 48px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-console span, .topbar-user-nome, .topbar-divider { display: none; }
  /* Le schede della barra scorrono in orizzontale invece di spingere fuori le azioni */
  .topbar-nav { flex: 1 1 0; min-width: 0; margin-left: 4px; overflow-x: auto; scrollbar-width: none; }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar-tab { white-space: nowrap; }
  .topbar-actions { flex-shrink: 0; margin-left: auto; gap: 6px; }
}
@media (max-width: 560px) {
  .topbar-title { display: none; }
  .page-title { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ---------- 10. Stile moderno: elenchi a conversazione, schede morbide, barra inferiore ---------- */
/* Pensato per il telefono, usato anche sul computer dove serve. Solo componenti: nessuna app li usa
   finché non li chiama per nome. Colori solo dai valori --… in :root. */

/* Intestazione di pagina con saluto: fascia navy a bordi arrotondati sotto */
.hero { background: var(--brand-800); color: var(--text-on-navy); padding: 22px 24px; margin: 0 0 20px; border-radius: 24px; }
.hero-eyebrow { font-size: 13px; color: var(--text-on-navy-dim); }
.hero-title { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; text-wrap: balance; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Numeri chiave: piastrelle morbide, senza bordo colorato */
.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border-radius: 20px; padding: 14px 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-valore { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; color: var(--brand-800); font-variant-numeric: tabular-nums; }
.tile-etichetta { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.tile.is-attenzione .tile-valore { color: var(--danger); }
.tile.is-ok .tile-valore { color: var(--success); }

/* Elenco a conversazione: pallino con iniziali, titolo, ultima riga, orario e novità */
.conv-list { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-sm); overflow: hidden; }
.conv { display: flex; align-items: center; gap: 12px; padding: 12px 16px; position: relative; color: inherit; text-decoration: none; cursor: pointer; transition: background 0.12s; }
.conv + .conv::before { content: ""; position: absolute; top: 0; left: 76px; right: 0; border-top: 1px solid var(--border); }
.conv:hover, .conv:active { background: var(--surface-2); text-decoration: none; }
.conv-avatar { width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 15px; font-weight: 600; background: var(--brand-100); color: var(--brand-800); }
.conv-avatar.tinta-accent { background: var(--accent-100); color: var(--warning-900); }
.conv-avatar.tinta-success { background: var(--success-100); color: var(--success-900); }
.conv-avatar.tinta-danger { background: var(--danger-100); color: var(--danger-900); }
.conv-avatar.tinta-info { background: var(--info-100); color: var(--info); }
.conv-corpo { flex: 1; min-width: 0; }
.conv-titolo { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: 15px; font-weight: 550; line-height: 1.3; color: var(--text); }
.conv-testo { display: block; font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.conv-lato { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 12px; color: var(--text-3); flex: none; }
.conv-lato.is-nuovo { color: var(--accent-text); font-weight: 550; }
.conv-conta { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent-500); color: #fff; font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }

/* Filtri a pillola */
.pillole { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.pillole::-webkit-scrollbar { display: none; }
.pillola { flex: none; padding: 7px 14px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 550; background: var(--surface); color: var(--text-2); border: 1px solid var(--border); cursor: pointer; }
.pillola.is-attiva { background: var(--accent-100); color: var(--warning-900); border-color: var(--accent-400); }

/* Pulsante tondo «+» per l'azione principale */
.fab { position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent-500); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-md); cursor: pointer; z-index: 40; text-decoration: none; }
.fab:hover { background: var(--accent-600); text-decoration: none; }
.fab svg { width: 26px; height: 26px; }

/* Barra inferiore (solo telefono): le sezioni principali sempre a portata di pollice */
.tabbar { display: none; }
@media (max-width: 900px) {
  /* su telefono la fascia esce dai margini della pagina e si appoggia in alto; le piastrelle la sovrappongono */
  .hero { margin: -20px -16px 0; padding: 20px 20px 36px; border-radius: 0 0 28px 28px; }
  .hero + .tile-grid { position: relative; margin-top: -20px; padding: 0 2px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 65;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .tabbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; font: inherit; font-size: 11.5px; font-weight: 500; color: var(--text-3); cursor: pointer; text-decoration: none; padding: 2px 0; min-width: 0; }
  .tabbar-item:hover { text-decoration: none; color: var(--text-2); }
  .tabbar-icona { width: 56px; height: 30px; border-radius: 999px; display: grid; place-items: center; transition: background 0.15s; }
  .tabbar-icona svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar-item.is-attivo { color: var(--brand-800); font-weight: 600; }
  .tabbar-item.is-attivo .tabbar-icona { background: var(--brand-100); }
  .tabbar-item.is-azione .tabbar-icona { background: var(--accent-500); color: #fff; }
  .tabbar-item.is-azione { color: var(--text-2); }
  /* lascia spazio alla barra sotto il contenuto */
  .app-shell.ha-tabbar .content { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}

/* Fumetti: storico di un lavoro letto come una conversazione */
.fumetti { display: flex; flex-direction: column; gap: 8px; padding: 14px; background: var(--surface-2); border-radius: 20px; }
.fumetto-giorno { align-self: center; font-size: 11.5px; background: var(--surface); color: var(--text-2); padding: 3px 12px; border-radius: 999px; }
.fumetto { max-width: 84%; padding: 8px 12px 6px; border-radius: 16px; font-size: 14px; line-height: 1.4; background: var(--surface); box-shadow: var(--shadow-xs); align-self: flex-start; border-bottom-left-radius: 4px; overflow-wrap: anywhere; }
.fumetto.is-mio { align-self: flex-end; background: var(--brand-100); border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }
.fumetto-autore { display: block; font-size: 12px; font-weight: 600; color: var(--accent-text); margin-bottom: 2px; }
.fumetto-ora { display: block; text-align: right; font-size: 11px; color: var(--text-3); margin-top: 2px; }
.fumetto-stato { align-self: center; background: var(--success-100); color: var(--success-900); font-size: 12.5px; font-weight: 550; padding: 6px 14px; border-radius: 999px; }

/* Stessa informazione in due forme: tabella sul computer, conversazione sul telefono */
.vista-conv { display: none; }
@media (max-width: 900px) { .vista-tabella { display: none; } .vista-conv { display: block; } }
@media (min-width: 640px) { .tile-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.tile-grid.in-scheda .tile { box-shadow: none; background: var(--surface-2); }
/* elenco a conversazione dentro una scheda: senza ombra, a filo dei bordi */
.card > .conv-list { box-shadow: none; border-radius: 0; margin: 0 -22px -20px; }
.card:has(> .conv-list) { overflow: hidden; }
.tile-etichetta { overflow-wrap: anywhere; }
.hero-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.conv-testo.is-lungo { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

/* ---------- 11. Dashboard e icone ---------- */
/* Gli stessi blocchi sul computer e sul telefono: a due colonne se c'è spazio (query sul contenitore .dash), in colonna se no */
.tinta-brand { background: var(--brand-100); color: var(--brand-800); }
.tinta-accent { background: var(--accent-100); color: var(--warning-900); }
.tinta-success { background: var(--success-100); color: var(--success-900); }
.tinta-info { background: var(--info-100); color: var(--info); }
.tinta-danger { background: var(--danger-100); color: var(--danger-900); }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tondo { width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; flex: none; }
.tondo .ico { width: 22px; height: 22px; }

/* Logo Sagires nella barra in alto: marchio, scritta chiara e, se serve, il nome dell'app in piccolo */
.topbar-wordmark { height: 15px; width: auto; display: block; }
.topbar-app { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-400); border-left: 1px solid rgba(255, 255, 255, 0.2); padding-left: 12px; margin-left: 2px; white-space: nowrap; }
@media (max-width: 560px) { .topbar-app { display: none; } .topbar-wordmark { height: 13px; } }

.dash { container-type: inline-size; }
.dash-griglia { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.dash-colonna { display: grid; gap: 16px; min-width: 0; align-content: start; grid-template-columns: minmax(0, 1fr); }
.blocco-titolo { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.blocco-titolo h2 { font-size: 15px; font-weight: 650; color: var(--brand-800); display: flex; align-items: center; gap: 8px; }
.blocco-titolo a { font-size: 13px; font-weight: 550; color: var(--brand-600); display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }
.blocco-titolo a .ico { width: 16px; height: 16px; }

.benvenuto { background: var(--brand-800); color: var(--text-on-navy); border-radius: 24px; padding: 20px 22px; display: grid; gap: 14px; position: relative; overflow: hidden; }
.benvenuto::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%; background: rgba(255, 255, 255, 0.05); pointer-events: none; }
.benvenuto-data { color: var(--text-on-navy-dim); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.benvenuto-data .ico { width: 15px; height: 15px; }
.benvenuto-titolo { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; }
.benvenuto-stato { display: flex; align-items: center; gap: 8px; font-size: 13.5px; background: rgba(255, 255, 255, 0.08); border-radius: 14px; padding: 9px 12px; width: fit-content; max-width: 100%; margin-top: 12px; }
.benvenuto-stato .ico { width: 16px; height: 16px; color: var(--accent-400); }
.benvenuto-stato b { color: var(--accent-400); }
.benvenuto-azioni { display: flex; flex-wrap: wrap; gap: 8px; position: relative; z-index: 1; }

.scorciatoie { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.scorciatoia { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-sm); padding: 14px 8px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 550; color: var(--text); text-align: center; cursor: pointer; border: 0; font-family: inherit; transition: transform 0.1s, box-shadow 0.15s; }
.scorciatoia:hover { box-shadow: var(--shadow-md); }
.scorciatoia:active { transform: translateY(1px); }

.numeri { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.numero { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-sm); padding: 14px; display: flex; gap: 12px; align-items: center; min-width: 0; }
.numero b { display: block; font-size: 26px; font-weight: 650; line-height: 1.05; letter-spacing: -0.02em; color: var(--brand-800); font-variant-numeric: tabular-nums; }
.numero span { font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }
.numero.is-attenzione b { color: var(--danger); }
.mix { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-sm); padding: 14px 16px; margin-top: 10px; }
.mix-barra { display: flex; height: 12px; border-radius: 999px; overflow: hidden; gap: 3px; }
.mix-barra i { display: block; height: 100%; min-width: 4px; }
.mix-legenda { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.mix-legenda span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--c); }

.percorso { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-sm); padding: 16px; }
.passi { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.passi::-webkit-scrollbar { display: none; }
.passo { flex: 1 0 104px; border-radius: 16px; background: var(--surface-2); padding: 12px; display: flex; flex-direction: column; gap: 6px; border: 0; font-family: inherit; text-align: left; cursor: pointer; }
.passo .ico { width: 18px; height: 18px; color: var(--text-3); }
.passo b { font-size: 24px; font-weight: 650; line-height: 1; color: var(--brand-800); }
.passo span { font-size: 12px; color: var(--text-2); }
.passo.da-fare { background: var(--accent-100); }
.passo.da-fare .ico, .passo.da-fare b { color: var(--warning-900); }
.passo.fatto .ico { color: var(--success); }

.agenda { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-sm); padding: 14px 16px; }
.agenda-voce { display: flex; gap: 12px; align-items: center; padding: 9px 0; }
.agenda-voce + .agenda-voce { border-top: 1px solid var(--border); }
.agenda-ora { font-size: 12px; font-weight: 600; color: var(--brand-600); width: 40px; flex: none; }
.agenda-voce b { display: block; font-size: 14px; font-weight: 550; }
.agenda-voce span { font-size: 12.5px; color: var(--text-2); }
.agenda-vuota { font-size: 13px; color: var(--text-2); padding: 6px 0; }

/* piccola icona del tipo sul pallino di una riga a conversazione */
.conv-avatar { position: relative; }
.conv-tipo { position: absolute; right: -3px; bottom: -3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; box-shadow: 0 0 0 1.5px var(--border); }
.conv-tipo .ico { width: 12px; height: 12px; }

@container (min-width: 900px) {
  .dash-griglia { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .dash-griglia > .benvenuto { grid-column: 1 / -1; grid-template-columns: 1fr auto; align-items: center; }
  .dash-griglia > .benvenuto .benvenuto-azioni { justify-content: flex-end; }
  .numeri { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .numero { flex-direction: column; align-items: flex-start; gap: 8px; }
  .passo { flex: 1 1 0; }
  .scorciatoie.in-colonna { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (max-width: 899px) {
  /* telefono: saluto, scorciatoie, poi i blocchi principali, in fondo l'agenda */
  .dash-colonna.laterale { display: contents; }
  .dash-griglia > .benvenuto { order: 0; }
  .scorciatoie-blocco { order: 1; }
  .scorciatoie.in-colonna { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .scorciatoie-blocco .blocco-titolo { display: none; }
  .dash-colonna.principale { order: 2; }
  .agenda-blocco { order: 3; }
}

/* Telefono: le parole non vanno a capo né si troncano. Le etichette sono brevi (nome breve sul telefono, completo dove c'è spazio) */
.scorciatoia .etichetta-lunga { display: none; }
.scorciatoia, .passo span, .numero span, .tab-etichetta { white-space: nowrap; }
.conv-riga .conv-titolo { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -webkit-line-clamp: unset; font-size: 15px; }
.conv-riga .conv-testo { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { align-items: center; }
.conv-data { margin-left: auto; font-size: 12px; color: var(--text-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.solo-largo { display: none; }
.conv-list { container-type: inline-size; }
@container (min-width: 560px) { .conv-testo.solo-largo { display: block; } }
@container (max-width: 899px) { .benvenuto-titolo { font-size: 24px; } .benvenuto-stato { font-size: 13px; } }
@container (min-width: 900px) {
  .scorciatoia .etichetta-breve { display: none; }
  .scorciatoia .etichetta-lunga { display: inline; }
}

/* Percorso dei rapportini e scorciatoie: nessuna scheda tagliata a metà, su telefono vanno su più righe */
.passi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
.passo:last-child:nth-child(odd) { grid-column: 1 / -1; }
@container (min-width: 900px) { .passi { grid-template-columns: repeat(5, minmax(0, 1fr)); } .passo:last-child:nth-child(odd) { grid-column: auto; } }
@container (max-width: 899px) { .scorciatoie.in-colonna { grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); } }

/* Senza l'agenda la colonna laterale è stretta e contiene solo le scorciatoie: più spazio alle schede del mese */
@container (min-width: 900px) {
  .dash-griglia { grid-template-columns: minmax(0, 1fr) 232px; }
  .numeri { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .scorciatoie.in-colonna { gap: 8px; }
  .scorciatoie.in-colonna .scorciatoia { padding: 10px 6px 9px; gap: 6px; font-size: 12px; border-radius: 18px; }
  .scorciatoie.in-colonna .tondo { width: 38px; height: 38px; border-radius: 13px; }
  .scorciatoie.in-colonna .tondo .ico { width: 19px; height: 19px; }
}
@container (min-width: 880px) { .numeri { grid-template-columns: repeat(5, minmax(0, 1fr)); } }

/* Tablet (e computer con poco spazio): una colonna ma con le schede affiancate, come sul computer */
@container (min-width: 600px) and (max-width: 899px) {
  .dash-griglia > .benvenuto { grid-template-columns: 1fr auto; align-items: center; }
  .benvenuto-azioni { justify-content: flex-end; }
  .scorciatoia .etichetta-breve { display: none; }
  .scorciatoia .etichetta-lunga { display: inline; }
  .scorciatoie.in-colonna { gap: 12px; }
}
@container (min-width: 620px) and (max-width: 899px) {
  .numeri { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .numero { flex-direction: column; align-items: flex-start; gap: 8px; }
  .passi { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .passo:last-child:nth-child(odd) { grid-column: auto; }
}

/* Con spazio le pillole vanno a capo invece di scorrere (nessuna tagliata) */
@media (min-width: 600px) { .pillole { flex-wrap: wrap; overflow: visible; } }

/* Schede del mese e percorso dei rapportini: contano lo spazio che hanno loro (non quello della pagina).
   Così vanno bene sia nella colonna stretta di un tablet sia a tutta larghezza. */
.blocco-numeri, .percorso { container-type: inline-size; }
.numeri { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.passi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@container (min-width: 420px) {
  .numeri { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .passi { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .passo:last-child:nth-child(odd) { grid-column: auto; }
}
@container (min-width: 600px) {
  .numeri { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .numero { flex-direction: column; align-items: flex-start; gap: 8px; }
}
@container (min-width: 640px) {
  .passi { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* I codici QR disegnati in SVG dalla libreria qrcode usano tratti larghi 1 e spigoli netti: la regola globale delle icone li rovinerebbe */
svg[shape-rendering="crispEdges"] { stroke-width: 1; stroke-linecap: butt; stroke-linejoin: miter; }

/* ---------- 12. Campanella degli avvisi comuni (js/campanella-avvisi.js) ---------- */
.avb { position: relative; }
.avb-btn { position: relative; }
.avb-conteggio {
  position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--accent-500); color: var(--brand-900); font-size: 11px; font-weight: 650; line-height: 17px; text-align: center;
}
.avb-conteggio[hidden], .avb-pannello[hidden], .avb-tutti[hidden] { display: none; }
.avb-pannello {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: min(380px, calc(100vw - 24px)); max-height: min(70vh, 520px);
  display: flex; flex-direction: column; overflow: hidden; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); visibility: visible;
}
.avb-testa { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.avb-tutti { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; font-weight: 550; color: var(--info); cursor: pointer; }
.avb-tutti:hover { text-decoration: underline; }
.avb-elenco { overflow-y: auto; }
.avb-vuoto { padding: 28px 16px; text-align: center; color: var(--text-2); font-size: 14px; }
.avb-voce {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 12px 14px; text-align: left; cursor: pointer;
  background: none; border: 0; border-bottom: 1px solid var(--border); font: inherit; color: inherit;
}
.avb-voce:last-child { border-bottom: 0; }
.avb-voce:hover { background: var(--surface-2); }
.avb-voce.is-letto { opacity: 0.62; }
.avb-icona { flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.avb-icona svg { width: 17px; height: 17px; }
.avb-corpo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.avb-titolo { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.avb-testo { font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.avb-meta { font-size: 12px; color: var(--text-3); }
.avb-punto { flex: none; width: 9px; height: 9px; margin-top: 6px; border-radius: 50%; background: var(--accent-500); }
.avb-voce.is-letto .avb-punto { visibility: hidden; }
.avb-tipo-urgente { background: var(--danger-100); color: var(--danger-900); }
.avb-tipo-attenzione { background: var(--warning-100); color: var(--warning-900); }
.avb-tipo-info { background: var(--info-100); color: var(--info); }

/* Telefono: il pannello degli avvisi si aggancia ai bordi dello schermo. Ancorato alla campanella (che sta a metà barra) usciva a sinistra e restava tagliato. */
@media (max-width: 640px) {
  .avb-pannello { position: fixed; left: 12px; right: 12px; top: calc(var(--topbar-h) + 8px); width: auto; max-height: calc(100vh - var(--topbar-h) - 32px); max-height: calc(100dvh - var(--topbar-h) - 32px); }
}

/* ---------- tono sobrio ---------- */
strong, b, th { font-weight: 600; }
h1, h2, h3, h4 { font-weight: 600; }

/* tono sobrio: font di sistema e pesi più leggeri (Console, app) */
/* contrasto: testi secondari e arancio come testo a norma WCAG AA */
