/* RESET & VARIABLES */
:root {
    --primary: #0d6efd;
    --primary-hover: #0b5ed7;
    --bg-light: #f4f7f9;
    --sidebar-bg: #f8f9fb;
    --border-color: #eaedf1;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --danger: #dc3545;
    --success: #198754;
    --warning: #ffc107;
    
    --sidebar-width: 260px;
    --header-height: 64px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ========================================
   DARK MODE STYLES
   ======================================== */

/* Dark Mode Variables Override */
body.dark-mode {
    --bg-light: #0f1419;
    --sidebar-bg: #1a1f26;
    --border-color: #2d3339;
    --text-dark: #e4e6eb;
    --text-muted: #8b92a0;
    background-color: var(--bg-light) !important;
    color: var(--text-dark) !important;
}

/* Cards & Containers */
body.dark-mode .stat-card,
body.dark-mode .card,
body.dark-mode .sidebar,
body.dark-mode .topbar {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-color) !important;
}

/* Form Elements */
body.dark-mode .form-control,
body.dark-mode input[type="text"],
body.dark-mode input[type="email"],
body.dark-mode input[type="password"],
body.dark-mode input[type="search"],
body.dark-mode select,
body.dark-mode textarea {
    background-color: #0f1419 !important;
    border-color: var(--border-color) !important;
    color: var(--text-dark) !important;
}

body.dark-mode .form-control::placeholder,
body.dark-mode input::placeholder {
    color: var(--text-muted) !important;
}

body.dark-mode .form-control:disabled {
    background-color: #1a1f26 !important;
    opacity: 0.6;
}

/* Text & Headings - Make sure all text is visible */
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode h4,
body.dark-mode h5,
body.dark-mode h6 {
    color: var(--text-dark) !important;
}

body.dark-mode p,
body.dark-mode span,
body.dark-mode div,
body.dark-mode label {
    color: var(--text-dark) !important;
}

body.dark-mode .text-muted {
    color: var(--text-muted) !important;
}

/* Buttons */
body.dark-mode .btn,
body.dark-mode button {
    color: var(--text-dark) !important;
}

body.dark-mode .btn-outline {
    border-color: var(--border-color) !important;
    color: var(--text-dark) !important;
    background-color: transparent !important;
}

body.dark-mode .btn-outline:hover {
    background-color: #2d3339 !important;
}

/* Settings primary action must stay visibly blue in both themes. */
body.dark-mode #save-settings-btn {
    background-color: var(--primary) !important;
}

/* Badges & Pills */
body.dark-mode .badge {
    background-color: #2d3339 !important;
    color: var(--text-dark) !important;
}

/* Navigation */
body.dark-mode .nav-item {
    color: var(--text-dark) !important;
}

body.dark-mode .nav-item:hover {
    background-color: #2d3339 !important;
}

body.dark-mode .nav-item.active {
    background-color: rgba(13, 110, 253, 0.1) !important;
}

/* Tables & Lists */
body.dark-mode .table,
body.dark-mode .email-item,
body.dark-mode table,
body.dark-mode tr,
body.dark-mode td,
body.dark-mode th {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-dark) !important;
}

body.dark-mode .email-item:hover,
body.dark-mode tr:hover {
    background-color: #2d3339 !important;
}

/* Icons & SVG */
body.dark-mode i,
body.dark-mode svg {
    color: var(--text-dark) !important;
    fill: var(--text-dark) !important;
}

/* Specific inline styles override */
body.dark-mode [style*="color: #"] {
    color: var(--text-dark) !important;
}

body.dark-mode [style*="background: #f8fafc"],
body.dark-mode [style*="background-color: #f8fafc"] {
    background-color: #1a1f26 !important;
}

/* Search boxes */
body.dark-mode .search-box,
body.dark-mode [class*="search"] {
    background-color: #0f1419 !important;
    border-color: var(--border-color) !important;
    color: var(--text-dark) !important;
}

/* Dropdowns & Modals */
body.dark-mode .dropdown-menu,
body.dark-mode .modal-content {
    background-color: var(--sidebar-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-dark) !important;
}

/* Admin Panel specific */
body.dark-mode .admin-card,
body.dark-mode .stat-box {
    background-color: var(--sidebar-bg) !important;
    color: var(--text-dark) !important;
}

/* Links */
body.dark-mode a {
    color: #4d9eff !important;
}

body.dark-mode a:hover {
    color: #6db3ff !important;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.5;
    font-size: 14px;
}

a {
    text-decoration: none;
    color: var(--primary);
}

button {
    cursor: pointer;
    font-family: inherit;
}

ul {
    list-style: none;
}

/* UTILITIES */
.d-flex { display: flex; }
.d-inline-flex { display: inline-flex; }
.flex-column { flex-direction: column; }
.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.justify-content-center { justify-content: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-end { justify-content: flex-end; }
.flex-grow-1 { flex-grow: 1; }
.flex-wrap { flex-wrap: wrap; }

/* Gap */
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.gap-4 { gap: 1.5rem; }

/* Width / Height */
.w-100 { width: 100%; }
.h-100 { height: 100%; }

/* Text */
.text-center { text-align: center; }
.text-end { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-dark { color: var(--text-dark); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.fw-bold { font-weight: 600; }
.fw-normal { font-weight: 400; }

/* Margin */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.ms-1 { margin-left: 0.25rem; }
.ms-2 { margin-left: 0.5rem; }
.ms-3 { margin-left: 1rem; }
.ms-auto { margin-left: auto; }
.me-1 { margin-right: 0.25rem; }
.me-2 { margin-right: 0.5rem; }
.me-3 { margin-right: 1rem; }
.me-auto { margin-right: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Padding */
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-3 { padding-left: 1rem; padding-right: 1rem; }
.px-4 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 1rem; padding-bottom: 1rem; }
.ps-2 { padding-left: 0.5rem; }
.ps-3 { padding-left: 1rem; }
.pe-2 { padding-right: 0.5rem; }
.pe-3 { padding-right: 1rem; }

/* Backgrounds */
.bg-light { background-color: #f8fafc; }
.bg-white { background-color: #fff; }
.bg-primary { background-color: var(--primary); }
.bg-transparent { background: transparent; }

/* Borders */
.border { border: 1px solid var(--border-color); }
.border-top { border-top: 1px solid var(--border-color); }
.border-bottom { border-bottom: 1px solid var(--border-color); }
.border-0 { border: none; }
.rounded { border-radius: 6px; }
.rounded-circle { border-radius: 50%; }

/* Overflow */
.overflow-hidden { overflow: hidden; }

/* Position */
.position-relative { position: relative; }
.position-absolute { position: absolute; }

/* AUTH LAYOUT */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f0f4f8;
    background-image: radial-gradient(#d1d5db 1px, transparent 1px);
    background-size: 20px 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    gap: 8px;
    margin-bottom: 0.5rem;
}

.auth-logo img {
    width: 24px;
    height: 24px;
}

.brand-logo {
    display: block;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    object-fit: contain;
}

.brand-logo-sidebar,
.brand-logo-topbar,
.brand-logo-simple {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
}

.brand-logo-auth {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
}

.auth-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    padding: 2rem;
}

/* FORMS */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: #f8f9fa;
    font-size: 0.875rem;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background-color: #fff;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1rem;
    border-radius: 6px;
    border: 1px solid transparent;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s;
    gap: 0.5rem;
}

.btn-primary {
    background-color: #1a202c;
    color: #fff;
}
.btn-primary:hover {
    background-color: #000;
}
.btn-blue {
    background-color: var(--primary);
    color: #fff;
}
.btn-blue:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: #fff;
    border-color: var(--border-color);
    color: var(--text-dark);
}
.btn-outline:hover {
    background-color: #f8f9fa;
}

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

/* APP LAYOUT */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 999;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 1.125rem;
}

.sidebar-search {
    padding: 1rem 1.5rem;
    flex-shrink: 0;
    min-height: 70px;
    display: block !important;
    visibility: visible !important;
    position: relative;
    z-index: 10;
}

.sidebar-search input {
    background-color: #fff;
    width: 100% !important;
    display: block !important;
    visibility: visible !important;
}

.sidebar-nav {
    flex-grow: 1;
    padding: 0 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    border-radius: 6px;
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.nav-item:hover {
    background-color: #f1f5f9;
    color: var(--text-dark);
}

.nav-item.active {
    background-color: var(--primary);
    color: #fff;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.quota-bar {
    height: 4px;
    background-color: #e2e8f0;
    border-radius: 2px;
    margin: 0.5rem 0;
    overflow: hidden;
}
.quota-fill {
    height: 100%;
    background-color: var(--primary);
    width: 82%;
}

/* MAIN CONTENT */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
}

.topbar {
    min-height: var(--header-height);
    height: auto;
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
    overflow: visible;
}

.page-content {
    padding: 1.5rem;
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: auto;
    min-width: 0;
/*    margin-bottom:100px;*/
}

/* STAT CARDS */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1.5rem;
}

.stat-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* TABLES */
.data-table {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.data-table table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th {
    background-color: #f8fafc;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.data-table td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background-color: #f8fafc;
}

/* BADGES */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.badge-blue { background: #e0e7ff; color: #4f46e5; }
.badge-red { background: #fee2e2; color: #ef4444; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-green { background: #dcfce7; color: #16a34a; }

/* EMAIL DETAILS SPLIT VIEW */
.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: auto;
    min-height: 420px;
    max-height: calc(100vh - 220px);
}

@media (max-width: 1100px) {
    .split-view {
        grid-template-columns: 1fr;
        max-height: none;
    }
}

.pane {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pane-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background-color: #f8fafc;
}

.pane-body {
    padding: 1.5rem;
    flex-grow: 1;
    overflow-y: auto;
}

.pane-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: #f8fafc;
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

/* UTILS */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.inbox-page {
    padding: 0;
    max-width: 100%;
    min-width: 0;
}

.inbox-table-wrap {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
}

.data-table.inbox-table-wrap {
    overflow: auto;
}

.inbox-table-wrap table {
    min-width: 760px;
    table-layout: fixed;
}

.search-wrap input {
    width: 100%;
    max-width: 260px;
}


/* ========================================
   ADDITIONAL DARK MODE FIXES
   ======================================== */

/* Override all hardcoded light colors in inline styles */
body.dark-mode [style*="background: #f8fafc"],
body.dark-mode [style*="background:#f8fafc"],
body.dark-mode [style*="background-color: #f8fafc"],
body.dark-mode [style*="background-color:#f8fafc"] {
    background: #1a1f26 !important;
    background-color: #1a1f26 !important;
}

body.dark-mode [style*="color: #1e293b"],
body.dark-mode [style*="color:#1e293b"],
body.dark-mode [style*="color: #2c3e50"],
body.dark-mode [style*="color: #333"],
body.dark-mode [style*="color:#333"] {
    color: #e4e6eb !important;
}

body.dark-mode [style*="color: #64748b"],
body.dark-mode [style*="color:#64748b"],
body.dark-mode [style*="color: #666"],
body.dark-mode [style*="color:#666"] {
    color: #8b92a0 !important;
}

body.dark-mode [style*="border: 1px solid #eaedf1"],
body.dark-mode [style*="border:1px solid #eaedf1"] {
    border-color: #2d3339 !important;
}

/* Stat cards with inline styles */
body.dark-mode [class*="stat"] {
    background-color: var(--sidebar-bg) !important;
    color: var(--text-dark) !important;
}

/* All divs with padding and background */
body.dark-mode div[style*="padding"][style*="background"] {
    background-color: var(--sidebar-bg) !important;
}

/* All text elements */
body.dark-mode * {
    border-color: var(--border-color);
}

/* Force all directly styled text to be visible */
body.dark-mode [style*="font-weight"] {
    color: var(--text-dark) !important;
}

/* Buttons with inline styles */
body.dark-mode button[style],
body.dark-mode [role="button"][style] {
    color: #fff !important;
}

/* Special case for buttons with outline style */
body.dark-mode button[class*="outline"],
body.dark-mode .btn-outline {
    color: var(--text-dark) !important;
    border-color: var(--border-color) !important;
}

/* Admin panel specific overrides */
body.dark-mode [class*="admin"],
body.dark-mode [class*="panel"],
body.dark-mode [class*="dashboard"] {
    background-color: var(--sidebar-bg) !important;
    color: var(--text-dark) !important;
}

/* Connection status badges */
body.dark-mode [style*="background: #"] {
    color: #fff !important;
}

/* Email provider cards */
body.dark-mode [class*="provider"],
body.dark-mode [class*="integration"] {
    background-color: var(--sidebar-bg) !important;
    color: var(--text-dark) !important;
}


/* ========================================
   DARK MODE - UNIVERSAL WHITE KILLER
   ======================================== */

/* Kill ALL white backgrounds in dark mode */
body.dark-mode * {
    background-color: #1a1f26 !important;
}

/* Exception: Keep body background */
body.dark-mode {
    background-color: #0f1419 !important;
}

/* Exception: Keep primary colored elements */
body.dark-mode [style*="#0d6efd"],
body.dark-mode [class*="btn-primary"],
body.dark-mode button[style*="var(--primary)"] {
    background-color: #0d6efd !important;
}

/* Exception: Keep success/danger/warning colors */
body.dark-mode [style*="#198754"] {
    background-color: #198754 !important;
}

body.dark-mode button[style*="#dc3545"],
body.dark-mode .btn[style*="#dc3545"] {
    background-color: #dc3545 !important;
}

body.dark-mode [style*="#ffc107"] {
    background-color: #ffc107 !important;
}

/* BUT: Dropdown items should NOT have red background */
body.dark-mode .dropdown-menu *,
body.dark-mode [class*="dropdown"] * {
    background-color: transparent !important;
}

/* Exception: Keep transparent backgrounds */
body.dark-mode [style*="transparent"] {
    background-color: transparent !important;
}

/* Force all text to be light colored */
body.dark-mode *:not(button) {
    color: #e4e6eb !important;
}

/* Buttons keep their text colors */
body.dark-mode button[style*="#0d6efd"],
body.dark-mode button[style*="var(--primary)"] {
    color: #ffffff !important;
}

/* ========================================
   SIDEBAR SEARCH - VISIBILITY FIX
   Ensures search bar is visible on all screen sizes
   ======================================== */

@media (min-width: 768px) {
    .sidebar {
        display: flex !important;
    }
    
    .sidebar-search {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .sidebar-search input {
        display: block !important;
        visibility: visible !important;
    }
}

@media (min-width: 1200px) {
    .sidebar {
        display: flex !important;
    }
    
    .sidebar-search {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .sidebar-search input {
        display: block !important;
        visibility: visible !important;
    }
}

/* Force search bar visibility regardless of viewport */
.sidebar-search,
.sidebar-search input {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}


/* Email Details Menu Dropdown */
#email-menu-dropdown a:hover {
    background-color: #f1f5f9;
}

#email-menu-dropdown a:active {
    background-color: #e2e8f0;
}


/* RFC-822 Modal */
#close-rfc822-modal:hover {
    background-color: #f1f5f9;
}

#rfc822-modal pre {
    tab-size: 4;
}

/* Syntax highlighting for RFC-822 */
#rfc822-content {
    background: #1e1e1e !important;
}
