/* Enterprise SaaS Admin Portal — Design System */

:root {
    --bg-body: #08070d;
    --bg-surface: #100e1b;
    --bg-surface-hover: #19162a;
    --bg-surface-active: #231f3b;
    
    --border-subtle: rgba(139, 92, 246, 0.12);
    --border-highlight: rgba(139, 92, 246, 0.25);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --brand-primary: #8b5cf6;
    --brand-primary-hover: #7c3aed;
    --brand-primary-light: rgba(139, 92, 246, 0.12);
    
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #3b82f6;
    
    --sidebar-width: 280px;
    --header-height: 70px;
}


body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    line-height: 1.5;
}

/* Layout */
.crm-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-body);
}

/* Sidebar */
.crm-sidebar {
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    position: fixed;
    height: 100vh;
    z-index: 50;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.logo-icon {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.logo-text {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-text .font-black {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    padding: 1.5rem 1rem;
    flex-grow: 1;
    overflow-y: auto;
}

.sidebar-group-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin: 1.5rem 0 0.5rem 0.5rem;
}

.sidebar-group-title:first-child {
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    margin-bottom: 2px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-item i {
    width: 20px;
    font-size: 1rem;
    margin-right: 0.75rem;
    text-align: center;
    opacity: 0.8;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.nav-item.active {
    color: #ffffff;
    background: var(--brand-primary);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

.nav-item.active i {
    opacity: 1;
    color: #ffffff;
}

/* Main Content */
.crm-main {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--bg-body);
}

.crm-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.page-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.header-nav {
    display: flex;
    gap: 0.5rem;
    margin-left: 1rem;
}

.header-nav-item {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    transition: all 0.15s;
}

.header-nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.header-nav-item.active {
    color: var(--text-primary);
    background: var(--bg-surface-active);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-widget {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border-radius: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-surface-active);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.75rem;
    cursor: pointer;
}

.crm-content {
    padding: 2rem;
    flex-grow: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* Cards - Strict Enterprise Style */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}

.card-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

/* Typography Utilities */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-brand { color: var(--brand-primary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-white { color: #fff; }

.font-bold { font-weight: 600; }
.font-semibold { font-weight: 500; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; letter-spacing: -0.01em; }
.text-xl { font-size: 1.25rem; letter-spacing: -0.02em; }
.text-2xl { font-size: 1.5rem; letter-spacing: -0.02em; }
.uppercase { text-transform: uppercase; }
.tracking-wider { letter-spacing: 0.05em; }

/* Grid */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) {
    .lg\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
    .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .lg\:col-span-1 { grid-column: span 1 / span 1; }
    .lg\:col-span-2 { grid-column: span 2 / span 2; }
    .lg\:col-span-3 { grid-column: span 3 / span 3; }
}
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.mt-1 { margin-top: 0.25rem; }
.w-full { width: 100%; }

/* Badges & Tags */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.badge-success { color: var(--color-success); border-color: rgba(16,185,129,0.3); background: rgba(16,185,129,0.1); }
.badge-warning { color: var(--color-warning); border-color: rgba(245,158,11,0.3); background: rgba(245,158,11,0.1); }
.badge-danger { color: var(--color-danger); border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.1); }
.badge-primary { color: var(--brand-primary); border-color: var(--border-highlight); background: var(--brand-primary-light); }
.badge-muted { color: var(--text-secondary); border-color: rgba(255,255,255,0.1); background: rgba(255,255,255,0.05); }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1.25rem;
}
.btn-primary {
    background: var(--brand-primary);
    color: #ffffff;
    box-shadow: 0 4px 14px 0 rgba(139, 92, 246, 0.3);
}
.btn-primary:hover {
    background: var(--brand-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 rgba(139, 92, 246, 0.4);
}
.btn-outline {
    background: var(--bg-body);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: var(--bg-surface);
}
.btn-danger {
    background: var(--color-danger);
    color: #ffffff;
    box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.4);
}
.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
}
.btn-icon:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* Form Controls */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    letter-spacing: 0.01em;
}

.form-control, .form-select {
    width: 100%;
    padding: 0.65rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}
.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--brand-primary);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}
textarea.form-control { resize: vertical; min-height: 80px; font-family: inherit; }

.search-bar { position: relative; display: inline-flex; align-items: center; }
.search-bar i { position: absolute; left: 1rem; color: var(--text-muted); font-size: 0.875rem; }
.search-bar input { padding-left: 2.75rem; width: 260px; }

/* Tables */
.table-container, .table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    text-align: left;
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(255, 255, 255, 0.01);
}

.table td {
    padding: 1.25rem 1.5rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s;
    font-size: 0.875rem;
}

.table tbody tr {
    transition: transform 0.2s, background 0.2s;
}

.table tbody tr:hover td {
    background: var(--bg-surface-active);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

/* Stats Cards */
.stat-card {
    padding: 1.5rem;
    background: var(--bg-body);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
}
.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* Activity Items */
.activity-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    border: 1px solid transparent;
    transition: all 0.15s;
    background: var(--bg-body);
}
.activity-item:hover {
    background: var(--bg-surface);
}
.activity-item + .activity-item {
    border-top: 1px solid var(--border-subtle);
    border-radius: 0;
}
.activity-item:hover + .activity-item {
    border-top-color: transparent;
}

/* Toasts */
.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
}
.toast-success { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.3); color: var(--color-success); }
.toast-error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.3); color: var(--color-danger); }
.toast-info { background: var(--brand-primary-light); border-color: var(--border-highlight); color: var(--brand-primary); }

/* Mobile menu toggle (hidden on desktop by default) */
.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-surface-active); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Added Utility & Layout Classes for View Compatibility */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -0.75rem;
    margin-left: -0.75rem;
}
.row > * {
    box-sizing: border-box;
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    padding-right: 0.75rem;
    padding-left: 0.75rem;
}
.g-6 {
    --bs-gutter-x: 1.5rem;
    --bs-gutter-y: 1.5rem;
    margin-top: calc(-1 * var(--bs-gutter-y));
    margin-right: calc(-0.5 * var(--bs-gutter-x));
    margin-left: calc(-0.5 * var(--bs-gutter-x));
}
.g-6 > * {
    padding-right: calc(var(--bs-gutter-x) * 0.5);
    padding-left: calc(var(--bs-gutter-x) * 0.5);
    margin-top: var(--bs-gutter-y);
}
.g-4 {
    --bs-gutter-x: 1rem;
    --bs-gutter-y: 1rem;
    margin-top: calc(-1 * var(--bs-gutter-y));
    margin-right: calc(-0.5 * var(--bs-gutter-x));
    margin-left: calc(-0.5 * var(--bs-gutter-x));
}
.g-4 > * {
    padding-right: calc(var(--bs-gutter-x) * 0.5);
    padding-left: calc(var(--bs-gutter-x) * 0.5);
    margin-top: var(--bs-gutter-y);
}
@media (min-width: 768px) {
    .col-md-3 { flex: 0 0 auto; width: 25%; }
    .col-md-4 { flex: 0 0 auto; width: 33.33333333%; }
    .col-md-6 { flex: 0 0 auto; width: 50%; }
    .col-md-8 { flex: 0 0 auto; width: 66.66666667%; }
}
@media (min-width: 1024px) {
    .col-lg-5 { flex: 0 0 auto; width: 41.66666667%; }
    .col-lg-7 { flex: 0 0 auto; width: 58.33333333%; }
}

.w-full { width: 100% !important; }
.h-full { height: 100% !important; }
.h-1\.5 { height: 0.375rem !important; }
.min-w-0 { min-width: 0 !important; }

.p-0 { padding: 0 !important; }
.p-3 { padding: 0.75rem !important; }
.p-4 { padding: 1rem !important; }
.p-5 { padding: 1.25rem !important; }
.p-6 { padding: 1.5rem !important; }
.p-8 { padding: 2rem !important; }

.px-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-3 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
.px-4 { padding-left: 1rem !important; padding-right: 1rem !important; }
.px-5 { padding-left: 1.25rem !important; padding-right: 1.25rem !important; }
.py-1 { padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; }
.py-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-3 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
.py-6 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
.py-8 { padding-top: 2rem !important; padding-bottom: 2rem !important; }

.pt-2 { padding-top: 0.5rem !important; }
.pt-3 { padding-top: 0.75rem !important; }
.pt-4 { padding-top: 1rem !important; }
.pt-5 { padding-top: 1.25rem !important; }
.pb-4 { padding-bottom: 1rem !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 0.75rem !important; }
.mb-4 { margin-bottom: 1rem !important; }
.mb-6 { margin-bottom: 1.5rem !important; }
.mb-8 { margin-bottom: 2rem !important; }

.mt-0\.5 { margin-top: 0.125rem !important; }
.mt-1 { margin-top: 0.25rem !important; }
.mt-1\.5 { margin-top: 0.375rem !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-4 { margin-top: 1rem !important; }
.mt-6 { margin-top: 1.5rem !important; }
.mr-1 { margin-right: 0.25rem !important; }
.mr-2 { margin-right: 0.5rem !important; }
.ml-2 { margin-left: 0.5rem !important; }

.flex-col { flex-direction: column !important; }
.flex-wrap { flex-wrap: wrap !important; }
.flex-grow { flex-grow: 1 !important; }
.flex-1 { flex: 1 1 0% !important; }
.items-start { align-items: flex-start !important; }
.items-end { align-items: flex-end !important; }
.justify-center { justify-content: center !important; }

.gap-1 { gap: 0.25rem !important; }

.inline { display: inline !important; }
.inline-block { display: inline-block !important; }
.inline-flex { display: inline-flex !important; }
.hidden { display: none !important; }
.d-flex { display: flex !important; }

.space-y-3 > * + * { margin-top: 0.75rem !important; }
.space-y-6 > * + * { margin-top: 1.5rem !important; }

.text-center { text-align: center !important; }
.text-right, .text-end { text-align: right !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whitespace-nowrap { white-space: nowrap !important; }
.whitespace-pre-wrap { white-space: pre-wrap !important; }
.leading-relaxed { line-height: 1.625 !important; }
.capitalize { text-transform: capitalize !important; }

.text-3xl { font-size: 1.875rem !important; font-weight: 800 !important; }
.font-black { font-weight: 900 !important; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important; }

.text-\[8px\] { font-size: 8px !important; }
.text-\[9px\] { font-size: 9px !important; }
.text-\[10px\] { font-size: 10px !important; }
.text-\[11px\] { font-size: 11px !important; }
.text-\[13px\] { font-size: 13px !important; }

.opacity-50 { opacity: 0.5 !important; }
.pointer-events-none { pointer-events: none !important; }

/* Borders unten / zwischen Elementen (fehlten für Ticket-View) */
.border-b { border-bottom: 1px solid var(--border-subtle) !important; }
.last\:border-0:last-child { border: 0 !important; }
.last\:border-b-0:last-child { border-bottom: 0 !important; }
.border-dashed { border-style: dashed !important; }
.border-2 { border-width: 2px !important; }

/* Schatten / Blur für Chat-Bubbles (fehlten) */
.shadow-lg { box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5) !important; }
.backdrop-blur-md { backdrop-filter: blur(12px) !important; -webkit-backdrop-filter: blur(12px) !important; }

/* Max-width für Chat-Bubbles (fehlte) */
.max-w-\[85\%\] { max-width: 85% !important; }

.rounded-md { border-radius: 0.375rem !important; }
.rounded-xl { border-radius: 0.75rem !important; }
.rounded-none { border-radius: 0 !important; }

/* Custom Colors & Borders for embeds (KORRIGIERT — vorheriges \27-Escaping war fehlerhaft und matchte nie) */
.bg-\[rgba\(29\,79\,254\,0\.1\)\] { background-color: rgba(29, 79, 254, 0.1) !important; }
.bg-\[rgba\(255\,255\,255\,0\.03\)\] { background-color: rgba(255, 255, 255, 0.03) !important; }
.bg-\[rgba\(255\,255\,255\,0\.02\)\] { background-color: rgba(255, 255, 255, 0.02) !important; }
.bg-\[rgba\(255\,255\,255\,0\.05\)\] { background-color: rgba(255, 255, 255, 0.05) !important; }
.bg-\[rgba\(239\,68\,68\,0\.1\)\] { background-color: rgba(239, 68, 68, 0.1) !important; }

.border-\[rgba\(29\,79\,254\,0\.2\)\] { border-color: rgba(29, 79, 254, 0.2) !important; }
.border-\[rgba\(255\,255\,255\,0\.08\)\] { border-color: rgba(255, 255, 255, 0.08) !important; }
.border-\[rgba\(255\,255\,255\,0\.05\)\] { border-color: rgba(255, 255, 255, 0.05) !important; }
.border-\[rgba\(255\,255\,255\,0\.1\)\] { border-color: rgba(255, 255, 255, 0.1) !important; }
.border-\[rgba\(239\,68\,68\,0\.3\)\] { border-color: rgba(239, 68, 68, 0.3) !important; }

/* ============================================================
   Chat / Ticket Conversation
   ============================================================ */
.chat-window {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 1.25rem;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
    overflow: hidden;
    min-height: 560px;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.75rem;
    flex-grow: 1;
    overflow-y: auto;
    max-height: 640px;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}
.chat-empty i { font-size: 1.75rem; margin-bottom: 0.5rem; display: block; opacity: 0.6; }
.chat-empty p { margin: 0; font-size: 0.875rem; }

.chat-row {
    display: flex;
    align-items: flex-end;
    gap: 0.65rem;
    max-width: 100%;
}
.chat-row-customer { justify-content: flex-start; }
.chat-row-team { justify-content: flex-end; }

.chat-col {
    display: flex;
    flex-direction: column;
    max-width: 68%;
}
.chat-row-team .chat-col { align-items: flex-end; }
.chat-row-customer .chat-col { align-items: flex-start; }

.chat-avatar {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
}
.chat-avatar-customer { background: var(--bg-surface-active); color: var(--text-secondary); border: 1px solid var(--border-subtle); }
.chat-avatar-team { background: var(--brand-primary); }

.chat-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    padding: 0 0.25rem;
}
.chat-meta-name { font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }
.chat-meta-time { font-size: 0.7rem; color: var(--text-muted); }
.chat-meta-badge { padding: 0.15rem 0.5rem; font-size: 0.6rem; }

.chat-bubble {
    padding: 0.85rem 1.1rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
    box-shadow: 0 4px 14px -6px rgba(0,0,0,0.4);
}
.chat-bubble-customer {
    background: var(--bg-surface-active);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-bottom-left-radius: 0.3rem;
}
.chat-bubble-team {
    background: var(--brand-primary);
    color: #ffffff;
    border-bottom-right-radius: 0.3rem;
}

.chat-composer {
    border-top: 1px solid var(--border-subtle);
    padding: 1.25rem 1.75rem;
    background: rgba(255,255,255,0.015);
}
.chat-input {
    width: 100%;
    resize: vertical;
    min-height: 70px;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    box-sizing: border-box;
}
.chat-input:focus {
    outline: none;
    border-color: var(--brand-primary);
    background: rgba(255,255,255,0.05);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}
.chat-composer-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
}

.chat-closed-banner {
    border-top: 1px solid var(--border-subtle);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
}
.chat-closed-banner i { font-size: 1.5rem; margin-bottom: 0.5rem; display: block; opacity: 0.6; }
.chat-closed-banner p { margin: 0; font-size: 0.875rem; }

@media (max-width: 640px) {
    .chat-col { max-width: 85%; }
}

/* Mobile responsive: Sidebar/Header */
@media (max-width: 1023px) {
    .crm-sidebar { transform: translateX(-100%); transition: transform 0.2s ease; }
    .crm-sidebar.open { transform: translateX(0); }
    .crm-main { margin-left: 0; }
    .mobile-menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
}