:root {
    /* Color Palette - Deep Dark Mode */
    --bg-main: #0a0a0c;
    --bg-sidebar: #111114;
    --bg-card: rgba(255, 255, 255, 0.03);
    --border-glass: rgba(255, 255, 255, 0.08);

    --text-primary: #ffffff;
    --text-secondary: #a0a0ab;
    --text-muted: #71717a;

    --accent-blue: #3b82f6;
    --accent-blue-glow: rgba(59, 130, 246, 0.3);
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-gold: #f59e0b;

    --sidebar-width: 260px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Responsive */
/* Responsive Layout */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    aside {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 10002;
        width: 280px !important;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
    }

    aside.mobile-open {
        left: 0;
    }

    main {
        padding: 1rem !important;
    }

    #mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    header {
        margin-bottom: 1rem;
    }

    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        z-index: 10001;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* --- FullCalendar Overrides --- */

#calendar-root {
    padding: 0;
    color: var(--text-primary);
}

.fc {
    font-family: 'Inter', sans-serif;
}

.fc-theme-standard td,
.fc-theme-standard th {
    border: 1px solid rgba(255, 255, 255, 0.05) !important;
}

.fc-theme-standard .fc-scrollgrid {
    border: none !important;
    border-radius: 12px;
}

.fc .fc-toolbar-title {
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 700;
}

.fc-col-header-cell-cushion {
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 10px !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.fc .fc-button-primary {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid var(--border-glass) !important;
    color: var(--text-secondary) !important;
    font-size: 0.8rem !important;
    font-weight: 500 !important;
    text-transform: capitalize !important;
    padding: 6px 16px !important;
    transition: var(--transition-smooth) !important;
}

.fc .fc-button-primary:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    color: white !important;
}

.fc .fc-button-active {
    background: var(--accent-blue) !important;
    border-color: transparent !important;
    color: white !important;
}

.fc .fc-button-primary:focus {
    box-shadow: none !important;
}

/* --- Layout --- */

aside {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: var(--transition-smooth);
}

main {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* --- Components --- */

.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    padding: 1.5rem;
    transition: var(--transition-smooth);
}

.glass-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 4px 14px 0 var(--accent-blue-glow);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

/* --- Sidebar Menu --- */

.menu-item {
    padding: 0.8rem 1rem;
    border-radius: 10px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    margin-bottom: 0.5rem;
    text-decoration: none;
}

.menu-item:hover,
.menu-item.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.menu-item.active i {
    color: var(--accent-blue);
}

/* --- Grid System --- */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* --- Auth Overlay --- */

#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

body:not(.auth-required) #login-overlay {
    display: none;
}

body.auth-required aside,
body.auth-required main {
    display: none;
}

/* --- Modal Styles --- */

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: var(--transition-smooth);
}

.modal-hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#event-modal {
    width: 95%;
    max-width: 500px;
    padding: 1.5rem;
    transform: translateY(0);
    transition: var(--transition-smooth);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-hide #event-modal {
    transform: translateY(20px);
}

/* --- Refined Calendar Events --- */

.fc-v-event {
    background-color: var(--accent-blue) !important;
    border: none !important;
    border-left: 4px solid rgba(255, 255, 255, 0.3) !important;
    padding: 2px 4px !important;
    border-radius: 6px !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
}

.fc-event-main {
    font-size: 0.85rem !important;
    font-weight: 500 !important;
}

.fc-event-time {
    font-weight: 700 !important;
    margin-right: 3px !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

.fc-day-today {
    background: rgba(59, 130, 246, 0.05) !important;
}

.fc-timegrid-slot-label-cushion {
    color: var(--text-secondary) !important;
    font-size: 0.8rem !important;
    font-weight: 600 !important;
}

.fc-timegrid-axis-cushion {
    color: var(--text-muted) !important;
}

/* --- CRM Enhancements --- */

.search-container {
    grid-column: 1 / -1;
    margin-bottom: 2rem;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-blue);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
}

.search-container i {
    position: absolute;
    left: 1.2rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 500px;
    overflow-y: auto;
    padding: 1rem;
}

/* Scrollbar for chat history */
.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.chat-bubble {
    max-width: 85%;
    padding: 1rem;
    border-radius: 15px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
}

.bubble-user {
    align-self: flex-end;
    background: var(--accent-blue);
    color: white;
    border-bottom-right-radius: 2px;
}

.bubble-ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.bubble-time {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 0.5rem;
    display: block;
    text-align: right;
}

.lead-status {
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-advisory {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent-green);
}

.status-parent {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
}

/* --- Manual Chat Input --- */
.manual-chat-container {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-glass);
    display: flex;
    gap: 10px;
}

.manual-chat-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    padding: 0.8rem;
    color: white;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.3s;
}

.manual-chat-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.send-manual-btn {
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 8px;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
}

.send-manual-btn:hover {
    transform: scale(1.05);
    background: #2563eb;
}

.send-manual-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Filter Buttons --- */

.filter-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-glass);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition-smooth);
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 10px var(--accent-blue-glow);
}

/* --- Animations --- */

/* --- WhatsApp Style CRM Layout --- */

.crm-layout {
    display: flex;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    overflow: hidden;
}

.crm-sidebar {
    width: 350px;
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
}

.dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-glass);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dropdown-list {
    max-height: 400px;
    overflow-y: auto;
}

.dropdown-footer {
    padding: 0.8rem;
    border-top: 1px solid var(--border-glass);
    text-align: center;
    background: rgba(0, 0, 0, 0.1);
}

.text-link {
    background: none;
    border: none;
    color: var(--accent-blue);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.text-link:hover {
    color: white;
    text-decoration: underline;
}

.dropdown-item {
    padding: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.crm-search-box {
    padding: 1rem;
    border-bottom: 1px solid var(--border-glass);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.contact-item.active {
    background: rgba(59, 130, 246, 0.1);
    border-left: 4px solid var(--accent-blue);
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    min-width: 65px;
}

.unread-badge {
    background: #25d366;
    /* WhatsApp Green */
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    border-radius: 50%;
    /* Perfect circle */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    animation: badgePulse 0.3s ease-out;
    border: 2px solid var(--bg-sidebar);
    /* Outline for contrast */
}

.intervention-badge {
    background: var(--accent-red);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    animation: badgePulse 0.3s ease-out;
    border: 2px solid var(--bg-sidebar);
}


@keyframes badgePulse {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Hide unread badge when empty */
.unread-badge:empty {
    display: none;
}

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    /* Premium CSS Pattern instead of external image */
    background-color: #0b0e11;
    background-image: radial-gradient(rgba(59, 130, 246, 0.05) 1px, transparent 1px);
    background-size: 30px 30px;
    position: relative;
}

.chat-header {
    padding: 1rem 1.5rem;
    background: rgba(18, 22, 28, 0.8);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.chat-messages {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    /* Increased gap for better airiness */
}

/* Glassmorphism for bubbles */
.chat-bubble {
    max-width: 80%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.bubble-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    border-bottom-right-radius: 4px;
}

.bubble-ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
    border-bottom-left-radius: 4px;
}

.bubble-time {
    display: block;
    font-size: 0.7rem;
    margin-top: 6px;
    opacity: 0.7;
    text-align: right;
}

.chat-input-area {
    padding: 1.2rem 2rem;
    background: rgba(18, 22, 28, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-glass);
}

/* Mobile Overrides for CRM */
@media (max-width: 768px) {
    .crm-sidebar {
        width: 100%;
        position: absolute;
        z-index: 100;
        height: 100%;
    }

    .crm-sidebar.hidden {
        display: none;
    }

    .chat-window {
        width: 100%;
    }

    .chat-window.hidden {
        display: none;
    }

    .back-btn {
        display: block !important;
        margin-right: 10px;
        background: none;
        border: none;
        color: white;
        font-size: 1.2rem;
    }
}

.back-btn {
    display: none;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}