/* =============================================================================
   Layout del gestionale (caricato dopo gestionale.css e theme.css):
   menu laterale compattabile con tooltip, menu a scomparsa su schermi stretti,
   badge di stato dei viaggi, stati vuoti guidati, agenda del calendario su smartphone.
   Solo variabili del tema: leggibile in modalita' chiara e scura.
   ============================================================================= */

.shell { transition: grid-template-columns .22s var(--ease, ease); }

/* --- Pulsante "Compatta / Espandi menu" in fondo alla sidebar ------------------------ */
.sidebar-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px dashed var(--tone-300); border-radius: 10px; background: transparent; color: var(--tone-800);
  font-size: 12px; font-weight: 700; cursor: pointer; text-align: left;
}
.sidebar-toggle:hover { background: var(--tone-50); border-style: solid; }
.sidebar-toggle .toggle-icon { flex-shrink: 0; transition: transform .2s var(--ease, ease); }
html[data-sidebar="compact"] .sidebar-toggle .toggle-icon { transform: scaleX(-1); }
.sidebar-toggle:focus-visible, .drawer-btn:focus-visible, .sidebar .nav button:focus-visible, .side-actions .btn:focus-visible {
  outline: 3px solid var(--focus-ring); outline-offset: 2px;
}
.side-actions .btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.side-actions .btn svg { flex-shrink: 0; }

/* --- Sidebar: scorrono solo sezioni e azioni; logo, «Compatta menu» e piede restano sempre visibili --- */
.sidebar { overflow: hidden; }
.sidebar-brand, .sidebar-toggle, .sidebar-bottom { flex-shrink: 0; }
.sidebar-scroll {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: inherit;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
  /* spazio per l'anello del focus e le ombre dei pulsanti, che il contenitore scorrevole taglierebbe */
  padding: 6px; margin: -6px;
}
.sidebar-brand > [data-brand-tagline][hidden], .eyebrow[data-brand-tagline][hidden] { display: none; }

/* --- Tooltip delle voci nella modalita' compatta (agganciato al body: mai tagliato) --- */
.nav-tooltip {
  position: fixed; z-index: 2000; max-width: 260px; padding: 7px 11px; border-radius: 8px;
  background: var(--gray-900); color: var(--gray-0); font-size: 12.5px; font-weight: 700; line-height: 1.3;
  white-space: nowrap; pointer-events: none; box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
  animation: nav-tip-in .12s var(--ease, ease);
}
.nav-tooltip::before {
  content: ''; position: absolute; left: -5px; top: 50%; width: 10px; height: 10px; margin-top: -5px;
  background: inherit; transform: rotate(45deg); border-radius: 2px;
}
.nav-tooltip[hidden] { display: none; }
@keyframes nav-tip-in { from { opacity: 0; transform: translateX(-4px); } to { opacity: 1; transform: none; } }

/* --- Modalita' compatta (desktop e tablet larghi) ---------------------------------------- */
@media (min-width: 768px) {
  html[data-sidebar="compact"] .shell { grid-template-columns: 80px minmax(0, 1fr); }
  html[data-sidebar="compact"] .sidebar { padding: 14px 10px; gap: 10px; overflow-x: hidden; }
  html[data-sidebar="compact"] .sidebar-brand { padding: 6px 4px; border-radius: 10px; }
  html[data-sidebar="compact"] .sidebar-brand .brand-logo { width: 100%; }
  html[data-sidebar="compact"] .sidebar-brand > span,
  html[data-sidebar="compact"] .sidebar-bottom { display: none; }
  html[data-sidebar="compact"] .nav { gap: 6px; }
  html[data-sidebar="compact"] .nav button { justify-content: center; gap: 0; padding: 0; min-height: 48px; flex-wrap: nowrap; }
  html[data-sidebar="compact"] .nav svg { width: 21px; height: 21px; }
  html[data-sidebar="compact"] .nav-number,
  html[data-sidebar="compact"] .nav-label,
  html[data-sidebar="compact"] .side-label,
  html[data-sidebar="compact"] .toggle-label {
    position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  html[data-sidebar="compact"] .side-actions .btn { padding: 0; min-height: 44px; }
  html[data-sidebar="compact"] .sidebar-toggle { justify-content: center; padding: 0; }
}

/* --- Menu a scomparsa (smartphone e tablet stretti) --------------------------------------- */
.drawer-btn, .drawer-backdrop { display: none; }
@media (max-width: 767px) {
  .shell { display: block; }
  .drawer-btn {
    display: inline-grid; place-items: center; flex-shrink: 0; width: 46px; height: 46px; margin-bottom: 4px;
    border: 1px solid var(--tone-200); border-radius: 12px; background: var(--gray-0); color: var(--tone-800); cursor: pointer;
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 1500; width: min(290px, 84vw); height: 100%; height: 100dvh;
    padding: 16px 12px; gap: 12px; overflow: hidden; transform: translateX(-105%); visibility: hidden;
    transition: transform .22s var(--ease, ease), visibility 0s linear .22s; box-shadow: 0 0 40px rgba(0, 0, 0, .28);
  }
  html.drawer-open .sidebar { transform: none; visibility: visible; transition: transform .22s var(--ease, ease); }
  .sidebar .nav button { font-size: 14px; flex-wrap: nowrap; min-height: 48px; }
  .sidebar .nav-label { flex-basis: auto; }
  .sidebar .side-actions .btn { font-size: 13px; padding: 11px; }
  .sidebar-toggle { display: none; }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 1400; background: var(--backdrop); }
  .drawer-backdrop[hidden] { display: none; }
  html.drawer-open, html.drawer-open body { overflow: hidden; }
}

/* --- Stati vuoti guidati ------------------------------------------------------------------ */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px; text-align: center; color: var(--muted); }
.empty-state svg { color: var(--tone-400); margin-bottom: 4px; }
.empty-state strong { color: var(--ink); font-size: 15px; }
.empty-state span { font-size: 13px; }
.empty-state .btn { margin-top: 8px; }
td.empty .empty-state, .panel.empty .empty-state { padding-block: 18px; }

@media print {
  .drawer-btn, .drawer-backdrop, .nav-tooltip, .sidebar-toggle{ display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .shell, .sidebar, .sidebar-toggle .toggle-icon, .nav-tooltip { transition: none !important; animation: none !important; }
}

/* =====================================================================================
   Tabelle: riga evidenziata al passaggio
   ===================================================================================== */
.table-wrap tbody tr:hover td { background: var(--tone-100); }

/* =====================================================================================
   B. Intestazione compatta del gestionale: una sola riga (nome azienda + strumenti), senza
   sopratitolo e slogan; piu' spazio verticale ai dati. In stampa resta l'intestazione completa.
   ===================================================================================== */
@media screen {
  .content-area { padding-top: 16px; }
  .header { align-items: center; padding: 0 0 12px; margin-bottom: 18px; min-height: 52px; }
  .header .eyebrow, .header .sub { display: none; }
  .header h1 { margin: 0; font-size: 22px; line-height: 1.25; letter-spacing: -0.015em; }
}

/* =====================================================================================
   Storico modifiche della scheda (history-panel.js)
   ===================================================================================== */
.history-dialog { width: min(860px, 96vw); }
.history-close {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--tone-200);
  border-radius: 10px; background: var(--gray-0); color: var(--tone-800); cursor: pointer;
}
.history-close:hover { background: var(--tone-50); }
.history-date { display: inline-flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 700; color: var(--gray-700); }
.history-date input { width: auto; min-height: 38px; }
.history-snapshot { margin-top: 12px; }
.history-snapshot h4 { margin: 0 0 6px; font-size: 13px; color: var(--tone-800); }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history-item { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--gray-0); }
.history-item.create { background: var(--tone-50); }
.history-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.history-head strong { color: var(--tone-800); font-size: 14px; }
.history-head > span:last-child { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.history-src { padding: 1px 7px; border-radius: 6px; background: var(--tone-100); color: var(--tone-700); font-size: 11px; font-weight: 700; }
.history-changes { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 13px; }
.history-changes th, .history-changes td {
  position: static; padding: 6px 8px; border-bottom: 1px solid var(--tone-150); background: transparent !important;
  color: var(--ink); text-align: left; white-space: normal; vertical-align: top; font-weight: 400;
}
.history-changes thead th { font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); }
.history-changes tbody th { width: 26%; font-weight: 700; color: var(--gray-700); }
.history-changes tr:last-child th, .history-changes tr:last-child td { border-bottom: 0; }
.history-changes td.from { color: var(--gray-700); }
.history-changes td.arrow { width: 18px; color: var(--muted); padding-left: 0; padding-right: 0; }
.history-changes td.act { width: 1%; white-space: nowrap; text-align: right; }
.history-restore {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border: 1px solid var(--tone-200);
  border-radius: 8px; background: var(--gray-0); color: var(--tone-800); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.history-restore:hover { background: var(--tone-50); border-color: var(--tone-300); }
.history-restore:disabled { opacity: .55; cursor: progress; }
.history-empty { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.history-note { margin: 0 0 10px; padding: 8px 10px; border-radius: 9px; background: var(--tone-50); color: var(--gray-700); font-size: 12px; }
.history-error { margin: 0; color: var(--bad-700); font-size: 13px; }
.history-error:empty { display: none; }
@media (max-width: 600px) {
  .history-changes thead { display: none; }
  .history-changes tr { display: grid; grid-template-columns: 1fr auto; border-bottom: 1px solid var(--tone-150); }
  .history-changes tbody th, .history-changes td { border: 0; width: auto; }
  .history-changes tbody th { grid-column: 1 / -1; padding-bottom: 0; }
  .history-changes td.arrow { display: none; }
  .history-changes td.from::before { content: 'Prima: '; color: var(--muted); }
  .history-changes td.to::before { content: 'Dopo: '; color: var(--muted); }
}

/* --- Documenti allegati (attachments.js) --------------------------------------------------------- */
.attachments-section h3 { display: flex; align-items: center; gap: 8px; }
.att-count { font-size: 12px; background: var(--tone-150); color: var(--tone-800); border-radius: 999px; padding: 1px 8px; }
.att-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.att-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--gray-0); }
.att-icon { flex: none; width: 38px; height: 38px; border-radius: 8px; display: grid; place-items: center; font-size: 10px; font-weight: 800; background: var(--tone-100); color: var(--tone-700); }
.att-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att-info a { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-info small { color: var(--muted); font-size: 11px; }
.att-empty { color: var(--muted); font-size: 13px; }
.att-add { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.att-add .field { min-width: 200px; }
.att-pick { cursor: pointer; }
.att-pick.disabled { opacity: .6; pointer-events: none; }
.att-hint { font-size: 11px; color: var(--muted); }
.att-error { color: var(--bad-700); font-size: 13px; margin: 8px 0 0; }

/* --- Fondo della sidebar: nome dell'applicazione e versione ---------------------------- */
.sidebar-bottom { display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.35; }
.sidebar-bottom .app-name { font-size: 11.5px; font-weight: 800; color: var(--tone-800); letter-spacing: .2px; }
.sidebar-bottom .app-version { font-size: 11px; color: var(--gray-600); font-variant-numeric: tabular-nums; }
.sidebar-bottom .app-version:empty { display: none; }

/* --- Documenti allegati: anteprima, scarica ------------------------------------------- */
.att-thumb { flex: none; width: 38px; height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--tone-100); cursor: zoom-in; }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-info .att-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; padding: 0; border: 0; background: none; color: var(--blue); cursor: pointer; font-size: 13px; }
.att-info button.att-name:hover { text-decoration: underline; }
.att-actions { display: flex; gap: 6px; flex: none; }
.att-viewer { width: min(1100px, 96vw); }
.att-viewer-body { display: grid; place-items: center; background: var(--tone-100); height: min(78vh, 900px); }
.att-viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.att-viewer-body iframe { width: 100%; height: 100%; border: 0; background: var(--gray-0); }
@media (max-width: 600px) { .att-item { flex-wrap: wrap; } .att-actions { width: 100%; justify-content: flex-end; } }

/* --- Scansione documenti (doc-scanner.js) ------------------------------------------------ */
.scan-dialog { width: min(980px, 96vw); }
.scan-sources { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.scan-sources label.btn { cursor: pointer; }
.scan-mode { min-width: 210px; }
.scan-live { margin-bottom: 12px; text-align: center; }
.scan-live video { width: 100%; max-height: 52vh; background: #000; border-radius: 12px; object-fit: contain; }
.scan-live-tools { display: flex; justify-content: center; gap: 10px; margin-top: 8px; }
.scan-pages { list-style: none; padding: 0; margin: 14px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.scan-page { position: relative; border: 1px solid var(--line); border-radius: 10px; background: var(--gray-0); padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.scan-page img { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: var(--tone-100); border-radius: 6px; }
.scan-num { position: absolute; top: 10px; left: 10px; background: var(--secondary); color: var(--on-secondary); border-radius: 999px; font-size: 11px; font-weight: 800; padding: 1px 8px; }
.scan-page-tools { display: flex; justify-content: space-between; gap: 4px; }
.scan-page-tools .btn { flex: 1; padding: 4px 0; min-height: 30px; }

/* --- Documenti: proposta della scadenza dopo il caricamento (attachments.js) ------------- */
.att-deadline { margin: 0 0 12px; padding: 12px 14px; border: 1px solid var(--warn-300); border-left: 4px solid var(--warn-500); border-radius: 10px; background: var(--warn-100); color: var(--warn-800); }
.att-deadline p { margin: 0 0 10px; font-size: 13px; }
.att-deadline-fields { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.att-deadline-fields .field { min-width: 160px; }
.att-deadline-fields .field input[type=number] { max-width: 140px; }

.scan-page-tools .btn.active { background: var(--tone-150); color: var(--tone-800); border-color: var(--tone-400); }
.att-private { margin: -4px 0 10px; font-size: 12px; color: var(--gray-700); }
