/* Admin Panel Styles */

/* Settings Sub-Navigation */
.settings-subnav {
    background: var(--gray-50, #f9fafb);
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
    padding: 0 24px;
}

.settings-subnav.hidden {
    display: none;
}

.settings-subnav-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.settings-tab {
    padding: 12px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500, #6b7280);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.settings-tab:hover {
    color: var(--gray-700, #374151);
}

.settings-tab.active {
    color: var(--gray-900, #111827);
    border-bottom-color: var(--gray-900, #111827);
}

/* Subnav vertical divider */
.subnav-divider {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--gray-300, #d1d5db);
    margin: auto 8px;
    flex-shrink: 0;
}

/* Impersonation Banner */
#impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 999;
    background: #fef3c7;
    border-bottom: 2px solid #f59e0b;
    padding: 8px 16px;
    text-align: center;
    font-size: 0.875rem;
    color: #92400e;
}

#impersonation-banner.hidden {
    display: none;
}

.impersonation-banner-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.impersonation-banner-content svg {
    flex-shrink: 0;
}

.impersonation-exit-btn {
    background: #dc2626;
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-left: 8px;
    transition: background 0.15s;
}

.impersonation-exit-btn:hover {
    background: #b91c1c;
}

/* Admin Brand Title — always visible, styled to complement logo */
.admin-brand-title {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    display: inline !important; /* Override config.js logoIncludesName hide */
}

/* Nav link colors — uses CSS variables set by brand theme */
.header-nav a {
    color: var(--brand-header-link, rgba(255, 255, 255, 0.8)) !important;
}

.header-nav a:hover,
.header-nav a.active {
    color: var(--brand-header-link-hover, #ffffff) !important;
}

.admin-header {
    margin-bottom: var(--space-6);
}

.admin-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--space-2);
}

.admin-header p {
    color: var(--gray-600);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.stat-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
    border-color: var(--gray-400);
    box-shadow: var(--shadow-md);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-pending {
    font-size: 0.875rem;
    color: var(--warning);
    margin-top: var(--space-1);
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.filter-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-600);
}

.filter-group .form-select {
    min-width: 180px;
}

/* Table Enhancements */
.table-container {
    margin: calc(-1 * var(--space-6));
    margin-bottom: 0;
    overflow-x: auto;
}

.table-container table {
    margin: 0;
}

th {
    position: sticky;
    top: 0;
    background: var(--gray-100);
    z-index: 1;
}

td {
    vertical-align: middle;
}

.table-name {
    font-weight: 500;
    color: var(--gray-900);
}

.table-email {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-4);
    border-top: 1px solid var(--gray-200);
    margin: 0 calc(-1 * var(--space-6));
    margin-bottom: calc(-1 * var(--space-6));
}

#page-info {
    color: var(--gray-600);
    font-size: 0.875rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 700px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: var(--space-1);
    line-height: 1;
}

.modal-close:hover {
    color: var(--gray-600);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Detail Fields */
.detail-section {
    margin-bottom: var(--space-6);
}

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

.detail-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--gray-200);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

@media (max-width: 640px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.detail-field.full-width {
    grid-column: 1 / -1;
}

.detail-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-value {
    color: var(--gray-900);
}

.detail-value a {
    color: var(--brand-secondary);
    text-decoration: none;
}

.detail-value a:hover {
    text-decoration: underline;
}

/* Status Actions */
.status-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.status-actions label {
    font-weight: 500;
    color: var(--gray-700);
}

.status-actions .form-select {
    width: auto;
    min-width: 120px;
}

/* View Link */
.view-link {
    color: var(--brand-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
}

.view-link:hover {
    text-decoration: underline;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--gray-500);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
}

/* Header positioning for mobile dropdown */
.header-content {
    position: relative;
}

/* Hamburger Button */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--brand-header-link, rgba(255, 255, 255, 0.8));
    border-radius: 1px;
    transition: transform 0.2s, opacity 0.2s;
}

.hamburger:hover span {
    background: var(--brand-header-link-hover, #fff);
}

/* Active Nav Indicator */
.header-nav .nav-link {
    position: relative;
    padding-bottom: 4px;
}

.header-nav .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--brand-header-link-hover, white);
    border-radius: 1px;
}

/* Checkbox Grid (brand access in user modal) */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-2);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    padding: var(--space-1) 0;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--gray-300);
    border-radius: 20px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #16a34a;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.3);
}

/* Badge Variants */
.badge-role {
    text-transform: capitalize;
    background: var(--gray-100);
    color: var(--gray-700);
}

.badge-brand {
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.75rem;
    margin: 1px;
}

.badge-audit {
    text-transform: capitalize;
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-success {
    background: #dcfce7;
    color: #16a34a;
}

.badge-error {
    background: #fef2f2;
    color: #dc2626;
}

.badge-info {
    background: #eff6ff;
    color: #1d4ed8;
}

/* Text Helpers */
.text-muted {
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* Users Table */
.brand-badges {
    max-width: 200px;
}

.user-actions {
    white-space: nowrap;
}

.user-actions .view-link {
    margin-right: var(--space-2);
}

/* Audit Details */
.audit-details {
    font-size: 0.8125rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

/* API Key Permissions Matrix */
.permissions-matrix {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.perm-row {
    display: grid;
    grid-template-columns: 1fr 60px 60px 60px;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--gray-200);
}

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

.perm-row.perm-header {
    background: var(--gray-100);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--gray-500);
    letter-spacing: 0.05em;
}

.perm-resource {
    font-size: 0.875rem;
    color: var(--gray-700);
}

.perm-toggle {
    text-align: center;
}

.perm-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* API Key Display Box */
.apikey-display-box {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}

.apikey-display-box code {
    flex: 1;
    font-size: 0.8125rem;
    word-break: break-all;
    color: var(--gray-900);
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

/* ========================================
   PROFILE SECTION
   ======================================== */

.profile-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: var(--space-6);
    align-items: start;
}

@media (max-width: 768px) {
    .profile-layout {
        grid-template-columns: 1fr;
    }
}

.profile-avatar-wrapper {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--gray-200);
}

.profile-avatar-large {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Nav avatar (small, in trigger & dropdown) */
.nav-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.nav-dropdown-header .profile-dropdown-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 6px;
    display: block;
}

/* ========================================
   NAV RESTRUCTURING — Dropdowns, Brand Selector, Profile
   ======================================== */

/* Nav Spacer — pushes right-side items */
.nav-spacer {
    flex: 1;
    min-width: var(--space-4);
}

/* Global Brand Selector — wrapper provides arrow + styling, select is invisible overlay */
.nav-brand-selector {
    display: flex;
    align-items: center;
    position: relative;
}

.nav-brand-selector::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid rgba(255, 255, 255, 0.7);
    pointer-events: none;
}

.header-light .nav-brand-selector::after {
    border-top-color: #6b7280;
}

select.nav-brand-select {
    color: var(--brand-header-link, rgba(255, 255, 255, 0.9));
    border-radius: var(--radius-md);
    padding: 6px 28px 6px 10px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background: rgba(255, 255, 255, 0.12) !important;
    border: 1px solid rgba(255, 255, 255, 0.25);
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

/* Light header — dark controls */
.header-light select.nav-brand-select {
    background: var(--gray-100, #f3f4f6) !important;
    border-color: var(--gray-300, #d1d5db);
    color: var(--gray-700, #374151);
}

select.nav-brand-select:hover {
    background: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.4);
}

.header-light select.nav-brand-select:hover {
    background: var(--gray-200, #e5e7eb) !important;
    border-color: var(--gray-400, #9ca3af);
}

select.nav-brand-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.header-light select.nav-brand-select:focus {
    border-color: var(--gray-400, #9ca3af);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.nav-brand-select option {
    color: var(--gray-900);
    background: white;
}

.nav-brand-select option.brand-select-divider {
    font-size: 0.625rem;
    color: var(--gray-400, #9ca3af);
}

/* Dropdown Container */
.nav-dropdown {
    position: relative;
    display: flex;
    align-items: center;
}

/* Dropdown Trigger Button */
.nav-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-header-link, rgba(255, 255, 255, 0.8));
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: var(--font-sans);
    padding: 4px 0;
    line-height: 1;
    white-space: nowrap;
    transition: color var(--transition-fast);
}

.nav-dropdown-trigger:hover {
    color: var(--brand-header-link-hover, #ffffff);
}

.nav-dropdown-trigger svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Dropdown Menu (hidden by default) */
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 14px);
    right: 0;
    min-width: 220px;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--gray-200);
    padding: var(--space-2) 0;
    z-index: 200;
}

.nav-dropdown.open .nav-dropdown-menu {
    display: block;
}

/* Dropdown Items — override the !important white colors from .header-nav a */
.nav-dropdown-menu a {
    display: block;
    padding: 8px 16px;
    color: var(--gray-700) !important;
    text-decoration: none !important;
    font-size: 0.875rem;
    font-weight: 400;
    transition: background var(--transition-fast);
}

.nav-dropdown-menu a:hover {
    background: var(--gray-50);
    color: var(--gray-900) !important;
}

/* Dropdown Section Label */
.nav-dropdown-section-label {
    padding: 6px 16px 2px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-400, #9ca3af);
}

/* Dropdown Divider */
.nav-dropdown-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 6px 0;
}

/* Dropdown Header (for profile info) */
.nav-dropdown-header {
    padding: 10px 16px;
    font-size: 0.8125rem;
    color: var(--gray-600);
    line-height: 1.5;
}

.nav-dropdown-header strong {
    display: block;
    color: var(--gray-900);
    font-size: 0.875rem;
    margin-bottom: 2px;
}

.nav-dropdown-header .badge {
    margin-top: 4px;
    display: inline-block;
}

/* ========================================
   NAV MOBILE OVERRIDES
   ======================================== */
@media (max-width: 768px) {
    .nav-spacer {
        display: none;
    }

    .nav-brand-selector {
        width: 100%;
        padding: var(--space-2) var(--space-3);
        order: -1;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        margin-bottom: var(--space-1);
    }

    .nav-brand-select {
        width: 100%;
        padding: 10px 32px 10px 12px;
        font-size: 0.875rem;
    }

    .nav-dropdown {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .nav-dropdown-trigger {
        padding: var(--space-2) var(--space-3);
        width: 100%;
        border-radius: var(--radius-md);
    }

    .nav-dropdown-trigger:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    .nav-dropdown-menu {
        position: static;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: transparent;
        padding: 0;
        min-width: 0;
    }

    .nav-dropdown-menu a {
        color: var(--brand-header-link, rgba(255, 255, 255, 0.8)) !important;
        padding: var(--space-2) var(--space-3);
        padding-left: calc(var(--space-3) + 22px);
        border-radius: var(--radius-md);
        font-size: 0.9375rem;
    }

    .nav-dropdown-menu a:hover {
        background: rgba(255, 255, 255, 0.1);
        color: var(--brand-header-link-hover, #ffffff) !important;
    }

    .nav-dropdown-header {
        color: rgba(255, 255, 255, 0.6);
        padding: var(--space-2) var(--space-3);
        padding-left: calc(var(--space-3) + 22px);
    }

    .nav-dropdown-header strong {
        color: rgba(255, 255, 255, 0.9);
    }

    .nav-dropdown-header .badge {
        background: rgba(255, 255, 255, 0.15);
    }

    .nav-dropdown-divider {
        background: rgba(255, 255, 255, 0.1);
        margin: var(--space-1) var(--space-3);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .header-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--brand-header-bg, var(--brand-primary));
        flex-direction: column;
        padding: var(--space-3);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 100;
    }

    .header-nav.open {
        display: flex;
    }

    .header-nav .nav-link {
        padding: var(--space-2) var(--space-3);
        border-radius: var(--radius-md);
    }

    .header-nav .nav-link:hover {
        background: rgba(255, 255, 255, 0.1);
    }

    .header-nav .nav-link.active::after {
        display: none;
    }

    .header-nav .nav-link.active {
        background: rgba(255, 255, 255, 0.15);
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group .form-select {
        min-width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        max-width: 100%;
        margin: var(--space-4);
        max-height: calc(100vh - var(--space-8));
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .status-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }

    .perm-row {
        grid-template-columns: 1fr 50px 50px 50px;
    }

    .perm-resource {
        font-size: 0.8125rem;
    }
}
