:root {
    --color-primary: #1649ff;
    --color-on-primary: rgba(255, 255, 255, 0.92);
    --color-on-primary-strong: #ffffff;

    /* Sfumatura del blu (gradienti, enfasi) — non va impostata a mano */
    --color-primary-shade: color-mix(in srgb, var(--color-primary), #000000 32%);
    --color-primary-emphasis: color-mix(in srgb, var(--color-primary), #000000 28%);

    /* Secondo primario */
    --color-primary-2: #47faa1;
    --color-on-primary-2: #063d22;

    --color-on-primary-border: rgba(255, 255, 255, 0.3);

    --color-page-bg: #f5f7fb;
    --color-admin-page-bg: #2c3138;
  }

  body {
    background: var(--color-page-bg);
    font-family: 'DM Sans', system-ui, sans-serif;
  }

  body.page-admin {
    background: var(--color-admin-page-bg);
    min-height: 100vh;
  }

  /* Intestazione panoramica admin: testo chiaro sul fondo pagina scuro */
  body.page-admin .admin-page-intro-title {
    color: #f1f5f9;
    font-weight: 600;
  }

  body.page-admin .admin-page-intro-text {
    color: rgba(241, 245, 249, 0.72);
  }

  .navbar-custom {
    background: linear-gradient(90deg, var(--color-primary), var(--color-primary-shade));
    font-family: 'DM Sans', system-ui, sans-serif;
  }

  .navbar-custom .navbar-brand.portal-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    color: var(--color-on-primary);
    text-decoration: none;
  }

  .navbar-custom .navbar-brand.portal-brand:hover {
    color: var(--color-primary-2);
    text-decoration: underline;
    text-underline-offset: 6px;
    text-decoration-thickness: 2px;
  }

  .portal-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
  }

  .portal-title {
    font-weight: 600;
    letter-spacing: 0.2px;
  }

  .portal-nav .nav-link {
    color: var(--color-on-primary);
    font-weight: 500;
    padding-left: 14px;
    padding-right: 14px;
  }

  .portal-nav .nav-link.active,
  .portal-nav .nav-link:hover {
    color: var(--color-primary-2);
    text-decoration: underline;
    text-underline-offset: 6px;
    text-decoration-thickness: 2px;
  }

  .navbar-custom .portal-actions .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--color-on-primary);
    font-weight: 600;
  }

  .navbar-custom .portal-actions .nav-link.active,
  .navbar-custom .portal-actions .nav-link:hover {
    color: var(--color-primary-2);
    text-decoration: underline;
    text-underline-offset: 6px;
    text-decoration-thickness: 2px;
  }

  .portal-icon {
    width: 18px;
    height: 18px;
    display: inline-block;
  }

  .portal-menu-toggle {
    border: 0;
    box-shadow: none !important;
    cursor: pointer;
  }

  @media (min-width: 992px) {
    .portal-menu-checkbox {
      display: none;
    }

    .navbar-custom .container-fluid {
      flex-wrap: nowrap;
      align-items: center;
    }

    .portal-topbar {
      width: auto !important;
      flex: 0 0 auto;
      min-width: 0;
    }

    .portal-menu {
      flex: 1 1 auto;
      min-width: 0;
      margin-top: 0;
    }

    .portal-nav {
      position: static;
      transform: none;
      translate: none;
      white-space: nowrap;
      margin-left: auto;
      margin-right: auto;
    }

    .portal-actions {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-left: 12px;
      flex-shrink: 0;
    }

    .portal-actions .nav-item,
    .portal-actions form {
      display: flex;
      align-items: center;
    }

    .navbar-custom .portal-actions .nav-link {
      padding-left: 0.5rem;
      padding-right: 0.5rem;
      white-space: nowrap;
    }
  }

  @media (max-width: 991.98px) {
    html.portal-menu-open,
    body.portal-menu-open {
      overflow: hidden;
      height: 100%;
      overscroll-behavior: none;
    }

    body.portal-menu-open {
      position: fixed;
      left: 0;
      right: 0;
      width: 100%;
    }

    .navbar-custom {
      position: relative;
      z-index: 1030;
      padding-top: 10px;
      padding-bottom: 10px;
    }

    .portal-topbar {
      width: 100%;
      min-height: 44px;
      position: relative;
      z-index: 1050;
    }

    .portal-brand {
      margin-right: 12px;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .portal-title {
      font-size: 1rem;
    }

    .portal-menu {
      display: none;
      position: fixed;
      top: var(--portal-mobile-menu-offset, 72px);
      right: 0;
      bottom: 0;
      left: 0;
      width: 100vw;
      height: auto;
      max-height: calc(100dvh - var(--portal-mobile-menu-offset, 72px));
      margin-top: 0;
      padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
      flex-direction: column;
      align-items: stretch;
      gap: 0;
      overflow-y: auto;
      overscroll-behavior: contain;
      -webkit-overflow-scrolling: touch;
      background: linear-gradient(180deg, var(--color-primary), var(--color-primary-shade));
      z-index: 1040;
    }

    .portal-menu-checkbox {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }

    .portal-menu-checkbox:checked ~ .portal-menu {
      display: flex;
    }

    .portal-nav,
    .portal-actions {
      width: 100%;
      margin: 0;
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 0;
    }

    .portal-nav {
      margin-bottom: 10px;
    }

    .portal-nav .nav-link,
    .portal-actions .nav-link {
      display: flex;
      align-items: center;
      padding: 12px 0;
      font-size: 1.05rem;
    }

    .portal-nav .nav-link.active,
    .portal-nav .nav-link:hover {
      text-underline-offset: 4px;
    }

    .navbar-custom .portal-actions .nav-link.active,
    .navbar-custom .portal-actions .nav-link:hover {
      text-underline-offset: 4px;
    }

    .navbar-custom .navbar-brand.portal-brand:hover {
      text-underline-offset: 4px;
    }

    .portal-actions {
      margin-top: auto;
      padding-top: 12px;
      border-top: 1px solid var(--color-on-primary-border);
    }
  }
  
  .card-custom {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  }
  
  .badge-role {
    background: var(--color-primary-2);
    color: var(--color-on-primary-2);
    font-weight: 500;
  }

  .btn-download-primary-2 {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--color-primary-2);
    color: var(--color-on-primary-2);
    border-color: var(--color-primary-2);
    font-weight: 600;
  }

  .btn-download-primary-2:hover {
    background: color-mix(in srgb, var(--color-primary-2), #000000 14%);
    border-color: color-mix(in srgb, var(--color-primary-2), #000000 14%);
    color: var(--color-on-primary-2);
  }

  .btn-download-primary-2 .btn-download-icon {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
  }
  
  .sidebar-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
  }

  /* Admin sidebar: navigazione + accordion mobile (checkbox, senza JS) */
  .admin-sidebar {
    position: relative;
  }

  .admin-sidebar-toggle-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .admin-sidebar-toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    margin: 0;
    padding: 0.65rem 0.9rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-primary-emphasis, #1e3a5f);
    background: color-mix(in srgb, var(--color-primary-2), transparent 92%);
    border: 1px solid color-mix(in srgb, var(--color-primary-2), transparent 78%);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
  }

  .admin-sidebar-chevron {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    transition: transform 0.2s ease;
  }

  .admin-sidebar-toggle-input:checked ~ .admin-sidebar-mobile-bar .admin-sidebar-chevron {
    transform: rotate(180deg);
  }

  .admin-sidebar-panel {
    display: none;
    padding-top: 0;
  }

  .admin-sidebar-toggle-input:checked ~ .admin-sidebar-panel {
    display: block;
  }

  .admin-sidebar-nav-list li + li {
    margin-top: 0.35rem;
  }

  .admin-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--color-primary-emphasis, #1e3a5f);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    transition: background 0.15s ease, color 0.15s ease;
  }

  .admin-sidebar-link:hover {
    background: color-mix(in srgb, var(--color-primary-2), transparent 90%);
    color: var(--color-primary-emphasis, #1e3a5f);
  }

  .admin-sidebar-link.is-active {
    background: color-mix(in srgb, var(--color-primary), transparent 90%);
    color: var(--color-primary-emphasis);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--color-primary);
  }

  .admin-sidebar-link-icon {
    width: 1.15rem;
    height: 1.15rem;
    flex-shrink: 0;
    opacity: 0.9;
  }

  @media (min-width: 768px) {
    .admin-sidebar-panel {
      display: block !important;
    }

    .admin-sidebar-mobile-bar {
      display: none !important;
    }
  }
  
  .doc-card {
    transition: 0.2s;
  }
  .doc-card:hover {
    transform: translateY(-3px);
  }

  .doc-cards-row {
    align-items: stretch;
  }

  .doc-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--color-primary-2), transparent 88%);
    color: var(--color-primary-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .doc-card-icon svg {
    width: 22px;
    height: 22px;
  }

  .doc-card-title {
    font-size: 1.05rem;
    line-height: 1.3;
    color: var(--color-primary-emphasis);
  }

  .doc-type-badge {
    background: color-mix(in srgb, var(--color-primary-2), transparent 82%);
    color: var(--color-on-primary-2);
    font-weight: 600;
    font-size: 0.75rem;
    padding: 0.35em 0.75em;
  }

  .doc-card-desc {
    line-height: 1.45;
    text-align: left;
  }

  .doc-card-updated {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.35;
    font-family: 'DM Sans', system-ui, sans-serif;
  }

  .doc-card-updated-label {
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
  }

  .doc-card-updated-date {
    font-weight: 600;
    color: var(--color-primary-emphasis);
    font-variant-numeric: tabular-nums;
  }

  .btn-download-primary-2.w-100 {
    justify-content: center;
  }

  .report-featured {
    border: 1px solid color-mix(in srgb, var(--color-primary-2), transparent 72%);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--color-primary), transparent 86%);
  }

  .report-featured .card-body {
    padding: 1.75rem 2rem;
  }

  .report-featured-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  .report-featured-icon svg {
    width: 30px;
    height: 30px;
  }

  .report-row + .report-row {
    border-top: 1px solid #eef1f6;
  }

  .report-row-meta {
    min-width: 0;
  }

  .report-title {
    color: var(--color-primary);
    font-size: 1.5rem;
    line-height: 1.2;
  }

  .report-title-sm {
    color: var(--color-primary);
    font-size: 1.1rem;
    line-height: 1.2;
    margin-bottom: 2px;
  }

  /* Admin: elenco «Report caricati» a card */
  .admin-uploaded-report-card {
    min-width: 0;
    padding: 1rem 1.1rem;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
    background: #fff;
  }

  .admin-uploaded-report-title {
    color: var(--color-primary);
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.25;
    word-break: break-word;
  }

  .admin-uploaded-report-desc {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    word-break: break-word;
    margin-bottom: 0;
  }

  .admin-uploaded-report-meta dd {
    word-break: break-word;
  }

  /* Admin: elenco «Documenti caricati» a card */
  .admin-uploaded-doc-card {
    min-width: 0;
    padding: 1rem 1.1rem;
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
    background: #fff;
  }

  .admin-uploaded-doc-title {
    color: var(--color-primary);
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.25;
    word-break: break-word;
  }

  .admin-uploaded-doc-desc {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    word-break: break-word;
    margin-bottom: 0;
  }

  .admin-uploaded-doc-meta dd {
    word-break: break-word;
  }

  .dashboard-link-card {
    display: block;
    text-decoration: none;
    color: inherit;
    min-height: 165px;
    border: 1px solid transparent;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  }

  .dashboard-link-card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--color-primary), transparent 72%);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--color-primary), transparent 86%);
  }

  .dashboard-link-head {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .dashboard-link-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--color-primary-2), transparent 88%);
    color: var(--color-primary-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .dashboard-link-icon svg {
    width: 22px;
    height: 22px;
  }

  .dashboard-link-cta {
    display: inline-block;
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--color-primary-emphasis);
    font-weight: 600;
  }

  .role-toggle-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .role-toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .role-toggle-label {
    border: 1px solid #dc3545;
    color: #dc3545;
    background: #fff5f5;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
  }

  .role-toggle-label:hover {
    filter: brightness(0.98);
  }

  .role-toggle-input:checked + .role-toggle-label {
    border-color: #198754;
    color: #198754;
    background: #ecfdf3;
  }

  .sidebar-user-label {
    margin-top: 0.15rem;
  }

  .sidebar-user-name,
  .sidebar-user-name strong {
    color: var(--color-primary);
  }

  .profile-header {
    align-items: center;
  }

  .profile-avatar-placeholder {
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: var(--color-primary);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .profile-avatar-placeholder svg {
    width: 24px;
    height: 24px;
  }

  .profile-fullname {
    color: var(--color-primary);
    font-size: 1.35rem;
    line-height: 1.2;
    font-weight: 600;
  }

  .profile-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 500;
  }

  .profile-edit-btn:hover {
    color: var(--color-on-primary-strong);
    background: var(--color-primary);
    border-color: var(--color-primary);
  }

  .profile-edit-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
  }

  .profile-fields {
    margin-top: 0.35rem;
  }

  .profile-field-label {
    color: #6b7280;
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
  }

  .profile-field-value {
    color: var(--color-primary);
    font-size: 1.2rem;
    line-height: 1.25;
    font-weight: 500;
    word-break: break-word;
  }
  
  .login-card {
    max-width: 420px;
    margin: auto;
  }
  
  @media (max-width: 768px) {
    .sidebar-card {
      margin-bottom: 20px;
    }

    .profile-fullname {
      font-size: 1.2rem;
    }

    .profile-field-value {
      font-size: 1.05rem;
    }
  }