:root {
    /* --- Colors --- */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --surface: #ffffff;
    
    /* --- Dimensions --- */
    --sidebar-width: 260px;
    --navbar-height: 50px;
    
    /* --- Design Tokens --- */
    --radius-sm: 3px;
    --radius-md: 5px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    display: flex;
    min-height: 100vh;
    padding-top: var(--navbar-height); /* Offset for fixed navbar */
}

/* =========================================
   GLOBAL LAYOUT & NAVBAR
   ========================================= */

/* --- Top Fixed Navbar --- */
.global-navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 60;
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}
.navbar-brand .material-symbols-outlined { font-size: 1.5rem; }

/* Navbar Right Side (Avatar + Menu Toggle) */
.navbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: pointer;
}
.navbar-avatar img { width: 100%; height: 100%; object-fit: cover; }

.mobile-menu-toggle {
    display: none; /* Hidden on desktop */
    background: transparent;
    color: var(--text);
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
}
.mobile-menu-toggle .material-symbols-outlined { font-size: 1.5rem; }

/* --- Sidebar Navigation (Dark Theme) --- */
.global-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: #011722; /* Dark Background */
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    color: #e2e8f0; /* Light Text */
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--navbar-height));
    position: sticky;
    top: var(--navbar-height);
    z-index: 50;
    transition: transform 0.3s ease;
}

.sidebar-header { 
    padding: 1.5rem; 
    border-bottom: 1px solid rgba(255, 255, 255, 0.1); 
}

.user-mini { display: flex; align-items: center; gap: 12px; }
.user-avatar-placeholder {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    background-color: var(--primary); color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 1.1rem;
    flex-shrink: 0; overflow: hidden;
}
.user-avatar-placeholder img { width: 100%; height: 100%; object-fit: cover; }

/* Override Text Colors in Sidebar Header for Dark Mode */
.global-sidebar .user-mini #header-user-name { color: #f1f5f9 !important; }
.global-sidebar .user-mini #header-user-email { color: #94a3b8 !important; }

.sidebar-content { 
    flex: 1; 
    padding: 1.5rem 0; /* Remove horizontal padding for full-width items */
    overflow-y: auto; 
}

.menu-category {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: #64748b; /* Slightly muted on dark */
    margin-bottom: 0.5rem; 
    margin-top: 1.5rem; 
    font-weight: 600;
    padding: 0 1.5rem; /* Re-add horizontal padding */
}
.menu-category:first-child { margin-top: 0; }

.nav-link {
    display: flex; align-items: center; gap: 12px; 
    padding: 12px 1.5rem; /* Full width padding */
    color: #94a3b8; /* Light muted text */
    text-decoration: none; 
    border-radius: 0; /* Remove radius */
    margin-bottom: 0; 
    font-weight: 500; font-size: 0.9rem; transition: all 0.2s;
}

.nav-link:hover { 
    background: rgba(255, 255, 255, 0.05); 
    color: #f8fafc; 
}

.nav-link.active { 
    background: #ffffff08; 
    color: #fff; 
    border-left: 3px solid var(--primary); /* Active indicator */
    padding-left: calc(1.5rem - 3px); /* Adjust padding for border */
}

.nav-link .material-symbols-outlined { font-size: 1.25rem; }

.sidebar-footer { 
    padding: 1rem 1.5rem; 
    border-top: 1px solid rgba(255, 255, 255, 0.1); 
}

.logout-btn { width: 100%; justify-content: flex-start; color: #ef4444; }
.logout-btn:hover { background: rgba(239, 68, 68, 0.1); color: #fca5a5; }

/* Backdrop for Mobile */
.sidebar-backdrop {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 40; backdrop-filter: blur(2px);
}

/* --- Content Wrapper --- */
.content {
    flex-grow: 1;
    min-width: 0; /* Prevents overflow */
    padding: 30px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* =========================================
   COMPONENTS
   ========================================= */

/* --- Cards --- */
.card {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 0; /* Removed padding for full-width header */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.section-header { 
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.section-title { 
    font-size: 1rem; 
    font-weight: 600; 
    color: var(--primary); 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    margin: 0; 
}

.section-description {
    margin: 4px 0 0 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
    line-height: 1.4;
}

.card-body {
    padding: 1.5rem;
}

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.page-header h2 { margin: 0; font-size: 1.5rem; font-weight: 600; }

/* --- Buttons --- */
.btn {
    padding: 10px 20px; background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-weight: 500; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 8px;
    transition: background 0.2s; font-family: inherit;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.7; cursor: not-allowed; }

.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.back-btn {
    display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); background: #fff;
    padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 20px; font-size: 0.9rem;
    font-weight: 500; color: var(--text-muted);
}
.back-btn:hover { background: #f8fafc; color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.btn-sm:hover { background: var(--primary-hover); }

/* --- Forms --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-group { margin-bottom: 0; } /* Grid handles spacing */
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 6px; font-weight: 600; color: var(--text); }

input, textarea, select {
    width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.95rem; color: var(--text); background: #fff; transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); }
input:disabled { background: #f1f5f9; cursor: not-allowed; color: var(--text-muted); }

/* --- Badges & Indicators --- */
.status-badge { padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.status-open { background: #dcfce7; color: #166534; }
.status-closed { background: #fee2e2; color: #991b1b; }
.status-badge.processing { background: #dbeafe; color: #1e40af; }

.validity-badge { padding: 4px 10px; border-radius: var(--radius-sm); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
.validity-active { background: #dcfce7; color: #166534; }
.validity-expired { background: #fee2e2; color: #991b1b; }

.current-badge { font-size: 0.7rem; background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 12px; font-weight: 600; text-transform: uppercase; }

/* --- Messages --- */
.message-box { padding: 12px; border-radius: var(--radius-sm); margin-bottom: 20px; text-align: center; display: none; font-size: 0.9rem; }
.success-message { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.error-message { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* =========================================
   SPECIFIC PAGE STYLES
   ========================================= */

/* --- Profile Info Grid --- */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; }
.info-item { display: flex; flex-direction: column; }
.info-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; margin-bottom: 0.35rem; letter-spacing: 0.02em; }
.info-value { font-size: 0.95rem; color: var(--text); font-weight: 500; min-height: 24px; display: flex; align-items: center; }
.info-value.empty { color: #94a3b8; font-style: italic; font-weight: 400; }

/* --- View/Edit Toggle --- */
.edit-mode-field { display: none; }
.view-mode-field { display: block; }
body.editing .edit-mode-field { display: block; }
body.editing .view-mode-field { display: none; }
body.editing .edit-btn { display: none; }
body.editing .save-actions { display: flex; }
.save-actions { display: none; gap: 10px; }

/* --- Ticket List & Chat --- */
.ticket-item { padding: 15px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; transition: all 0.2s; background: #fff; }
.ticket-item:hover { border-color: var(--primary); box-shadow: 0 2px 4px rgba(0,0,0,0.05); }

.msg-bubble { padding: 15px; border-radius: var(--radius-sm); margin-bottom: 15px; max-width: 85%; font-size: 0.95rem; line-height: 1.5; }
.msg-user { background: #eff6ff; margin-left: auto; color: #1e3a8a; border: 1px solid #dbeafe; }
.msg-admin { background: #f8fafc; border: 1px solid var(--border); margin-right: auto; }

/* --- Device List --- */
.device-item { display: flex; align-items: center; justify-content: space-between; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 0.8rem; background: #fff; }
.device-info { display: flex; flex-direction: column; }
.device-name { font-weight: 600; font-size: 0.95rem; color: var(--text); display: flex; align-items: center; gap: 8px; }
.device-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.btn-sm-danger { padding: 6px 12px; font-size: 0.8rem; background: #fff; color: #ef4444; border: 1px solid #fca5a5; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; transition: all 0.2s; }
.btn-sm-danger:hover { background: #fef2f2; border-color: #ef4444; }

/* --- Analysis & Subscriptions --- */
.analysis-item { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; background: #fff; transition: all 0.2s; }
.analysis-item:hover { border-color: var(--primary); box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.analysis-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.sample-name { font-weight: 600; font-size: 1rem; color: var(--text); display: block; }
.sample-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.analysis-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; font-size: 0.85rem; background: #f8fafc; padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.detail-row span:first-child { color: var(--text-muted); font-weight: 500; display: block; font-size: 0.75rem; text-transform: uppercase; margin-bottom: 2px; }

.sub-item { display: flex; justify-content: space-between; align-items: center; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; background: #fff; }
.sub-info h4 { margin: 0 0 4px 0; font-size: 1rem; color: var(--text); }
.sub-meta { font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }

/* =========================================
   AUTHENTICATION PAGES (Standalone)
   ========================================= */
body.auth-page {
    padding-top: 0;
    align-items: center;
    justify-content: center;
    background-color: var(--bg);
}

.auth-card { 
    background: var(--surface); 
    padding: 2.5rem; 
    border-radius: var(--radius-md); 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); 
    width: 100%; 
    max-width: 400px; 
    border: 1px solid var(--border);
}
.auth-card.wide { max-width: 450px; }

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-header h2 { margin: 0 0 0.5rem 0; font-weight: 600; color: var(--text); }
.auth-header p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

.form-group .field-icon { 
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%); 
    color: var(--text-muted); font-size: 1.25rem; pointer-events: none;
}
.auth-input { padding-left: 44px !important; }

/* Auth Dividers */
.divider { display: flex; align-items: center; text-align: center; margin: 1.5rem 0; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border); }
.divider::before { margin-right: .5em; } .divider::after { margin-left: .5em; }

.btn-google { 
    background: #fff; color: var(--text); border: 1px solid var(--border); 
    display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 500;
    width: 100%; padding: 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.95rem;
}
.btn-google:hover { background: #f8fafc; border-color: #cbd5e1; }

.auth-links { margin-top: 1.5rem; text-align: center; font-size: 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; }
.auth-links a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-links a:hover { text-decoration: underline; }

/* Captcha */
.captcha-box { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); height: 42px; overflow: hidden; margin-top: 5px; }
.captcha-input { border: none; padding-left: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; border-radius: 0; }
.captcha-input:focus { box-shadow: none; border: none; }
#refresh-c { background: #f1f5f9; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); cursor: pointer; padding: 0 12px; color: var(--text-muted); display: flex; align-items: center; }
#refresh-c .material-symbols-outlined { font-size: 1.2rem; pointer-events: auto; }
#refresh-c:hover { background: #e2e8f0; color: var(--text); }

/* Loader */
#page-loader {
    display: flex; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg); z-index: 9999; align-items: center; justify-content: center;
}
.spinner {
    width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   RESPONSIVENESS
   ========================================= */
@media (max-width: 768px) {
    /* Navbar & Sidebar Interaction */
    .global-sidebar {
        position: fixed; 
        left: 0; 
        top: var(--navbar-height); /* Below navbar */
        transform: translateX(-100%);
        width: 80%; 
        max-width: 300px;
        height: calc(100vh - var(--navbar-height));
        box-shadow: 4px 0 24px rgba(0,0,0,0.15);
    }
    .global-sidebar.open { transform: translateX(0); }
    
    .mobile-menu-toggle { display: block; }
    .sidebar-backdrop { top: var(--navbar-height); }
    .sidebar-backdrop.open { display: block; }
    
    /* Layout Adjustments */
    .form-grid { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .content { padding: 20px; }
    
    /* Auth */
    .auth-card { padding: 1.5rem; border: none; box-shadow: none; background: transparent; }
    body.auth-page { align-items: flex-start; background: #fff; }
}