/*
 * ROOT HTML FIX: Prevents the white "scroll-bounce" background
 * from appearing when users scroll past the top/bottom edge on mobile.
 */
html {
    background-color: #1a1a2e;
}

/* Admin Panel Styles */
.admin-container {
    min-height: 100vh;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    font-family: 'Inter', sans-serif;
    /* Prevent accidental horizontal scrolling from child elements */
    overflow-x: hidden;
}

.admin-header {
    background: rgba(255, 255, 255, 0.05);
    /* Added Webkit prefix for iOS compatibility */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(78, 205, 196, 0.2);
    padding: 20px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Tighter Header Spacing */
.admin-header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px; /* Tighter horizontal padding */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-header h1 {
    font-size: 28px;
    font-weight: 600;
    margin: 0;
    color: #4ecdc4;
}

/* Tighter Button Group Spacing */
.admin-actions {
    display: flex;
    gap: 8px; /* Tighter spacing between buttons */
    align-items: center;
}

.btn-back, .btn-refresh, .btn-toggle-signups {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
}

.btn-back {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.btn-refresh {
    background: #4ecdc4;
    color: #1a1a2e;
}

.btn-refresh:hover {
    background: #3ba89f;
    transform: translateY(-2px);
}

/* Toggle Signups Button */
.btn-toggle-signups {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-toggle-signups.enabled {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
    color: white;
    border: 1px solid rgba(39, 174, 96, 0.3);
}

.btn-toggle-signups.enabled:hover {
    background: linear-gradient(135deg, #229954 0%, #1e8449 100%);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.4);
    transform: translateY(-2px);
}

.btn-toggle-signups.disabled {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.btn-toggle-signups.disabled:hover {
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.4);
    transform: translateY(-2px);
}

.btn-toggle-signups:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-toggle-signups:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    gap: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(78, 205, 196, 0.2);
    border-top-color: #4ecdc4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 30px;
}

.error-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.error-state h2 {
    font-size: 32px;
    margin-bottom: 10px;
    color: #e74c3c;
}

.error-state p {
    font-size: 16px;
    color: #aaa;
    margin-bottom: 30px;
}

.btn-primary {
    padding: 12px 30px;
    background: #4ecdc4;
    color: #1a1a2e;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: inline-block;
}

.btn-primary:hover {
    background: #3ba89f;
    transform: translateY(-2px);
}

/* Users Table */
.users-table-container {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 30px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.table-header h2 {
    font-size: 24px;
    margin: 0;
}

.stats {
    display: flex;
    gap: 20px;
}

.stat {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
}

.stat strong {
    color: #4ecdc4;
    font-size: 18px;
    margin-left: 5px;
}

.table-wrapper {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(78, 205, 196, 0.2);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table thead {
    background: rgba(78, 205, 196, 0.1);
}

.users-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: #4ecdc4;
    border-bottom: 2px solid rgba(78, 205, 196, 0.3);
}

.users-table td {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.users-table tbody tr {
    transition: background 0.2s ease;
}

.users-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.user-id {
    font-weight: 600;
    color: #4ecdc4;
}

.admin-badge {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    margin-left: 10px;
    letter-spacing: 0.5px;
}

.date-time {
    color: #aaa;
    font-size: 13px;
}

.stat-badge {
    background: rgba(78, 205, 196, 0.2);
    color: #4ecdc4;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.btn-delete {
    background: #e74c3c;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 13px;
}

.btn-delete:hover:not(:disabled) {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-delete:disabled {
    background: rgba(255, 255, 255, 0.1);
    cursor: not-allowed;
    opacity: 0.5;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    /* FIX: Must be 100% to cover the whole screen and center content */
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    /* Added Webkit prefix for iOS compatibility */
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: #16213e;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(78, 205, 196, 0.2);
}

.modal-header {
    /* DEFAULT: Adequate desktop padding */
    padding: 20px 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    margin: 0;
    font-size: 22px;
    color: #e74c3c;
}

.modal-body {
    /* DEFAULT: Adequate desktop padding */
    padding: 20px 25px;
}

/* Tighter Modal Text Spacing */
.warning-text {
    font-size: 16px;
    margin-bottom: 10px; 
    color: #fff;
}

.warning-text strong {
    color: #4ecdc4;
}

.warning-subtext {
    color: #aaa;
    font-size: 14px;
    margin: 10px 0 5px 0; 
}

.warning-list {
    margin: 5px 0 10px 0; 
    padding-left: 25px;
    color: #aaa;
}

.warning-list li {
    margin: 4px 0; 
    font-size: 14px;
}

.danger-text {
    background: rgba(231, 76, 60, 0.1);
    border-left: 3px solid #e74c3c;
    padding: 12px 15px;
    margin: 8px 0;
    border-radius: 4px;
    color: #e74c3c;
    font-weight: 500;
    
    /* KEEP: Force onto one line on desktop */
    white-space: nowrap;
    overflow: hidden; 
    text-overflow: ellipsis; 
}

.modal-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

/* Consolidated Button Styling */
.btn-secondary, .btn-danger {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

/* CANCEL BUTTON STYLING RESTORED */
.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: #e74c3c;
    color: #fff;
}

.btn-danger:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

.btn-danger:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Responsive */

/* --- TABLET VIEW (968px and below) --- */
@media (max-width: 968px) {
    /* Header Stacking */
    .admin-header-content {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }

    /* Full-width buttons */
    .admin-actions {
        flex-direction: column;
        width: 100%;
    }

    .btn-toggle-signups,
    .btn-back,
    .btn-refresh {
        width: 100%;
        justify-content: center;
    }

    /* Adjusted Container Padding */
    .users-table-container {
        padding: 0 20px;
    }

    /* Modal size adjustment */
    .modal-content {
        width: 85%;
    }

    /* REMOVED HORIZONTAL SCROLLING AND MIN-WIDTH */
    .table-wrapper {
        overflow-x: visible;
    }

    .users-table {
        min-width: auto;
    }
}

/* --- MOBILE VIEW (768px and below) --- */
@media (max-width: 768px) {
    /* Header and Container Spacing */
    .admin-header-content {
        padding: 0 15px;
    }

    .users-table-container {
        padding: 0 15px;
    }

    /* Stats Stacking */
    .table-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
        margin-bottom: 15px;
    }

    .stats {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    .stat {
        width: 100%;
        text-align: left;
    }

    /* Modal Stacking */
    .modal-content {
        max-width: 95%;
        width: 95%;
        /* AGGRESSIVE FIX: Remove external margin to maximize vertical space. */
        margin: 0; 
        
        /* Keep for other text elements (like long emails/IDs) that need to wrap */
        word-break: break-word;
    }
    
    /* ------------------------------------------- */
    /* CRITICAL MOBILE MODAL COMPRESSION */
    /* ------------------------------------------- */

    .modal-header {
        /* EXTREME: Tighter vertical padding */
        padding: 5px 15px; 
    }

    .modal-body {
        /* EXTREME: Tighter vertical padding */
        padding: 5px 15px; 
    }
    
    .modal-header h3 {
        font-size: 18px; /* Reduced font size */
    }

    .warning-text {
        /* EXTREME COMPRESSION */
        margin-top: 5px;
        margin-bottom: 3px;
        font-size: 14px; 
    }
    
    .warning-subtext {
        /* EXTREME COMPRESSION */
        margin: 3px 0 2px 0;
        font-size: 12px;
    }
    
    .warning-list {
        /* EXTREME COMPRESSION: Almost no vertical space */
        margin: 0; 
        padding-left: 15px; /* Reduced list indent */
    }

    .warning-list li {
        margin: 1px 0; /* EXTREME reduction for list items */
        font-size: 12px; 
    }
    
    .danger-text {
        /* CRITICAL FIX: Allows the message to word-wrap and reduces vertical margin */
        margin: 4px 0; 
        padding: 8px 10px; /* Reduced internal padding */
        font-size: 13px; 
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .modal-actions {
        flex-direction: column;
        gap: 5px; /* Extremely tight gap */
        margin-top: 5px; /* Reduced top margin */
        padding-bottom: 5px; 
    }

    .btn-secondary, .btn-danger {
        padding: 8px; /* Tighter button padding */
        font-size: 13px;
    }
    
    /* ------------------------------------------- */
    /* KEY FIX: CARD-STYLE TABLE LAYOUT */
    /* ------------------------------------------- */

    /* Hide the original column headers */
    .users-table thead {
        display: none;
    }

    /* Force table elements to stack vertically */
    .users-table,
    .users-table tbody,
    .users-table tr {
        display: block;
        width: 100%;
    }

    /* Style the table rows as individual cards */
    .users-table tr {
        margin-bottom: 15px;
        border: 1px solid rgba(78, 205, 196, 0.2);
        border-radius: 8px;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.05);
    }

    /* Make each data cell a block to stack them */
    .users-table td {
        display: block;
        /* FIX: Force long text (like IDs/emails) in table cells to wrap */
        word-break: break-word;
        text-align: left !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.03);
        padding: 10px 15px;
        position: relative;
    }

    /* Insert the column header as a left-aligned label */
    .users-table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #4ecdc4;
        padding-right: 10px;
    }

    /* NEW RULE: Keep the delete button aligned to the right in the Actions column */
    .users-table td[data-label="Actions"] {
        text-align: right !important;
    }

    /* NEW RULE: Clear the float from the label on the Actions column to keep the button aligned right */
    .users-table td[data-label="Actions"]::before {
        float: none;
        display: block;
        text-align: left;
        margin-bottom: 5px;
    }

    /* Remove the bottom border from the last cell to tidy up the card */
    .users-table tr:last-child {
        border-bottom: none;
    }
}