/* ==========================================================================
   FLIGHTFAREHUB CRM - MASTER STYLESHEET (VANILLA CSS)
   ========================================================================== */

/* --- 1. Design System (Variables) --- */
:root {
    /* Brand Colors */
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-secondary: #ffffff;
    --color-secondary-hover: #f8fafc;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-success: #10b981;
    
    /* Typography & Backgrounds */
    --text-main: #1e293b;
    --text-muted: #64748b;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --border-color: #e2e8f0;
    
    /* Spacing & Borders */
    --radius-md: 0.375rem;
    --radius-lg: 0.75rem;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

/* --- 2. Base Reset & Typography --- */
* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    color: var(--text-main);
}

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

/* --- 3. The 3-Panel Layout --- */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden; /* Prevents the whole browser window from scrolling */
}

/* Left Navigation Sidebar */
.sidebar-left {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    /* Merged transition: handles both desktop collapse and mobile slide */
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Main Content Area */
.main-content {
    flex: 1;
    background: var(--bg-body);
    padding: 2rem;
    overflow-y: auto;
    /* Smooth reflow when sidebar collapses */
    transition: padding 0.3s ease;
}

/* Right Edit Sidebar (Sliding Panel) */
.sidebar-right {
    width: 1100px; /* INCREASED from 600px to hold lots of data/tables */
    max-width: 100vw; /* Keeps it perfectly responsive on small laptops/phones */
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    z-index: 50; 
    transform: translateX(100%); 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 15px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
}

.sidebar-right.open {
    transform: translateX(0);
}

/* ==========================================================================
   SIDEBAR TABS
   ========================================================================== */

.sidebar-tabs-header {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    overflow-x: auto; /* Allows scrolling on small phones */
    scrollbar-width: none; /* Hides scrollbar on Firefox */
}
.sidebar-tabs-header::-webkit-scrollbar { display: none; /* Hides scrollbar on Chrome */ }

.sidebar-tab-btn {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 0.9rem;
}

.sidebar-tab-btn:hover {
    color: var(--text-main);
}

.sidebar-tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.sidebar-tab-content {
    display: none; 
    padding: 1rem 0.5rem; 
    animation: fadeIn 0.3s ease;
}

.sidebar-tab-content.active {
    display: block; 
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- 4. UI Components (The "Legos") --- */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary { 
    background: var(--color-primary); 
    color: white; 
}
.btn-primary:hover { 
    background: var(--color-primary-hover); 
}

.btn-secondary { 
    background: var(--color-secondary); 
    color: var(--text-main); 
    border-color: var(--border-color); 
}
.btn-secondary svg {
    width: 1rem;
    height: 1rem;
    stroke-width: 2.5;
    display: block;
}
.btn-secondary:hover { 
    background: var(--color-secondary-hover); 
}

.btn-danger { 
    background: var(--color-danger); 
    color: white; 
}
.btn-danger:hover { 
    background: var(--color-danger-hover); 
}

/* Cards */
.card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.card h1, .card h2 {
    margin-bottom: 0.5rem;
}

.card p {
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-input {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s;
    background: var(--bg-card);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-input.input-error {
    border-color: var(--color-danger);
}

.error-text {
    color: var(--color-danger);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Layout Utilities */
.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* --- 5. Interactive Elements --- */

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 60;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal-card {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    background: #1e293b;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 1rem;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.toast.show {
    transform: translateX(0);
}

.toast.success { 
    border-left: 4px solid var(--color-success); 
}

.toast.error { 
    border-left: 4px solid var(--color-danger); 
}

/* ==========================================================================
   SIDEBAR & RESPONSIVE ENHANCEMENTS
   ========================================================================== */

/* --- Sidebar Header --- */
.sidebar-header {
    padding: 1rem 1.25rem;
    font-weight: bold;
    font-size: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0; /* Never shrink when sidebar animates */
}

.sidebar-header svg {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
}

.sidebar-logo-text {
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s ease, width 0.2s ease;
}

/* --- Sidebar Toggle Button --- */
.sidebar-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-md);
    transition: background 0.2s, color 0.2s, transform 0.3s ease;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-body);
    color: var(--color-primary);
}

/* --- Sidebar Menu Styles --- */
.sidebar-nav {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-bottom {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
    flex-shrink: 0;
}

/* Menu Links */
.nav-link {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.625rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, padding 0.3s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
    white-space: nowrap;
}

.nav-link:hover, .nav-link.active {
    background: var(--bg-body);
    color: var(--color-primary);
}

.nav-link.text-danger:hover {
    color: var(--color-danger);
    background: #fef2f2;
}

/* Nav icon — always visible */
.nav-icon {
    flex-shrink: 0;
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Nav label — hidden when collapsed */
.nav-label {
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.2s ease;
    flex: 1;
}

.nav-icon svg {
    width: 1.1rem;
    height: 1.1rem;
    stroke-width: 2;
}

.nav-sub-icon svg {
    width: 1.1rem;
    height: 1.1rem;
    stroke-width: 2;
}

/* Sub-Menu Styles */
.sub-menu {
    display: none;
    flex-direction: column;
    padding-left: 1rem;
    margin-top: 0.25rem;
    gap: 0.25rem;
    overflow: hidden;
}

.sub-menu.open {
    display: flex;
}

.sub-link {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    transition: background 0.2s;
    white-space: nowrap;
}

.sub-link:hover {
    background: var(--bg-body);
    color: var(--color-primary);
}

/* Arrow Animation */
.chevron {
    font-size: 0.6rem;
    transition: transform 0.2s ease;
    margin-left: auto;
    flex-shrink: 0;
}

.nav-group-toggle.open .chevron {
    transform: rotate(180deg);
}

/* --- Mobile Specific Elements --- */
.mobile-header {
    display: none;
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
    z-index: 30;
}
.mobile-header svg {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
}

.mobile-menu-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-main);
}

.mobile-menu-btn svg {
    width: 1.4rem;
    height: 1.4rem;
    stroke-width: 2;
    display: block; /* removes inline gap below svg */
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 45;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ==========================================================================
   COLLAPSIBLE SIDEBAR — DESKTOP ONLY
   ========================================================================== */

.sidebar-left.collapsed {
    width: 64px;
}

/* Hide text elements when collapsed */
.sidebar-left.collapsed .sidebar-logo-text,
.sidebar-left.collapsed .nav-label {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* Hide chevron — no point showing it with no label */
.sidebar-left.collapsed .chevron {
    display: none;
}

/* Center icons in nav links */
.sidebar-left.collapsed .nav-link {
    justify-content: center;
    padding: 0.65rem;
    gap: 0;
}

/* Center the toggle button inside the header */
.sidebar-left.collapsed .sidebar-header {
    justify-content: center;
    padding: 1rem 0.75rem;
}

/* Never show sub-menus when collapsed */
.sidebar-left.collapsed .sub-menu {
    display: none !important;
}

/* Tooltip on collapsed icons so users know what they are */
.sidebar-left.collapsed .nav-link[data-tooltip] {
    position: relative;
}

.sidebar-left.collapsed .nav-link[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 0.75rem);
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.35rem 0.65rem;
    border-radius: var(--radius-md);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
    box-shadow: var(--shadow-lg);
}

.sidebar-left.collapsed .nav-link[data-tooltip]:hover::after {
    opacity: 1;
}

/* ==========================================================================
   GLOBAL LOADER OVERLAY
   ========================================================================== */

.global-loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7); /* Semi-transparent white */
    backdrop-filter: blur(2px); /* Creates a nice glass effect */
    z-index: 9999; /* Stays above everything, including modals */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    /* Hidden by default with smooth transitions */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Add this class via JS to show the loader */
.global-loader-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Pure CSS Spinning Circle */
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--color-primary); /* Uses your brand color */
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    margin-top: 1rem;
    font-weight: 500;
    color: var(--text-main);
    font-size: 0.9rem;
}

/* ==========================================================================
   PASSWORD TOGGLE VISIBILITY
   ========================================================================== */

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-wrapper .form-input {
    width: 100%;
    padding-right: 2.5rem; /* Make room for the eye icon */
}

.password-toggle {
    position: absolute;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: color 0.2s ease;
}

.password-toggle:hover {
    color: var(--color-primary);
}

.password-toggle svg {
    width: 18px;
    height: 18px;
}

/* --- Responsiveness (Screens under 768px) --- */
@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    
    .mobile-header { display: flex; }
    
    .main-content {
        padding: 1rem;
        height: calc(100vh - 65px);
    }
    
    /* Make left sidebar slide in from left */
    .sidebar-left {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
        width: 280px !important; /* Override collapsed width on mobile */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .sidebar-left.open { transform: translateX(0); }
    
    /* Always show full labels on mobile regardless of collapsed state */
    .sidebar-left .sidebar-logo-text,
    .sidebar-left .nav-label,
    .sidebar-left .chevron {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: auto !important;
        display: inline-flex !important;
    }
    .sidebar-left .nav-link {
        justify-content: flex-start !important;
        padding: 0.6rem 1rem !important;
        gap: 0.625rem !important;
    }
    .sidebar-left .sidebar-header {
        justify-content: space-between !important;
    }
    .sidebar-left.collapsed .sub-menu.open {
        display: flex !important;
    }

    /* Hide the desktop collapse toggle on mobile */
    .sidebar-toggle-btn {
        display: none;
    }

    /* Make right sidebar take full width on phones */
    .sidebar-right { width: 100%; }
}

/* ==========================================================================
   FLATPICKR CUSTOM CRM THEME
   ========================================================================== */
.flatpickr-calendar {
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color, #e2e8f0);
    font-family: inherit;
    font-size: 0.85rem;
}
.flatpickr-calendar .flatpickr-months {
    background: #f8fafc;
    border-top-left-radius: var(--radius-md, 8px);
    border-top-right-radius: var(--radius-md, 8px);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}
.flatpickr-calendar .flatpickr-current-month {
    font-weight: 600;
    color: var(--text-main, #1e293b);
}
.flatpickr-day.selected, 
.flatpickr-day.startRange, 
.flatpickr-day.endRange, 
.flatpickr-day.selected:focus, 
.flatpickr-day.selected:hover {
    background: var(--color-primary, #4f46e5) !important;
    border-color: var(--color-primary, #4f46e5) !important;
}
.flatpickr-day.today {
    border-color: var(--color-primary, #4f46e5);
}
.flatpickr-day.today:hover {
    background: #e0e7ff;
}
.flatpickr-day:hover {
    background: #f1f5f9;
}