/* ===================================================
   AI Control Centre — Design System (Dark Mode)
   =================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-base:     #0d0f14;
    --bg-surface:  #13161e;
    --bg-elevated: #1a1d28;
    --bg-hover:    #1e2230;
    --border:      #252836;
    --border-light:#2e3248;

    --text-primary:   #e8eaf2;
    --text-secondary: #8890a8;
    --text-muted:     #545c78;

    --accent:        #6366f1;
    --accent-hover:  #7577f3;
    --accent-glow:   rgba(99,102,241,0.18);
    --green:         #22d3a0;
    --green-glow:    rgba(34,211,160,0.15);
    --orange:        #f97316;
    --orange-glow:   rgba(249,115,22,0.15);
    --purple:        #a855f7;
    --purple-glow:   rgba(168,85,247,0.15);
    --red:           #f43f5e;

    --sidebar-w: 240px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow:    0 4px 24px rgba(0,0,0,0.35);
    --transition: 0.18s ease;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
}

/* ─── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 99px; }

/* ─── Sidebar ────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-logo {
    width: 40px; height: 40px;
    background: var(--accent-glow);
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.brand-name { display: block; font-weight: 700; font-size: 14px; color: var(--text-primary); }
.brand-sub  { display: block; font-size: 11px; color: var(--text-muted); }

.sidebar-nav {
    padding: 10px 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }

.badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 99px;
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.health-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.health-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-dot.offline { background: var(--red); }

/* ─── Main ──────────────────────────────────────── */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    max-width: calc(100vw - var(--sidebar-w));
}

/* ─── Tabs ──────────────────────────────────────── */
.tab { display: none; }
.tab.active { display: block; }

/* ─── Page Header ────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

/* ─── Stats Grid ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--border-light); }

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.stat-icon--blue   { background: var(--accent-glow); color: var(--accent); }
.stat-icon--green  { background: var(--green-glow); color: var(--green); }
.stat-icon--purple { background: var(--purple-glow); color: var(--purple); }
.stat-icon--orange { background: var(--orange-glow); color: var(--orange); }

.stat-value { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-label { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ─── Cards ──────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 900px) { .cards-row { grid-template-columns: 1fr; } }

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 22px;
}

.card-header { margin-bottom: 16px; }
.card-header h2 { font-size: 15px; font-weight: 600; }

/* ─── Buttons ────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 500;
    font-family: inherit;
    transition: background var(--transition), opacity var(--transition);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost  { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: rgba(244,63,94,0.12); color: var(--red); border: 1px solid rgba(244,63,94,0.25); }
.btn-danger:hover { background: rgba(244,63,94,0.2); }
.btn-full { width: 100%; justify-content: center; padding: 11px; }

.action-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

/* ─── Pipeline ───────────────────────────────────── */
.pipeline { display: flex; flex-direction: column; gap: 0; }
.pipeline-step { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.pipeline-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
    flex-shrink: 0;
}
.pipeline-label { font-size: 13px; font-weight: 500; }
.pipeline-sub   { font-size: 11px; color: var(--text-muted); }
.pipeline-line  { width: 2px; height: 18px; background: var(--border-light); margin-left: 4px; }

/* ─── Table ──────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; padding: 11px 14px;
    font-size: 11.5px; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text-primary);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.table-empty { text-align: center; color: var(--text-muted); padding: 40px !important; }

.status-tag {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 11.5px;
    font-weight: 600;
}
.status-tag.indexed   { background: var(--green-glow); color: var(--green); }
.status-tag.pending   { background: var(--orange-glow); color: var(--orange); }

.table-actions { display: flex; gap: 6px; }
.btn-icon {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: rgba(244,63,94,.12); color: var(--red); border-color: rgba(244,63,94,.3); }

/* ─── Chat ───────────────────────────────────────── */
.chat-wrap {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    max-height: 680px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin: auto;
}

.chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    line-height: 1.65;
    font-size: 13.5px;
    word-break: break-word;
    animation: fadeSlide 0.2s ease;
}

@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-bubble.user {
    background: var(--accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 3px;
}

.chat-bubble.ai {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 3px;
}

.chat-bubble.ai .bubble-meta {
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 8px;
    display: flex;
    gap: 10px;
}

.chat-bubble.error {
    background: rgba(244,63,94,0.1);
    border: 1px solid rgba(244,63,94,0.25);
    color: var(--red);
    align-self: flex-start;
}

.thinking {
    display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.thinking span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: blink 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: .2s; }
.thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity:.2; } 40% { opacity:1; } }

.chat-input-row {
    display: flex;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}
.chat-input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 14px;
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.chat-input:focus { border-color: var(--accent); }

/* ─── Settings ───────────────────────────────────── */
.settings-card h2 { font-size: 15px; margin-bottom: 6px; }
.settings-note { color: var(--text-muted); font-size: 12.5px; margin-bottom: 20px; }
.settings-note code { background: var(--bg-elevated); padding: 1px 5px; border-radius: 3px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .settings-grid { grid-template-columns: 1fr; } }

.setting-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.setting-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.setting-value { font-size: 13.5px; font-weight: 500; }
.setting-value.ok  { color: var(--green); }
.setting-value.bad { color: var(--red); }

.divider { height: 1px; background: var(--border); margin: 22px 0; }

.endpoint-list { display: flex; flex-direction: column; gap: 10px; }
.endpoint { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.method { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.method.post { background: rgba(99,102,241,.18); color: var(--accent); }
.method.get  { background: var(--green-glow); color: var(--green); }
.endpoint-desc { color: var(--text-muted); font-size: 12.5px; }
.endpoint code { font-size: 12.5px; background: var(--bg-elevated); padding: 2px 7px; border-radius: 4px; }

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(5,7,12,0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: modalIn 0.22s ease;
}
@keyframes modalIn {
    from { opacity:0; transform: translateY(-16px) scale(0.97); }
    to   { opacity:1; transform: translateY(0) scale(1); }
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; }
.modal-close:hover { color: var(--text-primary); }

.tab-toggle { display: flex; background: var(--bg-elevated); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 20px; gap: 3px; }
.toggle-btn {
    flex: 1; padding: 8px; border: none; border-radius: 5px;
    background: transparent; color: var(--text-secondary);
    cursor: pointer; font-size: 13px; font-family: inherit; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.toggle-btn.active { background: var(--bg-surface); color: var(--text-primary); box-shadow: 0 1px 4px rgba(0,0,0,0.3); }

/* ─── Form ───────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

.form-input, .form-textarea {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 13px;
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}
.form-input:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 120px; }

/* ─── Dropzone ───────────────────────────────────── */
.dropzone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-md);
    padding: 36px;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    color: var(--text-secondary);
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-glow); }
.dropzone svg { display: block; margin: 0 auto 12px; color: var(--text-muted); }
.dropzone p { font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.dropzone span { font-size: 11.5px; color: var(--text-muted); }

.file-chosen {
    background: var(--green-glow);
    border: 1px solid rgba(34,211,160,.25);
    color: var(--green);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    margin-top: 10px;
}

.modal-msg {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.modal-msg.success { background: var(--green-glow); border: 1px solid rgba(34,211,160,.25); color: var(--green); }
.modal-msg.error   { background: rgba(244,63,94,.1);  border: 1px solid rgba(244,63,94,.3);  color: var(--red); }

/* ─── Toast ──────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    font-size: 13.5px;
    box-shadow: var(--shadow);
    z-index: 9999;
    animation: toastIn .25s ease;
    transition: opacity .3s;
}
@keyframes toastIn {
    from { opacity:0; transform: translateY(10px); }
    to   { opacity:1; transform: translateY(0); }
}
.toast.success { border-color: rgba(34,211,160,.4); color: var(--green); }
.toast.error   { border-color: rgba(244,63,94,.4);  color: var(--red); }

/* ═══════════════════════════════════════════════════
   RESPONSIVE — Mobile-first overhaul
   ═══════════════════════════════════════════════════ */

/* ── Hamburger toggle button ─────────────────────── */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    line-height: 1;
    font-size: 22px;
    transition: color var(--transition);
}
.menu-toggle:hover { color: var(--accent); }

/* ── Sidebar overlay (mobile) ────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 90;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── Business dropdown always full-width ─────────── */
.biz-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ══════════════════════════════════════════════════════
   LIVE CHAT — WhatsApp-style two-panel layout
   ══════════════════════════════════════════════════════ */
.wa-layout {
    display: flex;
    height: calc(100vh - 145px);
    min-height: 500px;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg);
}

/* ── Left panel: session list ── */
.wa-left {
    width: 320px;
    min-width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
}
.wa-search {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.wa-search input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 13px;
    color: var(--text);
    outline: none;
}
.wa-search input:focus { border-color: var(--primary); }
.wa-sessions {
    flex: 1;
    overflow-y: auto;
}

/* Session list item */
.wa-session-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,.04);
    transition: background 0.15s;
    position: relative;
}
.wa-session-item:hover  { background: rgba(99,102,241,.08); }
.wa-session-item.active { background: rgba(99,102,241,.15); border-left: 3px solid var(--primary); }

.wa-session-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    position: relative;
}
.vis-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    position: absolute;
    bottom: 0;
    right: 0;
}
.vis-dot.online  { background: #22c55e; }
.vis-dot.idle    { background: #f59e0b; }
.vis-dot.away    { background: #f97316; }
.vis-dot.offline { background: #6b7280; }

.wa-session-info    { flex: 1; min-width: 0; }
.wa-session-name    { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-session-preview { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.wa-session-badges  { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.wa-session-time    { font-size: 10px; color: var(--text-muted); }
.wa-session-unread  {
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
}

/* ── Right panel: chat room ── */
.wa-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

/* Chat room header */
.wa-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.btn-back-sessions { display: none; padding: 6px 10px; }
.wa-chat-header .wa-session-avatar { width: 36px; height: 36px; font-size: 12px; }
.wa-header-actions { position: relative; display: flex; align-items: center; }
.wa-header-actions-menu { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; align-items: center; }
.wa-header-actions-menu .btn { font-size: 11px; padding: 5px 10px; }

/* Messages area */
.wa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg);
}

/* Day divider */
.wa-day-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
    font-size: 11px;
    color: var(--text-muted);
}
.wa-day-divider::before, .wa-day-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Message rows */
.wa-msg { display: flex; }
.wa-msg.visitor { justify-content: flex-start; }
.wa-msg.outgoing, .wa-msg.agent { justify-content: flex-end; }
.wa-msg.system { justify-content: center; }

/* Bubbles */
.wa-bubble {
    max-width: 72%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
    position: relative;
}
.wa-bubble.visitor  { background: var(--surface); border-bottom-left-radius: 3px; }
.wa-bubble.ai       { background: rgba(99,102,241,.18); border-bottom-right-radius: 3px; border: 1px solid rgba(99,102,241,.2); }
.wa-bubble.agent    { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.wa-bubble.system   { background: transparent; color: var(--text-muted); font-size: 11px; padding: 4px 10px; max-width: 90%; text-align: center; border-radius: 20px; border: 1px solid var(--border); }

.wa-bubble-sender { font-size: 10px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.wa-bubble-time   { font-size: 10px; color: var(--text-muted); margin-top: 5px; text-align: right; opacity: 0.7; }
.wa-bubble.agent .wa-bubble-time, .wa-bubble.agent .wa-bubble-sender { color: rgba(255,255,255,.7); }

/* Bubble markdown */
.wa-bubble p { margin-bottom: 6px; }
.wa-bubble p:last-child { margin-bottom: 0; }
.wa-bubble ul, .wa-bubble ol { padding-left: 18px; }
.wa-bubble li { margin-bottom: 3px; }
.wa-bubble code { background: rgba(0,0,0,.25); padding: 1px 4px; border-radius: 3px; font-family: monospace; font-size: 12px; }

/* Typing indicator */
.wa-typing-indicator { padding: 8px 16px; font-size: 11px; color: var(--text-muted); display: none; }
.wa-typing-dots { display: inline-flex; gap: 3px; margin-right: 6px; }
.wa-typing-dots span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); animation: typingBounce 1.2s infinite; }
.wa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.wa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-4px)} }

/* Input bar */
.wa-typing-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
}
.wa-typing-bar .form-input { border-radius: 20px; font-size: 13px; }

/* Scrollbar */
.wa-sessions::-webkit-scrollbar, .wa-chat-messages::-webkit-scrollbar { width: 4px; }
.wa-sessions::-webkit-scrollbar-thumb, .wa-chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Tablet (≤1024px) ────────────────────────────── */
@media (max-width: 1024px) {
    :root { --sidebar-w: 220px; }
    .main { padding: 24px 20px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Mobile (≤768px) ─────────────────────────────── */
@media (max-width: 768px) {
    /* Sidebar slides in from left */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 100;
        width: 260px;
    }
    .sidebar.open { transform: translateX(0); }

    /* Top bar gets hamburger */
    .menu-toggle { display: flex; align-items: center; justify-content: center; }

    /* Main takes full width */
    .main {
        margin-left: 0;
        max-width: 100%;
        padding: 20px 16px;
    }

    /* Mobile top bar */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px 16px;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 80;
    }
    .mobile-topbar-title {
        font-size: 15px;
        font-weight: 700;
        color: var(--text-primary);
        flex: 1;
    }

    /* Stats: 2 cols on mobile, 1 on very small */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .cards-row  { grid-template-columns: 1fr; }

    /* Page headers stack */
    .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .page-header h1 { font-size: 19px; }

    /* Cards */
    .card { padding: 16px; }
    .modal { padding: 20px; }

    /* Tables — horizontal scroll already set */
    .data-table th, .data-table td { padding: 10px 10px; font-size: 12.5px; }

    /* Live Chat mobile UI toggle */
    .wa-layout { 
        flex-direction: row !important; 
        position: relative; 
        height: calc(100vh - 120px) !important; 
        overflow: hidden; 
    }
    .wa-left {
        width: 100% !important;
        min-width: 100% !important;
        height: 100% !important;
        border-right: none !important;
    }
    .wa-right {
        position: absolute;
        top: 0; left: 0;
        width: 100% !important;
        height: 100% !important;
        z-index: 10;
        display: none !important;
    }
    .wa-layout.chat-open .wa-left { display: none !important; }
    .wa-layout.chat-open .wa-right { display: flex !important; }

    .btn-back-sessions { display: inline-flex !important; margin-right: 8px; }

    /* Wa Header Actions dropdown for mobile */
    .wa-header-mobile-toggle { display: inline-flex !important; }
    .wa-header-actions-menu {
        display: none !important;
        position: absolute;
        top: 100%;
        right: 0;
        margin-top: 8px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 8px;
        flex-direction: column;
        gap: 6px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 1000;
        min-width: 120px;
    }
    .wa-header-actions-menu .btn { width: 100%; justify-content: flex-start; }
    .wa-header-actions.open .wa-header-actions-menu { display: flex !important; }

    /* Plan grid */
    .plans-grid { grid-template-columns: 1fr; }

    /* Billing stats half-half on mobile */
    .billing-stats-grid { grid-template-columns: 1fr 1fr !important; }

    /* Buttons */
    .action-buttons { flex-wrap: wrap; }
    .btn { font-size: 13px; padding: 8px 14px; }

    /* Toast */
    .toast { left: 12px; right: 12px; bottom: 16px; text-align: center; }

    /* Grid-2 forms */
    .grid-2 { grid-template-columns: 1fr !important; }
}

/* ── Very small screens (≤480px) ─────────────────── */
@media (max-width: 480px) {
    .main { padding: 14px 12px; }
    .stats-grid { grid-template-columns: 1fr; }
    .billing-stats-grid { grid-template-columns: 1fr !important; }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 20px; }
    .page-header h1 { font-size: 17px; }
    .plans-grid { grid-template-columns: 1fr; }
    .data-table th, .data-table td { padding: 8px; font-size: 12px; }
    .modal { max-height: 95vh; }
    .dropzone { padding: 24px 16px; }
}

/* ===================================================
   Module 8 — Global Select / Dropdown Standardisation
   =================================================== */

/* Force all <select> elements to use our dark palette */
select,
select.form-input,
.form-input[type="select"],
.biz-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bg-elevated, #1a1d28) !important;
    color: var(--text-primary, #e8eaf2) !important;
    border: 1px solid var(--border, #252836) !important;
    border-radius: 6px;
    padding: 8px 32px 8px 10px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238890a8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.2s, background-color 0.2s;
}
select:focus,
select.form-input:focus,
.biz-select:focus {
    border-color: var(--accent, #6366f1) !important;
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow, rgba(99,102,241,0.18));
}
select option,
select.form-input option {
    background-color: #1a1d28;
    color: #e8eaf2;
}
/* Sidebar agent-status select */
#agentStatusSelect {
    background-color: var(--bg-elevated, #1a1d28) !important;
    color: var(--text-primary, #e8eaf2) !important;
    border-color: var(--border, #252836) !important;
    width: 100%;
}
/* .btn-danger for hard-delete etc. */
.btn-danger, button.btn-danger {
    background: #ef4444 !important;
    color: #fff !important;
    border: none;
}
.btn-danger:hover { background: #dc2626 !important; }

/* ===================================================
   Responsive Grid Utility Classes
   Use these instead of inline grid-template-columns
   =================================================== */

/* Two-column grid that stacks on mobile */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
/* Three-column grid that stacks on mobile */
.grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
}
/* Generic collapsible column used in JS-generated HTML */
.col-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.col-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

/* Plans grid defaults to 3 across */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin-bottom: 24px;
}

/* Billing stats defaults to 4 across */
.billing-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

/* ── Tablet (≤1024px) ─────────────── */
@media (max-width: 1024px) {
    .plans-grid           { grid-template-columns: repeat(2, 1fr); }
    .billing-stats-grid   { grid-template-columns: repeat(2, 1fr) !important; }
    .grid-3, .col-3       { grid-template-columns: 1fr 1fr; }
}

/* ── Mobile (≤768px) — stack everything to 1-column ─ */
@media (max-width: 768px) {
    /* All multi-column grids collapse to single column */
    .grid-2,
    .grid-3,
    .col-2,
    .col-3,
    .cards-row,
    .settings-grid,
    .plans-grid,
    .billing-stats-grid   { grid-template-columns: 1fr !important; }

    /* stats-grid: 2 cols on tablet, 1 on mobile */
    .stats-grid           { grid-template-columns: repeat(2, 1fr); }

    /* Inline style grids — catch-all via JS output */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Form rows wrap instead of overflow */
    .form-row, .form-row-2 {
        flex-direction: column !important;
    }

    /* Ensure all inline flex rows with fixed widths can wrap */
    [style*="display:flex"],
    [style*="display: flex"] {
        flex-wrap: wrap;
    }

    /* Action button bars wrap gracefully */
    .action-buttons,
    .table-actions       { flex-wrap: wrap; gap: 6px; }

    /* Ensure all tables scroll horizontally */
    .data-table          { min-width: 480px; }

    /* Make page-header stack vertically */
    .page-header         { flex-direction: column; gap: 10px; align-items: flex-start; }
    .page-header h1      { font-size: 19px; }

    /* Cards padding reduce on mobile */
    .card                { padding: 16px; }

    /* Modal full width */
    .modal               { padding: 18px; max-height: 95vh; }
    .modal-overlay       { padding: 10px; }

    /* Chat header actions wrap */
    .wa-header-actions   { flex-wrap: wrap; gap: 4px; }
    .wa-header-actions .btn { font-size: 11px; padding: 4px 8px; }
}

/* ── Small mobile (≤480px) ──────────── */
@media (max-width: 480px) {
    .main                { padding: 12px 10px; }
    .stats-grid          { grid-template-columns: 1fr; }
    .billing-stats-grid  { grid-template-columns: 1fr !important; }
    .stat-card           { padding: 12px; }
    .stat-value          { font-size: 20px; }
    .page-header h1      { font-size: 17px; }
    .plans-grid          { grid-template-columns: 1fr; }
    .data-table th,
    .data-table td       { padding: 8px; font-size: 12px; }
    .dropzone            { padding: 22px 14px; }
    .btn                 { font-size: 13px; padding: 8px 12px; }

    /* Tighten modal */
    .modal               { padding: 14px; }

    /* Inline 2-col grids */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

