:root {
    --primary-color: #5b46e5; /* Purple */
    --secondary-color: #10b981; /* Green */
    --bg-color: #f8f9fa;
    --sidebar-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --red-danger: #ef4444;
    --card-bg: #ffffff;
}

body.dark-mode {
    --bg-color: #111827;
    --sidebar-bg: #1f2937;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: #374151;
    --card-bg: #1f2937;
}

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

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

/* Sidebar */
.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 100;
    transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    white-space: nowrap;
    overflow-x: hidden;
}

.sidebar.collapsed {
    width: 64px;
}

/* Hide text labels smoothly */
.sidebar.collapsed .logo-text,
.sidebar.collapsed .sidebar-menu li a .menu-label {
    display: none;
}

/* Center icons when collapsed */
.sidebar.collapsed .sidebar-menu li a {
    padding: 14px 0;
    justify-content: center;
}

.sidebar.collapsed .sidebar-menu li a .icon {
    margin-right: 0;
    font-size: 18px;
    width: auto;
}

/* Tooltip on hover when collapsed */
.sidebar.collapsed .sidebar-menu li {
    position: relative;
}

.sidebar.collapsed .sidebar-menu li a::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 68px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e1e2e;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.sidebar.collapsed .sidebar-menu li a:hover::after {
    opacity: 1;
}

/* Collapsed logo: show only icon centered */
.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .logo-icon {
    margin-right: 0;
}

.sidebar-header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    background: var(--secondary-color);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 10px;
}

.logo-text {
    font-weight: 600;
    font-size: 14px;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
    list-style: none;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
}

.sidebar-menu li a:hover {
    background: #f3f4f6;
    color: var(--primary-color);
}

.sidebar-menu li.active a {
    background: #f5f3ff;
    color: var(--primary-color);
    border-right: 3px solid var(--primary-color);
    font-weight: 500;
}

.sidebar-menu li a .icon {
    width: 20px;
    margin-right: 10px;
    text-align: center;
}

.sidebar-menu li.logout a {
    color: var(--red-danger);
}

/* Main Content */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.top-header {
    height: 60px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.header-left .menu-toggle {
    cursor: pointer;
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-icon {
    color: var(--text-muted);
    cursor: pointer;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.page-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
}

/* Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
}

.stat-title {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 10px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-value .icon {
    font-size: 20px;
}

.stat-subtitle {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 10px;
}

.color-primary { color: var(--primary-color); }
.color-blue { color: #3b82f6; }
.color-red { color: var(--red-danger); }
.color-green { color: var(--secondary-color); }

/* Status tags */
.status-tags {
    display: flex;
    gap: 10px;
}

.status-tag {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    background: #ecfdf5;
    color: var(--secondary-color);
    border: 1px solid #a7f3d0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Forms & Tables */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    overflow-x: auto; /* Allow tables inside card to scroll horizontally on mobile */
}

.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}

input[type="text"], input[type="password"], select, textarea {
    width: 100%;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background: var(--card-bg);
    color: var(--text-main);
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: #4f3cc9;
}

.alert {
    padding: 12px 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #10b981;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #ef4444;
}

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

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

th {
    color: var(--text-muted);
    font-weight: 500;
    background: var(--bg-color);
}

/* Utility */
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }

/* Overlay for Mobile Sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
}
.sidebar-overlay.active {
    display: block;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -250px;
        width: 250px !important;
        z-index: 9999;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    }
    .sidebar.mobile-open {
        left: 0;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 14px;
    }
    .stat-value {
        font-size: 20px;
    }
    .stat-title {
        font-size: 12px;
    }
    
    .header-right {
        gap: 10px;
    }
    
    .user-name, .user-role {
        display: none;
    }
    
    .content-area {
        padding: 12px;
        padding-bottom: 80px;
    }
    
    .page-title {
        font-size: 17px;
        margin-bottom: 12px;
    }
    
    .card {
        padding: 12px;
        border-radius: 6px;
        -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    }
    
    /* ── Tables: horizontal scroll with min-width ── */
    table {
        min-width: 600px; /* Default min-width, prevents crushing */
    }
    
    table th {
        white-space: nowrap;
        font-size: 12px;
        padding: 10px 12px;
    }
    
    table td {
        font-size: 13px;
        padding: 10px 12px;
    }
    
    /* ── Forms: stack vertically ── */
    .form-group[style*="inline-block"] {
        display: block !important;
        max-width: 100% !important;
        margin-right: 0 !important;
    }
    
    /* ── Dashboard header ── */
    .dashboard-header-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }
    
    /* ── Live Chat: responsive panels ── */
    .livechat-container {
        flex-direction: column !important;
        height: auto !important;
        min-height: auto !important;
    }
    .livechat-container .lc-sidebar {
        width: 100% !important;
        border-radius: 10px !important;
        max-height: 200px;
    }
    .livechat-container .lc-conversations {
        width: 100% !important;
        border-radius: 0 !important;
        max-height: 280px;
    }
    .livechat-container .lc-chatbox {
        border-radius: 0 0 10px 10px !important;
        min-height: 350px;
    }
    /* Hide panels when one is "active" on mobile */
    .livechat-container.chat-active .lc-sidebar,
    .livechat-container.chat-active .lc-conversations {
        display: none !important;
    }
    .livechat-container.conv-active .lc-sidebar {
        display: none !important;
    }
    .livechat-container.conv-active .lc-chatbox {
        display: none !important;
    }
    
    /* ── Buttons & actions ── */
    .btn {
        padding: 8px 14px;
        font-size: 13px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .stat-value {
        font-size: 18px;
    }
}
