/**
 * ═══════════════════════════════════════════════════════════════════════════════
 * DMAGH.AI Platform - Mobile Navigation PWA
 * Sophisticated role-based navigation with Authentik integration
 * ═══════════════════════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════════════════════
   MOBILE HEADER
   ═══════════════════════════════════════════════════════════════════════════════ */

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(env(safe-area-inset-top, 0px) + 56px);
    padding-top: env(safe-area-inset-top, 0px);
    background: linear-gradient(180deg, rgba(15,15,30,1) 0%, rgba(15,15,30,0.98) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    z-index: 1000;
    align-items: center;
    justify-content: space-between;
    padding-left: env(safe-area-inset-left, 16px);
    padding-right: env(safe-area-inset-right, 16px);
}

.mobile-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 56px;
    padding: 0 16px;
}

.hamburger-btn {
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:active {
    transform: scale(0.95);
    background: rgba(249,115,22,0.2);
}

.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: #f97316;
    border-radius: 2px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-10px);
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

.mobile-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-logo-icon {
    width: 32px;
    height: 32px;
    background: url('/icons/icon-72x72.png') center/contain no-repeat;
    border-radius: 8px;
}

.mobile-logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #f97316, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mobile-user-btn {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, rgba(249,115,22,0.2), rgba(139,92,246,0.2));
    border: 1px solid rgba(249,115,22,0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.mobile-user-btn:active {
    transform: scale(0.95);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MOBILE DRAWER
   ═══════════════════════════════════════════════════════════════════════════════ */

.mobile-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.mobile-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: linear-gradient(180deg, #0f0f1f 0%, #0a0a15 100%);
    z-index: 1001;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow: hidden;
}

.mobile-drawer.active {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0,0,0,0.5);
}

/* Drawer Header */
.drawer-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: linear-gradient(135deg, rgba(249,115,22,0.1), rgba(139,92,246,0.1));
}

.drawer-user {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.drawer-avatar {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #f97316, #8b5cf6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    font-weight: 600;
}

.drawer-user-info {
    flex: 1;
    min-width: 0;
}

.drawer-user-email {
    font-weight: 600;
    font-size: 0.95rem;
    color: #f97316;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-user-role {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(139,92,246,0.2);
    border: 1px solid rgba(139,92,246,0.3);
    border-radius: 12px;
    font-size: 0.65rem;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.role-badge.admin {
    background: rgba(249,115,22,0.2);
    border-color: rgba(249,115,22,0.3);
    color: #fb923c;
}

.role-badge.superadmin {
    background: linear-gradient(135deg, rgba(249,115,22,0.3), rgba(239,68,68,0.3));
    border-color: rgba(239,68,68,0.4);
    color: #fca5a5;
}

/* Drawer Navigation */
.drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.drawer-section {
    padding: 12px 16px 8px;
}

.drawer-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.4);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.drawer-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(255,255,255,0.1), transparent);
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin: 2px 8px;
    border-radius: 12px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.drawer-item:active {
    transform: scale(0.98);
    background: rgba(249,115,22,0.15);
}

.drawer-item:hover {
    background: rgba(255,255,255,0.05);
}

.drawer-item.active {
    background: linear-gradient(135deg, rgba(249,115,22,0.2), rgba(249,115,22,0.1));
    color: #f97316;
    border: 1px solid rgba(249,115,22,0.2);
}

.drawer-item-icon {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.drawer-item.active .drawer-item-icon {
    background: rgba(249,115,22,0.2);
}

.drawer-item-content {
    flex: 1;
    min-width: 0;
}

.drawer-item-label {
    font-size: 0.9rem;
    font-weight: 500;
}

.drawer-item-desc {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    margin-top: 2px;
}

.drawer-item-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #f97316;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drawer-item-badge.alert {
    background: #ef4444;
    animation: pulse 2s infinite;
}

/* Admin Section - Only visible for admins */
.drawer-section.admin-only {
    display: none;
    border-top: 1px solid rgba(249,115,22,0.2);
    margin-top: 8px;
    padding-top: 16px;
}

.drawer-section.admin-only .drawer-section-title {
    color: rgba(249,115,22,0.6);
}

body.is-admin .drawer-section.admin-only,
body.is-superadmin .drawer-section.admin-only {
    display: block;
}

/* Superadmin Section */
.drawer-section.superadmin-only {
    display: none;
    border-top: 1px solid rgba(239,68,68,0.2);
}

body.is-superadmin .drawer-section.superadmin-only {
    display: block;
}

/* Drawer Footer */
.drawer-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.2);
}

.drawer-sync {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 12px;
}

.drawer-sync-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
}

.drawer-sync.connected .drawer-sync-dot {
    background: #22c55e;
    animation: pulse 2s infinite;
}

.drawer-logout {
    width: 100%;
    padding: 10px;
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.2);
    border-radius: 10px;
    color: #f87171;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.drawer-logout:active {
    background: rgba(239,68,68,0.2);
    transform: scale(0.98);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   BOTTOM TAB BAR
   ═══════════════════════════════════════════════════════════════════════════════ */

.bottom-tab-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(env(safe-area-inset-bottom, 0px) + 65px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: linear-gradient(180deg, rgba(15,15,30,0.98) 0%, rgba(10,10,20,1) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
}

.bottom-tab-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 65px;
    padding: 0 8px;
}

.bottom-tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    min-width: 64px;
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    border-radius: 12px;
}

.bottom-tab-item:active {
    transform: scale(0.95);
}

.bottom-tab-item.active {
    color: #f97316;
}

.bottom-tab-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: #f97316;
    border-radius: 0 0 3px 3px;
}

.bottom-tab-icon {
    font-size: 1.4rem;
    margin-bottom: 4px;
    transition: transform 0.2s;
}

.bottom-tab-item.active .bottom-tab-icon {
    transform: scale(1.1);
}

.bottom-tab-label {
    font-size: 0.65rem;
    font-weight: 500;
}

.bottom-tab-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(12px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }
    
    .bottom-tab-bar {
        display: block;
    }
    
    .sidebar {
        display: none !important;
    }
    
    .main {
        margin-left: 0 !important;
        padding-top: calc(env(safe-area-inset-top, 0px) + 56px + 16px) !important;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 80px) !important;
    }
    
    footer {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* Haptic feedback simulation */
@media (hover: none) and (pointer: coarse) {
    .drawer-item:active,
    .bottom-tab-item:active,
    .hamburger-btn:active {
        transition: transform 0.1s;
    }
}
