/* ============================================
   Global Styles & CSS Variables
   ============================================ */
:root {
    --primary-color: #0078d4;
    --primary-hover: #006abc;
    --secondary-color: #5a5a5a;
    --success-color: #107c10;
    --danger-color: #d13438;
    --warning-color: #ff8c00;
    --background-color: #f3f2f1;
    --surface-color: #ffffff;
    --text-primary: #323130;
    --text-secondary: #605e5c;
    --text-muted: #8a8886;
    --border-color: #e1dfdd;
    --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.13);
    --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.13);
    --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.13);
    --border-radius: 4px;
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================
   Navigation Bar
   ============================================ */
.navbar {
    background-color: var(--surface-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 2px solid var(--primary-color);
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 20px;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-brand i {
    font-size: 1.8rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 10px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.nav-link:hover,
.nav-link.active {
    background-color: var(--primary-color);
    color: white;
}

.nav-link-logout {
    background-color: var(--danger-color);
    color: white;
}

.nav-link-logout:hover {
    background-color: #a61e22;
}

.nav-user-info {
    display: flex;
    align-items: center;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: #f3f2f1;
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-weight: 500;
}

.user-badge i {
    color: var(--primary-color);
    font-size: 1.2rem;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    padding: 30px 0;
}

/* ============================================
   Flash Messages
   ============================================ */
.flash-messages {
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 20px;
}

.alert {
    padding: 15px 20px;
    border-radius: var(--border-radius);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.alert i {
    font-size: 1.2rem;
}

.alert-error {
    background-color: #fde7e9;
    color: var(--danger-color);
    border-left: 4px solid var(--danger-color);
}

.alert-success {
    background-color: #dff6dd;
    color: var(--success-color);
    border-left: 4px solid var(--success-color);
}

.close-btn {
    position: absolute;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

.close-btn:hover {
    opacity: 1;
}

/* ============================================
   Page Header
   ============================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.header-content h1 {
    font-size: 2rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 5px;
}

.header-content h1 i {
    color: var(--primary-color);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.header-stats {
    display: flex;
    gap: 15px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary-color) 0%, #005a9e 100%);
    color: white;
    padding: 20px 30px;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: var(--shadow-md);
    min-width: 150px;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 5px;
}

/* ============================================
   Search Section
   ============================================ */
.search-section {
    background-color: var(--surface-color);
    padding: 25px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 30px;
}

.search-form {
    display: flex;
    gap: 15px;
    align-items: center;
}

.search-input-group {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 15px;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.search-input {
    width: 100%;
    padding: 12px 45px 12px 45px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 120, 212, 0.1);
}

.clear-search {
    position: absolute;
    right: 15px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    text-decoration: none;
}

.clear-search:hover {
    color: var(--danger-color);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #474747;
    box-shadow: var(--shadow-md);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.875rem;
}

/* ============================================
   Table
   ============================================ */
.table-container {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 20px;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table thead {
    background-color: #f8f8f8;
    border-bottom: 2px solid var(--border-color);
}

.users-table th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.users-table th i {
    margin-right: 5px;
    color: var(--primary-color);
}

.users-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.users-table tbody tr:hover {
    background-color: #f8f9fa;
}

.users-table td {
    padding: 15px;
    vertical-align: middle;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #005a9e 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.user-name {
    font-weight: 600;
    color: var(--text-primary);
}

.user-upn {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.email {
    color: var(--primary-color);
    text-decoration: none;
}

.email:hover {
    text-decoration: underline;
}

.text-center {
    text-align: center !important;
}

.text-muted {
    color: var(--text-muted);
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.badge-success {
    background-color: #dff6dd;
    color: var(--success-color);
}

.badge-danger {
    background-color: #fde7e9;
    color: var(--danger-color);
}

/* ============================================
   Table Footer
   ============================================ */
.table-footer {
    background-color: var(--surface-color);
    padding: 15px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    color: var(--text-secondary);
}

.table-footer i {
    color: var(--primary-color);
    margin-right: 5px;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    background-color: var(--surface-color);
    padding: 60px 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.empty-state i {
    font-size: 4rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 25px;
}

/* ============================================
   Breadcrumb
   ============================================ */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 25px;
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

.separator {
    color: var(--text-muted);
}

.breadcrumb .current {
    color: var(--text-primary);
    font-weight: 500;
}

/* ============================================
   User Detail Page
   ============================================ */
.user-detail-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #005a9e 100%);
    color: white;
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 25px;
}

.user-avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 2.5rem;
    border: 4px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
    overflow: hidden; /* ensure image is clipped to circle */
}

.user-avatar-large .avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* fill box, keep aspect ratio, crop overflow */
    display: block;
}

.user-header-info h1 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.user-header-info .user-upn {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 15px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.detail-card {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    background-color: #f8f8f8;
    padding: 15px 20px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-header.clickable {
    cursor: pointer;
    user-select: none;
}

.card-header.clickable:hover {
    background-color: #f0f0f0;
}

.card-header i {
    color: var(--primary-color);
    font-size: 1.2rem;
}

.card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
}

.toggle-icon {
    transition: var(--transition);
}

.card-body {
    padding: 20px;
}

.detail-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-item:last-child {
    border-bottom: none;
}

.detail-item label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.detail-item label i {
    color: var(--primary-color);
    width: 20px;
}

.detail-value {
    color: var(--text-primary);
    padding-left: 28px;
}

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

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

.detail-value code {
    background-color: #f5f5f5;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 0.9rem;
    color: var(--text-primary);
    word-break: break-all;
}

pre {
    background-color: #f5f5f5;
    padding: 15px;
    border-radius: var(--border-radius);
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.5;
}

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

/* ============================================
   Error Page
   ============================================ */
.error-container {
    background-color: var(--surface-color);
    padding: 60px 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.error-icon {
    font-size: 5rem;
    color: var(--danger-color);
    margin-bottom: 20px;
}

.error-container h1 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.error-message {
    background-color: #fde7e9;
    border-left: 4px solid var(--danger-color);
    padding: 20px;
    border-radius: var(--border-radius);
    margin: 25px 0;
    color: var(--danger-color);
    font-weight: 500;
}

.error-suggestions {
    text-align: left;
    margin: 30px 0;
}

.error-suggestions h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.error-suggestions ul {
    list-style: none;
}

.error-suggestions li {
    padding: 10px 0;
    color: var(--text-secondary);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.error-suggestions li i {
    color: var(--primary-color);
    margin-top: 3px;
}

.error-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 20px 0;
    margin-top: auto;
}

.footer p {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer i {
    color: var(--primary-color);
    margin: 0 5px;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        gap: 15px;
    }

    .nav-menu {
        flex-direction: column;
        width: 100%;
    }

    .nav-link {
        justify-content: center;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-form {
        flex-direction: column;
    }

    .table-container {
        overflow-x: auto;
    }

    .users-table {
        min-width: 800px;
    }

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

    .user-detail-header {
        padding: 30px 20px;
    }

    .user-profile {
        flex-direction: column;
        text-align: center;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
}

