/**
 * Admin Panel Styles
 * All admin-specific styles are isolated here to keep them separate from normal user functionality
 */

/* Admin Users Modal - 90% screen size */
.admin-modal-content {
    width: 90vw !important;
    max-width: 90vw !important;
    max-height: 90vh !important;
    min-height: 80vh;
    height: auto;
}

/* Remove default modal body padding for admin users modal */
/* Reserve space at top for bulk actions bar - always 60px so it doesn't push table */
#admin-users-modal .modal-body,
#admin-reports-modal .modal-body {
    padding: 60px 0 0 0;
    position: relative;
    display: flex;
    flex-direction: column;
    height: calc(90vh - 120px); /* Fixed height to prevent resizing */
    min-height: calc(90vh - 120px);
    max-height: calc(90vh - 120px);
    overflow: hidden;
}

#admin-reports-modal .modal-body {
    padding: 60px 0 0 0;
    position: relative;
    display: flex;
    flex-direction: column;
    height: calc(90vh - 120px);
    min-height: calc(90vh - 120px);
    max-height: calc(90vh - 120px);
    overflow: hidden;
}

/* Adjust search position - it's below the reserved bulk actions space */
.admin-users-search {
    margin-top: 0;
}

/* Users Table - Fixed widths, no flex behavior */
.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    table-layout: fixed !important;
    min-width: 100%;
    max-width: 100%;
    /* Prevent layout shift */
    transform: translateZ(0);
}

/* Table container: single scroll container with stable scrollbar gutter */
#users-table-container,
#reports-table-container {
    overflow: auto;
    flex: 1;
    scrollbar-gutter: stable both-edges;
    position: relative;
    min-height: 0;
}

#reports-table-container {
    overflow: auto;
    flex: 1;
    scrollbar-gutter: stable both-edges;
    position: relative;
    min-height: 0;
}
/* Restore native table header grouping; no width/table-layout overrides */
.users-table thead { 
    display: table-header-group;
    background: var(--bg-main);
}
.users-table tbody { display: table-row-group; width: 100%; }
.users-table tbody tr { display: table-row; width: 100%; table-layout: fixed; }

/* Ensure native table display to avoid separate width calculations */
.users-table thead tr,
.users-table tbody tr { display: table-row; }

/* Base styles - IDENTICAL for th and td - NO FLEX */
.users-table th,
.users-table td {
    padding: 1rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-secondary);
    box-sizing: border-box !important;
    /* Prevent any flex/grow behavior */
    flex: none;
    flex-grow: 0;
    flex-shrink: 0;
}

/* Header visual styles only - SAME STRUCTURE as td */
.users-table th {
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    background: var(--bg-main);
    /* Same border width as td to prevent width mismatch */
    border-bottom-width: 1px;
    /* Visual thicker border effect without affecting width */
    box-shadow: inset 0 -1px 0 var(--border-secondary);
}

/* Body cell visual styles only */
.users-table td {
    color: var(--text-primary);
    word-wrap: break-word;
}

.action-menu { 
    overflow: visible; 
    position: relative;
    display: inline-block;
}

/* Column widths: removed explicit nth-child widths to avoid thead/tbody drift.
   Let the browser auto-calculate based on content while table stays 100%. */
.users-table td:nth-child(8),
.users-table td.actions-col { 
    position: relative;
    overflow: visible;
}

/* Colgroup-based widths: lock checkbox/actions; let others flex */
.users-table col.col-select { width: 48px; }
/* Make email column wider */
.users-table col.col-email { width: 30%; }
/* Make actions column narrower */
.users-table col.col-actions { width: 80px; }

/* Data columns use intrinsic sizing; no explicit width constraints */

/* Sticky header row for legacy table (first row) */
.users-table tr:first-child th,
.users-table th {
    position: sticky;
    top: 0;
    z-index: 100; /* above cells, below dropdowns */
    background: var(--bg-main);
    /* Prevent layout shift - ensure consistent positioning */
    transform: translateZ(0);
    will-change: transform;
}

/* Keep the three-dot menu anchored to the right in the last column */
.users-table th.actions-col,
.users-table td.actions-col { 
    text-align: right;
    overflow: visible;
}

/* Removed tablet-specific width overrides to keep single source of truth */

.users-table tbody tr:hover {
    background: var(--bg-hover);
}

.users-table tbody tr:last-child td {
    border-bottom: none;
}

/* Admin Badges */
.verified-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.verified-badge.verified {
    background: var(--success-bg);
    color: var(--success-fg-on-bg);
}

.verified-badge.unverified {
    background: var(--danger-bg);
    color: var(--danger-fg-on-bg);
}

.verified-badge.suspended {
    background: var(--warning-bg-muted);
    color: var(--warning-fg-on-bg);
    border: 1px solid var(--warning-border-strong);
    font-weight: 600;
}

/* Highlight suspended user rows */
.users-table tbody tr.suspended-user {
    background: var(--warning-row-bg);
    opacity: 0.85;
}

.users-table tbody tr.suspended-user:hover {
    background: var(--warning-row-hover-bg);
    opacity: 1;
}

.users-table tbody tr.suspended-user td {
    color: var(--warning-fg-on-bg);
}

.plan-badge-table {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: capitalize;
}

.plan-badge-table.free {
    background: var(--badge-neutral-bg);
    color: var(--badge-neutral-text);
}

.plan-badge-table.premium {
    background: var(--plan-badge-premium-gradient);
    color: var(--text-primary);
}

.plan-badge-table.advanced {
    background: var(--plan-badge-advanced-gradient);
    color: var(--text-on-accent);
}

.plan-badge-table.owner {
    background: var(--plan-badge-owner-gradient);
    color: var(--plan-badge-owner-text);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.plan-badge-table.owner i {
    margin-right: 0.25rem;
    font-size: 0.75rem;
}

.owner-protected-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.reports-count {
    font-weight: 500;
    color: var(--accent-primary);
}

/* Action Menu Dropdown */
.action-menu {
    position: relative;
    display: inline-block;
}

.action-menu-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-menu-btn:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.action-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    background: var(--bg-card);
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    box-shadow: var(--shadow-card);
    min-width: 180px;
    z-index: 10000;
    display: none;
    overflow: hidden;
    white-space: nowrap;
}

.action-dropdown.show {
    display: block;
    animation: adminFadeIn 0.15s ease-out;
}

@keyframes adminFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.action-item {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.action-item:hover {
    background: var(--bg-main);
}

.action-item.danger {
    color: var(--danger-color);
}

.action-item.danger:hover {
    background: var(--danger-bg-hover);
    color: var(--danger-fg-strong);
}

.action-item i {
    width: 16px;
    text-align: center;
}

.action-divider {
    height: 1px;
    background: var(--border-secondary);
    margin: 0.25rem 0;
}

/* Bulk Selection Checkboxes */
.user-select-checkbox,
#select-all-users {
    cursor: pointer;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: none;
    vertical-align: middle;
}

/* Admin Users Search */
.admin-users-search {
    padding: 0;
    background: transparent;
    border: none;
    flex: 0 0 auto;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    max-width: 300px;
}

.search-container i.fa-search {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
    z-index: 1;
}

#users-search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

#reports-search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

#reports-search-input:focus {
    outline: none;
    border-color: var(--info-color);
    box-shadow: 0 0 0 3px var(--info-focus-ring);
}

#users-search-input:focus {
    outline: none;
    border-color: var(--info-color);
    box-shadow: 0 0 0 3px var(--info-focus-ring);
}

.clear-search-btn {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-search-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Bulk Actions Bar */
.bulk-actions-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--info-surface-bg);
    border-bottom: 2px solid var(--info-surface-border);
    margin-bottom: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 90;
    box-shadow: var(--shadow-subtle);
}


.bulk-actions-info {
    font-weight: 600;
    color: var(--info-surface-text);
    font-size: 0.95rem;
    flex: 0 0 auto;
    white-space: nowrap;
}

.bulk-actions-menu {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 0 0 auto;
    margin-left: auto;
}

.bulk-action-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--info-surface-border);
    background: var(--input-bg);
    color: var(--info-surface-btn-text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bulk-action-btn:hover:not(:disabled):not(.disabled) {
    background: var(--info-surface-border);
    color: var(--text-on-accent);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px var(--info-shadow-hover);
}

.bulk-action-btn:disabled,
.bulk-action-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.bulk-action-btn.danger {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.bulk-action-btn.danger:hover {
    background: var(--danger-color);
    color: var(--text-on-accent);
    box-shadow: 0 2px 6px var(--danger-focus-ring);
}

.bulk-action-btn i {
    font-size: 0.9rem;
}

.bulk-action-btn span {
    white-space: nowrap;
}

/* Pagination */
.admin-users-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-secondary);
    flex-wrap: wrap;
    gap: 1rem;
}

.pagination-info {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-secondary);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-secondary);
    border-color: var(--info-surface-border);
    color: var(--info-color);
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-pages {
    display: flex;
    gap: 0.25rem;
}

.pagination-page-btn {
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--border-secondary);
    background: var(--input-bg);
    color: var(--text-primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination-page-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--info-surface-border);
    color: var(--info-color);
}

.pagination-page-btn.active {
    background: var(--info-surface-border);
    border-color: var(--info-surface-border);
    color: var(--text-on-accent);
    font-weight: 600;
}

.pagination-page-btn.active:hover {
    background: var(--pagination-accent-hover-bg);
}

/* Responsive Admin Modal */
@media (max-width: 768px) {
    .admin-modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
    }
    
    .users-table {
        font-size: 0.85rem;
    }
    
    .users-table th,
    .users-table td {
        padding: 0.5rem;
    }
}

/* Maintenance-mode toggle in admin users modal header */
.maintenance-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
    margin-right: 1rem;
    font-size: 0.85rem;
    color: var(--text-color, #cbd5e1);
}
.maintenance-toggle.is-on .maintenance-label {
    color: #ef4444;
    font-weight: 600;
}
.maintenance-toggle.read-error .maintenance-label {
    color: #f59e0b;
    font-weight: 600;
}
.maintenance-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
    flex-shrink: 0;
}
.maintenance-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.maintenance-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #475569;
    border-radius: 22px;
    transition: background-color .2s;
}
.maintenance-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 3px;
    top: 3px;
    background-color: #fff;
    border-radius: 50%;
    transition: transform .2s;
}
.maintenance-switch input:checked + .maintenance-slider {
    background-color: #ef4444;
}
.maintenance-switch input:checked + .maintenance-slider::before {
    transform: translateX(20px);
}
.maintenance-switch input:disabled + .maintenance-slider {
    opacity: 0.6;
    cursor: wait;
}
