:root {
    --bg: #0b141a;
    --bg-elevated: #111b21;
    --panel: #1b2730;
    --panel-soft: #202c33;
    --panel-strong: #23333c;
    --accent: #00a884;
    --accent-soft: rgba(0, 168, 132, 0.2);
    --text: #e9edef;
    --muted: #9fb0b9;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

* { scrollbar-width: thin; scrollbar-color: #41525d transparent; }
body {
    background: linear-gradient(180deg, #081116 0%, #0f171d 100%);
    color: var(--text);
    font-family: 'Manrope', sans-serif;
    font-size: 13px;
    min-height: 100vh;
}

a { text-decoration: none; }
.app-shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.app-main { padding: 14px 18px; }
.glass-panel {
    background: linear-gradient(180deg, rgba(32, 44, 51, 0.9), rgba(17, 27, 33, 0.94));
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}
.sidebar {
    padding: 14px 10px;
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(9, 18, 23, 0.98), rgba(14, 22, 28, 0.95));
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}
.brand-mark { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.brand-logo, .hero-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(0, 168, 132, 0.25), rgba(64, 128, 255, 0.22));
    color: #fff;
    font-size: 1rem;
}
.brand-title { font-weight: 700; font-size: 0.85rem; letter-spacing: 0.02em; }
.brand-subtitle, .eyebrow, .text-secondary { color: var(--muted) !important; font-size: 0.75rem; }
.sidebar .nav-link {
    color: var(--muted);
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    border-radius: 8px;
    margin-bottom: 2px;
    font-size: 0.82rem;
    transition: 150ms ease;
}
.sidebar .nav-link i { width: 16px; text-align: center; font-size: 0.85rem; }
.sidebar .nav-link.active, .sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}
.sidebar-foot { margin-top: auto; padding: 8px; }
.tiny-url { word-break: break-all; color: var(--muted); font-size: 0.7rem; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    margin-bottom: 12px;
}
.page-title { margin: 0; font-size: 1.1rem; font-weight: 700; }
.topbar-actions, .quick-actions, .filter-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-pill, .user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.06);
    font-size: 0.78rem;
}
.hero-banner, .section-head, .stat-card, .metric-row, .action-card, .campaign-card, .status-card, .user-row, .info-card { position: relative; overflow: hidden; }
.hero-banner {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 16px;
    margin-bottom: 14px;
}
.hero-banner h2 { margin: 0; font-weight: 700; font-size: 1.05rem; }
.hero-banner p { font-size: 0.8rem; color: var(--muted); margin: 4px 0 0; }
.section-head h3 { margin: 0; font-weight: 700; font-size: 0.95rem; }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.stat-card { padding: 12px 14px; }
.stat-card span { font-size: 0.75rem; color: var(--muted); }
.stat-card strong { display: block; font-size: 1.4rem; margin: 4px 0 2px; }
.stat-card small { font-size: 0.72rem; color: var(--muted); }
.dashboard-grid, .content-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 12px;
}
.dashboard-grid > .glass-panel, .content-grid > .glass-panel { padding: 14px; }
.activity-panel { grid-row: span 2; }
.chart-panel canvas { min-height: 220px; }
.metric-stack, .activity-feed, .campaign-list, .user-list { display: grid; gap: 8px; }
.metric-row, .user-row, .info-card, .campaign-card {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255,255,255,0.06);
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.action-card {
    padding: 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(0,168,132,0.08), rgba(255,255,255,0.03));
    border: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text);
    font-size: 0.82rem;
}
.action-card i { font-size: 1rem; color: var(--accent); }
.activity-item { display: flex; gap: 10px; align-items: flex-start; font-size: 0.8rem; }
.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    margin-top: 4px;
    background: linear-gradient(180deg, #00a884, #46c8a3);
    box-shadow: 0 0 0 3px rgba(0,168,132,0.15);
    flex-shrink: 0;
}

/* Chat */
.chat-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 240px;
    gap: 10px;
    min-height: calc(100vh - 120px);
}
.chat-sidebar, .chat-center, .contact-sidebar { overflow: hidden; display: flex; flex-direction: column; }
.panel-toolbar, .chat-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.conversation-list { overflow: auto; padding: 6px; }
.conversation-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: inherit;
    display: flex;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    margin-bottom: 3px;
    transition: 150ms ease;
    text-align: left;
    font-size: 0.82rem;
}
.conversation-item:hover, .conversation-item.active { background: rgba(255, 255, 255, 0.06); }
.conversation-avatar, .contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(0, 168, 132, 0.16);
    color: var(--accent);
    font-size: 0.85rem;
}
.conversation-body { min-width: 0; flex: 1; }
.conversation-top, .conversation-meta { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.conversation-preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-size: 0.78rem; }
.status-dot { width: 8px; height: 8px; border-radius: 999px; }
.status-online { background: #00a884; }
.status-assigned { background: #53a2ff; }
.status-closed { background: #667781; }
.unread-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    background: var(--accent);
    color: #041b14;
    font-size: 0.68rem;
    font-weight: 700;
    display: grid;
    place-items: center;
}
.chat-messages {
    flex: 1;
    overflow: auto;
    padding: 14px;
    background: linear-gradient(rgba(11,20,26,0.86), rgba(11,20,26,0.92));
}
.message-row { display: flex; margin-bottom: 8px; }
.message-row.own { justify-content: flex-end; }
.message-bubble {
    max-width: min(72%, 520px);
    border-radius: 10px;
    padding: 8px 10px 6px;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.message-bubble.sent {
    background: linear-gradient(180deg, #005c4b, #0a7b63);
    border-bottom-right-radius: 4px;
}
.message-bubble.received {
    background: #202c33;
    border-bottom-left-radius: 4px;
}
.message-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    font-size: 0.68rem;
    margin-top: 4px;
    color: rgba(233, 237, 239, 0.6);
}
.chat-input {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
}
.bot-banner {
    display: none;
    padding: 8px 12px;
    background: rgba(0,168,132,0.16);
    color: #7ce5c6;
    font-size: 0.78rem;
    border-bottom: 1px solid rgba(0,168,132,0.26);
}
.bot-banner.show { display: block; }
.contact-sidebar { padding: 14px; }
.contact-card { text-align: center; }
.contact-card .contact-avatar { margin: 0 auto 10px; width: 52px; height: 52px; }
.contact-empty, .empty-chat, .empty-state {
    min-height: 120px;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}
.filter-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 10px 0;
    flex-wrap: wrap;
}
.filter-tabs button, .day-pill span {
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.03);
    color: var(--muted);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.75rem;
}
.filter-tabs button.active {
    background: var(--accent-soft);
    color: #88f0ce;
    border-color: rgba(0,168,132,0.3);
}
.content-grid.two-col { grid-template-columns: 1.6fr 1fr; }
.table-dark { --bs-table-bg: transparent; --bs-table-border-color: rgba(255,255,255,0.06); }
.table > :not(caption) > * > * { padding: 0.5rem 0.5rem; color: var(--text); font-size: 0.82rem; }
.modal-content, .form-control, .form-select, .input-group-text {
    background-color: rgba(255,255,255,0.04) !important;
    border-color: rgba(255,255,255,0.08) !important;
    color: var(--text) !important;
    font-size: 0.85rem;
}
.form-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.form-control::placeholder { color: #7d8d97; }
.form-control:focus, .form-select:focus {
    box-shadow: 0 0 0 0.2rem rgba(0,168,132,0.15);
    border-color: rgba(0,168,132,0.4) !important;
}
.btn { font-size: 0.82rem; padding: 6px 14px; }
.btn-lg { font-size: 0.9rem; padding: 8px 18px; }
.btn-success {
    background: linear-gradient(135deg, #00a884, #17c296);
    border-color: transparent;
    color: #061711;
    font-weight: 700;
}
.btn-outline-light, .btn-ghost {
    color: var(--text);
    border-color: rgba(255,255,255,0.14);
    background: rgba(255,255,255,0.03);
}
.progress {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
}
.code-area { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.78rem; }
.day-pill { position: relative; overflow: hidden; }
.day-pill input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.day-pill input:checked + span {
    background: var(--accent-soft);
    color: #8ceacf;
    border-color: rgba(0,168,132,0.32);
}
.status-card, .qr-card { padding: 12px; border-radius: 10px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.06); }
.status-label { font-size: 1rem; font-weight: 700; }
.toast-stack {
    position: fixed;
    top: 14px;
    right: 14px;
    z-index: 1080;
    display: grid;
    gap: 6px;
}

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: #0b141a; }
.login-shell {
    width: min(900px, 100%);
    display: grid;
    grid-template-columns: 1.2fr 360px;
    gap: 16px;
    align-items: stretch;
}
.login-hero, .login-panel { padding: 24px; border-radius: 14px; }
.login-hero {
    background:
        radial-gradient(circle at top left, rgba(0,168,132,0.18), transparent 16rem),
        linear-gradient(180deg, rgba(17, 27, 33, 0.92), rgba(10, 16, 21, 0.96));
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.login-brand { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 20px; }
.login-brand h1 { font-size: 1.6rem; margin: 0 0 8px; line-height: 1.1; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 0.85rem; }
.hero-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hero-metric { padding: 12px; }
.hero-metric span { color: var(--muted); display: block; margin-bottom: 4px; font-size: 0.75rem; }
.hero-metric strong { font-size: 0.9rem; }
.login-panel { display: flex; flex-direction: column; justify-content: center; }
.login-panel-head h2 { font-weight: 700; margin-bottom: 6px; font-size: 1.1rem; }

.alert { font-size: 0.82rem; padding: 8px 12px; border-radius: 8px; }

/* Responsive */
@media (max-width: 1180px) {
    .app-shell, .chat-layout, .dashboard-grid, .content-grid.two-col, .login-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 4px; }
    .sidebar .nav-link { margin-bottom: 0; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
    .stats-grid, .hero-grid, .action-grid { grid-template-columns: 1fr; }
    .chat-layout { min-height: auto; }
    .chat-sidebar, .contact-sidebar { min-height: 260px; }
}

/* Fix overflow / scroll */
html, body { height: 100%; margin: 0; overflow: hidden; }
.app-shell { height: 100vh; overflow: hidden; }
.app-main { overflow-y: auto; height: 100vh; }
.sidebar { overflow-y: auto; overflow-x: hidden; }
.sidebar-foot .tiny-url { font-size: 0.65rem; overflow: hidden; text-overflow: ellipsis; }
.dashboard-grid { margin-bottom: 14px; }
.activity-feed { max-height: 300px; overflow-y: auto; }

/* Fix chart resize loop */
.chart-panel { position: relative; }
.chart-panel canvas { min-height: 0 !important; max-height: 200px; }
