/* ============================================
   CSS Variables & Themes
   ============================================ */
:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f8f9fa;
    --text-primary: #1a1d23;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --border-color: #e1e5eb;
    --sidebar-bg: #0f1729;
    --sidebar-text: #a0aec0;
    --sidebar-active: #3b82f6;
    --sidebar-hover: rgba(59,130,246,0.1);
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-teal: #14b8a6;
    --accent-pink: #ec4899;
    --card-bg: #ffffff;
    --input-bg: #f8f9fa;
    --header-bg: rgba(255,255,255,0.85);
    --modal-overlay: rgba(0,0,0,0.5);
    --table-hover: #f1f5f9;
    --chart-grid: #e2e8f0;
    --toggle-bg: #cbd5e1;
    --badge-bg: #fee2e2;
    --badge-text: #dc2626;
}

[data-theme="dark"] {
    --bg-primary: #0f1729;
    --bg-secondary: #1a2332;
    --bg-tertiary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #2d3748;
    --sidebar-bg: #0a0f1e;
    --sidebar-text: #94a3b8;
    --sidebar-active: #3b82f6;
    --sidebar-hover: rgba(59,130,246,0.15);
    --accent-blue: #3b82f6;
    --accent-blue-hover: #60a5fa;
    --accent-green: #10b981;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-teal: #14b8a6;
    --accent-pink: #ec4899;
    --card-bg: #1a2332;
    --input-bg: #0f1729;
    --header-bg: rgba(15,23,41,0.9);
    --modal-overlay: rgba(0,0,0,0.7);
    --table-hover: #1e293b;
    --chart-grid: #2d3748;
    --toggle-bg: #475569;
    --badge-bg: rgba(239,68,68,0.2);
    --badge-text: #fca5a5;
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

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

.logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-blue);
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.sidebar-close {
    display: none;
    color: var(--sidebar-text);
    padding: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}

.nav-item i, .nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 8px 16px;
}

.nav-logout { color: var(--accent-red); }
.nav-logout:hover { background: rgba(239,68,68,0.1); color: var(--accent-red); }

/* ============================================
   Main Content
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin var(--transition);
}

/* ============================================
   Top Header
   ============================================ */
.top-header {
    position: sticky;
    top: 0;
    z-index: 900;
    height: var(--header-height);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    transition: background var(--transition), border var(--transition);
}

.header-left { display: flex; align-items: center; gap: 16px; }

.sidebar-toggle {
    display: none;
    color: var(--text-primary);
    padding: 6px;
    border-radius: var(--radius-sm);
}

.sidebar-toggle:hover { background: var(--bg-tertiary); }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box .search-icon {
    position: absolute;
    left: 12px;
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.search-input {
    width: 280px;
    padding: 9px 14px 9px 38px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

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

/* Language Selector */
.language-selector { position: relative; }

.lang-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    transition: all var(--transition);
}

.lang-btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.lang-btn i, .lang-btn svg { width: 18px; height: 18px; }

.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 130px;
    z-index: 100;
    overflow: hidden;
}

.lang-dropdown.show { display: block; }

.lang-option {
    display: block;
    width: 100%;
    padding: 10px 16px;
    text-align: left;
    font-size: 14px;
    color: var(--text-primary);
    transition: background var(--transition);
}

.lang-option:hover { background: var(--bg-tertiary); }
.lang-option.active { color: var(--accent-blue); font-weight: 600; }

/* Header Icon Buttons */
.header-icon-btn {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition);
}

.header-icon-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.header-icon-btn i, .header-icon-btn svg { width: 20px; height: 20px; }

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

.notification-btn { position: relative; }

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 18px;
    height: 18px;
    background: var(--accent-red);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Profile Dropdown */
.profile-dropdown-wrapper { position: relative; }

.profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px 4px 4px;
    border-radius: var(--radius-md);
    transition: background var(--transition);
}

.profile-btn:hover { background: var(--bg-tertiary); }

.profile-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
}

.profile-name { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.profile-btn > i, .profile-btn > svg { width: 16px; height: 16px; color: var(--text-muted); }

.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 100;
    overflow: hidden;
}

.profile-dropdown.show { display: block; }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-primary);
    transition: background var(--transition);
}

.dropdown-item:hover { background: var(--bg-tertiary); }
.dropdown-item i, .dropdown-item svg { width: 18px; height: 18px; color: var(--text-muted); }

.dropdown-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

/* ============================================
   Page Content
   ============================================ */
.page-content { padding: 28px 24px; }

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

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

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.page-header p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn i, .btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}

.btn-primary:hover { background: var(--accent-blue-hover); box-shadow: 0 4px 12px rgba(59,130,246,0.4); }

.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--border-color); }

.btn-outline { background: transparent; color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-outline:hover { background: var(--bg-tertiary); border-color: var(--accent-blue); color: var(--accent-blue); }

.btn-danger { background: var(--accent-red); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.resolve-btn { margin-left: 8px; }

/* ============================================
   Stats Grid
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 16px;
    border: 1px solid var(--border-color);
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon i, .stat-icon svg { width: 22px; height: 22px; color: #fff; }

.stat-icon.blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stat-icon.green { background: linear-gradient(135deg, #10b981, #059669); }
.stat-icon.purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.stat-icon.orange { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.teal { background: linear-gradient(135deg, #14b8a6, #0d9488); }
.stat-icon.pink { background: linear-gradient(135deg, #ec4899, #db2777); }

.stat-value { font-size: 26px; font-weight: 700; display: block; line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-secondary); }

/* ============================================
   Charts Grid
   ============================================ */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.chart-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 22px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.chart-card:last-child { grid-column: 1 / -1; }

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.chart-header h3 { font-size: 16px; font-weight: 600; }

.chart-filter {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 13px;
}

/* Satisfaction Chart */
.satisfaction-chart {
    display: flex;
    align-items: center;
    gap: 40px;
    justify-content: center;
    padding: 20px 0;
}

.satisfaction-ring { position: relative; width: 120px; height: 120px; }

.satisfaction-ring svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border-color); stroke-width: 10; }
.ring-fill { fill: none; stroke: var(--accent-green); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 1s ease; }

.ring-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 700;
}

.satisfaction-legend { display: flex; flex-direction: column; gap: 10px; }

.legend-item { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); }

.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.green { background: var(--accent-green); }
.legend-dot.yellow { background: var(--accent-orange); }
.legend-dot.red { background: var(--accent-red); }

/* ============================================
   Filters Bar
   ============================================ */
.filters-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-filter {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-filter i, .search-filter svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
}

.search-filter input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition);
}

.search-filter input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.filter-select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    min-width: 150px;
    transition: all var(--transition);
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* ============================================
   Data Table
   ============================================ */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--table-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.table-action-btn {
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition);
}

.table-action-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.table-action-btn i, .table-action-btn svg { width: 16px; height: 16px; }

.actions-cell { display: flex; gap: 4px; }

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.active { background: rgba(16,185,129,0.12); color: #059669; }
.status-badge.inactive { background: rgba(107,114,128,0.12); color: #6b7280; }
.status-badge.draft { background: rgba(245,158,11,0.12); color: #d97706; }
.status-badge.new { background: rgba(59,130,246,0.12); color: #2563eb; }
.status-badge.open { background: rgba(16,185,129,0.12); color: #059669; }
.status-badge.waiting { background: rgba(245,158,11,0.12); color: #d97706; }
.status-badge.resolved { background: rgba(139,92,246,0.12); color: #7c3aed; }
.status-badge.closed { background: rgba(107,114,128,0.12); color: #6b7280; }
.status-badge.connected { background: rgba(16,185,129,0.12); color: #059669; }

[data-theme="dark"] .status-badge.active { background: rgba(16,185,129,0.2); color: #34d399; }
[data-theme="dark"] .status-badge.inactive { background: rgba(107,114,128,0.2); color: #9ca3af; }
[data-theme="dark"] .status-badge.draft { background: rgba(245,158,11,0.2); color: #fbbf24; }
[data-theme="dark"] .status-badge.new { background: rgba(59,130,246,0.2); color: #60a5fa; }
[data-theme="dark"] .status-badge.open { background: rgba(16,185,129,0.2); color: #34d399; }
[data-theme="dark"] .status-badge.waiting { background: rgba(245,158,11,0.2); color: #fbbf24; }
[data-theme="dark"] .status-badge.resolved { background: rgba(139,92,246,0.2); color: #a78bfa; }
[data-theme="dark"] .status-badge.closed { background: rgba(107,114,128,0.2); color: #9ca3af; }
[data-theme="dark"] .status-badge.connected { background: rgba(16,185,129,0.2); color: #34d399; }

/* ============================================
   Table Pagination
   ============================================ */
.table-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px;
}

.table-pagination button {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.table-pagination button:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.table-pagination button.active { background: var(--accent-blue); color: #fff; }

/* ============================================
   Conversations Page
   ============================================ */
.conv-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 0;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    height: calc(100vh - 200px);
    min-height: 500px;
}

.conv-list {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conv-list-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.conv-items { flex: 1; overflow-y: auto; }

.conv-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background var(--transition);
}

.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active { background: var(--table-hover); border-left: 3px solid var(--accent-blue); }

.conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }

.conv-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conv-name { font-size: 14px; font-weight: 600; }
.conv-time { font-size: 11px; color: var(--text-muted); }

.conv-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conv-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.conv-badge {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chat Area */
.conv-chat { display: flex; flex-direction: column; overflow: hidden; }

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
}

.empty-icon { width: 48px; height: 48px; }

.chat-active { display: flex; flex-direction: column; height: 100%; }

.chat-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info { flex: 1; }
.chat-header-name { font-size: 15px; font-weight: 600; }
.chat-header-meta { font-size: 12px; color: var(--text-muted); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    max-width: 75%;
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.chat-msg.customer {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border-bottom-left-radius: 4px;
}

.chat-msg.agent {
    align-self: flex-end;
    background: var(--accent-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.chat-suggestions {
    padding: 10px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.suggestion-chip {
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--accent-blue);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition);
}

.suggestion-chip:hover { background: var(--accent-blue); color: #fff; border-color: var(--accent-blue); }

.chat-input-area {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-action-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: all var(--transition);
}

.chat-action-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.chat-action-btn i, .chat-action-btn svg { width: 20px; height: 20px; }

.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 14px;
}

.chat-input:focus { outline: none; border-color: var(--accent-blue); }

.send-btn { color: var(--accent-blue); }
.send-btn:hover { background: rgba(59,130,246,0.1); }

/* ============================================
   Integrations Grid
   ============================================ */
.integrations-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px;
}

.integration-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 28px;
    border: 1px solid var(--border-color);
    text-align: center;
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
}

.integration-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.integration-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.integration-icon i, .integration-icon svg { width: 26px; height: 26px; }
.integration-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.integration-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }

.integration-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

/* ============================================
   Settings Page
   ============================================ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
}

.settings-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 28px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.settings-card h3 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.settings-actions {
    margin-top: 24px;
    display: flex;
    justify-content: flex-end;
}

/* ============================================
   Forms
   ============================================ */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 14px;
    transition: all var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.variable-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.variable-tags code {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--accent-blue);
}

.checkbox-group { display: flex; gap: 16px; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

.toggle-group { display: flex; flex-direction: column; gap: 14px; }

.toggle-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.toggle-item span { font-size: 14px; }

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--toggle-bg);
    border-radius: 24px;
    cursor: pointer;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: all var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider { background: var(--accent-blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.show { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

.modal-sm { max-width: 420px; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h2 { font-size: 20px; font-weight: 700; }

.modal-close {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition);
}

.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.modal-close i, .modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 20px 28px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 28px 22px;
    border-top: 1px solid var(--border-color);
}

/* Modal Tabs */
.modal-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.modal-tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
}

.modal-tab:hover { color: var(--text-primary); }
.modal-tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); }

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

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--accent-blue);
    min-width: 300px;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3s forwards;
    font-size: 14px;
}

.toast.success { border-left-color: var(--accent-green); }
.toast.error { border-left-color: var(--accent-red); }
.toast.warning { border-left-color: var(--accent-orange); }

.toast i, .toast svg { width: 20px; height: 20px; flex-shrink: 0; }
.toast.success i, .toast.success svg { color: var(--accent-green); }
.toast.error i, .toast.error svg { color: var(--accent-red); }
.toast.warning i, .toast.warning svg { color: var(--accent-orange); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(50px); }
}

/* ============================================
   FAQ Table Cell Helpers
   ============================================ */
.faq-question { font-weight: 500; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.faq-answer { color: var(--text-secondary); max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.category-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(59,130,246,0.1);
    color: var(--accent-blue);
}

/* Customer Table Helpers */
.cust-email { color: var(--text-secondary); font-size: 13px; }

/* ============================================
   View FAQ Modal Content
   ============================================ */
.view-faq-section { margin-bottom: 18px; }
.view-faq-section h4 { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.view-faq-section p { font-size: 14px; line-height: 1.6; }

/* ============================================
   Scrollbar Styling
   ============================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .charts-grid { grid-template-columns: 1fr; }
    .chart-card:last-child { grid-column: auto; }
    .conv-layout { grid-template-columns: 1fr; height: auto; }
    .conv-list { max-height: 400px; }
    .conv-chat { min-height: 500px; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-close { display: block; }
    .sidebar-toggle { display: flex; }

    .main-content {
        margin-left: 0;
    }

    .page-content { padding: 20px 16px; }

    .search-input { width: 160px; }

    .profile-name { display: none; }

    .page-header { flex-direction: column; }

    .stats-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }

    .stat-card { padding: 16px; }
    .stat-value { font-size: 22px; }

    .form-row { grid-template-columns: 1fr; }

    .settings-grid { grid-template-columns: 1fr; }

    .modal { margin: 10px; max-height: 90vh; }
    .modal-body { padding: 16px 20px; }
    .modal-footer { padding: 12px 20px 16px; }

    .filters-bar { flex-direction: column; }
    .filter-select { min-width: auto; }

    .page-actions { width: 100%; }
    .page-actions .btn { flex: 1; justify-content: center; }
}

@media (max-width: 480px) {
    .header-right { gap: 4px; }
    .search-box { display: none; }
    .lang-btn span { display: none; }

    .stats-grid { grid-template-columns: 1fr 1fr; }

    .conv-list-header { flex-direction: column; }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.show { display: block; }
