:root {
    /* Primary Colors */
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.2);
    --secondary: #6366f1;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.2);
    
    /* Backgrounds & Surfaces */
    --bg-deep: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #f8fafc;
    
    /* Text */
    --text-white: #000000;
    --text-dim: #475569;
    --text-muted: #94a3b8;
    
    /* Layout & Borders */
    --border: rgba(0, 0, 0, 0.06);
    --border-hover: rgba(0, 0, 0, 0.1);
    --sidebar-width: 280px;
    --sidebar-collapsed: 80px;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    
    /* Effects */
    --glass: blur(20px) saturate(180%) rgba(255, 255, 255, 0.7);
    --shadow-main: 0 4px 20px 0 rgba(0, 0, 0, 0.05);
}

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

body {
    background-color: var(--bg-deep);
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.03) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.03) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.02) 0px, transparent 50%);
    color: var(--text-white);
    font-family: 'Outfit', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #cbd5e1;
}

/* Layout Classes */
.app-container {
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    backdrop-filter: var(--glass);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
}

.main-content {
    flex: 1;
    padding: 2.5rem 3rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Logo */
.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #0f172a, #64748b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: opacity 0.3s ease;
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2.5rem;
    gap: 10px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hamburger-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-dim);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.hamburger-btn:hover {
    background: rgba(59, 130, 246, 0.05);
    color: var(--primary);
}

.sidebar.collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    gap: 1.5rem;
}

.sidebar.collapsed .logo-container {
    justify-content: center;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
    padding: 1.5rem 0.5rem;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .chevron-icon {
    display: none;
    opacity: 0;
}

.sidebar.collapsed .submenu {
    display: none !important;
}

.sidebar.collapsed .nav-item a {
    justify-content: center;
    padding: 12px;
}

/* Navigation */
.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: var(--text-dim);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-item.active a,
.nav-item a:hover {
    background: rgba(59, 130, 246, 0.05);
    color: var(--primary);
}

.nav-item.active a {
    background: rgba(59, 130, 246, 0.08);
    border-left: 3px solid var(--primary);
    padding-left: 13px; /* account for border */
}

/* Submenu & Dropdown */
.nav-item-dropdown {
    display: flex;
    flex-direction: column;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between !important;
}

.dropdown-trigger .nav-link-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chevron-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
    margin-left: auto;
}

.nav-item-dropdown.open .chevron-icon {
    transform: rotate(180deg);
}

.submenu {
    list-style: none;
    margin-top: 4px;
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease-out;
    padding-left: 1.5rem;
}

.nav-item-dropdown.open .submenu {
    max-height: 500px;
}

.submenu-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text-dim);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.submenu-item.active a,
.submenu-item a:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.submenu-item.active a {
    font-weight: 600;
}

/* Glass Card */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-main);
    padding: 2rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text-white);
}

.stat-label {
    color: var(--text-dim);
    font-size: 0.95rem;
    font-weight: 400;
}

/* Table */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1.25rem 1.5rem;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-white);
    font-size: 0.95rem;
}

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

tr:hover td {
    background: rgba(59, 130, 246, 0.02);
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 14px 0 var(--primary-glow);
}

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

/* Badges */
.badge {
    padding: 4px 12px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeIn 0.6s ease forwards;
}

/* Mobile Topbar & Drawer */
.mobile-topbar {
    display: none;
}

.mobile-close-icon {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

/* Admin Emails & History Components */
.admin-emails-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.admin-header-left {
    min-width: 0;
}

.admin-breadcrumb-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.admin-emails-title {
    font-size: clamp(1.6rem, 4vw, 2.25rem);
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.admin-emails-subtitle {
    color: var(--text-dim);
    margin-top: 4px;
    font-size: 0.9rem;
}

.admin-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.refresh-btn {
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.scope-banner {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    padding: 12px 18px;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    border-radius: var(--radius-md);
}

.scope-banner-text {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-all;
}

.scope-clear-link {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.admin-kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-card {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 6px;
    letter-spacing: 0.03em;
}

.kpi-val {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.2;
}

.kpi-sub {
    font-size: 0.7rem;
    margin-top: 4px;
}

.filter-toolbar-card {
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-md);
}

.admin-filter-form {
    display: flex;
    gap: 0.85rem 1rem;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
}

.filter-field {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dim);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.filter-field select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-sidebar);
    color: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    max-width: 180px;
    height: 38px;
    outline: none;
    transition: border-color 0.2s ease;
}

.filter-field select:focus {
    border-color: var(--primary);
}

.filter-search-group {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.filter-search-group .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    color: var(--text-dim);
    pointer-events: none;
}

.filter-search-group input {
    width: 100%;
    height: 38px;
    padding: 8px 12px 8px 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-sidebar);
    color: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.filter-search-group input:focus {
    border-color: var(--primary);
}

.filter-action-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-submit-btn {
    padding: 8px 18px;
    font-size: 0.85rem;
    height: 38px;
}

.filter-reset-link {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-decoration: none;
    padding: 6px 10px;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
    .admin-kpi-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: var(--sidebar-collapsed);
        padding: 2rem 1rem;
    }
    .sidebar .logo-text, 
    .sidebar .nav-text,
    .sidebar .chevron-icon {
        display: none !important;
    }
    .sidebar .submenu {
        display: none !important;
    }
    .sidebar .nav-item a {
        justify-content: center;
        padding: 12px;
    }
    .sidebar .sidebar-header {
        flex-direction: column;
        justify-content: center;
        gap: 1.5rem;
    }
    .sidebar .logo-container {
        justify-content: center;
    }
    .main-content {
        padding: 2rem;
    }
}

@media (max-width: 900px) {
    .admin-filter-form {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    .filter-field {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        width: 100%;
    }
    .filter-field select {
        max-width: 100%;
        width: 100%;
    }
    .filter-search-group {
        grid-column: span 2;
        min-width: 100%;
        width: 100%;
    }
    .filter-action-group {
        grid-column: span 2;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        min-height: 100vh;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    /* Mobile Sticky Topbar */
    .mobile-topbar {
        display: flex;
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        height: 62px;
        padding: 0 1.25rem;
        background: var(--bg-sidebar);
        border-bottom: 1px solid var(--border);
        backdrop-filter: var(--glass);
        z-index: 99;
        align-items: center;
        justify-content: space-between;
    }

    .mobile-hamburger-btn {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(59, 130, 246, 0.08);
        border: 1px solid var(--border);
        color: var(--text-white);
        border-radius: 10px;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .mobile-hamburger-btn:active {
        transform: scale(0.95);
        background: rgba(59, 130, 246, 0.15);
    }

    /* Backdrop */
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        backdrop-filter: blur(4px);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Mobile Sidebar as Drawer */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        max-width: 85vw;
        height: 100vh;
        height: 100dvh;
        background: var(--bg-sidebar);
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 1.5rem 1.25rem;
        border-right: 1px solid var(--border);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        box-shadow: none;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.25);
    }

    .sidebar .logo-text,
    .sidebar .nav-text {
        display: inline-block !important;
        opacity: 1 !important;
    }

    .sidebar .chevron-icon {
        display: block !important;
        opacity: 1 !important;
    }

    .sidebar .nav-item a {
        justify-content: flex-start !important;
        padding: 12px 16px !important;
    }

    .sidebar-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 1.75rem !important;
    }

    .sidebar .desktop-menu-icon {
        display: none !important;
    }

    .sidebar .mobile-close-icon {
        display: inline-block !important;
        width: 20px;
        height: 20px;
    }

    .hamburger-btn {
        width: 38px;
        height: 38px;
        background: rgba(0, 0, 0, 0.05);
        border-radius: 8px;
    }

    .main-content {
        padding: 1.5rem 1rem !important;
        min-width: 0;
        max-width: 100%;
        overflow-x: hidden;
    }

    .admin-emails-header {
        margin-bottom: 1.25rem !important;
    }

    .admin-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.25rem;
    }

    .kpi-card {
        padding: 1rem 0.85rem;
    }

    .kpi-val {
        font-size: 1.35rem;
    }

    .kpi-card-failures {
        grid-column: span 2;
    }

    .modal-dialog {
        padding: 1.25rem !important;
        border-radius: 14px !important;
    }

    .modal-meta-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    .modal-message-id-row {
        grid-column: span 1 !important;
    }
}

@media (max-width: 520px) {
    .main-content {
        padding: 1.25rem 0.75rem !important;
    }

    .filter-toolbar-card {
        padding: 1rem !important;
    }

    .admin-filter-form {
        grid-template-columns: 1fr;
    }

    .filter-search-group {
        grid-column: span 1;
    }

    .filter-action-group {
        grid-column: span 1;
        width: 100%;
    }

    .filter-action-group .btn-primary {
        flex: 1;
        justify-content: center;
    }

    .admin-pagination-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .admin-pagination-bar > div {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }

    .kpi-label {
        font-size: 0.68rem;
    }

    .kpi-val {
        font-size: 1.25rem;
    }
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 400px;
    background: #fff;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    animation: toast-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    transition: all 0.3s ease;
}

.toast-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-content {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-white);
}

.toast.success { border-left: 4px solid var(--accent); border-color: rgba(16, 185, 129, 0.2); }
.toast.error { border-left: 4px solid #ef4444; border-color: rgba(239, 68, 68, 0.2); }
.toast.info { border-left: 4px solid var(--primary); border-color: rgba(59, 130, 246, 0.2); }

.toast.success .toast-icon { color: var(--accent); }
.toast.error .toast-icon { color: #ef4444; }
.toast.info .toast-icon { color: var(--primary); }

.toast.hiding {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { transform: translateX(100%) scale(0.9); opacity: 0; }
    to { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes toast-out {
    from { transform: translateX(0) scale(1); opacity: 1; }
    to { transform: translateX(100%) scale(0.9); opacity: 0; }
}

/* Password Toggle */
.password-input-wrapper {
    position: relative;
    width: 100%;
}

.password-input-wrapper input {
    padding-right: 48px;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.password-toggle:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

