/* 
    Modern Side Navigation Bar Styles
    ez-accounts.com UI System
*/

:root {
    /* Deep Slate Theme (Reverted) */
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #ffffff;
    --sidebar-active-bg: rgba(255, 255, 255, 0.08);
    --sidebar-active-accent: #2563eb;
    --sidebar-divider: rgba(255, 255, 255, 0.05);
    --sidebar-label: #475569;
}

.app-shell {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    background-color: #ffffff;
}

.main {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    background-color: #ffffff;
    scroll-behavior: smooth;
    position: relative;
    padding: 0;
}

.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text-hover);
    padding: 30px 16px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-divider);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', 'IBM Plex Sans Thai', 'Outfit', sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Brand Section */
.brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    margin-bottom: 16px;
}

.brand-link {
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}

.brand-link:hover {
    transform: scale(1.02);
}

.brand-logo {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    padding: 0; 
    border: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 8px rgba(37, 99, 235, 0.05);
    /* Animation applied to the entire frame */
    animation: sidebarFloat 6s ease-in-out infinite;
}

.brand-placeholder {
    width: 48px;
    height: 48px;
    border: 1.5px dashed rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--sidebar-text);
    transition: all 0.2s;
    background: transparent;
    gap: 4px;
}

.brand-placeholder::before {
    content: '\F5AE'; /* Phosphor Plus Icon */
    font-family: "Phosphor";
    font-size: 16px;
    font-weight: bold;
}

.brand-placeholder span {
    font-size: 8px;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    display: none; /* Hide text in small size */
}

.brand-link:hover .brand-placeholder {
    border-color: var(--sidebar-active-accent);
    color: var(--sidebar-active-accent);
    background: rgba(255, 255, 255, 0.05);
}

.brand-logo img {
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
    object-fit: cover; /* Absolutely fills the circle edge-to-edge */
    filter: brightness(1.15) contrast(1.05);
}

.brand-credits {
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--sidebar-text);
    opacity: 0.4;
    margin-top: 8px;
    text-align: center;
    user-select: none;
    transition: all 0.2s;
}

.brand-link:hover + .brand-credits {
    opacity: 0.8;
    color: white;
}

@keyframes sidebarFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.brand-name {
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

/* Modern Company Dropdown */
.company-dropdown {
    position: relative;
    margin-bottom: 24px;
    z-index: 1001;
}

.dropdown-trigger {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(8px);
    border-radius: 50px;
    padding: 12px 16px;
    border: 1px solid var(--sidebar-divider);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.dropdown-trigger:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
}

.dropdown-trigger:hover span {
    color: white;
}

.dropdown-trigger i:first-child {
    font-size: 18px;
    color: var(--sidebar-active-accent);
}

.dropdown-trigger span {
    flex: 1;
    font-size: 14.5px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
    letter-spacing: -0.2px;
}

.dropdown-trigger #dropdown-caret {
    font-size: 12px;
    color: var(--sidebar-text);
    transition: transform 0.3s ease;
}

.dropdown-trigger #dropdown-caret.open {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 100%;
    background: #1e293b;
    backdrop-filter: blur(20px);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 4px;
    animation: dropdownPop 0.2s ease-out;
}

.dropdown-menu.open {
    display: flex;
}

@keyframes dropdownPop {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s;
    color: #cbd5e1;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.dropdown-item.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--sidebar-active-accent);
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.item-info .co-name {
    font-size: 13.5px;
    font-weight: 600;
}

.item-info .co-role {
    font-size: 11px;
    opacity: 0.6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dropdown-item i {
    font-size: 16px;
}

/* Navigation Items */
.nav-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 800;
    color: var(--sidebar-label);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin: 24px 0 8px 14px;
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    color: var(--sidebar-text);
    font-size: 14.5px;
    position: relative;
}

/* Notification Badge on Sidebar Icon */
.nav-notif-badge {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 7px;
    height: 7px;
    background: #ef4444;
    border: 1px solid var(--sidebar-bg);
    border-radius: 50%;
    display: none; /* Hidden by default */
    animation: pulseBadge 2s infinite;
    z-index: 10;
    pointer-events: none;
}

@keyframes pulseBadge {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.nav-item i:first-child {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--sidebar-text-hover);
}

.nav-item.active {
    background: var(--sidebar-active-accent);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-item.active i {
    color: white;
}

/* Sub-menu styling (Accordion) */
.nav-sub-group {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.015);
    border-radius: 20px;
    margin: 0 4px;
}

.nav-sub-group.expanded {
    max-height: 500px;
    margin-bottom: 8px;
    padding: 4px 0;
}

.nav-sub-item {
    padding: 10px 16px 10px 48px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    border-radius: 50px;
    margin: 2px 8px;
    position: relative;
}

/* Indentation cue */
.nav-sub-item::before {
    content: '';
    position: absolute;
    left: 24px;
    width: 1px;
    height: 100%;
    background: var(--sidebar-divider);
    top: 0;
}

.nav-sub-item:first-child::before {
    height: 50%;
    top: 50%;
}

.nav-sub-item:last-child::before {
    height: 50%;
}

.nav-sub-item:hover {
    color: var(--sidebar-text-hover);
    background: rgba(255, 255, 255, 0.06);
    transform: translateX(4px);
}

.nav-sub-item.active {
    color: white;
    font-weight: 700;
    background: rgba(37, 99, 235, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Dropdown Arrow */
.has-dropdown .dropdown-arrow {
    margin-left: auto;
    font-size: 14px;
    transition: transform 0.3s ease;
    opacity: 0.4;
}

.has-dropdown.expanded .dropdown-arrow {
    transform: rotate(180deg);
    opacity: 0.9;
    color: white;
}

/* Divider for Visual Separation */
.nav-divider-text {
    height: 1px;
    background: var(--sidebar-divider);
    margin: 24px 12px 12px 12px;
    position: relative;
}


/* User Profile Section */
.user-profile {
    margin-top: auto;
    padding-top: 24px;
    border-top: 1px solid var(--sidebar-divider);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    background: #334155;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid rgba(255, 255, 255, 0.1);
    color: white;
}

.user-details {
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    display: block;
    font-size: 14px;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #f1f5f9;
}

.user-role {
    color: var(--sidebar-text);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Package Badges */
.package-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.package-badge.free {
    background: linear-gradient(135deg, #64748b, #475569);
    color: #f1f5f9;
}

.package-badge.standard {
    background: linear-gradient(135deg, #3b82f6, #1e40af);
    color: #eff6ff;
}

.package-badge.professional {
    background: linear-gradient(135deg, #f59e0b, #b45309);
    color: #fffbeb;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 50px;
    background: rgba(239, 68, 68, 0.08);
    color: #fca5a5;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

/* Custom Scrollbar for Sidebar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Expiry Alert */
.expiry-alert {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15), rgba(185, 28, 28, 0.25));
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 24px;
    display: none;
    animation: sidebarPulse 2s infinite;
}

.expiry-alert i {
    color: #f87171;
    font-size: 18px;
    margin-bottom: 4px;
}

.expiry-alert .alert-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: #fca5a5;
    letter-spacing: 0.5px;
    display: block;
}

.expiry-alert .alert-msg {
    font-size: 12.5px;
    font-weight: 600;
    color: white;
    line-height: 1.4;
}

@keyframes sidebarPulse {
    0% { border-color: rgba(239, 68, 68, 0.4); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
    50% { border-color: rgba(239, 68, 68, 0.8); box-shadow: 0 0 10px 0 rgba(239, 68, 68, 0.3); }
    100% { border-color: rgba(239, 68, 68, 0.4); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--sidebar-divider);
        padding: 16px 20px;
    }

    .nav-group {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 12px;
        gap: 8px;
    }

    .nav-item {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .nav-section-label,
    .nav-divider-text,
    .company-selector,
    .user-profile {
        display: none;
    }

    .nav-sub-group {
        display: none;
    }

    /* On mobile, submenus might need a different approach or just direct links */
}

/* ============================================================
   Floating Chat Widget — Premium Support Widget
   Inspired by Intercom / Crisp
   ============================================================ */

/* FAB (Floating Action Button) */
.chat-widget-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    box-shadow:
        0 4px 20px rgba(37, 99, 235, 0.5),
        0 8px 32px rgba(124, 58, 237, 0.3),
        0 0 0 0 rgba(37, 99, 235, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
    animation: fabEntrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    user-select: none;
}

.chat-widget-fab:hover {
    transform: scale(1.1);
    box-shadow:
        0 8px 30px rgba(37, 99, 235, 0.65),
        0 12px 40px rgba(124, 58, 237, 0.4);
}

.chat-widget-fab:active {
    transform: scale(0.95);
}

/* Pulse ring behind the FAB */
.fab-pulse-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(37, 99, 235, 0.5);
    animation: fabPulse 2.5s ease-out infinite;
    pointer-events: none;
}

@keyframes fabPulse {
    0%   { transform: scale(1); opacity: 0.8; }
    70%  { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(1.4); opacity: 0; }
}

@keyframes fabEntrance {
    from { transform: scale(0) rotate(-180deg); opacity: 0; }
    to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Icon container inside FAB */
.fab-icon-wrap {
    position: relative;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-icon-wrap i {
    position: absolute;
    font-size: 26px;
    color: white;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.fab-icon-headset  { opacity: 1; transform: scale(1) rotate(0deg); }
.fab-icon-close    { opacity: 0; transform: scale(0) rotate(-90deg); font-size: 20px; }

.chat-widget-fab.widget-open .fab-icon-headset { opacity: 0; transform: scale(0) rotate(90deg); }
.chat-widget-fab.widget-open .fab-icon-close   { opacity: 1; transform: scale(1) rotate(0deg); }

/* Pulsing ring stops when open */
.chat-widget-fab.widget-open .fab-pulse-ring {
    animation: none;
    opacity: 0;
}

/* ---- Chat Window ---- */
.chat-widget-window {
    position: fixed;
    bottom: 104px;
    right: 28px;
    z-index: 99998;
    width: 380px;
    height: 560px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(37, 99, 235, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Hidden by default */
    opacity: 0;
    transform: translateY(24px) scale(0.95);
    pointer-events: none;
    transition:
        opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
    transform-origin: bottom right;
}

.chat-widget-window.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Minimized state — collapses to just the header bar */
.chat-widget-window.minimized {
    height: 64px;
    cursor: pointer;
}

.chat-widget-window.minimized .chat-widget-body,
.chat-widget-window.minimized .chat-widget-footer {
    opacity: 0;
    pointer-events: none;
}

/* ---- Header ---- */
.chat-widget-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #4c1d95 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: 20px 20px 0 0;
    transition: border-radius 0.3s ease;
}

.chat-widget-window.minimized .chat-widget-header {
    border-radius: 20px;
    cursor: pointer;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar-wrap {
    position: relative;
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.25);
}

.chat-avatar-wrap i {
    font-size: 20px;
    color: white;
}

.chat-avatar-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #1e3a8a;
    animation: avatarPulse 2s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    50%       { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-header-title {
    font-size: 14.5px;
    font-weight: 700;
    color: white;
    letter-spacing: -0.2px;
}

.chat-header-status {
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-action-btn {
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, transform 0.15s;
}

.chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.1);
}

.chat-action-btn.chat-close-btn:hover {
    background: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

/* ---- Body ---- */
.chat-widget-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    transition: opacity 0.25s ease;
}

/* Loading Spinner */
.chat-widget-loader {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.9);
    z-index: 2;
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.chat-loader-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spinLoader 0.8s linear infinite;
}

@keyframes spinLoader {
    to { transform: rotate(360deg); }
}

/* Iframe */
.chat-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    transition: opacity 0.4s ease;
    background: transparent;
}

/* ---- Footer ---- */
.chat-widget-footer {
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 10.5px;
    color: rgba(255, 255, 255, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    transition: opacity 0.25s ease;
    letter-spacing: 0.2px;
}

.chat-widget-footer i {
    font-size: 12px;
}

/* Mobile responsiveness for chat widget */
@media (max-width: 480px) {
    .chat-widget-window {
        width: calc(100vw - 24px);
        right: 12px;
        bottom: 90px;
    }

    .chat-widget-fab {
        bottom: 16px;
        right: 16px;
    }
}