/* MFDirectorHub – Patch UI 2.8.1: desktop + mobile responsive.
   Solo presentazione. Il foglio principale e personnel.css restano invariati. */
:root { --mf-ui-sidebar: 252px; --mf-ui-topbar: 70px; }
html { min-width: 320px; }
*, *::before, *::after { box-sizing: border-box; }
body, #app { min-width: 0; }
#app .layout, #app .layout > div, #app .page { min-width: 0; }
#app .page { box-sizing: border-box; }
#app .page img, #app .page video { max-width: 100%; height: auto; }
#app .page .card, #app .page .tile, #app .page .module-card,
#app .page .pm-person-card { min-width: 0; overflow-wrap: anywhere; }
#app .page .pm-matrix-scroll { max-width: 100%; }
#app .page input, #app .page select, #app .page textarea { max-width: 100%; }
#app .mf-nav-shade { display:none; }

/* Desktop: una sola navigazione, contenuti realmente espansi. */
@media (min-width: 821px) {
  #app > .layout {
    display: grid !important;
    grid-template-columns: var(--mf-ui-sidebar) minmax(0, 1fr) !important;
    grid-template-rows: auto !important;
    align-items: stretch !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }
  #app > .layout > .mf-nav-shade { display: none !important; }
  #app > .layout > .mf-nav-drawer {
    display: flex !important;
    flex-direction: column !important;
    position: sticky !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    top: 0 !important;
    bottom: auto !important;
    left: auto !important;
    width: var(--mf-ui-sidebar) !important;
    max-width: var(--mf-ui-sidebar) !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    padding: 24px 14px 20px !important;
    transform: none !important;
    transition: width .18s ease, max-width .18s ease !important;
    border-radius: 0 !important;
    background: #153344 !important;
    color: #f1f9fc !important;
    box-shadow: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    z-index: 20 !important;
  }
  #app > .layout > .mf-nav-drawer .brand { flex-shrink: 0; margin-bottom: 25px; }
  #app > .layout > .mf-nav-drawer .nav {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    min-width: 0;
    gap: 4px;
  }
  #app > .layout > .mf-nav-drawer .nav-btn {
    display: flex !important;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-start;
    width: 100% !important;
    min-height: 43px;
    gap: 11px;
    margin: 0;
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
    border-radius: 11px;
  }
  #app > .layout > .mf-nav-drawer .nav-btn .ico { flex: 0 0 22px; text-align: center; }
  #app > .layout > .mf-nav-drawer .sidebar-footer { margin-top: auto; padding-top: 22px; }
  #app > .layout > div:last-child {
    display: flex !important;
    flex-direction: column !important;
    grid-column: 2 !important;
    grid-row: 1 !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible;
  }
  #app > .layout > div:last-child > .mobile-top {
    display: flex !important;
    flex: 0 0 auto;
    position: sticky !important;
    top: 0 !important;
    align-items: center;
    gap: 16px;
    width: 100% !important;
    min-height: var(--mf-ui-topbar);
    margin: 0 !important;
    padding: 10px clamp(20px, 3vw, 44px) !important;
    color: #163b4a !important;
    background: #fff !important;
    border-bottom: 1px solid #dfebee;
    box-shadow: 0 3px 16px rgba(15, 45, 56, .035);
    z-index: 15;
  }
  #app > .layout > div:last-child > .mobile-top .brand,
  #app > .layout > div:last-child > .mobile-top .brand.light { color: #163b4a !important; }
  #app > .layout > div:last-child > .mobile-top .brand-logo { flex: 0 0 auto; }
  #app > .layout > div:last-child > .mobile-top #logout-mobile { margin-left: auto !important; }
  #app > .layout > div:last-child > .mobile-nav { display: none !important; }
  #app > .layout > div:last-child > .page {
    display: block;
    flex: 1 1 auto;
    width: 100% !important;
    max-width: 1480px !important;
    min-height: calc(100vh - var(--mf-ui-topbar));
    margin: 0 auto !important;
    padding: clamp(22px, 2.5vw, 40px) clamp(20px, 2.7vw, 46px) 64px !important;
    overflow: visible;
  }
  #app > .layout .page > .grid,
  #app > .layout .page section.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: 18px;
  }
  #app > .layout .page .pm-person-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); }
  #app > .layout .page .pm-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #app > .layout .page .pm-mobile-sections { display: none !important; }
  #app > .layout .page .pm-filter > .pm-tabs { display: flex !important; }
  #app > .layout .page .pm-ctc-mobile { display: none !important; }
  #app > .layout .page .pm-ctc-desktop { display: block !important; }
  #app .mf-menu-button { min-height: 43px; min-width: 43px; font-size: 20px; padding: 7px 10px; }
  body.mf-ui-nav-collapsed #app > .layout { --mf-ui-sidebar: 74px; }
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer { padding-inline: 9px !important; }
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer .brand { justify-content: center; }
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer .brand > span:not(.brand-logo),
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer .sidebar-footer { display: none !important; }
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer .nav-btn {
    justify-content: center !important;
    gap: 0;
    padding-inline: 4px;
    font-size: 0 !important;
  }
  body.mf-ui-nav-collapsed #app > .layout > .mf-nav-drawer .nav-btn .ico { font-size: 22px !important; flex-basis: 30px; }
}

@media (min-width: 821px) and (max-width: 1120px) {
  #app > .layout { --mf-ui-sidebar: 220px; }
  #app > .layout .page .pm-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.mf-ui-nav-collapsed #app > .layout { --mf-ui-sidebar: 74px; }
}

/* Smartphone e tablet: una sola pagina, drawer a scomparsa. */
@media (max-width: 820px) {
  #app > .layout {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  #app > .layout > div:last-child { width: 100% !important; max-width: none !important; min-width: 0; }
  #app > .layout > .mf-nav-drawer {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    z-index: 1001 !important;
    width: min(86vw, 320px) !important;
    max-width: 320px !important;
    height: 100dvh !important;
    display: flex !important;
    flex-direction: column;
    overflow-y: auto;
    transform: translateX(-108%) !important;
    background: #153344 !important;
  }
  #app > .layout > .mf-nav-drawer.open { transform: translateX(0) !important; }
  #app > .layout > .mf-nav-shade { display: none !important; }
  #app > .layout > .mf-nav-shade.open { display: block !important; position: fixed; inset: 0; z-index: 1000; background: rgba(5, 24, 36, .62); }
  #app > .layout > div:last-child > .mobile-top {
    display: flex !important;
    position: sticky !important;
    top: 0;
    width: 100% !important;
    min-height: 62px;
    padding: 9px 14px !important;
    margin: 0 !important;
    align-items: center;
    gap: 10px;
    background: #173847;
    color: #fff;
    z-index: 40;
  }
  #app > .layout > div:last-child > .mobile-top .brand { min-width: 0; font-size: 1rem; }
  #app > .layout > div:last-child > .mobile-top .brand-logo { flex-shrink: 0; }
  #app > .layout > div:last-child > .mobile-top #logout-mobile { margin-left: auto; }
  #app > .layout > div:last-child > .mobile-nav { display: none !important; }
  #app > .layout > div:last-child > .page {
    width: 100% !important;
    max-width: none !important;
    min-height: calc(100dvh - 62px);
    margin: 0 !important;
    padding: 18px 15px 76px !important;
  }
  #app > .layout .page .grid { grid-template-columns: 1fr !important; }
  #app > .layout .page .pm-person-grid,
  #app > .layout .page .pm-mini-list { grid-template-columns: 1fr !important; }
  #app > .layout .page .pm-fields { grid-template-columns: 1fr !important; }
  #app > .layout .page .pm-fields .pm-wide { grid-column: auto !important; }
  #app > .layout .page .pm-ctc-desktop { display: none !important; }
  #app > .layout .page .pm-ctc-mobile { display: grid !important; }
}
@media (min-width: 600px) and (max-width: 820px) {
  #app > .layout .page .grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #app > .layout .page .pm-person-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  #app > .layout .page .pm-fields { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (prefers-reduced-motion: reduce) { #app > .layout > .mf-nav-drawer { transition: none !important; } }
