/* Mobile Optimization Styles */

/* General Mobile Optimizations */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }

    .container, .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* Increase touch target sizes for better mobile usability */
    button, .btn, .nav-link, a {
        padding: 8px 12px;
        margin-bottom: 5px;
    }

    /* Enhanced sidebar toggle button for mobile */
    .toggle-sidebar-btn {
        font-size: 24px;
        padding: 8px 12px;
        background-color: transparent;
        border: none;
        color: #4154f1;
        cursor: pointer;
        transition: all 0.3s;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
    }

    .toggle-sidebar-btn:hover,
    .toggle-sidebar-btn:focus {
        background-color: rgba(65, 84, 241, 0.1);
        transform: scale(1.1);
    }

    /* Adjust header for mobile */
    .header {
        padding: 10px 15px;
        height: 60px;
    }

    .logo img {
        max-height: 36px !important;
    }

    /* Improve form elements on mobile */
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        max-width: 100%;
    }

    /* Card adjustments for mobile */
    .card {
        margin-bottom: 15px;
    }

    .card-body {
        padding: 15px;
    }

    /* Table optimizations for mobile */
    .table-responsive {
        border: 0;
        margin-bottom: 0;
    }

    /* Improve modal display on mobile */
    .modal-dialog {
        margin: 10px;
    }

    /* Adjust spacing for mobile */
    .mt-4, .my-4 {
        margin-top: 2rem !important;
    }

    .mb-4, .my-4 {
        margin-bottom: 2rem !important;
    }

    /* Improve dropdown menus on mobile */
    .dropdown-menu {
        width: 100%;
        max-height: 80vh;
        overflow-y: auto;
    }
}

/* Table to Card View Transformation for very small screens */
@media (max-width: 576px) {
    /* Hide table headers on small screens */
    .mobile-card-view thead {
        display: none;
    }

    /* Make table rows display as cards */
    .mobile-card-view tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #dee2e6;
        border-radius: 5px;
        padding: 10px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        background-color: #fff;
    }

    /* Style table cells as flex items */
    .mobile-card-view tbody td {
        display: flex;
        flex-direction: column;
        padding: 8px 10px;
        border: none;
        border-bottom: 1px solid #f0f0f0;
        overflow-wrap: break-word;
        word-wrap: break-word;
        word-break: break-word;
    }

    .mobile-card-view tbody td:last-child {
        border-bottom: none;
    }

    /* Add labels for each cell based on data-label attribute */
    .mobile-card-view tbody td:before {
        content: attr(data-label);
        font-weight: bold;
        margin-bottom: 5px;
        display: block;
        font-size: 0.85em;
        color: #666;
    }

    /* Adjust action buttons in tables */
    .mobile-card-view .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
        margin-top: 5px;
    }

    .mobile-card-view .btn-sm {
        padding: 8px 12px;
        margin-bottom: 5px;
        text-align: left;
        width: 100%;
    }

    .mobile-card-view .btn-sm i {
        margin-right: 8px;
    }

    /* Improve display of specific content types */
    .mobile-card-view a {
        word-break: break-all;
        display: inline-block;
    }

    .mobile-card-view .badge {
        display: inline-block;
        margin: 2px;
        font-size: 0.8em;
    }

    /* Add more spacing between rows */
    .mobile-card-view tbody tr {
        margin-bottom: 20px;
    }

    /* Improve visual hierarchy */
    .mobile-card-view tbody td[data-label="Vorname"]:before,
    .mobile-card-view tbody td[data-label="Nachname"]:before,
    .mobile-card-view tbody td[data-label="Email"]:before,
    .mobile-card-view tbody td[data-label="Rollen"]:before,
    .mobile-card-view tbody td[data-label="Aktionen"]:before {
        color: #4154f1;
    }
}

/* Tablet View Optimizations (iPad, etc.) */
@media (min-width: 577px) and (max-width: 992px) {
    /* Ensure tables are properly responsive on tablets */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Optimize table display for tablets */
    .tablet-view {
        font-size: 0.9rem;
    }

    .tablet-view th,
    .tablet-view td {
        padding: 0.5rem;
    }

    /* Improve action buttons on tablets */
    .tablet-view .btn-group {
        display: flex;
        flex-wrap: wrap;
    }

    .tablet-view .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
        margin: 0.1rem;
    }

    /* Ensure icons are visible */
    .tablet-view .btn-sm i {
        font-size: 0.8rem;
        margin-right: 0.3rem;
    }

    /* Improve card layouts on tablets */
    .col-md-3.col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Enhance visual appeal of cards on tablets */
    .card {
        margin-bottom: 1rem;
        transition: transform 0.2s;
    }

    .card:hover {
        transform: translateY(-5px);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    }

    /* Improve form elements on tablets */
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
    }

    /* Fix for iPad sidebar header - hide duplicate menu text */
    .sidebar-header .logo-text {
        display: none;
    }
}

/* Mobile Tooltips */
.mobile-tip {
    display: none;
}

@media (max-width: 768px) {
    .mobile-tip {
        display: block;
        background-color: #f8f9fa;
        border-left: 4px solid #4154f1;
        padding: 10px 15px;
        margin-bottom: 15px;
        border-radius: 4px;
        font-size: 14px;
        color: #666;
    }

    .mobile-tip i {
        color: #4154f1;
        margin-right: 5px;
    }

    /* Hide mobile tips after they've been seen */
    .mobile-tip.seen {
        display: none;
    }
}

/* Sidebar Improvements for Mobile - Mobile First Approach */
/* Base styles for mobile first */
.sidebar {
    padding: 15px 10px;
    -webkit-overflow-scrolling: touch;
    width: 85%;
    max-width: 280px;
    border-radius: 0 15px 15px 0;
    box-shadow: 3px 0 15px rgba(0, 0, 0, 0.1);
    left: -100%;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.toggle-sidebar .sidebar {
    left: 0;
    box-shadow: 3px 0 20px rgba(0, 0, 0, 0.2);
    z-index: 1999;
}

/* User profile section in sidebar */
.sidebar-user-profile {
    display: none; /* Hide on mobile */
    flex-direction: column;
    align-items: center;
    padding: 15px 10px;
    margin-bottom: 15px;
    background-color: rgba(65, 84, 241, 0.05);
    border-radius: 10px;
    max-width: 100%;
    overflow: hidden;
}

/* Center navigation menu on mobile */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 20px;
}

.sidebar-nav .nav-item {
    width: 100%;
    max-width: 200px;
}

.sidebar-nav .nav-link {
    justify-content: center;
}

.sidebar-nav .nav-link i {
    margin-right: 8px;
}

.sidebar-nav .nav-heading {
    text-align: center;
    margin: 15px 0 10px;
    width: 100%;
}

/* Mobile user profile section at bottom */
.sidebar-user-profile-mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 10px;
    margin-top: auto; /* Push to bottom */
    background-color: rgba(65, 84, 241, 0.05);
    border-radius: 10px;
    margin-top: 20px;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
}

.sidebar-user-profile-mobile .mobile-profile-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.sidebar-user-profile-mobile .profile-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border: 2px solid #4154f1;
    margin-bottom: 10px;
}

.sidebar-user-profile-mobile .user-info {
    width: 100%;
    text-align: center;
}

.sidebar-user-profile-mobile h6 {
    margin-bottom: 10px;
    font-weight: 600;
    color: #2c384e;
    font-size: 16px;
}

.sidebar-user-profile-mobile .user-links {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.sidebar-user-profile-mobile .user-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #f6f9ff;
    color: #4154f1;
    transition: all 0.3s;
}

.sidebar-user-profile-mobile .user-link:hover {
    background-color: #4154f1;
    color: #fff;
    transform: translateY(-3px);
}

/* Dark mode styles for sidebar */
body.theme-dark .sidebar,
body.dark-mode .sidebar {
    background-color: #1f1f27;
    box-shadow: 3px 0 15px rgba(0, 0, 0, 0.2);
}

body.theme-dark .sidebar-user-profile,
body.dark-mode .sidebar-user-profile,
body.theme-dark .sidebar-user-profile-mobile,
body.dark-mode .sidebar-user-profile-mobile {
    background-color: rgba(255, 255, 255, 0.05);
}

body.theme-dark .sidebar-user-profile h6,
body.dark-mode .sidebar-user-profile h6,
body.theme-dark .sidebar-user-profile-mobile h6,
body.dark-mode .sidebar-user-profile-mobile h6 {
    color: #e0e0e0;
}

body.theme-dark .sidebar-user-profile .user-link,
body.dark-mode .sidebar-user-profile .user-link,
body.theme-dark .sidebar-user-profile-mobile .user-link,
body.dark-mode .sidebar-user-profile-mobile .user-link {
    background-color: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
}

body.theme-dark .sidebar-user-profile .user-link:hover,
body.dark-mode .sidebar-user-profile .user-link:hover,
body.theme-dark .sidebar-user-profile-mobile .user-link:hover,
body.dark-mode .sidebar-user-profile-mobile .user-link:hover {
    background-color: #4154f1;
    color: #fff;
}

body.theme-dark .sidebar-divider,
body.dark-mode .sidebar-divider {
    border-top-color: rgba(255, 255, 255, 0.1);
}

.sidebar-user-profile .profile-image {
    width: 32px;
    height: 32px;
    object-fit: cover;
    margin-bottom: 10px;
    border: 2px solid #4154f1;
}

.sidebar-user-profile .user-info {
    text-align: center;
    width: 100%;
}

.sidebar-user-profile h6 {
    margin-bottom: 10px;
    font-weight: 600;
    color: #2c384e;
}

.sidebar-user-profile .user-links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.sidebar-user-profile .user-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #f6f9ff;
    color: #4154f1;
    transition: all 0.3s;
}

.sidebar-user-profile .user-link:hover {
    background-color: #4154f1;
    color: #fff;
    transform: translateY(-3px);
}

.sidebar-divider {
    margin: 15px 0;
    border-top: 1px solid #e9ecef;
}

.sidebar-nav .nav-link {
    padding: 10px 15px;
    font-size: 14px;
    border-radius: 8px;
    margin-bottom: 5px;
}

.sidebar-nav .nav-link i {
    font-size: 16px;
    margin-right: 10px;
}

/* Tablet and larger screens */
@media (min-width: 769px) {
    .sidebar {
        width: 280px;
    }

    /* Reset centered navigation for tablet/desktop */
    .sidebar-nav {
        align-items: flex-start;
        text-align: left;
    }

    .sidebar-nav .nav-item {
        max-width: 100%;
    }

    .sidebar-nav .nav-link {
        justify-content: flex-start;
    }

    .sidebar-nav .nav-heading {
        text-align: left;
        margin: 10px 0 5px 15px;
    }

    .sidebar-user-profile {
        display: flex; /* Show on tablet/desktop */
        flex-direction: row;
        align-items: center;
        text-align: left;
        padding: 15px;
        transition: all 0.3s ease;
    }

    .sidebar-user-profile-mobile {
        display: none !important; /* Hide on tablet/desktop */
    }

    .sidebar-user-profile .profile-image {
        margin-bottom: 0;
        margin-right: 15px;
        width: 32px;
        height: 32px;
    }

    .sidebar-user-profile .user-info {
        text-align: left;
    }

    .sidebar-user-profile .user-links {
        justify-content: flex-start;
    }
}

/* Large desktop screens */
@media (min-width: 1200px) {
    /* Floating sidebar layout for desktop */
    body:not(.toggle-sidebar) .sidebar {
        left: 20px;
        top: 20px;
        width: 300px;
        padding: 20px;
        box-shadow: 0 0 30px rgba(1, 41, 112, 0.1);
        border-radius: 15px;
        background-color: #f9fafc;
        height: calc(100vh - 40px);
    }

    body:not(.toggle-sidebar) #main,
    body:not(.toggle-sidebar) #footer {
        margin-left: 340px;
    }

    .toggle-sidebar .sidebar {
        left: -350px;
    }

    .toggle-sidebar #main,
    .toggle-sidebar #footer {
        margin-left: 0;
    }

    /* Sidebar header styles */
    .sidebar-header {
        margin-bottom: 15px;
    }

    .sidebar-header .logo-text {
        font-size: 18px;
        font-weight: 700;
        color: #2c384e;
        margin-left: 8px;
    }

    .sidebar-header .toggle-sidebar-btn {
        font-size: 22px;
        background-color: transparent;
        border: none;
        color: #4154f1;
        cursor: pointer;
        transition: all 0.3s;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-header .toggle-sidebar-btn:hover {
        background-color: rgba(65, 84, 241, 0.1);
        transform: scale(1.1);
    }

    /* Enhanced user profile for desktop */
    .sidebar-user-profile {
        background-color: #ffffff;
        border-radius: 12px;
        padding: 20px;
        margin-bottom: 25px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        border: 1px solid #eaedf2;
    }

    .sidebar-user-profile .profile-image {
        width: 32px;
        height: 32px;
        border: 2px solid #4154f1;
        transition: all 0.3s ease;
    }

    .sidebar-user-profile:hover .profile-image {
        transform: scale(1.05);
    }

    /* Ensure mobile profile is hidden on desktop */
    .sidebar-user-profile-mobile {
        display: none !important;
    }

    .sidebar-user-profile h6 {
        font-size: 16px;
        margin-bottom: 12px;
        font-weight: 700;
        color: #2c384e;
    }

    .sidebar-user-profile .user-links {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    .sidebar-user-profile .user-link {
        width: 38px;
        height: 38px;
        font-size: 18px;
        background-color: #f0f3ff;
        transition: all 0.3s ease;
    }

    .sidebar-user-profile .user-link:hover {
        transform: translateY(-5px);
        box-shadow: 0 5px 10px rgba(65, 84, 241, 0.2);
    }

    /* Enhanced sidebar navigation for desktop */
    .sidebar-nav .nav-link {
        padding: 12px 18px;
        margin-bottom: 8px;
        border-radius: 8px;
        transition: all 0.3s ease;
    }

    .sidebar-nav .nav-link:hover {
        transform: translateX(5px);
        background-color: #eef2ff;
    }

    .sidebar-nav .nav-link i {
        font-size: 18px;
        margin-right: 12px;
    }

    .sidebar-nav .nav-heading {
        font-size: 12px;
        margin: 20px 0 10px 15px;
        color: #6c757d;
        letter-spacing: 1px;
    }

    /* Dark mode adjustments for desktop */
    body.theme-dark .sidebar-user-profile,
    body.dark-mode .sidebar-user-profile {
        background-color: #2c2c38;
        border-color: #3a3a4a;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    body.theme-dark .sidebar-nav .nav-link:hover,
    body.dark-mode .sidebar-nav .nav-link:hover {
        background-color: #3a3a4a;
    }

    body.theme-dark .sidebar,
    body.dark-mode .sidebar {
        background-color: #252531;
    }
}

/* Form Improvements for Mobile */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 15px;
    }

    .form-label {
        margin-bottom: 5px;
        font-weight: 600;
    }

    /* Stack form columns on mobile */
    .row.g-3 > [class*="col-"] {
        margin-bottom: 10px;
    }

    /* Improve select2 on mobile */
    .select2-container {
        width: 100% !important;
    }

    /* Improve date/time inputs on mobile */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 38px;
    }
}

/* Floating Action Button for Mobile */
.mobile-fab {
    display: none;
}

@media (max-width: 768px) {
    .mobile-fab {
        display: block;
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background-color: #4154f1;
        color: white;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
    }

    .mobile-fab i {
        font-size: 24px;
    }

    .mobile-fab:hover, .mobile-fab:focus {
        background-color: #3142d0;
        transform: scale(1.05);
    }

    /* FAB Menu Styles */
    .mobile-fab-menu {
        position: fixed;
        bottom: 85px;
        right: 20px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        z-index: 999;
        gap: 10px;
    }

    .mobile-fab-action {
        display: flex;
        align-items: center;
        background-color: white;
        color: #333;
        border-radius: 30px;
        padding: 8px 16px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        text-decoration: none;
        transition: all 0.2s ease;
        max-width: 200px;
    }

    .mobile-fab-action i {
        margin-right: 8px;
        color: #4154f1;
        font-size: 18px;
    }

    .mobile-fab-action span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-fab-action:hover, .mobile-fab-action:focus {
        background-color: #f8f9fa;
        transform: translateX(-5px);
        color: #333;
        text-decoration: none;
    }

    /* Animation for FAB menu */
    .mobile-fab-menu {
        transition: all 0.3s ease;
    }

    .mobile-fab-action {
        animation: slideIn 0.3s forwards;
        opacity: 0;
        transform: translateX(20px);
    }

    @keyframes slideIn {
        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Ensure FAB is above other elements but below modals */
    .mobile-fab {
        z-index: 1050;
    }

    .mobile-fab-menu {
        z-index: 1049;
    }

    /* Adjust for bottom navigation if present */
    .has-bottom-nav .mobile-fab {
        bottom: 70px;
    }

    .has-bottom-nav .mobile-fab-menu {
        bottom: 135px;
    }
}
