/* ═══════════════════════════════════════════════════════════════════════════
   MedArchivio — Responsive & PWA
   Breakpoint principale: 768px
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --sidebar-w: 210px;
  --topbar-h: 52px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 90;
}
.sidebar-overlay.open { display: block; }

.btn-menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  border-radius: var(--radius);
  color: var(--c-text-2);
  flex-shrink: 0;
  padding: 0;
}
.btn-menu:hover { background: var(--c-bg); }
.btn-menu svg { stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar-footer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (max-width: 768px) {

  .app-layout { position: relative; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { padding: 10px 12px; gap: 8px; }
  .btn-menu { display: flex; }
  .topbar-sub { display: none; }
  .topbar-title { font-size: 13px; }

  .search-wrap { flex: 1; max-width: none; min-width: 0; }

  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 6px 8px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .section-wrap { padding: 10px; }
  .card { padding: 11px; margin-bottom: 9px; }

  .doc-row { padding: 9px 10px; gap: 8px; }
  .doc-actions { gap: 3px; }
  .icon-btn { width: 32px; height: 32px; }

  .filter-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 5px;
  }
  .chip { white-space: nowrap; flex-shrink: 0; }

  .viewer-container {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    position: fixed;
    inset: 0;
  }

  .viewer-body { flex-direction: column; }
  .viewer-sidebar {
    width: 100%;
    border-left: none;
    border-top: 0.5px solid var(--c-border);
    max-height: 220px;
    overflow-y: auto;
    flex-shrink: 0;
  }

  .viewer-topbar { padding: 8px 10px; gap: 5px; }
  .viewer-actions {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    flex-shrink: 1;
  }
  .viewer-title { font-size: 12px; max-width: 120px; }

  .login-card { border-radius: var(--radius); padding: 1.5rem; margin: 12px; }
  .screen-login { align-items: flex-start; padding-top: 60px; }

  .pat-btn { padding: 8px 9px; font-size: 13px; }
  .pat-avatar { width: 26px; height: 26px; font-size: 10px; }

  .nav-item { padding: 9px 8px; font-size: 13px; }
  .nav-icon { width: 17px; height: 17px; }

  .log-ip { display: none; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 185px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .viewer-sidebar { width: 200px; }
}

@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
  }
}

/* ── Fix viewer mobile: z-index e touch ─────────────────────────────────── */
.viewer-overlay {
  z-index: 200 !important;
  -webkit-overflow-scrolling: touch;
}
.viewer-container {
  -webkit-overflow-scrolling: touch;
}
.viewer-canvas-wrap {
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
}
/* Bottoni viewer: area tap più grande su mobile */
@media (max-width: 768px) {
  .btn-view-file {
    min-width: 36px;
    min-height: 36px;
    touch-action: manipulation;
  }
}

/* ── Bottone ℹ️ metadati: solo su mobile ─────────────────────────────────── */
.btn-mobile-only { display: none; }
@media (max-width: 768px) {
  .btn-mobile-only { display: inline-flex; }
}

/* ── Disabilita pull-to-refresh su PWA Android ───────────────────────────── */
@media (display-mode: standalone) {
  body {
    overscroll-behavior-y: contain;
  }
}
html {
  overscroll-behavior-y: contain;
}

/* ── Dimensioni testo aumentate su mobile ────────────────────────────────── */
@media (max-width: 768px) {

  /* Lista documenti */
  .doc-name { font-size: 13px; }
  .doc-meta { font-size: 11px; }

  /* Badge categoria */
  .badge { font-size: 11px; padding: 3px 8px; }

  /* File dentro cartella */
  .file-nome { font-size: 13px !important; }
  .file-row span[style*="font-size:10px"] { font-size: 12px !important; }
  .file-row span[style*="font-size:11px"] { font-size: 13px !important; }

  /* Note */
  .note-text { font-size: 13px; }
  .note-who { font-size: 11px; }

  /* Stat cards */
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 20px; }

  /* Topbar */
  .topbar-title { font-size: 14px; }

  /* Metadati viewer */
  .vs-row { font-size: 12px; }
  .vs-lbl { font-size: 11px; }
  .vs-val { font-size: 12px; }
  .vs-title { font-size: 12px; }

  /* Bottoni viewer */
  .btn-sm { font-size: 12px; padding: 6px 10px; }

  /* Chip filtri */
  .chip { font-size: 12px; padding: 5px 12px; }

  /* Log */
  .log-row { font-size: 13px; }
  .log-time { font-size: 11px; }
}

/* ── Bottone privato: solo desktop nella riga file ───────────────────────── */
@media (max-width: 768px) {
  .btn-toggle-privato { display: none; }
}

/* ── File row mobile: layout a due righe ────────────────────────────────── */
@media (max-width: 768px) {
  .file-row {
    flex-wrap: wrap;
    gap: 4px;
  }
  .file-nome {
    width: 100%;
    flex: none !important;
    font-size: 12px !important;
    order: -1;
  }
  .file-row > span[style*="font-size:10px"],
  .file-row > span[style*="font-size:13px"] {
    font-size: 11px !important;
  }
}

/* ── Cartella row: layout adattivo ──────────────────────────────────────── */
/* Desktop: riga singola */
.doc-row-top { display: flex; align-items: center; gap: 10px; }
.doc-row-footer { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* Mobile: nome su riga intera, non troncato */
@media (max-width: 768px) {
  .doc-row-top .doc-name {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: unset !important;
    line-height: 1.3;
  }
  .doc-row-footer .doc-actions {
    gap: 4px;
  }
  .doc-row-footer .icon-btn {
    width: 32px;
    height: 32px;
  }
}

/* ── Cartella row mobile: bottoni footer ────────────────────────────────── */
@media (max-width: 768px) {
  /* Nascondi btn apri cartella su mobile (tap sulla riga già apre) */
  .doc-row-footer .btn-open-cartella { display: none; }
  /* Assicura che doc-actions non vada fuori schermo */
  .doc-row-footer { flex-wrap: nowrap; overflow: visible; }
  .doc-row-footer .doc-actions { flex-shrink: 0; display: flex; gap: 4px; }
}
