/* ══════════════════════════════════════════════════════════════
   Watel - Light Luxury Theme
   Messenger Integration Platform for Bitrix24
   ══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    /* ── Backgrounds ── */
    --bg-primary: #F0F2F5;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #E4E8EC;
    --bg-hover: #E8EBEF;
    --bg-active: #D8DDE3;

    /* ── Sidebar ── */
    --sidebar-bg: #1A2332;
    --sidebar-bg-hover: #243044;
    --sidebar-bg-active: #2D3B50;
    --sidebar-text: #8899AA;
    --sidebar-text-active: #FFFFFF;
    --sidebar-border: #243044;
    --sidebar-accent: #00B8A9;

    /* ── Text ── */
    --text-primary: #1A2332;
    --text-secondary: #546478;
    --text-muted: #8899AA;
    --text-white: #FFFFFF;

    /* ── Accent (teal brand) ── */
    --accent-blue: #00B8A9;
    --accent-blue-hover: #009E92;
    --accent-blue-light: #E6F7F6;
    --accent-blue-soft: #CCF0EE;
    --accent-green: #00C48C;
    --accent-green-hover: #00A878;
    --accent-green-light: #E6FAF3;
    --accent-green-soft: #CCF5E7;

    /* ── Status ── */
    --success: #00C48C;
    --error: #FF6B6B;
    --warning: #FFB946;
    --info: #00B8A9;

    /* ── Borders ── */
    --border: #D0D6DD;
    --border-light: #E4E8EC;
    --border-focus: #00B8A9;

    /* ── Shadows (deeper, warmer) ── */
    --shadow-xs: 0 1px 2px rgba(26, 35, 50, 0.04);
    --shadow-sm: 0 2px 4px rgba(26, 35, 50, 0.06), 0 1px 2px rgba(26, 35, 50, 0.04);
    --shadow-md: 0 4px 16px rgba(26, 35, 50, 0.08);
    --shadow-lg: 0 8px 32px rgba(26, 35, 50, 0.10);
    --shadow-xl: 0 16px 48px rgba(26, 35, 50, 0.14);

    /* ── Radius (softer) ── */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* ── Typography ── */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* ── Layout ── */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;

    /* ── Transitions ── */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: var(--transition-fast);
}

a:hover {
    color: var(--accent-blue-hover);
}

/* ── Layout ────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-height: 100vh;
    transition: var(--transition);
    background: var(--bg-primary);
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1A2332 0%, #151D2A 100%);
    border-right: none;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: var(--transition);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #00B8A9, #00C48C);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.5px;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 184, 169, 0.3);
}

.sidebar-logo,
.sidebar-header img {
    box-shadow: 0 2px 12px rgba(0, 184, 169, 0.3);
}

.sidebar-brand {
    font-size: 18px;
    font-weight: 700;
    color: #E8EDF3;
    letter-spacing: -0.5px;
}

.sidebar-brand span {
    color: #00B8A9;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 8px;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #546478;
    padding: 8px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition-fast);
    text-decoration: none;
    position: relative;
}

.nav-item:hover {
    background: rgba(0, 184, 169, 0.08);
    color: #D0D6DD;
}

.nav-item.active {
    background: rgba(0, 184, 169, 0.12);
    color: #FFFFFF;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #00B8A9;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}
.nav-icon-img {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(0.8);
    transition: filter 0.15s;
}
.nav-item:hover .nav-icon-img,
.nav-item.active .nav-icon-img {
    filter: brightness(0) invert(1);
}

.nav-item .nav-badge,
.nav-badge {
    margin-left: auto;
    background: #00B8A9;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
    box-shadow: 0 0 8px rgba(0, 184, 169, 0.4);
    animation: badgePulse 2s ease-in-out infinite;
}
@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 8px rgba(0, 184, 169, 0.4); }
    50% { box-shadow: 0 0 14px rgba(0, 184, 169, 0.6); }
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

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

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #00B8A9, #00C48C);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 184, 169, 0.3);
}

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

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: #F1F5F9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-plan {
    font-size: 11px;
    font-weight: 600;
    color: #00B8A9;
}

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.3;
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.1px;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.card-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Stats Cards ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    transition: box-shadow 0.2s ease;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-card:nth-child(1) { border-left-color: #00B8A9; }
.stat-card:nth-child(2) { border-left-color: #00C48C; }
.stat-card:nth-child(3) { border-left-color: #FFB946; }
.stat-card:nth-child(4) { border-left-color: #7C5CFC; }

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 12px;
}

.stat-card-icon.blue {
    background: rgba(0, 184, 169, 0.1);
    color: var(--accent-blue);
}

.stat-card-icon.green {
    background: rgba(0, 196, 140, 0.1);
    color: var(--accent-green);
}

.stat-card-icon.amber {
    background: rgba(255, 185, 70, 0.1);
    color: #D97706;
}

.stat-card-icon.purple {
    background: rgba(124, 58, 237, 0.1);
    color: #7C3AED;
}

.stat-card-icon.red {
    background: rgba(220, 38, 38, 0.1);
    color: #DC2626;
}

/* ── Shared icon utility ─────────────────────────────────── */
.icon-svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.icon-btn .icon-svg {
    width: 16px;
    height: 16px;
}

/* ── Unified choice-card (used by routing modes, claim modes, etc.) ── */
.choice-card {
    border: 2px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 20px 16px;
    background: var(--bg-secondary);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.choice-card:hover {
    border-color: #00B8A9;
}
.choice-card.active {
    border-color: #00B8A9;
    box-shadow: 0 0 0 3px rgba(0, 184, 169, 0.1);
}
.choice-card input[type=radio] { display: none; }
.choice-card-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 10px;
    border-radius: var(--radius-md);
    background: rgba(0, 184, 169, 0.08);
    color: #00B8A9;
    display: flex;
    align-items: center;
    justify-content: center;
}
.choice-card.active .choice-card-icon {
    background: #00B8A9;
    color: white;
}
.choice-card-icon .icon-svg { width: 22px; height: 22px; }
.choice-card-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--text-primary);
}
.choice-card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.stat-card-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -1px;
    line-height: 1.2;
}

.stat-card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #00B8A9;
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    transition: background 0.2s ease;
}

.btn-primary:hover:not(:disabled) {
    background: #009E92;
}

.btn-primary:active:not(:disabled) {
    background: #008A7E;
}

.btn-success {
    background: var(--accent-green);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: var(--accent-green-hover);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: #00B8A9;
    color: #00B8A9;
}

.btn-danger {
    background: #FF6B6B;
    color: white;
    border: none;
}

.btn-danger:hover:not(:disabled) {
    background: #EE5A5A;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--radius-md);
    padding: 8px 12px;
    transition: var(--transition-fast);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-block {
    width: 100%;
}

/* ── Form Elements ─────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

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

.form-label .required {
    color: var(--error);
    margin-left: 2px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

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

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: var(--text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: #00B8A9;
    box-shadow: 0 0 0 3px rgba(0, 184, 169, 0.12);
    outline: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

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

.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error {
    font-size: 12px;
    color: var(--error);
    margin-top: 4px;
}

/* ── Integration Cards ─────────────────────────────────────── */
.integration-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.integration-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: box-shadow 0.2s ease;
}

.integration-card:hover {
    box-shadow: var(--shadow-md);
}

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

.integration-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
    overflow: hidden;
}

.integration-icon.whatsapp { background: #DCF8C6; color: #25D366; }
.integration-icon.telegram { background: #E3F2FD; color: #0088CC; }
.integration-icon.messenger { background: #EDE7F6; color: #0084FF; }

/* ── Messenger Icon Images ────────────────────────────────── */
.messenger-icon {
    object-fit: contain;
    vertical-align: middle;
    flex-shrink: 0;
    border-radius: 50%;
}

.integration-icon .messenger-icon {
    width: 28px !important;
    height: 28px !important;
    border-radius: 50%;
}

.chat-avatar {
    position: relative;
    width: 49px;
    height: 49px;
    flex-shrink: 0;
}

.avatar-img {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.avatar-placeholder {
    width: 49px;
    height: 49px;
    border-radius: 50%;
    background: var(--bg-tertiary, #3A3F55);
    color: var(--text-secondary, #8B92A5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
}

.avatar-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary, #fff);
    background: var(--bg-secondary, #fff);
    object-fit: contain;
}

.chat-avatar .messenger-icon,
.chat-item-avatar .messenger-icon {
    width: 24px;
    height: 24px;
}

.chat-item-platform .messenger-icon {
    width: 12px !important;
    height: 12px !important;
}

.integration-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

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

/* ── Status Badges ─────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-full);
    letter-spacing: 0.2px;
}

.badge-success {
    background: var(--accent-green-light);
    color: var(--accent-green);
}

.badge-error {
    background: #FEF2F2;
    color: var(--error);
}

.badge-warning {
    background: #FFFBEB;
    color: var(--warning);
}

.badge-info {
    background: var(--accent-blue-light);
    color: var(--accent-blue);
}

.badge-muted {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ── Chat UI ───────────────────────────────────────────────── */
.chat-layout {
    display: flex;
    height: calc(100vh - 100px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.chat-list {
    width: 340px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.chat-list-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.chat-list-search {
    width: 100%;
    padding: 9px 14px 9px 36px;
    font-size: 13px;
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    outline: none;
    transition: var(--transition-fast);
}

.chat-list-search:focus {
    background: var(--bg-secondary);
    border-color: #00B8A9;
    box-shadow: 0 0 0 3px rgba(0, 184, 169, 0.1);
}

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

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition-fast);
    border-bottom: 1px solid var(--border-light);
}

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

.chat-item.active {
    background: var(--accent-blue-light);
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-header-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.chat-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-time {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    white-space: nowrap;
}

.chat-time.chat-time-unread {
    color: #25D366;
    font-weight: 600;
}

.chat-preview-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 3px;
}

.chat-last-msg {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-preview-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item.unread .chat-last-msg {
    color: var(--text-secondary);
}

/* Message status checkmarks */
.msg-status {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin-right: 1px;
}

/* Media type icon in preview */
.msg-media-icon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    color: var(--text-muted);
}

/* Unread badge — small colored circle */
.chat-unread-badge {
    background: #25D366;
    color: white;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
}

/* Legacy classes kept for compatibility */
.chat-item-avatar {
    width: 49px;
    height: 49px;
    border-radius: var(--radius-full);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    position: relative;
}

.chat-item-platform {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    border: 1.5px solid var(--bg-secondary);
    box-shadow: var(--shadow-xs);
}

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

.chat-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
}

.chat-item-meta {
    text-align: right;
    flex-shrink: 0;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-item-unread {
    background: #25D366;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    margin-top: 4px;
    display: inline-block;
}

/* Chat conversation area */
.chat-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-conversation-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── Chat Header Buttons ──────────────────────────────── */
.chat-header-actions {
    flex-shrink: 0;
}
.chat-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 36px;
    min-height: 36px;
    padding: 6px 10px;
    border: none;
    background: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}
.chat-header-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.chat-header-btn--close:hover {
    background: #FEE2E2;
    color: #DC2626;
}
.chat-header-btn--danger {
    color: var(--error);
}
.chat-header-btn--danger:hover {
    background: #FEE2E2;
    color: #DC2626;
}
.chat-header-btn .icon-svg {
    flex-shrink: 0;
}

/* CRM dropdown menu */
.crm-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 4px 0;
    margin-top: 4px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.crm-dropdown-menu.open {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* CRM dropdown menu items */
.crm-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    text-align: left;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition-fast);
}
.crm-menu-item:hover {
    background: var(--bg-tertiary);
}
.crm-menu-icon {
    display: inline-flex;
    color: var(--text-muted);
}

/* ── Confirmation Modal ──────────────────────────────── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: confirmFadeIn 0.15s ease;
}
@keyframes confirmFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.confirm-modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 420px;
    width: calc(100% - 32px);
    padding: 24px;
    animation: confirmSlideIn 0.15s ease;
}
@keyframes confirmSlideIn {
    from { transform: translateY(-8px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}
.confirm-icon-area {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.confirm-icon-area--danger {
    background: #FEE2E2;
    color: #DC2626;
}
.confirm-icon-area--default {
    background: var(--accent-blue-soft);
    color: var(--accent-blue);
}
.confirm-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.confirm-message {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 20px;
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}
.confirm-actions .btn {
    min-width: 90px;
}
.confirm-modal .btn-danger {
    background: #FF6B6B;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}
.confirm-modal .btn-danger:hover {
    background: #EE5A5A;
}
.btn-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}
.btn-cancel:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

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

.chat-message {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    position: relative;
}

.chat-message.incoming {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    border-radius: 16px 16px 16px 4px;
}

.chat-message.outgoing {
    align-self: flex-end;
    background: linear-gradient(135deg, #00B8A9, #009E92);
    color: white;
    border-radius: 16px 16px 4px 16px;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

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

.chat-input {
    flex: 1;
    padding: 10px 16px;
    font-size: 14px;
    font-family: var(--font);
    background: var(--bg-tertiary);
    border: 1.5px solid transparent;
    border-radius: var(--radius-xl);
    outline: none;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    transition: var(--transition-fast);
}

.chat-input:focus {
    background: var(--bg-secondary);
    border-color: #00B8A9;
}

.chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--accent-blue-hover);
    transform: scale(1.05);
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* ── Empty States ──────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state-text {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.5;
}

/* ── Auth Pages ────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1A2332 0%, #151D2A 100%);
    padding: 20px;
}

.auth-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-light);
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo-icon {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #00B8A9, #00C48C);
    border-radius: var(--radius-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.auth-logo-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.auth-logo-text span {
    color: var(--accent-blue);
}

.auth-title {
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 24px;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 13px;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--accent-blue);
    font-weight: 600;
}

.auth-error {
    background: #FEF2F2;
    color: var(--error);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ── Tables ────────────────────────────────────────────────── */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

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

th {
    background: var(--bg-primary);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border-light);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
    color: var(--text-primary);
}

tr:hover td {
    background: var(--bg-hover);
}

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

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: var(--accent-green-light);
    color: #065F46;
    border: 1px solid var(--accent-green-soft);
}

.alert-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FEE2E2;
}

.alert-warning {
    background: #FFFBEB;
    color: #92400E;
    border: 1px solid #FEF3C7;
}

.alert-info {
    background: var(--accent-blue-light);
    color: #047A72;
    border: 1px solid var(--accent-blue-soft);
}

/* ── Spinner ───────────────────────────────────────────────── */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── QR Code Display ──────────────────────────────────────── */
.qr-code-container {
    text-align: center;
    padding: 20px;
}

.qr-code-container img {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-width: 300px;
    width: 100%;
    height: auto;
}

.qr-instructions {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 12px;
    line-height: 1.5;
}

/* ── Verification Code Input ──────────────────────────────── */
.code-input {
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 8px;
    font-family: var(--font-mono);
    padding: 12px 20px;
}

/* ── Alert Variants (used in modals) ──────────────────────── */
.alert-danger {
    background: #FEF2F2;
    color: #DC2626;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid #FEE2E2;
}

/* ── Badge secondary ──────────────────────────────────────── */
.badge-secondary {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.badge-danger {
    background: #FEF2F2;
    color: var(--error);
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.animate-fadeIn {
    animation: fadeIn 0.4s ease-out;
}

.animate-slideIn {
    animation: slideIn 0.3s ease;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Sidebar Toggle Button (mobile hamburger) ────────────── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

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

.sidebar-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: var(--transition-fast);
    position: relative;
}

.sidebar-toggle span::before,
.sidebar-toggle span::after {
    content: '';
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    position: absolute;
    left: 0;
    transition: var(--transition-fast);
}

.sidebar-toggle span::before {
    top: -6px;
}

.sidebar-toggle span::after {
    top: 6px;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
    }

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

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 64px;
    }

    .page-header .page-title,
    .page-header h1 {
        font-size: 20px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .chat-layout {
        flex-direction: column;
        height: calc(100vh - 80px);
    }

    .chat-list {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .chat-message {
        max-width: 85%;
    }

    /* Tables: horizontal scroll */
    .table-wrapper {
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    /* Modals: near full-width on mobile */
    .modal {
        width: 95%;
        max-width: 95%;
        margin: 10px;
    }

    .auth-card {
        padding: 24px;
        width: 95%;
    }

    .emoji-picker {
        width: 280px;
        right: 10px;
    }

    .card {
        padding: 16px;
    }

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

/* Very small screens */
@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .page-header .page-title,
    .page-header h1 {
        font-size: 18px;
    }

    .main-content {
        padding: 12px;
        padding-top: 60px;
    }

    .chat-message {
        max-width: 90%;
    }
}

/* ── Chat Filters ─────────────────────────────────────────── */
.chat-filters {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}

.chat-filter-btn {
    flex: 1;
    padding: 6px 0;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.chat-filter-btn:hover {
    background: var(--bg-hover);
}

.chat-filter-btn.active {
    background: #00B8A9;
    color: white;
    border-color: #00B8A9;
}

/* ── Chat Attach & Emoji Buttons ─────────────────────────── */
.chat-attach-btn,
.chat-emoji-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.chat-attach-btn:hover,
.chat-emoji-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-blue);
}

/* ── File Preview ─────────────────────────────────────────── */
.chat-file-preview {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-tertiary);
}

.chat-file-preview img {
    max-height: 80px;
    border-radius: var(--radius-sm);
}

.file-preview-remove {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    margin-left: auto;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.file-preview-remove:hover {
    background: var(--bg-hover);
    color: var(--error);
}

/* ── Emoji Picker ─────────────────────────────────────────── */
.emoji-picker {
    position: absolute;
    bottom: 60px;
    right: 50px;
    width: 320px;
    max-height: 320px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    padding: 12px;
    z-index: 100;
}

.emoji-category-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 0 4px;
    margin-top: 4px;
}

.emoji-category-label:first-child {
    margin-top: 0;
    padding-top: 0;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emoji-grid button {
    font-size: 20px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    line-height: 1;
}

.emoji-grid button:hover {
    background: var(--bg-tertiary);
    transform: scale(1.15);
}

/* ── Typing Indicator ─────────────────────────────────────── */
.typing-active {
    color: var(--accent-green) !important;
    animation: typingPulse 1.5s ease-in-out infinite;
}

@keyframes typingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Message styles (inline) ──────────────────────────────── */
.message {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: fadeIn 0.2s ease;
}

.message-incoming {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    border-radius: 16px 16px 16px 4px;
}

.message-outgoing {
    align-self: flex-end;
    background: linear-gradient(135deg, #00B8A9, #009E92);
    color: white;
    border-radius: 16px 16px 4px 16px;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: 4px;
}

.message-outgoing .message-sender {
    color: rgba(255,255,255,0.8);
}

.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-meta {
    font-size: 11px;
    opacity: 0.65;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.message-media img,
.message-media video {
    display: block;
    margin-bottom: 4px;
}

.file-link {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
}

.message-outgoing .file-link {
    color: white;
}

/* ── Message Media Container ─────────────────────────────── */
.message-media {
    margin: 4px 0;
    max-width: 300px;
    border-radius: 12px;
    overflow: hidden;
}

.message-media img {
    display: block;
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-media img:hover {
    opacity: 0.9;
}

.message-media video {
    display: block;
    max-width: 100%;
    border-radius: 8px;
}

.message-media audio {
    display: block;
    width: 100%;
    max-width: 280px;
    margin: 4px 0;
}

/* ── Message File ────────────────────────────────────────── */
.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    margin: 4px 0;
    max-width: 280px;
}

.message-file .file-icon {
    font-size: 24px;
    flex-shrink: 0;
}

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

.message-file .file-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-file .file-size {
    font-size: 11px;
    color: var(--text-muted);
}

.message-outgoing .message-file {
    background: rgba(255, 255, 255, 0.15);
}

.message-outgoing .message-file .file-name {
    color: white;
}

/* ── Image/Video Thumbnails ──────────────────────────── */
.msg-image-thumb {
    max-width: 280px;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity 0.15s ease;
    display: block;
}
.msg-image-thumb:hover {
    opacity: 0.88;
}
.msg-video-thumb {
    max-width: 280px;
    border-radius: 12px;
    display: block;
}

/* ── File Card ───────────────────────────────────────── */
.message-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    max-width: 280px;
}
.message-outgoing .message-file-card {
    background: rgba(255, 255, 255, 0.15);
}
.message-file-icon {
    flex-shrink: 0;
    color: var(--accent-blue);
    display: flex;
}
.message-file-info {
    flex: 1;
    min-width: 0;
}
.message-file-name {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-outgoing .message-file-name {
    color: white;
}
.message-file-dl {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--accent-blue);
    flex-shrink: 0;
    transition: var(--transition-fast);
}
.message-file-dl:hover {
    background: var(--accent-blue-soft);
}

/* ── Message Status Indicators ───────────────────────────── */
.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-outgoing .message-time {
    color: rgba(255, 255, 255, 0.7);
    justify-content: flex-end;
}

.message-status-icon {
    font-size: 12px;
}

/* ── Location Card ───────────────────────────────────────── */
.message-location {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s;
    max-width: 260px;
}

.message-location:hover {
    background: var(--bg-active);
}

/* ── Sticker ─────────────────────────────────────────────── */
.message-sticker img {
    max-width: 180px;
    max-height: 180px;
    background: transparent;
}

/* ── Contact Card ────────────────────────────────────────── */
.message-contact {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-hover);
    border-radius: 12px;
    max-width: 260px;
}

/* ── Image Popup Overlay ─────────────────────────────────── */
.image-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}

.image-popup-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ── Voice Player (WhatsApp-style) ────────────────────── */
.voice-player {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    min-width: 220px;
    max-width: 320px;
}
.voice-player audio { display: none; }

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #25D366;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}
.voice-play-btn:hover { background: #1da851; }
.voice-play-btn:active { transform: scale(0.92); }
.message-outgoing .voice-play-btn { background: rgba(255,255,255,0.25); }
.message-outgoing .voice-play-btn:hover { background: rgba(255,255,255,0.35); }

.voice-wave-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.voice-wave {
    position: relative;
    height: 28px;
    cursor: pointer;
    overflow: hidden;
    border-radius: 4px;
}
.voice-wave-progress {
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 0%;
    background: rgba(37, 211, 102, 0.25);
    border-radius: 4px;
    transition: width 0.1s linear;
    z-index: 1;
}
.message-outgoing .voice-wave-progress {
    background: rgba(255,255,255,0.2);
}

.voice-wave-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 100%;
    position: relative;
    z-index: 2;
}
.voice-wave-bars span {
    flex: 1;
    min-width: 2px;
    max-width: 5px;
    background: #93c5a4;
    border-radius: 2px;
    transition: background 0.2s;
}
.voice-player.playing .voice-wave-bars span {
    background: #25D366;
}
.message-outgoing .voice-wave-bars span {
    background: rgba(255,255,255,0.4);
}
.message-outgoing .voice-player.playing .voice-wave-bars span {
    background: rgba(255,255,255,0.8);
}

.voice-time {
    font-size: 11px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.message-outgoing .voice-time {
    color: rgba(255,255,255,0.6);
}

.chat-unread {
    background: #25D366;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.chat-type {
    font-size: 10px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

/* ── Utility Classes ───────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent-green); }
.text-error { color: var(--error); }
.text-blue { color: var(--accent-blue); }
.font-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }

/* ── Modal ────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: modalFadeIn 0.2s ease;
}
.modal {
    background: var(--bg-secondary);
    border-radius: 16px;
    width: 90%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: modalSlideIn 0.2s ease;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border, #E2E8F0);
}
.modal-header h2 {
    margin: 0;
    font-size: 18px;
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary, #64748B);
    padding: 4px;
}
.modal-body {
    padding: 24px;
}
.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 13px;
}
.settings-label {
    color: var(--text-secondary);
    font-weight: 500;
}
.settings-value {
    color: var(--text-primary);
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 12px;
}
.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}
.alert-info {
    background: #E6F7F6;
    color: #047A72;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.5;
}
.alert-danger {
    background: #FEF2F2;
    color: #DC2626;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-warning {
    background: #FFFBEB;
    color: #D97706;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}
.form-hint {
    display: block;
    font-size: 12px;
    color: var(--text-secondary, #64748B);
    margin-top: 6px;
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Image Popup ─────────────────────────────────── */
#image-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.2s ease;
}

.image-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
}

.image-popup-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-popup-content img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.image-popup-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.image-popup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.image-popup-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ══════════════════════════════════════════════════════════
   ROUTING UI STYLES
   ══════════════════════════════════════════════════════════ */

/* ── Chat Info Bar ─────────────────────────────────────── */
#chat-info-bar {
    padding: 6px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12px;
    min-height: 32px;
}

.btn-tag-add {
    background: none;
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 1px 8px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-tag-add:hover {
    border-color: #00B8A9;
    color: #00B8A9;
}

/* ── Canned Responses Bar ──────────────────────────────── */
#canned-bar {
    padding: 6px 12px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
}
#canned-bar .btn-ghost {
    transition: all 0.15s;
}
#canned-bar .btn-ghost:hover {
    background: var(--accent-blue-light);
    border-color: var(--accent-blue);
}

/* ── CSAT Stars ────────────────────────────────────────── */
.csat-star {
    font-size: 28px;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.3;
    transition: transform 0.15s, opacity 0.15s;
    padding: 4px;
}
.csat-star:hover {
    transform: scale(1.3) !important;
    opacity: 1 !important;
}

/* ── Operator Status Badges ────────────────────────────── */
.status-available { color: #10B981; }
.status-busy { color: #F59E0B; }
.status-away { color: #94A3B8; }
.status-dnd { color: #EF4444; }
.status-offline { color: #CBD5E1; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}
.status-dot.available { background: #10B981; }
.status-dot.busy { background: #F59E0B; }
.status-dot.away { background: #94A3B8; }
.status-dot.dnd { background: #EF4444; }
.status-dot.offline { background: #CBD5E1; }

/* ── SLA Badge Colors ──────────────────────────────────── */
.sla-ok { background: #D1FAE5; color: #065F46; }
.sla-at-risk { background: #FEF3C7; color: #92400E; }
.sla-breached { background: #FEE2E2; color: #991B1B; animation: slaPulse 2s ease-in-out infinite; }

@keyframes slaPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ── Tag Pills ─────────────────────────────────────────── */
.chat-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}
.chat-tag:hover {
    background: #FEE2E2;
    color: #991B1B;
}

/* ── Assign Operator List ──────────────────────────────── */
#assign-operators-list > div {
    transition: background 0.15s;
}
#assign-operators-list > div:hover {
    background: var(--bg-hover);
}
#assign-operators-list > div:last-child {
    border-bottom: none;
}

/* ── Canned Response List Items ────────────────────────── */
#canned-list > div:last-child {
    border-bottom: none;
}

/* ── Mobile Responsive for Routing UI ──────────────────── */
@media (max-width: 768px) {
    #chat-info-bar {
        padding: 4px 10px;
        font-size: 11px;
    }
    #canned-bar {
        padding: 4px 8px;
    }
    #canned-bar .btn-ghost {
        font-size: 11px !important;
        padding: 2px 6px !important;
    }
    .csat-star {
        font-size: 24px;
    }
}

/* ── Mobile chat list (<=768px) — vertical stack instead of side-by-side ── */
@media (max-width: 768px) {
    .chat-layout { flex-direction: column; }
    .chat-sidebar {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-light, var(--border));
    }
    .chat-main { flex: 1; min-height: 60vh; }
    /* iOS Safari zooms inputs <16px — force 16px */
    input.form-input, textarea.form-input, select.form-input { font-size: 16px; }
    /* Hide elements flagged desktop-only */
    .hide-on-mobile { display: none !important; }
    /* Touch targets min 44px */
    .nav-item, .btn, .chat-item { min-height: 44px; }
}

@media (max-width: 480px) {
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
    .sidebar { width: 260px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .card { padding: 12px; }
    .save-bar { left: 0; }
}

/* ── Contacts: responsive table + checkboxes ───────────────── */
@media (max-width: 768px) {
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrapper table {
        min-width: 700px;
    }
    .save-bar { left: 0; }
}
.contacts-table input[type="checkbox"],
.table input[type="checkbox"],
table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #00B8A9;
}

/* ── Disabled / readonly form fields ───────────────────────── */
.form-input[disabled], .form-input[readonly] {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    cursor: not-allowed;
    border-style: dashed;
}

/* ── Usage bars (settings subscription) ────────────────────── */
.usage-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    overflow: hidden;
}
.usage-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--accent-blue);
    transition: width 0.3s ease;
}
.usage-bar-fill.warning { background: #F59E0B; }
.usage-bar-fill.danger { background: #EF4444; }

/* ── Save bar (routing unsaved changes) ────────────────────── */
.save-bar {
    position: fixed;
    bottom: 0;
    left: 260px;
    right: 0;
    padding: 12px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    animation: slideUp 0.2s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ── Focus states ──────────────────────────────────────────── */
:focus-visible {
    outline: 2px solid #00B8A9;
    outline-offset: 2px;
}
.btn:focus-visible, .form-input:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 184, 169, 0.2);
}

/* ══════════════════════════════════════════════════════════════
   Dark Mode
   ══════════════════════════════════════════════════════════════ */

/* Shared dark-mode overrides — used by both @media and .dark-mode */

/* Auto dark mode via OS preference */
@media (prefers-color-scheme: dark) {
    :root:not(.light-mode) {
        --bg-primary: #0D1117;
        --bg-secondary: #161B22;
        --bg-tertiary: #21262D;
        --bg-hover: #1C2128;
        --bg-active: #2D333B;
        --text-primary: #E6EDF3;
        --text-secondary: #8B949E;
        --text-muted: #6E7681;
        --border-light: #21262D;
        --border: #30363D;
        --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 16px rgba(0,0,0,0.35);
        --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
        --shadow-xl: 0 16px 48px rgba(0,0,0,0.5);
        --accent-blue-light: rgba(0, 184, 169, 0.1);
        --accent-green-light: rgba(0, 196, 140, 0.1);
        --accent-blue-soft: rgba(0, 184, 169, 0.15);
        --accent-green-soft: rgba(0, 196, 140, 0.15);
    }
}

/* Manual dark mode class */
body.dark-mode {
    --bg-primary: #0D1117;
    --bg-secondary: #161B22;
    --bg-tertiary: #21262D;
    --bg-hover: #1C2128;
    --bg-active: #2D333B;
    --text-primary: #E6EDF3;
    --text-secondary: #8B949E;
    --text-muted: #6E7681;
    --border-light: #21262D;
    --border: #30363D;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.35);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.5);
    --accent-blue-light: rgba(0, 184, 169, 0.1);
    --accent-green-light: rgba(0, 196, 140, 0.1);
    --accent-blue-soft: rgba(0, 184, 169, 0.15);
    --accent-green-soft: rgba(0, 196, 140, 0.15);
}

/* Dark mode element overrides — apply to both auto and manual */
@media (prefers-color-scheme: dark) {
    :root:not(.light-mode) .card,
    :root:not(.light-mode) .stat-card {
        background: var(--bg-secondary);
        border-color: var(--border-light);
    }
    :root:not(.light-mode) .card:hover,
    :root:not(.light-mode) .stat-card:hover {
        box-shadow: var(--shadow-md);
    }
    :root:not(.light-mode) .integration-card {
        background: var(--bg-secondary);
        border-color: var(--border-light);
    }
    :root:not(.light-mode) .integration-card:hover {
        box-shadow: var(--shadow-md);
    }
    :root:not(.light-mode) .form-input,
    :root:not(.light-mode) .form-select,
    :root:not(.light-mode) select.form-input,
    :root:not(.light-mode) textarea.form-input,
    :root:not(.light-mode) .form-textarea {
        background: var(--bg-tertiary);
        border-color: var(--border);
        color: var(--text-primary);
    }
    :root:not(.light-mode) th {
        background: var(--bg-tertiary);
        color: var(--text-secondary);
    }
    :root:not(.light-mode) td {
        border-color: var(--border-light);
    }
    :root:not(.light-mode) tr:hover td {
        background: var(--bg-tertiary);
    }
    :root:not(.light-mode) .modal,
    :root:not(.light-mode) .confirm-modal {
        background: var(--bg-secondary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .modal-overlay,
    :root:not(.light-mode) .confirm-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
    :root:not(.light-mode) .chat-item:hover {
        background: var(--bg-tertiary);
    }
    :root:not(.light-mode) .chat-item.active {
        background: var(--accent-blue-light);
    }
    :root:not(.light-mode) .message-incoming {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .chat-message.incoming {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .btn-secondary {
        background: var(--bg-tertiary);
        border-color: var(--border);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .btn-ghost {
        color: var(--text-secondary);
    }
    :root:not(.light-mode) .btn-ghost:hover {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .btn-cancel {
        background: var(--bg-tertiary);
        color: var(--text-secondary);
    }
    :root:not(.light-mode) .btn-cancel:hover {
        background: var(--bg-active);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .choice-card {
        background: var(--bg-secondary);
        border-color: var(--border-light);
    }
    :root:not(.light-mode) .choice-card:hover {
        background: var(--accent-blue-light);
    }
    :root:not(.light-mode) .rule-card {
        background: var(--bg-secondary);
        border-color: var(--border-light);
    }
    :root:not(.light-mode) .stat-card-icon.blue { background: rgba(0, 184, 169, 0.12); }
    :root:not(.light-mode) .stat-card-icon.green { background: rgba(16, 185, 129, 0.12); }
    :root:not(.light-mode) .stat-card-icon.amber { background: rgba(217, 119, 6, 0.12); color: #FBBF24; }
    :root:not(.light-mode) .stat-card-icon.purple { background: rgba(124, 58, 237, 0.12); }
    :root:not(.light-mode) .stat-card-icon.red { background: rgba(220, 38, 38, 0.12); }
    :root:not(.light-mode) .empty-state-icon { color: var(--text-muted); }
    :root:not(.light-mode) code,
    :root:not(.light-mode) pre {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) img { opacity: 0.95; }
    :root:not(.light-mode) .chat-input {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .chat-list-search {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }
    :root:not(.light-mode) .emoji-picker {
        background: var(--bg-secondary);
        border-color: var(--border);
    }
    :root:not(.light-mode) .alert-info { background: rgba(0, 184, 169, 0.12); color: #5EEAD4; border-color: rgba(0, 184, 169, 0.2); }
    :root:not(.light-mode) .alert-danger { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
    :root:not(.light-mode) .alert-warning { background: rgba(245, 158, 11, 0.12); color: #FCD34D; border-color: rgba(245, 158, 11, 0.2); }
    :root:not(.light-mode) .alert-success { background: rgba(16, 185, 129, 0.12); color: #6EE7B7; border-color: rgba(16, 185, 129, 0.2); }
    :root:not(.light-mode) .alert-error { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
    :root:not(.light-mode) .auth-error { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
    :root:not(.light-mode) .badge-secondary { background: var(--bg-tertiary); color: var(--text-muted); }
    :root:not(.light-mode) .badge-success { background: rgba(16, 185, 129, 0.15); }
    :root:not(.light-mode) .badge-error,
    :root:not(.light-mode) .badge-danger { background: rgba(239, 68, 68, 0.15); }
    :root:not(.light-mode) .badge-warning { background: rgba(245, 158, 11, 0.15); }
    :root:not(.light-mode) .badge-info { background: rgba(0, 184, 169, 0.15); }
    :root:not(.light-mode) .badge-muted { background: var(--bg-tertiary); }
    :root:not(.light-mode) .badge-success { color: #34D399; }
    :root:not(.light-mode) .badge-error,
    :root:not(.light-mode) .badge-danger { color: #F87171; }
    :root:not(.light-mode) .badge-warning { color: #FBBF24; }
    :root:not(.light-mode) .badge-info { color: #5EEAD4; }
    :root:not(.light-mode) .status-dot.offline { background: #64748B; }
    :root:not(.light-mode) .status-dot.away { background: #94A3B8; }
    :root:not(.light-mode) [style*="border-radius:999px"][style*="background:"] { filter: brightness(1.3); }
    :root:not(.light-mode) .message-file-card { background: var(--bg-tertiary); }
    :root:not(.light-mode) .message-file { background: rgba(255, 255, 255, 0.06); }
    :root:not(.light-mode) .crm-dropdown-menu { background: var(--bg-secondary); border-color: var(--border); }
    :root:not(.light-mode) .crm-menu-item:hover { background: var(--bg-tertiary); }
    :root:not(.light-mode) .settings-row { background: var(--bg-tertiary); }
    :root:not(.light-mode) .chat-filter-btn { border-color: var(--border); color: var(--text-secondary); }
    :root:not(.light-mode) .chat-filter-btn:hover { background: var(--bg-tertiary); }
    :root:not(.light-mode) .chat-tag { background: var(--bg-tertiary); }
    /* Scrollbars */
    :root:not(.light-mode) ::-webkit-scrollbar-track { background: var(--bg-primary); }
    :root:not(.light-mode) ::-webkit-scrollbar-thumb { background: var(--bg-tertiary); }
    :root:not(.light-mode) ::-webkit-scrollbar-thumb:hover { background: #475569; }
}

/* Duplicate overrides for manual .dark-mode class */
body.dark-mode .card,
body.dark-mode .stat-card {
    background: var(--bg-secondary);
    border-color: var(--border-light);
}
body.dark-mode .card:hover,
body.dark-mode .stat-card:hover {
    box-shadow: var(--shadow-md);
}
body.dark-mode .integration-card {
    background: var(--bg-secondary);
    border-color: var(--border-light);
}
body.dark-mode .integration-card:hover {
    box-shadow: var(--shadow-md);
}
body.dark-mode .form-input,
body.dark-mode .form-select,
body.dark-mode select.form-input,
body.dark-mode textarea.form-input,
body.dark-mode .form-textarea { background: var(--bg-tertiary); border-color: var(--border); color: var(--text-primary); }
body.dark-mode th { background: var(--bg-tertiary); color: var(--text-secondary); }
body.dark-mode td { border-color: var(--border-light); }
body.dark-mode tr:hover td { background: var(--bg-tertiary); }
body.dark-mode .modal,
body.dark-mode .confirm-modal { background: var(--bg-secondary); color: var(--text-primary); }
body.dark-mode .modal-overlay,
body.dark-mode .confirm-overlay { background: rgba(0, 0, 0, 0.7); }
body.dark-mode .chat-item:hover { background: var(--bg-tertiary); }
body.dark-mode .chat-item.active { background: var(--accent-blue-light); }
body.dark-mode .message-incoming,
body.dark-mode .chat-message.incoming { background: var(--bg-tertiary); color: var(--text-primary); }
body.dark-mode .btn-secondary { background: var(--bg-tertiary); border-color: var(--border); color: var(--text-primary); }
body.dark-mode .btn-ghost { color: var(--text-secondary); }
body.dark-mode .btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }
body.dark-mode .btn-cancel { background: var(--bg-tertiary); color: var(--text-secondary); }
body.dark-mode .btn-cancel:hover { background: var(--bg-active); color: var(--text-primary); }
body.dark-mode .choice-card { background: var(--bg-secondary); border-color: var(--border-light); }
body.dark-mode .choice-card:hover { background: var(--accent-blue-light); }
body.dark-mode .rule-card {
    background: var(--bg-secondary);
    border-color: var(--border-light);
}
body.dark-mode .stat-card-icon.blue { background: rgba(0, 184, 169, 0.12); }
body.dark-mode .stat-card-icon.green { background: rgba(16, 185, 129, 0.12); }
body.dark-mode .stat-card-icon.amber { background: rgba(217, 119, 6, 0.12); color: #FBBF24; }
body.dark-mode .stat-card-icon.purple { background: rgba(124, 58, 237, 0.12); }
body.dark-mode .stat-card-icon.red { background: rgba(220, 38, 38, 0.12); }
body.dark-mode .empty-state-icon { color: var(--text-muted); }
body.dark-mode code,
body.dark-mode pre { background: var(--bg-tertiary); color: var(--text-primary); }
body.dark-mode img { opacity: 0.95; }
body.dark-mode .chat-input { background: var(--bg-tertiary); color: var(--text-primary); }
body.dark-mode .chat-list-search { background: var(--bg-tertiary); color: var(--text-primary); }
body.dark-mode .emoji-picker { background: var(--bg-secondary); border-color: var(--border); }
body.dark-mode .alert-info { background: rgba(0, 184, 169, 0.12); color: #5EEAD4; border-color: rgba(0, 184, 169, 0.2); }
body.dark-mode .alert-danger { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
body.dark-mode .alert-warning { background: rgba(245, 158, 11, 0.12); color: #FCD34D; border-color: rgba(245, 158, 11, 0.2); }
body.dark-mode .alert-success { background: rgba(16, 185, 129, 0.12); color: #6EE7B7; border-color: rgba(16, 185, 129, 0.2); }
body.dark-mode .alert-error { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
body.dark-mode .auth-error { background: rgba(220, 38, 38, 0.12); color: #FCA5A5; border-color: rgba(220, 38, 38, 0.2); }
body.dark-mode .badge-secondary { background: var(--bg-tertiary); color: var(--text-muted); }
body.dark-mode .badge-success { background: rgba(16, 185, 129, 0.2); color: #34D399; }
body.dark-mode .badge-error,
body.dark-mode .badge-danger { background: rgba(239, 68, 68, 0.2); color: #F87171; }
body.dark-mode .badge-warning { background: rgba(245, 158, 11, 0.2); color: #FBBF24; }
body.dark-mode .badge-info { background: rgba(0, 184, 169, 0.2); color: #5EEAD4; }
body.dark-mode .badge-muted { background: var(--bg-tertiary); }

/* ── Dark mode: status dots (routing operators) ──────── */
body.dark-mode .status-dot.offline { background: #64748B; }
body.dark-mode .status-dot.away { background: #94A3B8; }

/* ── Dark mode: platform-add-btn (integrations) ──────── */
body.dark-mode .platform-add-btn,
:root:not(.light-mode) .platform-add-btn {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-primary);
}
body.dark-mode .platform-add-btn:hover:not(.is-disabled),
:root:not(.light-mode) .platform-add-btn:hover:not(.is-disabled) {
    background: var(--bg-tertiary) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ── Dark mode: operator status badges (inline-styled) ──── */
body.dark-mode [style*="border-radius:999px"][style*="background:"] {
    filter: brightness(1.3);
}
body.dark-mode .message-file-card { background: var(--bg-tertiary); }
body.dark-mode .message-file { background: rgba(255, 255, 255, 0.06); }
body.dark-mode .crm-dropdown-menu { background: var(--bg-secondary); border-color: var(--border); }
body.dark-mode .crm-menu-item:hover { background: var(--bg-tertiary); }
body.dark-mode .settings-row { background: var(--bg-tertiary); }
body.dark-mode .chat-filter-btn { border-color: var(--border); color: var(--text-secondary); }
body.dark-mode .chat-filter-btn:hover { background: var(--bg-tertiary); }
body.dark-mode .chat-tag { background: var(--bg-tertiary); }
body.dark-mode ::-webkit-scrollbar-track { background: var(--bg-primary); }
body.dark-mode ::-webkit-scrollbar-thumb { background: var(--bg-tertiary); }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ── Theme Toggle Button ─────────────────────────────────────── */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 16px;
    flex-shrink: 0;
}
.theme-toggle:hover {
    background: rgba(255,255,255,0.2);
}

/* ══════════════════════════════════════════════════════════════
   Micro-interactions & Polish
   ══════════════════════════════════════════════════════════════ */

/* ── Loading Skeleton ────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Button Loading State ────────────────────────────────────── */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}
.btn.loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
}

/* ── Rule Cards (Automation) ──────────────────────────────────── */
.rule-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-left: 3px solid #00B8A9;
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 12px;
    transition: box-shadow 0.2s ease;
}

.rule-card:hover {
    box-shadow: var(--shadow-md);
}

.rule-card.rule-inactive {
    opacity: 0.6;
    border-left-color: var(--border);
}
