/* ============================================================================
   Site CSS - FileInsoluti
   Stili per il layout con sidebar verticale
   ============================================================================ */

/* === Variabili CSS === */
:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #475569;
    --success-color: #16a34a;
    --danger-color: #dc2626;
    --warning-color: #d97706;
    --text-color: #1e293b;
    --text-muted: #475569;
    --bg-color: #f1f5f9;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
}

/* === Reset e Base === */
html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
}

/* ============================================================================
   ACCESSIBILITY - SKIP LINKS
   ============================================================================ */

.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 12px 24px;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 10000;
    transition: top 0.3s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

/* ============================================================================
   ACCESSIBILITY - FOCUS STATES (WCAG 2.4.7)
   ============================================================================ */

/* Focus states generali - outline visibile e ad alto contrasto */
:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Focus states per bottoni e form */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--primary-color);
    outline: none;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-check-input:focus-visible {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem var(--primary-color);
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

/* Focus per link nella sidebar */
.sidebar .nav-link:focus-visible,
.nav-sublink:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: -2px;
    background-color: rgba(255, 255, 255, 0.15);
}

/* Focus per dropdown items */
.dropdown-item:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: -2px;
    background: #e0e7ff;
}

/* ============================================================================
   MOBILE MENU TOGGLE (HAMBURGER)
   ============================================================================ */

.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: background 0.3s ease, transform 0.3s ease;
}

.mobile-menu-toggle:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.mobile-menu-toggle:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    width: 100%;
}

.hamburger-icon span {
    display: block;
    height: 3px;
    width: 100%;
    background: white;
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Hamburger animazione quando menu aperto */
.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================================================================
   SIDEBAR NAVIGATION
   ============================================================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header */
.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
}

.brand-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
}

.brand-icon i {
    color: #22c55e;
}

.brand-text {
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .brand-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 0.25rem 0;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    min-height: 48px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    font-size: inherit;
}

.sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.sidebar .nav-link.active {
    background-color: rgba(37, 99, 235, 0.2);
    color: white;
    border-left: 4px solid var(--primary-color);
}

.nav-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
}

.nav-text {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Submenu */
.has-submenu .nav-link {
    justify-content: flex-start;
}

.submenu-arrow {
    font-size: 0.75rem;
    transition: transform 0.3s ease, opacity 0.3s ease;
    flex-shrink: 0;
    margin-right: 0.5rem;
    order: -1;
}

.nav-item.open .submenu-arrow i {
    transform: rotate(90deg);
}

.sidebar.collapsed .submenu-arrow {
    opacity: 0;
}

.nav-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background-color: rgba(0, 0, 0, 0.2);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-item.open .nav-submenu {
    max-height: 500px;
}

.nav-subitem {
    margin: 0;
}

.nav-sublink {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem 0.75rem 3.5rem;
    min-height: 44px;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.sidebar.collapsed .nav-sublink {
    padding-left: 1.25rem;
}

.nav-sublink:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-sublink.active {
    background-color: rgba(37, 99, 235, 0.3);
    color: white;
    font-weight: 600;
}

.nav-subtext {
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .nav-subtext {
    opacity: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.version-info {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .version-info {
    opacity: 0;
}

/* Sidebar Toggle Button */
.sidebar-toggle-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.3s ease;
    position: absolute;
    bottom: 100%;
    right: 1rem;
    margin-bottom: 0.5rem;
}

.sidebar-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.sidebar-toggle-btn:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 2px;
}

.toggle-icon {
    font-size: 1rem;
    font-weight: normal;
    line-height: 1;
    transition: transform 0.3s ease;
}

.sidebar.collapsed .toggle-icon i {
    transform: rotate(180deg);
}

/* ============================================================================
   MAIN CONTENT AREA
   ============================================================================ */

.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    background-color: var(--bg-color);
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed-width);
}

/* Top Header */
.top-header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.header-left {
    flex: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-left: auto;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

/* Footer */
.content-footer {
    background-color: var(--text-color);
    color: white;
    padding: 1.5rem 2rem;
    text-align: center;
    margin-top: auto;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
}

.footer-content p {
    margin: 0;
    opacity: 0.8;
    font-size: 0.9rem;
}

.footer-help {
    margin-top: 0.5rem !important;
}

.footer-help a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-help a:hover {
    color: white;
    text-decoration: underline;
}

/* ============================================================================
   USER MENU
   ============================================================================ */

.user-menu {
    position: relative;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    min-height: 44px;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s;
    border: none;
    font-family: inherit;
    font-size: inherit;
}

.user-info:hover {
    background: rgba(0, 0, 0, 0.05);
}

.user-info:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

.user-icon {
    font-size: 1.2rem;
    color: var(--text-color);
}

.user-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-color);
}

.user-badge-role {
    background: #ef4444;
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border-radius: 8px;
    min-width: 200px;
    z-index: 1001;
    overflow: visible;
    padding-top: 10px;
}

/* Ponte invisibile tra il bottone utente e il dropdown per evitare che
   il menu scompaia quando il mouse attraversa il gap */
.user-dropdown::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    right: 0;
    height: 10px;
}

.user-dropdown-content {
    border-radius: 8px;
    overflow: hidden;
    background: white;
    padding: 8px 0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

/* Apertura via hover O via JavaScript (classe .open) */
.user-menu:hover .user-dropdown,
.user-menu.open .user-dropdown {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    min-height: 44px;
    color: #374151;
    text-decoration: none;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: #f3f4f6;
}

.dropdown-item:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: -2px;
    background: #e0e7ff;
}

.dropdown-item.logout {
    border-top: 1px solid #e5e7eb;
    color: #dc2626;
}

.dropdown-item.logout:hover {
    background: #fee2e2;
}

/* ============================================================================
   PAGE HEADER
   ============================================================================ */

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--text-muted);
    font-size: 1rem;
    margin: 0;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
    color: white;
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    color: white;
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
    color: white;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    color: white;
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: #d97706;
    color: white;
}

.btn-info {
    background: #0ea5e9;
    color: white;
}

.btn-info:hover {
    background: #0284c7;
    color: white;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    min-height: 24px;
    min-width: 24px;
}

/* ============================================================================
   BADGES
   ============================================================================ */

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.badge-primary {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
}

.badge-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success-color);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-secondary {
    background: rgba(100, 116, 139, 0.1);
    color: var(--secondary-color);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media screen and (max-width: 768px) {
    /* Mostra hamburger menu su mobile */
    .mobile-menu-toggle {
        display: block;
    }

    /* Sidebar nascosta di default su mobile */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Nascondo il toggle della sidebar su mobile (usiamo hamburger) */
    .sidebar-toggle-btn {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }

    .main-content.sidebar-collapsed {
        margin-left: 0;
    }

    .content-wrapper {
        padding: 1rem;
        padding-top: 5rem;
    }

    .top-header {
        padding: 1rem;
        padding-left: 4.5rem;
    }

    .page-title {
        font-size: 1.25rem;
    }

    .header-content {
        gap: 1rem;
    }

    /* User menu su mobile */
    .user-name {
        display: none;
    }

    .user-badge-role {
        display: none;
    }

    /* Touch targets minimi su mobile */
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-sm {
        min-height: 44px;
        min-width: 44px;
        padding: 0.5rem 1rem;
    }

    /* Tabelle responsive */
    .table-responsive {
        font-size: 0.875rem;
    }

    .table td, .table th {
        padding: 0.75rem 0.5rem;
    }
}

/* Extra small devices */
@media screen and (max-width: 480px) {
    .content-wrapper {
        padding: 0.75rem;
        padding-top: 5rem;
    }

    .page-title {
        font-size: 1.1rem;
    }

    /* Stack buttons su mobile piccoli */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
        border-radius: 6px !important;
        margin-bottom: 0.5rem;
    }
}

/* ============================================================================
   UTILITY CLASSES (solo override necessari, Bootstrap gestisce il resto)
   ============================================================================ */

.text-muted {
    color: var(--text-muted);
}
