/* Liquid Glass Theme - Professional & Clean */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Core Colors - Deep Space & Glass */
    --bg-body: #020617; /* Slate 950 */
    --bg-glass: rgba(255, 255, 255, 0.03);
    --bg-glass-hover: rgba(255, 255, 255, 0.06);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);
    
    /* Text */
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    --text-dim: #64748B;
    
    /* Accents - Refined & Professional */
    --primary: #6366F1; /* Indigo 500 */
    --primary-glow: rgba(99, 102, 241, 0.25);
    --success: #10B981;
    --success-glow: rgba(16, 185, 129, 0.2);
    --danger: #EF4444;
    --danger-glow: rgba(239, 68, 68, 0.2);
    --warning: #F59E0B;
    
    /* Layout */
    --nav-height: 70px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    
    /* Glass Effect */
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --backdrop: blur(20px);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    background-image: 
        radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.12) 0%, transparent 40%),
        radial-gradient(circle at 85% 100%, rgba(139, 92, 246, 0.12) 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Auth Visibility Control --- */
/* Hide admin content by default to prevent flashing */
body.admin-body {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

/* Show content only after auth check */
body.admin-body.auth-checked {
    opacity: 1;
    visibility: visible;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* --- Admin Header (Floating Glass) --- */
.admin-header {
    position: sticky;
    top: 20px;
    z-index: 100;
    margin: 0 20px;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: var(--backdrop);
    -webkit-backdrop-filter: var(--backdrop);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.admin-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--nav-height);
    padding: 0 24px;
}

.admin-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-main);
}

.admin-logo i {
    font-size: 1.4rem;
    color: var(--primary);
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.admin-nav-links {
    display: flex;
    gap: 4px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link:hover {
    color: var(--text-main);
    background: var(--bg-glass-hover);
}

.nav-link.active {
    color: white;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-info { text-align: right; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.user-role { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.logout-btn {
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

/* --- Main Layout --- */
.admin-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
}

.page-header { margin-bottom: 40px; }
.page-title { font-size: 2rem; font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.page-title i { color: var(--primary); }
.page-subtitle { color: var(--text-muted); font-size: 1.05rem; }

/* --- Cards (Liquid Glass) --- */
.card {
    background: var(--bg-glass);
    backdrop-filter: var(--backdrop);
    -webkit-backdrop-filter: var(--backdrop);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--glass-shadow);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.card:hover {
    border-color: var(--border-glass-hover);
    transform: translateY(-2px);
}

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

.card-title { font-size: 1.25rem; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card-title i { color: var(--text-dim); font-size: 1.1rem; }

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s;
}

.stat-card:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(99, 102, 241, 0.2);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.stat-number { font-size: 1.5rem; font-weight: 700; color: white; line-height: 1.2; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); }

/* --- Forms & Inputs --- */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }

input, select, textarea, .form-control {
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: white;
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(220, 38, 38, 0.1);
    color: #F87171;
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.btn-danger:hover {
    background: rgba(220, 38, 38, 0.2);
    border-color: rgba(220, 38, 38, 0.4);
}

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

/* --- Status & Badges --- */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    border-radius: 20px;
    font-size: 0.85rem;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-dot.connected { background: var(--success); box-shadow: 0 0 8px var(--success-glow); }
.status-dot.disconnected { background: var(--danger); box-shadow: 0 0 8px var(--danger-glow); }

.badge { padding: 4px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #34D399; border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #FBBF24; border: 1px solid rgba(245, 158, 11, 0.2); }

/* --- Tables & Logs --- */
.table-container { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-glass); }
.table { width: 100%; border-collapse: collapse; background: rgba(0, 0, 0, 0.1); }
.table th { text-align: left; padding: 16px; font-size: 0.8rem; text-transform: uppercase; color: var(--text-muted); border-bottom: 1px solid var(--border-glass); background: rgba(255, 255, 255, 0.02); }
.table td { padding: 16px; font-size: 0.9rem; border-bottom: 1px solid var(--border-glass); color: var(--text-main); }
.table tr:last-child td { border-bottom: none; }

.log-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.log-item::before {
    content: ''; position: absolute; top: 0; left: 0; bottom: 0; width: 3px; background: var(--text-muted);
}
.log-item.sent::before { background: var(--success); }
.log-item.received::before { background: var(--primary); }

.log-header { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.8rem; color: var(--text-muted); }
.log-content { font-size: 0.95rem; color: #E2E8F0; }

/* --- Login Page Specifics --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #020617;
    position: relative;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-header i { font-size: 3rem; color: var(--primary); margin-bottom: 16px; display: block; filter: drop-shadow(0 0 12px var(--primary-glow)); }
.login-header h1 { font-size: 1.5rem; font-weight: 700; color: white; }

/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

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

.modal-content {
    background: #0F172A;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    padding: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s;
}

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

.modal-header { padding: 20px; border-bottom: 1px solid var(--border-glass); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 24px; }
.modal-footer { padding: 20px; border-top: 1px solid var(--border-glass); display: flex; justify-content: flex-end; gap: 12px; background: rgba(0,0,0,0.2); }

.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.2rem; transition: color 0.2s; }
.modal-close:hover { color: white; }

/* --- Notifications --- */
.notification {
    position: fixed;
    top: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2000;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.notification.show { transform: translateX(0); }
.notification-success { border-left: 4px solid var(--success); }
.notification-error { border-left: 4px solid var(--danger); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .admin-nav { height: auto; padding: 16px; flex-direction: column; gap: 16px; }
    .admin-nav-links { flex-wrap: wrap; justify-content: center; }
    .form-row { grid-template-columns: 1fr; }
    .stat-card { flex-direction: column; text-align: center; }
}

/* --- Login Button & Spinner --- */
.login-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), #4F46E5);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 12px var(--primary-glow);
    position: relative;
    overflow: hidden;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--primary-glow);
    filter: brightness(1.1);
}

.login-btn:active {
    transform: translateY(0);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Ensure login card is clickable */
.login-card {
    position: relative;
    z-index: 10;
}
