:root {
    --bg-color: #f4f6f9;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #eaeaea;
    --primary-color: #3498db;
    --success-color: #2ecc71;
    --warning-color: #f1c40f;
    --danger-color: #e74c3c;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1b1e;
        --card-bg: #25262b;
        --text-primary: #e0e0e0;
        --text-secondary: #a0a0a0;
        --border-color: #373a40;
        --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    }
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

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

/* Login Page */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-title {
    margin-bottom: 24px;
    font-size: 24px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 16px;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.error-msg {
    color: var(--danger-color);
    margin-bottom: 16px;
    font-size: 14px;
    display: none;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px 0;
}

.header-title h1 {
    font-size: 24px;
    font-weight: 700;
}

.header-actions .btn-logout {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    width: auto;
}

/* Grid Layout */
.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.user-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    cursor: pointer;
}

.user-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
    border-color: var(--primary-color);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.user-email-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    /* Enable truncation */
}

.online-indicator {
    width: 8px;
    height: 8px;
    background-color: #2ecc71;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.2);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(46, 204, 113, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
    }
}

.user-email {
    font-weight: 600;
    font-size: 15px;
    word-break: break-all;
    color: var(--text-primary);
    line-height: 1.4;
}

.status-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    margin-left: 8px;
}

.status-normal {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success-color);
}

.status-soon {
    background: rgba(241, 196, 15, 0.15);
    color: var(--warning-color);
}

.status-expired {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger-color);
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    font-weight: 500;
    color: var(--text-primary);
}

.progress-bar-container {
    margin-top: 8px;
}

.progress-bar {
    height: 6px;
    background: var(--bg-color);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* Loading State */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    color: white;
    font-size: 18px;
    display: none;
}

.empty-state {
    text-align: center;
    padding: 60px;
    grid-column: 1 / -1;
    color: var(--text-secondary);
}

/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(2px);
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.95);
    transition: transform 0.2s ease;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header .modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal-body {
    padding: 24px;
}

/* Redesigned Modal Layout */
.detail-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.detail-lg-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    word-break: break-all;
}

.detail-sub-value {
    font-size: 13px;
    color: var(--text-secondary);
}

.detail-status {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    margin-left: 10px;
}

.detail-status.status-normal {
    background: rgba(46, 204, 113, 0.1);
    color: var(--success-color);
}

.detail-status.status-soon {
    background: rgba(241, 196, 15, 0.1);
    color: var(--warning-color);
}

.detail-status.status-expired {
    background: rgba(231, 76, 60, 0.1);
    color: var(--danger-color);
}

.detail-divider {
    height: 1px;
    background: var(--border-color);
    margin: 20px 0;
}

.detail-grid-compact {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.detail-block {
    display: flex;
    flex-direction: column;
}

.detail-value-highlight {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin: 4px 0;
}

.detail-sub-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.detail-row {
    margin-top: 10px;
}

.uuid-box {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s;
}

.uuid-box:hover {
    background: #f1f3f5;
    border-color: var(--primary-color);
}

.uuid-text {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 10px;
    flex: 1;
}

.copy-icon {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Node Badges */
.node-badge-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.node-badge {
    background-color: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
    border: 1px solid rgba(46, 204, 113, 0.3);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    display: inline-block;
    transition: all 0.2s;
}

.node-badge:hover {
    background-color: rgba(46, 204, 113, 0.25);
    transform: translateY(-1px);
}

/* =========================================
   Admin Panel Styles (Migrated from admin.php)
   ========================================= */
.admin-container {
    max-width: 800px;
    margin: 40px auto;
    padding: 20px;
}

.form-row {
    display: flex;
    gap: 20px;
}

.form-row .form-group {
    flex: 1;
}

.settings-card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 12px 24px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    color: var(--text-secondary);
}

.tab-btn.active {
    border-bottom-color: var(--primary-color);
    color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.section-title {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-primary);
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
}

.alert {
    padding: 12px;
    margin-bottom: 20px;
    border-radius: 8px;
}

.alert-success {
    background: rgba(46, 204, 113, 0.15);
    color: #27ae60;
}

.alert-error {
    background: rgba(231, 76, 60, 0.15);
    color: #c0392b;
}

.btn-secondary {
    background-color: #95a5a6;
}

.code-block {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #eee;
    font-family: monospace;
    font-size: 12px;
    color: #333;
    margin-top: 10px;
    white-space: pre-wrap;
    display: none;
}

/* =========================================
   Mobile Responsiveness
   ========================================= */
@media (max-width: 768px) {

    /* Container Adjustments */
    .admin-container,
    .container {
        padding: 10px;
        margin: 10px auto;
    }

    /* Header: Stack title and actions */
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .header-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
        gap: 10px;
    }

    .header-actions .btn {
        flex: 1;
        text-align: center;
        justify-content: center;
    }

    /* Admin Navigation: Horizontal Scroll */
    .tab-nav {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        /* Smooth scroll on iOS */
        scrollbar-width: none;
        /* Hide scrollbar for cleaner look */
        margin-left: -20px;
        /* Bleed out to edge */
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 20px;
    }

    .tab-nav::-webkit-scrollbar {
        display: none;
    }

    .tab-btn {
        padding: 12px 16px;
        flex-shrink: 0;
    }

    /* Forms: Stack inputs vertically */
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .settings-card {
        padding: 20px;
    }

    /* User Grid: 1 column on very small screens if needed, 
       but minmax(280px, 1fr) usually handles it. 
       Let's ensure it doesn't overflow. */
    .user-grid {
        grid-template-columns: 1fr;
    }

    /* Stats Layout in User Detail */
    .detail-grid-compact {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    /* Modal responsive */
    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}