:root {
    --wa-green: #25D366;
    --wa-teal: #128C7E;
    --wa-dark-teal: #075E54;
    --wa-light-green: #dcf8c6;
    --wa-bg: #eae6df;
    --wa-chat-bg: #efeae2;
    --surface: #ffffff;
    --surface-secondary: #f0f2f5;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --border-color: #e9edef;
    --danger: #ea4335;
    --warning: #f59e0b;
    --blue: #3b82f6;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--wa-bg);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    background: var(--surface);
}

/* TOP HEADER */
.top-header {
    height: 60px;
    background: var(--wa-dark-teal);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10;
}

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

.logo-icon {
    font-size: 28px;
    color: var(--wa-green);
}

.logo-text h2 {
    font-size: 17px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-cloud {
    background: rgba(37, 211, 102, 0.2);
    color: var(--wa-green);
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--wa-green);
}

.sub-text {
    font-size: 11px;
    opacity: 0.8;
}

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

.meta-status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.12);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-dot.green { background: #10b981; }
.status-dot.red { background: #ef4444; }

.webhook-pill {
    background: rgba(255, 255, 255, 0.12);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}
.webhook-pill:hover {
    background: rgba(255, 255, 255, 0.22);
}
.copy-icon {
    font-size: 11px;
    opacity: 0.7;
}

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

.global-ai-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.12);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #94a3b8;
    transition: .3s;
    border-radius: 20px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--wa-green); }
input:checked + .slider:before { transform: translateX(16px); }

/* MAIN BODY */
.main-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* SIDE NAVIGATION */
.side-nav {
    width: 70px;
    background: var(--surface-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 10px;
}

.nav-item {
    position: relative;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 56px;
    height: 52px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 500;
    transition: all 0.2s;
}
.nav-item i { font-size: 18px; }
.nav-item:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
}
.nav-item.active {
    background: white;
    color: var(--wa-teal);
    box-shadow: var(--shadow-sm);
}

.nav-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    background: var(--wa-green);
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 10px;
}

/* TAB CONTENT */
.tab-content {
    display: none;
    flex: 1;
    height: 100%;
    overflow: hidden;
}
.tab-content.active {
    display: flex;
}

/* INBOX LAYOUT */
#tab-inbox {
    display: none;
    flex: 1;
    height: 100%;
}
#tab-inbox.active {
    display: flex;
}

.inbox-sidebar {
    width: 380px;
    border-right: 1px solid var(--border-color);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-top {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

.search-bar {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}
.search-bar i { color: var(--text-secondary); font-size: 14px; }
.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    font-size: 13px;
}

.filter-pills {
    display: flex;
    gap: 6px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    overflow-x: auto;
}
.filter-pill {
    background: var(--surface-secondary);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.filter-pill:hover, .filter-pill.active {
    background: var(--wa-teal);
    color: white;
    border-color: var(--wa-teal);
}

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

/* CHAT ITEM CARD */
.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    gap: 12px;
    transition: background 0.15s;
    position: relative;
}
.chat-item:hover {
    background: var(--surface-secondary);
}
.chat-item.active {
    background: #f0f7f5;
    border-left: 4px solid var(--wa-teal);
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #d1d7db;
    color: #54656f;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: none;
}

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

.chat-top-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}
.chat-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-time {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-mid-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.intent-pill {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e2e8f0;
    color: #475569;
    font-weight: 600;
}
.intent-pill.price { background: #fee2e2; color: #dc2626; }
.intent-pill.urgent { background: #fef3c7; color: #b45309; }
.intent-pill.lead { background: #dcfce7; color: #15803d; }

.chat-ai-pill {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}
.chat-ai-pill.active { background: #ecfdf5; color: #059669; border: 1px solid #10b981; }
.chat-ai-pill.paused { background: #fef2f2; color: #b91c1c; border: 1px solid #f87171; }

.chat-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.unread-badge {
    background: var(--wa-green);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: 6px;
}

/* CHAT VIEWPORT */
.chat-viewport {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--wa-chat-bg);
    position: relative;
    height: 100%;
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}
.big-icon {
    font-size: 64px;
    color: var(--wa-green);
    margin-bottom: 16px;
}

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

/* CHAT HEADER */
.chat-header {
    height: 60px;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 5;
}

.chat-header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}
.user-meta .name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-meta h3 {
    font-size: 15px;
    font-weight: 600;
}
.intent-badge {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e2e8f0;
    font-weight: 600;
}
.phone-number {
    font-size: 12px;
    color: var(--text-secondary);
}

.btn-ai-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: all 0.2s;
}
.btn-ai-toggle.active {
    background: #10b981;
    color: white;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}
.btn-ai-toggle.paused {
    background: #f59e0b;
    color: white;
}

/* 24-HOUR WINDOW BANNER */
.meta-window-banner {
    padding: 6px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.3s;
}
.meta-window-banner.active-window {
    background: #ecfdf5;
    color: #065f46;
    border-bottom: 1px solid #a7f3d0;
}
.meta-window-banner.expired-window {
    background: #fef2f2;
    color: #991b1b;
    border-bottom: 1px solid #fecaca;
}

.btn-outline-white {
    background: white;
    border: 1px solid #dc2626;
    color: #dc2626;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
}

/* MESSAGES THREAD */
.messages-thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg-row {
    display: flex;
    width: 100%;
}
.msg-row.outbound {
    justify-content: flex-end;
}
.msg-row.inbound {
    justify-content: flex-start;
}

.msg-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    line-height: 1.45;
    position: relative;
    box-shadow: var(--shadow-sm);
    word-break: break-word;
}
.msg-row.outbound .msg-bubble {
    background: var(--wa-light-green);
    border-top-right-radius: 2px;
}
.msg-row.inbound .msg-bubble {
    background: white;
    border-top-left-radius: 2px;
}

.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.ai-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    color: #047857;
    background: rgba(16, 185, 129, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.template-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    color: #1e40af;
    background: #dbeafe;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.msg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.status-ticks {
    font-size: 11px;
}
.status-ticks.read { color: #34b7f1; }
.status-ticks.failed { color: var(--danger); }

/* AI TYPING BAR */
.ai-typing-bar {
    padding: 6px 16px;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--wa-teal);
    font-weight: 600;
    border-top: 1px solid var(--border-color);
}

/* SMART ACTION BAR */
.smart-action-bar {
    padding: 6px 16px;
    background: var(--surface-secondary);
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border-color);
}
.smart-action-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.smart-action-btn:hover {
    background: var(--wa-teal);
    color: white;
    border-color: var(--wa-teal);
}

/* CHAT INPUT BAR (AUTO-EXPANDING MULTI-LINE) */
.chat-input-bar {
    padding: 10px 16px;
    background: var(--surface-secondary);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border-color);
}
.chat-input-bar textarea {
    flex: 1;
    min-height: 54px;
    max-height: 220px;
    height: auto;
    padding: 12px 16px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    outline: none;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    overflow-y: auto;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-bar textarea.expanded-composer {
    height: 260px !important;
    max-height: 380px !important;
}
.chat-input-bar textarea:focus {
    border-color: var(--wa-teal);
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.12);
}

.btn-send {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    margin-bottom: 2px;
    border-radius: 50%;
    background: var(--wa-teal);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
}
.btn-send:hover {
    background: var(--wa-dark-teal);
}

/* BUTTONS */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.btn-primary {
    background: var(--wa-teal);
    color: white;
}
.btn-primary:hover {
    background: var(--wa-dark-teal);
}
.btn-outline {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.btn-outline:hover {
    background: var(--surface-secondary);
}
.btn-icon {
    padding: 8px 12px;
}
.btn-sm {
    padding: 4px 8px;
    font-size: 11px;
}

/* CONFIG PAGE / CARDS */
.config-page {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    background: var(--surface-secondary);
}

.page-header {
    margin-bottom: 24px;
}
.page-header.flex-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.page-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.page-header p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.card {
    background: white;
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}
.card.full-width {
    grid-column: 1 / -1;
}

.card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    font-size: 13px;
    outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--wa-teal);
}
.form-group small {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.badge-success-box {
    background: #ecfdf5;
    border: 1px solid #10b981;
    color: #065f46;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}

.test-feedback {
    font-size: 12px;
    font-weight: 600;
}
.test-feedback.success { color: #10b981; }
.test-feedback.error { color: var(--danger); }

.card-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
}
.save-status {
    font-size: 12px;
    font-weight: 600;
    color: #10b981;
}

/* TEMPLATES & BROADCAST */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.template-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.template-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.template-title {
    font-size: 14px;
    font-weight: 700;
}
.template-status {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
}
.template-status.APPROVED { background: #dcfce7; color: #15803d; }
.template-status.PENDING { background: #fef3c7; color: #b45309; }
.template-status.REJECTED { background: #fee2e2; color: #dc2626; }

.template-body {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--surface-secondary);
    padding: 10px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    line-height: 1.4;
    white-space: pre-wrap;
}

/* MODALS */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal.hidden { display: none; }

.modal-box {
    background: white;
    width: 480px;
    max-width: 90vw;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.close-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 12px 20px;
    background: var(--surface-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.template-preview-box {
    background: var(--wa-chat-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 10px;
    font-size: 12px;
}
.preview-label {
    font-weight: 700;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

/* VPS Steps */
.vps-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.step-item {
    background: var(--surface-secondary);
    padding: 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.step-item code {
    background: #1e293b;
    color: #38bdf8;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    word-break: break-all;
}

/* AI BUBBLE CORRECTION BUTTON */
.btn-bubble-correct {
    background: transparent;
    border: none;
    color: #059669;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.15s;
    margin-right: auto;
}
.btn-bubble-correct:hover {
    background: rgba(16, 185, 129, 0.15);
}

.corrections-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    background: white;
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.corrections-table th {
    background: var(--surface-secondary);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}
.corrections-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}
.correction-category {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: #e0f2fe;
    color: #0369a1;
    display: inline-block;
}

.security-log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 12px;
}
.security-badge {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
}
.security-badge.prompt_injection { background: #fee2e2; color: #b91c1c; }
.security-badge.off_topic { background: #fef3c7; color: #92400e; }

/* PHASE 1: NEEDS HUMAN BANNER, CRM SIDE PANEL & QUICK REPLIES */
.needs-human-banner {
    background: linear-gradient(90deg, #dc2626, #ea580c);
    color: white;
    padding: 8px 16px;
    font-size: 12.5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-body-split {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.chat-thread-col {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    position: relative;
}

.crm-side-panel {
    width: 300px;
    background: white;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.crm-panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-secondary);
}

.crm-panel-header h4 {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.crm-panel-body {
    padding: 14px 16px;
    overflow-y: auto;
    flex: 1;
}

.crm-panel-body .form-group {
    margin-bottom: 12px;
}

.crm-panel-body label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}

.crm-panel-body input,
.crm-panel-body select,
.crm-panel-body textarea {
    width: 100%;
    font-size: 12.5px;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.quick-replies-popup {
    position: absolute;
    bottom: 96px;
    left: 16px;
    right: 16px;
    max-width: 520px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.14);
    z-index: 30;
    overflow: hidden;
}

.qr-popup-header {
    padding: 8px 12px;
    background: var(--surface-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-secondary);
}

.btn-link {
    background: none;
    border: none;
    color: var(--wa-teal);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.qr-popup-list {
    max-height: 220px;
    overflow-y: auto;
}

.qr-item {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.15s;
}

.qr-item:hover {
    background: #f0fdf4;
}

.qr-item-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.qr-shortcut-tag {
    background: #dcfce7;
    color: #166534;
    font-family: monospace;
    font-size: 11.5px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 4px;
}

.qr-title-text {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-primary);
}

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

/* PHASE 2: STAFF PROFILE PILL, ASSIGNED AGENT & AUDIT LOG STYLES */
.staff-profile-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    padding: 5px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.staff-profile-pill:hover {
    background: rgba(255, 255, 255, 0.24);
}
.role-chip {
    background: #10b981;
    color: white;
    font-size: 9.5px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    letter-spacing: 0.3px;
}
.role-chip.agent-role {
    background: #3b82f6;
}

.assigned-agent-box {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: white;
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 18px;
}
.assigned-agent-box select {
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
}

.staff-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    color: #0369a1;
    background: #e0f2fe;
    padding: 2px 6px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.contact-agent-badge {
    font-size: 10px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
}

/* ==========================================
   PHASE 3: ANALYTICS DASHBOARD STYLES
   ========================================== */
.an-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.an-kpi-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.15s, box-shadow 0.15s;
}

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

.an-kpi-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.an-kpi-num {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 4px;
}

.an-kpi-sub {
    font-size: 11.5px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Bar Chart Container */
.an-bar-chart-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 180px;
    padding: 16px 8px 6px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow-x: auto;
}

.an-bar-col {
    flex: 1;
    min-width: 24px;
    max-width: 44px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    transition: opacity 0.15s;
}

.an-bar-col:hover {
    opacity: 0.85;
}

.an-bar-value {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 3px;
    height: 14px;
    line-height: 14px;
}

.an-bar-track {
    width: 100%;
    height: 130px;
    background: #e2e8f0;
    border-radius: 4px 4px 0 0;
    display: flex;
    flex-direction: column-reverse;
    overflow: hidden;
}

.an-bar-seg {
    width: 100%;
    transition: height 0.3s ease;
}

.an-bar-seg.inbound {
    background: #94a3b8;
}

.an-bar-seg.ai {
    background: #10b981;
}

.an-bar-seg.staff {
    background: #3b82f6;
}

.an-bar-label {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
    white-space: nowrap;
    text-align: center;
}

/* ==========================================
   PWA TOAST & MOBILE BUTTONS
   ========================================== */
.pwa-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: white;
    border: 1px solid #334155;
    border-radius: 30px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 99999;
    font-size: 13px;
    animation: pwaSlideUp 0.3s ease;
}
.pwa-toast-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
@keyframes pwaSlideUp {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.btn-mobile-back {
    display: none;
    background: transparent;
    border: none;
    font-size: 18px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px 10px 6px 2px;
    line-height: 1;
}

.crm-backdrop {
    display: none;
}

/* ==========================================
   RESPONSIVE MOBILE BREAKPOINT (<= 768px)
   ========================================== */
@media (max-width: 768px) {
    .app-container {
        height: 100dvh;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }

    /* Header adjustments on mobile */
    .top-header {
        height: 52px;
        padding: 0 10px;
    }
    .logo-area .logo-icon {
        font-size: 22px;
    }
    .logo-text h2 {
        font-size: 14px;
    }
    .logo-text .sub-text,
    .header-center {
        display: none !important;
    }
    .header-actions {
        gap: 6px;
    }
    .staff-profile-pill {
        padding: 3px 8px;
        font-size: 11.5px;
    }
    .global-ai-toggle {
        display: none !important;
    }

    /* Layout transforms: Bottom Navigation on mobile */
    .main-body {
        flex-direction: column-reverse;
        height: calc(100% - 52px);
        overflow: hidden;
    }

    .side-nav {
        width: 100%;
        height: 54px;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border-color);
        padding: 2px 4px;
        background: #0f172a;
        justify-content: space-around;
        align-items: center;
        flex-shrink: 0;
        z-index: 100;
    }

    .side-nav .nav-item {
        flex: 1;
        height: 48px;
        padding: 4px 2px;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2px;
        border-radius: 8px;
    }
    .side-nav .nav-item i {
        font-size: 16px;
    }
    .side-nav .nav-item span {
        font-size: 10px;
        font-weight: 500;
    }
    .side-nav .nav-badge {
        top: 2px;
        right: 18%;
    }

    /* Content Area full width */
    .tab-content {
        height: calc(100% - 54px);
        width: 100%;
    }

    /* INBOX TAB: Native-like List -> Chat Screen Transition */
    #tab-inbox {
        position: relative;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .inbox-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-right: none;
        z-index: 10;
        transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.24s ease;
        background: var(--surface);
    }

    .chat-viewport {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
        background: #efeae2;
    }

    /* When user opened a chat on mobile */
    #tab-inbox.mobile-chat-open .inbox-sidebar {
        transform: translateX(-25%);
        opacity: 0.6;
        pointer-events: none;
    }

    #tab-inbox.mobile-chat-open .chat-viewport {
        transform: translateX(0);
        z-index: 30;
    }

    #tab-inbox.mobile-chat-open .no-chat-selected {
        display: none !important;
    }

    /* Chat Header on mobile */
    .btn-mobile-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chat-header {
        height: 54px;
        padding: 0 10px;
    }
    .chat-header-user .user-meta h3 {
        max-width: 110px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 13.5px;
    }
    .chat-header-actions .assigned-agent-box {
        max-width: 90px;
        padding: 2px 6px;
    }
    .chat-header-actions .assigned-agent-box select {
        max-width: 70px;
        font-size: 11px;
    }
    .btn-ai-toggle {
        padding: 4px 8px;
        font-size: 11px;
    }
    .btn-ai-toggle span {
        display: none;
    }

    /* Chat Messages */
    .messages-thread {
        padding: 10px 10px 14px;
    }
    .msg-bubble {
        max-width: 86%;
        font-size: 13px;
        padding: 7px 10px;
    }

    /* Chat Actions Bar & Composer */
    .chat-actions-bar {
        padding: 4px 8px;
        gap: 6px;
        overflow-x: auto;
        white-space: nowrap;
    }
    .smart-action-btn {
        padding: 4px 8px;
        font-size: 11px;
        flex-shrink: 0;
    }
    #btnExpandComposer {
        display: none; /* Mobile keyboard handles scrolling naturally */
    }

    .chat-input-bar {
        padding: 6px 10px 10px;
    }
    .chat-input-bar textarea {
        font-size: 14px; /* Prevents auto-zoom on iOS Safari */
    }

    /* CRM Panel Mobile Bottom Sheet / Drawer */
    .crm-side-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        max-height: 80vh;
        border-radius: 18px 18px 0 0;
        z-index: 1000;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
        transform: translateY(0);
        transition: transform 0.26s cubic-bezier(0.16, 1, 0.3, 1);
        display: flex;
        flex-direction: column;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
    .crm-side-panel.hidden {
        transform: translateY(105%);
        display: flex !important;
        pointer-events: none;
    }
    .crm-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: block;
        backdrop-filter: blur(2px);
    }
    .crm-backdrop.hidden {
        display: none;
    }

    /* Quick replies popup on mobile */
    .quick-replies-popup {
        left: 10px;
        right: 10px;
        bottom: 60px;
        max-width: none;
    }

    /* Analytics page on mobile */
    .an-kpi-grid {
        grid-template-columns: 1fr;
    }
    .cards-grid {
        grid-template-columns: 1fr !important;
    }
    .an-bar-chart-wrap {
        height: 150px;
    }

    /* Modal adjustments on mobile */
    .modal-box {
        width: 94%;
        max-width: 94%;
        margin: auto;
        padding: 16px;
    }
}

.hidden { display: none !important; }
