@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Open+Sans:wght@300;400;500;600;700&display=swap');

:root {
    /* Primary Colors */
    --primary: #6C4CF5;
    --primary-dark: #5B3DF5;
    --primary-light: #7B61FF;
    --primary-gradient: linear-gradient(135deg, #6C4CF5 0%, #7B61FF 100%);
    
    /* Accent Colors */
    --success: #29D697;
    --info: #4DA8FF;
    --warning: #FFB648;
    --danger: #FF6B81;
    
    /* Background Colors */
    --bg-main: #F6F8FC;
    --bg-card: #FFFFFF;
    --bg-section: #F9FAFB;
    
    /* Text Colors */
    --text-main: #1E293B;
    --text-muted: #64748B;
    --text-on-primary: #FFFFFF;
    
    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 48px;
    --space-8: 64px;
    
    /* Radius */
    --radius-input: 14px;
    --radius-card: 20px;
    --radius-container: 28px;
    --radius-pill: 500px;
    
    /* Shadows */
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.04);
    --shadow-medium: 0 15px 40px rgba(108, 76, 245, 0.1);
    --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    
    /* Layout */
    --sidebar-width: 280px;
    --navbar-height: 64px;
    
    /* Transitions */
    --transition-fast: 200ms ease-in-out;
    --transition-normal: 350ms ease-in-out;
}

[data-theme="dark"] {
    --bg-main: #0F172A;
    --bg-card: #1E293B;
    --bg-section: #111827;
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --shadow-soft: 0 10px 30px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 15px 40px rgba(0, 0, 0, 0.4);
    --border-color: #334155;
}

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

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-main);
}

p, span, input, select, textarea, td, th {
    font-family: 'Open Sans', sans-serif;
}

/* Layout Structure */
.app-container {
    display: flex;
    min-height: 100vh;
    padding: var(--space-3);
    gap: var(--space-3);
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-gradient);
    border-radius: var(--radius-container);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: calc(100vh - (var(--space-3) * 2));
    z-index: 1000;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-medium);
    overflow: hidden;
}

.sidebar-header {
    padding: var(--space-6) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    max-height: 32px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    margin-bottom: var(--space-2);
    filter: brightness(0) invert(1); /* Force pure white logo for purple sidebar */
}

.main-content {
    flex: 1;
    margin-left: calc(var(--sidebar-width) + var(--space-3));
    display: flex;
    flex-direction: column;
    height: calc(100vh - (var(--space-3) * 2));
    overflow-y: auto;
    min-width: 0;
    scrollbar-width: thin;
}

.navbar {
    height: var(--navbar-height);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--radius-card);
    display: flex;
    align-items: center;
    padding: 0 var(--space-3);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-bottom: var(--space-3);
    flex-shrink: 0;
}

[data-theme="dark"] .navbar {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.content-area {
    padding: 0;
    width: 100%;
}

/* Components */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-card);
    padding: var(--space-4);
    box-shadow: var(--shadow-soft);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    border: 1px solid transparent;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-medium);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 12px 24px;
    border-radius: var(--radius-pill);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    font-size: 0.875rem;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 76, 245, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(108, 76, 245, 0.4);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
    background: var(--bg-section);
    border-color: var(--primary-light);
}

/* Forms */
.form-control {
    width: 100%;
    padding: 12px 20px;
    border-radius: var(--radius-input);
    border: 1.5px solid rgba(0, 0, 0, 0.05);
    background: var(--bg-section);
    transition: all var(--transition-fast);
    font-size: 0.875rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(108, 76, 245, 0.1);
    background: var(--bg-card);
}

/* Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    background: var(--bg-section);
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    transition: background var(--transition-fast);
}

tr:hover td {
    background: rgba(108, 76, 245, 0.02);
}

/* Removed duplicate sidebar structure */

.sidebar-header {
    padding: var(--space-4) var(--space-3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    max-width: 120px;
    height: auto;
    display: block;
    margin-bottom: var(--space-1);
}

.mini-logo {
    display: none;
    max-width: 32px;
}

.sidebar-header p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.75rem;
    font-weight: 500;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    padding: var(--space-4) var(--space-2);
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

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

.sidebar-nav:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.nav-item {
    margin-bottom: var(--space-1);
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.88rem;
    transition: all var(--transition-fast);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link i:first-child {
    width: 20px;
    height: 20px;
}

.nav-link .chevron {
    margin-left: auto;
    width: 14px;
    height: 14px;
    transition: transform var(--transition-fast);
    opacity: 0.5;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-item.open > .nav-link {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.nav-item.open > .nav-link .chevron {
    transform: rotate(90deg);
    opacity: 1;
}

/* Submenu & Curved Tree-Lines */
.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: all var(--transition-normal);
    position: relative;
    padding-left: 20px;
}

.nav-item.open > .submenu {
    max-height: 1000px;
    margin-top: 4px;
    margin-bottom: 8px;
}

.submenu-item {
    position: relative;
    padding-left: 12px;
    margin-bottom: 2px;
}

.submenu-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: -10px;
    width: 12px;
    height: 28px;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    border-bottom-left-radius: 6px;
}

.submenu-item:first-child::before {
    height: 22px;
    top: -2px;
}

.submenu-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.8rem;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
}

.submenu-link span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.submenu-link i,
.submenu-link svg {
    width: 18px !important;
    height: 18px !important;
    opacity: 0.6;
    stroke-width: 1.5px;
}

.submenu-link:hover,
.submenu-link.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.submenu-link.active i,
.submenu-link:hover i {
    opacity: 1;
}

/* Navbar Components */
.navbar-brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.navbar-brand {
    margin-right: auto;
    margin-left: var(--space-3);
}

.navbar-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.navbar {
    height: 56px !important;
}

.navbar .btn {
    padding: 8px 12px !important;
    height: 36px;
}

.navbar .btn i,
.navbar .btn svg {
    width: 18px !important;
    height: 18px !important;
}

#sidebar-toggle {
    display: none;
    background: transparent;
    color: var(--text-main);
}

/* Theme Toggle Stylized */
.theme-btn {
    background: var(--bg-section) !important;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    border-radius: 20px !important;
    padding: 6px 14px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    font-size: 0.8rem !important;
    font-weight: 600 !important;
    color: var(--text-main) !important;
    transition: all var(--transition-fast) !important;
    cursor: pointer !important;
}

[data-theme="dark"] .theme-btn {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

.theme-btn span {
    display: inline-block !important;
}

[data-theme="dark"] .theme-btn {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

.theme-btn:hover {
    background: var(--primary) !important;
    color: white !important;
    border-color: transparent !important;
    transform: translateY(-1px);
}

.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: block; }

/* Profile Container & Dropdown */
.profile-container {
    position: relative;
}

.avatar {
    width: 28px;
    height: 28px;
    background: var(--primary-gradient);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(108, 76, 245, 0.2);
}

.profile-trigger {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.profile-trigger:hover {
    transform: scale(1.05);
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    width: 260px;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
    border: 1px solid rgba(0,0,0,0.05);
    padding: 16px;
    z-index: 5000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-normal);
}

[data-theme="dark"] .profile-dropdown {
    background: #1e293b;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.profile-dropdown.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.avatar-large {
    width: 48px;
    height: 48px;
    background: var(--primary-gradient);
    border-radius: 12px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-display-name {
    font-weight: 600;
    color: var(--text-main);
    font-size: 0.95rem;
}

.user-display-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-divider {
    height: 1px;
    background: rgba(0,0,0,0.05);
    margin: 12px 0;
}

[data-theme="dark"] .dropdown-divider {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-section);
}

.logout-item {
    color: #ff6b81 !important;
    background: rgba(255, 107, 129, 0.05) !important;
    border: 1px solid rgba(255, 107, 129, 0.1) !important;
    font-weight: 600 !important;
    margin-top: 4px !important;
    justify-content: center !important;
}

.logout-item:hover {
    background: #ff6b81 !important;
    color: white !important;
}

.alert-card {
    border-left: 4px solid var(--info);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    background: var(--bg-card);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-soft);
}

/* Dark Mode Overrides for Specific Components */
[data-theme="dark"] .sidebar-nav a {
    color: rgba(255, 255, 255, 0.7);
}

[data-theme="dark"] .sidebar-nav a:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .form-control {
    background: var(--bg-section);
    border-color: rgba(255, 255, 255, 0.05);
}

/* Utility Classes */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }

.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}

.actions-group {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-muted);
}

.btn-icon:hover {
    background: var(--bg-section);
    color: var(--primary);
}

.btn-danger {
    background: rgba(255, 107, 129, 0.1);
    color: var(--danger);
}

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

.empty-state {
    padding: var(--space-6) !important;
    color: var(--text-muted);
    font-style: italic;
}

/* Theme-aware Logos */
[data-theme="light"] .theme-logo-light { display: none !important; }
[data-theme="light"] .theme-logo-dark { display: block !important; }
[data-theme="dark"] .theme-logo-light { display: block !important; }
[data-theme="dark"] .theme-logo-dark { display: none !important; }

.auth-logo {
    max-height: 50px !important;
    width: auto !important;
    max-width: 180px !important;
    object-fit: contain !important;
    margin: 0 auto var(--space-6) !important;
    display: block;
}

.tenant-login {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
}

.btn-clear-tenant {
    color: var(--danger);
    display: flex;
    align-items: center;
    text-decoration: none;
}

.theme-toggle-fixed {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 9999;
}

/* Modal System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-container {
    background: var(--bg-card);
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius-container);
    box-shadow: var(--shadow-large);
    border: 1px solid var(--border-light);
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}

.modal-overlay.active .modal-container {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: var(--space-6) var(--space-6) var(--space-2);
    text-align: center;
}

.modal-icon-circle {
    width: 64px;
    height: 64px;
    background: rgba(108, 76, 245, 0.1);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-4);
}

.modal-header h3 {
    font-size: 1.25rem;
    color: var(--text-main);
    font-weight: 700;
}

.modal-body {
    padding: var(--space-2) var(--space-6) var(--space-6);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.6;
}

.modal-footer {
    padding: var(--space-4) var(--space-6) var(--space-6);
    display: flex;
    gap: var(--space-3);
}

.modal-footer .btn {
    flex: 1;
    justify-content: center;
}

/* Responsive Sidebar Overrides */
@media (max-width: 1200px) {
    :root {
        --sidebar-width: 68px;
    }
    
    .sidebar-header .logo-text,
    .sidebar-header p,
    .nav-link span,
    .nav-link .chevron {
        display: none !important;
    }
    
    .sidebar,
    .sidebar-nav {
        overflow: visible !important;
    }
    
    .main-logo {
        display: none !important;
    }
    
    .mini-logo {
        display: block !important;
        margin: 0 auto;
    }
    
    .sidebar {
        padding: var(--space-4) 0;
    }
    
    .nav-link {
        justify-content: center;
        padding: 10px 0;
        margin: var(--space-1) var(--space-2);
    }
    
    /* Floating Popover Submenu */
    .submenu {
        position: absolute;
        top: 0;
        left: 100%;
        width: 220px;
        background: #1a1a1a;
        border-radius: 14px;
        box-shadow: 0 15px 50px rgba(0,0,0,0.3);
        border: 1px solid rgba(255,255,255,0.1);
        padding: 8px;
        z-index: 5000;
        max-height: none !important;
        opacity: 0;
        visibility: hidden;
        transform: translateX(10px);
        transition: all var(--transition-normal);
        pointer-events: none;
    }
    
    .nav-item:hover .submenu {
        opacity: 1;
        visibility: visible;
        transform: translateX(5px);
        pointer-events: all;
    }

    /* Smart Vertical Positioning for bottom items (last 5 items) */
    .nav-item:nth-last-child(-n+5) .submenu {
        top: auto;
        bottom: 0;
        transform: translateX(10px);
    }

    .nav-item:nth-last-child(-n+5):hover .submenu {
        transform: translateX(5px);
    }

    .submenu {
        padding: 8px !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
        scrollbar-width: thin;
        scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
    }

    .submenu::-webkit-scrollbar {
        width: 3px;
    }

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

    .submenu-item {
        padding-left: 0 !important;
    }

    .submenu-item::before {
        display: none !important;
    }

    .submenu-link {
        color: rgba(255, 255, 255, 0.6) !important;
        padding: 8px 12px !important;
    }

    .submenu-link:hover,
    .submenu-link.active {
        background: rgba(255, 255, 255, 0.1) !important;
        color: #fff !important;
    }
    
    .nav-item:hover::after {
        opacity: 1;
        visibility: visible;
        top: -25px;
    }

    .main-content {
        margin-left: calc(var(--sidebar-width) + var(--space-2));
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }
    
    .sidebar {
        transform: translateX(calc(-100% - var(--space-4)));
        height: 100vh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 2000;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-header .logo-text,
    .sidebar-header p,
    .nav-link span,
    .nav-link .chevron {
        display: block !important;
    }
    
    .submenu {
        display: block !important;
        position: static;
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0;
        padding-left: var(--space-6);
        width: 100%;
        max-height: 0;
        overflow: hidden;
    }

    .nav-item.open > .submenu {
        max-height: 1000px;
    }

    .main-content {
        margin-left: 0;
    }
    
    #sidebar-toggle {
        display: flex;
    }
}

