/**
 * Admin View-As Widget Styles
 * 
 * Styles for the admin impersonation widget and banner
 */

/* Admin Widget Container */
#admin-view-as-widget {
    position: fixed;
    bottom: 100px; /* Positioned above zoom controls to avoid overlap */
    left: 24px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.admin-widget-container {
    position: relative;
}

/* Widget Toggle Button */
.admin-widget-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fe8a43;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(254, 138, 67, 0.4);
    transition: all 0.3s ease;
    white-space: nowrap;
    position: relative;
}

.admin-widget-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(254, 138, 67, 0.5);
}

.admin-widget-toggle:active {
    transform: translateY(0);
}

.admin-widget-toggle svg {
    flex-shrink: 0;
}

/* Active viewing state */
.admin-widget-toggle.viewing-as-active {
    background: #fe8a43;
    box-shadow: 0 4px 20px rgba(254, 138, 67, 0.4);
    padding-right: 20px;
}

.admin-widget-toggle.viewing-as-active:hover {
    box-shadow: 0 6px 25px rgba(254, 138, 67, 0.5);
}

/* Dropdown Container */
.admin-widget-dropdown {
    position: absolute;
    bottom: 60px;
    left: 0;
    background: white;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
    width: 360px;
    max-height: 480px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.2s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dropdown Header */
.admin-dropdown-header {
    padding: 16px;
    border-bottom: 2px solid #f0f0f0;
    background: #fafafa;
}

/* Search Input */
.admin-search-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
    box-sizing: border-box;
    background: #FFFFFF;
}

/* Remove any red validation borders */
.admin-search-input:invalid,
.admin-search-input:user-invalid {
    border-color: #e5e7eb;
    box-shadow: none;
}

.admin-search-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Override focus-visible if needed */
.admin-search-input:focus-visible {
    border-color: #667eea;
    outline: none;
}

.admin-search-input::placeholder {
    color: #9ca3af;
}

/* User List Container */
.admin-user-list {
    overflow-y: auto;
    max-height: 400px;
    padding: 8px;
}

/* Custom scrollbar */
.admin-user-list::-webkit-scrollbar {
    width: 8px;
}

.admin-user-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.admin-user-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.admin-user-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* User Item */
.admin-user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.admin-user-item:hover {
    background: #f8f9ff;
    transform: translateX(2px);
}

.admin-user-item.active {
    background: #e0e7ff;
    border-left: 3px solid #667eea;
    padding-left: 11px;
}

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

.admin-user-name {
    font-weight: 600;
    color: #1f2937;
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-user-email {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-user-workspace {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* Account Type Badge */
.admin-user-type {
    display: inline-block;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    margin-left: 8px;
}

.admin-user-type.admin {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

.admin-user-type.user {
    background: #e0e7ff;
    color: #4f46e5;
}

/* Loading and No Results States */
.admin-loading,
.admin-no-results {
    padding: 32px 20px;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
}

.admin-loading::before {
    content: '⏳ ';
}

.admin-no-results::before {
    content: '🔍 ';
}

/* ===================================
   Impersonation Banner Styles
   =================================== */

#admin-impersonation-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    padding: 6px 20px;
    z-index: 99999;
    box-shadow: 0 1px 4px rgba(245, 87, 108, 0.2);
    /* Animation removed for static banner */
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

.banner-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
    gap: 16px;
}

.banner-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.banner-left svg {
    flex-shrink: 0;
}

.banner-left strong {
    font-weight: 700;
}

/* Exit Button */
.exit-btn {
    background: white;
    color: #f5576c;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.exit-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.exit-btn:active {
    transform: scale(0.98);
}

/* Body adjustment and border when impersonating */
body.impersonating {
    padding-top: 0 !important;
    position: relative;
}

/* Full-screen border overlay when impersonating */
body.impersonating::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 3px solid #fe8a43;
    pointer-events: none;
    z-index: 99998;
    box-sizing: border-box;
}

/* Floating Exit Button (to the right of View As widget) */
.admin-exit-view-as-floating {
    position: fixed;
    bottom: 100px; /* Positioned above zoom controls to avoid overlap */
    /* left position calculated dynamically by JavaScript based on widget width + 25px gap */
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #EF4444;
    color: white;
    border: none;
    padding: 13px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.admin-exit-view-as-floating:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.6);
    background: #DC2626;
}

.admin-exit-view-as-floating:active {
    transform: translateY(0);
}

.admin-exit-view-as-floating svg {
    flex-shrink: 0;
}

/* Floating Stats Button (to the right of Exit button) */
.admin-view-stats-floating {
    position: fixed;
    bottom: 100px; /* Positioned above zoom controls to avoid overlap */
    /* left position calculated dynamically by JavaScript */
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #3B82F6;
    color: white;
    border: none;
    padding: 13px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.admin-view-stats-floating:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(59, 130, 246, 0.6);
    background: #2563EB;
}

.admin-view-stats-floating:active {
    transform: translateY(0);
}

.admin-view-stats-floating svg {
    flex-shrink: 0;
}

/* Stats Modal Styles */
.admin-stats-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.admin-stats-modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.admin-stats-modal-header {
    padding: 24px;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 16px 16px 0 0;
}

.admin-stats-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.admin-stats-modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

.admin-stats-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.admin-stats-modal-body {
    padding: 24px;
}

.stats-section {
    margin-bottom: 24px;
}

.stats-section:last-child {
    margin-bottom: 0;
}

.stats-section h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #E5E7EB;
    padding-bottom: 8px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #F3F4F6;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span {
    color: #6B7280;
    font-size: 14px;
}

.stat-row strong {
    color: #111827;
    font-weight: 600;
    font-size: 14px;
}

/* ===================================
   Responsive Styles
   =================================== */

@media (max-width: 768px) {
    #admin-view-as-widget {
        bottom: 200px; /* Positioned above zoom controls */
        left: 16px;
    }

    .admin-widget-dropdown {
        width: calc(100vw - 32px);
        max-width: 360px;
    }

    .banner-content {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .banner-left {
        justify-content: center;
        font-size: 12px;
    }

    body.impersonating {
        padding-top: 0 !important;
    }
    
    .admin-exit-view-as-floating {
        bottom: 200px; /* Positioned above zoom controls */
        /* left calculated dynamically by JavaScript */
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .admin-exit-view-as-floating svg {
        width: 16px;
        height: 16px;
    }
}

@media (max-width: 480px) {
    #admin-view-as-widget {
        bottom: 180px; /* Positioned above zoom controls on mobile */
    }

    .admin-widget-toggle {
        padding: 10px 16px;
        font-size: 13px;
    }

    .admin-widget-toggle.viewing-as-active {
        padding-right: 10px;
    }

    .admin-widget-toggle span {
        display: none;
    }

    .admin-widget-toggle.viewing-as-active span {
        display: inline;
        font-size: 11px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .admin-widget-dropdown {
        width: calc(100vw - 24px);
        bottom: 55px;
    }

    .admin-user-item {
        padding: 10px 12px;
    }

    .banner-left {
        font-size: 11px;
    }

    .exit-btn {
        padding: 5px 12px;
        font-size: 11px;
    }
    
    .admin-exit-view-as-floating {
        bottom: 180px; /* Positioned above zoom controls on mobile */
        /* left calculated dynamically by JavaScript */
        right: auto;
        padding: 10px 14px;
        font-size: 12px;
    }
    
    .admin-exit-view-as-floating svg {
        width: 16px;
        height: 16px;
    }
    
    .admin-exit-view-as-floating span {
        display: inline; /* Keep "Stop Viewing As" text visible */
    }
    
    .admin-view-stats-floating {
        bottom: 180px; /* Positioned above zoom controls on mobile */
        /* left calculated dynamically by JavaScript */
        right: auto;
        padding: 10px 14px;
        font-size: 12px;
    }
    
    .admin-view-stats-floating svg {
        width: 16px;
        height: 16px;
    }
    
    .admin-view-stats-floating span {
        display: inline; /* Keep "View Stats" text visible */
    }
    
    .admin-stats-modal-content {
        width: 95%;
        max-height: 90vh;
    }
}

/* ===================================
   Print Styles
   =================================== */

@media print {
    #admin-view-as-widget,
    #admin-impersonation-banner,
    .admin-exit-view-as-floating,
    .admin-view-stats-floating,
    .admin-stats-modal-overlay {
        display: none !important;
    }

    body.impersonating {
        padding-top: 0 !important;
        box-shadow: none !important;
    }
}

/* ===================================
   Accessibility
   =================================== */

.admin-widget-toggle:focus,
.admin-search-input:focus,
.exit-btn:focus,
.admin-exit-view-as-floating:focus,
.admin-view-stats-floating:focus,
.admin-stats-modal-close:focus {
    outline: 3px solid rgba(245, 87, 108, 0.5);
    outline-offset: 2px;
}

.admin-user-item:focus {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .admin-widget-toggle,
    #admin-impersonation-banner {
        border: 2px solid currentColor;
    }

    .admin-user-item:hover {
        border: 2px solid #667eea;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .admin-widget-toggle,
    .admin-user-item,
    .admin-search-input,
    .exit-btn,
    .admin-exit-view-as-floating {
        transition: none;
    }

    @keyframes slideUp {
        from {
            opacity: 0;
        }
        to {
            opacity: 1;
        }
    }

    @keyframes slideDown {
        from {
            opacity: 0;
        }
        to {
            opacity: 1;
        }
    }
}

