:root {
    --primary-color: #0376f7;
    --accent-color: #0376f7;
    --success-color: #2ecc71;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #f4f7f6;
    --card-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
    --glass-effect: rgba(255, 255, 255, 0.9);
}

/* --- FIX: AUTH CLOAK & LOADER --- */

/* Ensures 'hidden' always overrides other display rules */
.hidden {
    display: none !important;
}

/* Full screen loader to cover the login/dashboard flicker */
#app-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}

.spinner {
    width: 45px;
    height: 45px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- Base Styles --- */
body {
    background-color: var(--light-bg);
    font-family: 'Inter', 'Segoe UI', Roboto, sans-serif;
    color: var(--primary-color);
    overflow-x: hidden;
    line-height: 1.6;
}

/* --- Navigation --- */
.nav-header {
    background: var(--glass-effect);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.avatar-circle {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #007bff, #00c6ff);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

/* --- Dashboard Elements --- */
.card {
    border: none;
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #fff;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

.stat-icon {
    font-size: 1.8rem;
    margin-bottom: 8px;
    transition: transform 0.3s ease;
    display: block;
}

.med-item-card {
    background: #ffffff;
    border-left: 6px solid var(--accent-color) !important;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

/* Behavior Insight Card Refinement */
#behavior-card {
    transition: all 0.5s ease;
    border-radius: 16px;
    min-height: 280px;
}

#behavior-quote {
    font-style: italic;
    opacity: 0.95;
    font-size: 1.1rem;
}

/* Dashboard Chart Container */
.chart-container {
    position: relative;
    height: 220px;
    width: 100%;
}

.adherence-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary-color);
}

/* --- Telemetry & Network --- */
.network-badge {
    background: rgba(0, 0, 0, 0.03);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-online {
    width: 10px;
    height: 10px;
    background: var(--success-color);
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    box-shadow: 0 0 8px var(--success-color);
    animation: pulse-green 2s infinite;
}

/* Hardware Status Text States */
.text-success {
    color: var(--success-color) !important;
}

.text-danger {
    color: var(--danger-color) !important;
}

/* --- Logs & Lists --- */
#log-container {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

/* Custom Scrollbar */
#log-container::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 6px;
}

#log-container::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

#log-container::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

/* --- Interaction States --- */
.door-open-anim {
    color: var(--danger-color) !important;
    animation: pulse-danger 1.5s infinite;
}

.door-closed-style {
    color: var(--success-color);
}

/* --- Forms & Modals --- */
.modal-content {
    border: none;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-header {
    border-bottom: 1px solid #f1f5f9;
    padding: 1.5rem;
}

.pill-row {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 14px;
    border-radius: 12px;
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.pill-row:hover {
    border-color: var(--accent-color);
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.form-control,
.form-select {
    border-radius: 10px;
    padding: 0.7rem 1rem;
    border: 1px solid #e2e8f0;
    font-size: 0.95rem;
}

.form-control:focus {
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.1);
    border-color: var(--accent-color);
}

/* --- WiFi Specific --- */
.wifi-setup-card {
    border: 2px dashed #e2e8f0;
    background: transparent;
    cursor: pointer;
}

.wifi-setup-card:hover {
    border-color: var(--accent-color);
    background: rgba(52, 152, 219, 0.02);
}

/* --- Animations --- */
@keyframes pulse-danger {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(46, 204, 113, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#dashboard-section:not(.hidden) {
    animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Reporting & Print --- */
#report-list table {
    font-size: 0.9rem;
}

@media print {
    body * {
        visibility: hidden;
    }

    #reportModal,
    #reportModal * {
        visibility: visible;
    }

    #reportModal {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }

    .btn-close,
    .modal-footer,
    .btn-primary {
        display: none !important;
    }
}

/* --- Mobile Adjustments --- */
@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
    }

    .nav-cg-name-text {
        display: none;
    }

    .adherence-value {
        font-size: 1.4rem;
    }

    .display-6 {
        font-size: 1.8rem;
    }
}