/* ============================================================
   ChatFlow AI — Main Stylesheet
   Advanced Live Chat System with AI Triage
   ============================================================ */

/* === CSS VARIABLES === */
:root {
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    --secondary: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --bg-input: #0f172a;
    --bg-hover: #334155;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;

    --sidebar-width: 280px;
    --header-height: 60px;
    --chat-input-height: 80px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 20px rgba(79,70,229,0.3);

    --transition: all 0.2s ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* === RESET & BASE === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary-light);
    text-decoration: none;
    transition: var(--transition);
}
a:hover { color: var(--primary); }

img { max-width: 100%; display: block; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   AUTH PAGES (login.php, register.php)
   ============================================================ */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
    position: relative;
    overflow: hidden;
}

.auth-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(79,70,229,0.15) 0%, transparent 70%);
    top: -200px;
    right: -200px;
    border-radius: 50%;
}

.auth-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(14,165,233,0.1) 0%, transparent 70%);
    bottom: -100px;
    left: -100px;
    border-radius: 50%;
}

.auth-container {
    width: 100%;
    max-width: 440px;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 28px;
    color: white;
    box-shadow: var(--shadow-glow);
}

.auth-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.auth-form label i {
    margin-right: 6px;
    color: var(--primary-light);
}

.auth-form input[type="email"],
.auth-form input[type="password"],
.auth-form input[type="text"],
.auth-form input[type="tel"],
.auth-form input[type="number"],
.auth-form input[type="date"],
.auth-form textarea,
.auth-form select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font);
    transition: var(--transition);
    outline: none;
}

.auth-form input:focus,
.auth-form textarea:focus,
.auth-form select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.2);
}

.password-input {
    position: relative;
}

.password-input input {
    padding-right: 44px;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
}

.toggle-password:hover { color: var(--text-primary); }

.auth-footer {
    text-align: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-demo {
    margin-top: 20px;
    text-align: center;
}

.auth-demo p {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 10px;
}

.demo-accounts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.demo-account {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.demo-account:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    color: #fca5a5;
}

.alert-success {
    background: rgba(16,185,129,0.1);
    border: 1px solid rgba(16,185,129,0.3);
    color: #6ee7b7;
}

.alert-info {
    background: rgba(6,182,212,0.1);
    border: 1px solid rgba(6,182,212,0.3);
    color: #67e8f9;
}

.alert i { font-size: 1.1rem; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    box-shadow: 0 4px 12px rgba(79,70,229,0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: #1a1a2e; }
.btn-info { background: var(--info); color: white; }
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; }

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   FORM CONTROLS
   ============================================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.2);
}

.form-control-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

select.form-control {
    appearance: auto;
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 40px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group .form-control {
    flex: 1;
}

/* ============================================================
   LAYOUT — SIDEBAR + MAIN CONTENT
   Used by: dashboard.php, customer-chat.php, agent-chat.php,
            chat-history.php, settings.php, admin-users.php
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    overflow: hidden;
    transition: var(--transition);
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
}

.sidebar-logo i {
    font-size: 1.4rem;
    color: var(--primary-light);
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
}

.sidebar-close:hover { color: var(--text-primary); }

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
    text-decoration: none;
}

.sidebar-nav .nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-nav .nav-item.active {
    background: rgba(79,70,229,0.1);
    color: var(--primary-light);
    border-left-color: var(--primary);
}

.sidebar-nav .nav-item i {
    width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.sidebar-footer .nav-logout {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.sidebar-footer .nav-logout:hover {
    color: var(--danger);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    margin-left: var(--sidebar-width);
    overflow: hidden;
    min-width: 0;
}

/* === TOPBAR === */
.topbar {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
}

.sidebar-toggle:hover { color: var(--text-primary); }

.page-title {
    font-size: 1.1rem;
    font-weight: 700;
    flex: 1;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* === CONTENT AREA === */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ============================================================
   DASHBOARD PAGE
   ============================================================ */

/* === STAT CARDS === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
    display: block;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

/* Stat card color variants */
.stat-card-blue .stat-icon { background: rgba(79,70,229,0.15); color: var(--primary-light); }
.stat-card-green .stat-icon { background: rgba(16,185,129,0.15); color: var(--success); }
.stat-card-orange .stat-icon { background: rgba(249,115,22,0.15); color: #f97316; }
.stat-card-purple .stat-icon { background: rgba(139,92,246,0.15); color: #8b5cf6; }
.stat-card-yellow .stat-icon { background: rgba(234,179,8,0.15); color: #eab308; }
.stat-card-teal .stat-icon { background: rgba(6,182,212,0.15); color: var(--info); }
.stat-card-indigo .stat-icon { background: rgba(99,102,241,0.15); color: #6366f1; }

/* === CHARTS === */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.chart-actions {
    display: flex;
    gap: 8px;
}

.chart-body {
    flex: 1;
    min-height: 200px;
}

.chart-large {
    grid-column: span 1;
}

.chart-small {
    grid-column: span 1;
}

/* === DEPARTMENT CARDS === */
.dept-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.dept-cards-grid .dept-performance-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.dept-cards-grid .dept-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    font-size: 1rem;
}

.dept-cards-grid h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.dept-cards-grid .dept-stats {
    display: flex;
    justify-content: space-around;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.dept-cards-grid .dept-stats span {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ============================================================
   TABLES
   ============================================================ */
.table-section {
    margin-bottom: 24px;
}

.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.table-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.table-responsive {
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tr:hover td {
    background: var(--bg-hover);
}

.table-sm th,
.table-sm td {
    padding: 8px 12px;
    font-size: 0.8rem;
}

/* === USER CELL === */
.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.user-email {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === AVATAR === */
.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    color: white;
    flex-shrink: 0;
}

/* === BADGES === */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-danger {
    background: rgba(239,68,68,0.15);
    color: #f87171;
}

/* === ROLE BADGE === */
.role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.role-badge.role-admin { background: rgba(239,68,68,0.15); color: #f87171; }
.role-badge.role-manager { background: rgba(245,158,11,0.15); color: #fbbf24; }
.role-badge.role-agent { background: rgba(16,185,129,0.15); color: #34d399; }
.role-badge.role-customer { background: rgba(6,182,212,0.15); color: #22d3ee; }

/* === STATUS DOT === */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--text-muted); }

/* === DASHBOARD PAGE BODY === */
.dashboard-page {
    overflow: hidden;
}

/* === USER INFO (sidebar footer) === */
.user-name-sm {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.user-role-sm {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === ONLINE STATUS === */
.online-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--success);
}

.online-status i {
    font-size: 0.6rem;
}

/* ============================================================
   CHAT PAGE LAYOUT
   Used by: customer-chat.php, agent-chat.php
   ============================================================ */
.chat-page {
    overflow: hidden;
}

.customer-chat-page .main-content {
    /* same as default */
}

.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-height));
}

/* === SESSIONS PANEL === */
.sessions-panel {
    width: 300px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sessions-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.sessions-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

/* === FILTER TABS === */
.filter-tabs {
    display: flex;
    gap: 4px;
}

.filter-tab {
    padding: 4px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
}

.filter-tab:hover, .filter-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* === CHAT PANEL === */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* === CHAT HEADER === */
.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chat-header-info strong {
    color: var(--text-primary);
    font-size: 0.95rem;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* === MESSAGES CONTAINER === */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-primary);
}

/* === MESSAGE FORM === */
.message-form {
    padding: 0;
}

.message-form .input-group {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 4px 4px 4px 12px;
}

.message-form .input-group:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.message-form .form-control {
    border: none;
    background: none;
    padding: 8px;
}

.message-form .form-control:focus {
    box-shadow: none;
}

/* === CHAT INPUT AREA === */
.chat-input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

/* ============================================================
   START CHAT (Customer)
   ============================================================ */
.start-chat-hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.start-chat-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin-bottom: 20px;
    box-shadow: var(--shadow-glow);
}

.start-chat-hero h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.start-chat-hero p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 400px;
}

.start-chat-form {
    width: 100%;
    max-width: 500px;
}

.start-chat-form textarea {
    min-height: 100px;
    text-align: center;
}

.quick-topics {
    margin-top: 24px;
}

.quick-topics p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    margin: 4px;
}

.chip:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-overlay:not(.active) {
    display: none;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
}

.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 0.85rem;
}

.empty-state-large {
    padding: 80px 40px;
}

.empty-state-large i {
    font-size: 4rem;
}

/* ============================================================
   DATE FILTER
   ============================================================ */
.date-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-filter input[type="date"] {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
    font-family: var(--font);
}

.date-filter input[type="date"]:focus {
    border-color: var(--primary);
}

.date-filter span {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ============================================================
   FILTERS BAR (Chat History)
   ============================================================ */
.filters-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filters-bar .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 150px;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
}

.pagination .page-info {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ============================================================
   SETTINGS PAGE
   ============================================================ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 20px;
}

.settings-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
}

.settings-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.settings-card .form-group {
    margin-bottom: 14px;
}

.settings-card .form-group label {
    font-size: 0.8rem;
}

.settings-card .form-group input[type="checkbox"] {
    margin-right: 8px;
}

/* === DEPARTMENT ITEMS === */
.dept-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.dept-item:last-child {
    border-bottom: none;
}

.dept-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dept-details {
    flex: 1;
    min-width: 0;
}

.dept-details strong {
    display: block;
    font-size: 0.9rem;
}

.dept-details span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ============================================================
   NOTIFICATION TOAST
   ============================================================ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    min-width: 280px;
    font-size: 0.9rem;
}

.toast-success, .toast.success { border-left: 4px solid var(--success); }
.toast-error, .toast.error { border-left: 4px solid var(--danger); }
.toast-info, .toast.info { border-left: 4px solid var(--info); }
.toast-warning, .toast.warning { border-left: 4px solid var(--warning); }

.toast-hiding {
    opacity: 0;
    transform: translateX(100px);
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease; }
.slide-up { animation: slideUp 0.3s ease; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .charts-row {
        grid-template-columns: 1fr;
    }
    .chart-large, .chart-small {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .sidebar {
        left: -100%;
        position: fixed;
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        margin-left: 0;
    }

    .sessions-panel {
        width: 260px;
        min-width: 260px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        flex-direction: column;
    }

    .filters-bar .form-group {
        width: 100%;
    }

    .topbar-actions .date-filter {
        display: none;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .chat-layout {
        flex-direction: column;
    }

    .sessions-panel {
        width: 100%;
        min-width: 0;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

/* ============================================================
   CHAT SESSION ITEMS (Dynamic JS)
   ============================================================ */
.session-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.selected { background: rgba(79,70,229,0.15); border-left: 3px solid var(--primary); }
.session-item.session-active { border-left: 3px solid var(--success); }
.session-item.session-closed { opacity: 0.7; }
.session-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.session-code { font-weight: 600; font-size: 0.85rem; color: var(--primary-light); }
.session-customer { font-size: 0.85rem; font-weight: 500; margin-bottom: 2px; }
.session-subject { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { display: flex; gap: 12px; font-size: 0.75rem; color: var(--text-muted); }
.session-preview { font-size: 0.75rem; color: var(--text-muted); font-style: italic; margin-top: 4px; }
.unread-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* === CHAT MESSAGES (Dynamic JS) === */
.message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: fadeIn 0.2s ease;
}
.message-me { flex-direction: row-reverse; }
.message-other { flex-direction: row; }
.message-ai .message-content { background: rgba(14,165,233,0.15); border: 1px solid rgba(14,165,233,0.3); }
.message-system { text-align: center; margin: 12px 0; }
.message-system span {
    display: inline-block;
    padding: 4px 14px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.message-date-separator { text-align: center; margin: 16px 0; }
.message-date-separator span {
    display: inline-block;
    padding: 4px 14px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.message-avatar { flex-shrink: 0; }
.message-avatar img { width: 32px; height: 32px; border-radius: 50%; }
.message-body { max-width: 70%; }
.message-sender { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
.message-content {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}
.message-me .message-content { background: var(--primary); color: #fff; border-radius: var(--radius-md) var(--radius-md) 0 var(--radius-md); }
.message-other .message-content { border-radius: var(--radius-md) var(--radius-md) var(--radius-md) 0; }
.message-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; text-align: right; }
.message-me .message-time { text-align: right; }
.message-image img { max-width: 240px; max-height: 200px; border-radius: var(--radius-sm); cursor: pointer; }
.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}
.message-file .file-info { flex: 1; min-width: 0; }
.message-file .file-name { display: block; font-size: 0.85rem; font-weight: 500; }
.message-file .file-size { font-size: 0.75rem; color: var(--text-muted); }
.ai-label {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--secondary);
    background: rgba(14,165,233,0.15);
    padding: 1px 6px;
    border-radius: 4px;
    margin-right: 4px;
}

/* === FILE PREVIEW === */
.file-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.file-preview img { max-height: 60px; border-radius: 4px; }

/* === REVIEW FORM (Dynamic JS) === */
.review-form {
    text-align: center;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin: 16px 0;
}
.review-form h3 { margin-bottom: 12px; font-size: 1rem; }
.star-rating { display: flex; justify-content: center; gap: 6px; margin-bottom: 12px; }
.star-rating .fa-star { font-size: 1.5rem; cursor: pointer; color: var(--text-muted); transition: color 0.2s; }
.star-rating .fa-star.active { color: #fbbf24; }
.review-form textarea { width: 100%; max-width: 400px; margin: 0 auto 12px; display: block; }
.review-submitted { text-align: center; padding: 24px; }
.review-submitted .fa-check-circle { font-size: 2.5rem; color: var(--success); margin-bottom: 8px; }

/* === CATEGORY BADGES === */
.category-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.cat-insurance { background: rgba(59,130,246,0.15); color: #3b82f6; }
.cat-finance { background: rgba(16,185,129,0.15); color: #10b981; }
.cat-membership { background: rgba(245,158,11,0.15); color: #f59e0b; }
.cat-technical { background: rgba(239,68,68,0.15); color: #ef4444; }
.cat-general { background: rgba(107,114,128,0.15); color: #9ca3af; }

/* === STATUS BADGES === */
.status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.status-active { background: rgba(16,185,129,0.15); color: #10b981; }
.status-waiting { background: rgba(245,158,11,0.15); color: #f59e0b; }
.status-closed { background: rgba(107,114,128,0.15); color: #9ca3af; }
.status-transferred { background: rgba(14,165,233,0.15); color: #0ea5e9; }

/* === CONFIDENCE BAR === */
.confidence-bar {
    position: relative;
    width: 100px;
    height: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger), var(--warning), var(--success));
    border-radius: 8px;
    transition: width 0.3s;
}
.confidence-bar span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 2px rgba(0,0,0,0.5);
}

/* === ROLE BADGES === */
.role-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}
.role-admin { background: rgba(239,68,68,0.15); color: #ef4444; }
.role-manager { background: rgba(245,158,11,0.15); color: #f59e0b; }
.role-agent { background: rgba(59,130,246,0.15); color: #3b82f6; }
.role-customer { background: rgba(16,185,129,0.15); color: #10b981; }
.role-ai { background: rgba(14,165,233,0.15); color: #0ea5e9; }
.badge-system { background: rgba(107,114,128,0.15); color: #9ca3af; }
.badge-custom { background: rgba(79,70,229,0.15); color: #6366f1; }

/* === CHARTS GRID === */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    .sidebar, .sidebar-toggle, .chat-header-actions, .chat-input-area {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .content-area, .messages-container {
        overflow: visible !important;
    }
}
