/* Main Variables */
:root {
    --primary-color: #4eadf9;
    --secondary-color: #6366f1;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --dark-bg: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --card-hover: rgba(56, 189, 248, 0.1);
}

* {
    box-sizing: border-box;
}

html {
    overflow-y: scroll;
    /* Prevents scrollbar layout shift */
}

body {
    background-color: var(--dark-bg);
    background-image:
        radial-gradient(at 0% 0%, rgba(78, 173, 249, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    margin: 0;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transform: translateZ(0);
    /* Hardware acceleration */
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 320px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    border-right: 1px solid var(--glass-border);
    overflow-y: auto;
}

.main-content {
    flex: 1;
    margin-left: 320px;
    padding: 2rem;
    max-width: 1600px;
}

/* Sidebar Components */
.brand {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary-color);
}

.sidebar-actions {
    width: 100%;
    margin-top: 1rem;
}

.nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 12px;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(78, 173, 249, 0.1);
    color: var(--primary-color);
}

.nav-link.active {
    border-left: 3px solid var(--primary-color);
}

/* Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

/* Search Box */
.search-box {
    position: relative;
    width: 300px;
    margin: 0 1.5rem;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(30, 41, 59, 0.8);
    box-shadow: 0 0 0 3px rgba(78, 173, 249, 0.1);
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.page-title h1 {
    font-size: 2rem;
    margin: 0;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.action-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(78, 173, 249, 0.4);
}

/* Stats Section */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    /* Force 4 columns */
    gap: 1.5rem;
    margin-bottom: 3rem;
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    padding: 1.5rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.03);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
}

.stat-info h3 {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0.25rem 0 0 0;
}

/* User Grid */
.users-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1400px) {
    .users-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1100px) {
    .users-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .users-grid {
        grid-template-columns: 1fr;
    }
}

.user-card {
    border-radius: 16px;
    padding: 1.5rem;
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    display: flex;
    flex-direction: column;
    will-change: transform;
}

.user-card:hover {
    transform: translateY(-5px);
    border-color: rgba(78, 173, 249, 0.3);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.user-avatar {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    object-fit: cover;
    /* or contain, depending on preference for icons */
    background: rgba(255, 255, 255, 0.05);
    /* Match stat-icon */
    padding: 2px;
    /* Slight padding to frame it */
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.85rem;
    color: var(--primary-color);
    margin: 0.15rem 0 0.5rem 0;
    font-weight: 500;
}

.user-meta {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.user-meta span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-meta span i {
    width: 14px;
    text-align: center;
    color: rgba(255, 255, 255, 0.4);
}

.user-stats {
    display: flex;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: auto;
}

.mini-stat {
    text-align: center;
}

.mini-stat span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mini-stat strong {
    display: block;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-top: 0.25rem;
}

.card-actions {
    position: absolute;
    top: 1rem;
    right: 1rem;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 0.5rem;
}

.user-card:hover .card-actions {
    opacity: 1;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--primary-color);
}

.icon-btn.delete:hover {
    background: var(--danger-color);
}

/* Controls & Filters */
.filter-toolbar {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.filter-select {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    padding: 0.5rem 2rem 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}

.filter-select:focus {
    border-color: var(--primary-color);
}

.view-btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.view-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.view-btn.active {
    background: rgba(78, 173, 249, 0.1);
    color: var(--primary-color);
    border-color: rgba(78, 173, 249, 0.3);
}

/* User List View */
.users-list-container {
    display: flex;
    flex-direction: column;
}

.user-list-item {
    display: grid;
    grid-template-columns: 48px 2fr 1.5fr 1.5fr 1fr 80px;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.user-list-item:last-child {
    border-bottom: none;
}

.user-list-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.list-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.05);
}

.list-name {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.list-unit {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.list-tc {
    color: var(--text-secondary);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9rem;
}

.role-badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.role-badge.admin {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger-color);
}

.role-badge.user {
    background: rgba(78, 173, 249, 0.15);
    color: var(--primary-color);
}

.list-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: #1e293b;
    width: 100%;
    max-width: 500px;
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid var(--glass-border);
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

.modal-title {
    font-size: 1.5rem;
    margin: 0 0 1.5rem 0;
    color: white;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    cursor: pointer;
}

.btn-submit {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Badge specific styles can be added if needed */
.status-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #1e293b;
}

.status-online {
    background-color: var(--success-color);
}

.status-offline {
    background-color: var(--text-secondary);
}