/* 
   WhatsApp CRM & AI Automation Design System
   Vanilla CSS with CSS Variables, Grid, Glassmorphism, and Animations.
*/

:root {
    /* Fonts */
    --font-primary: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    
    /* Layout Constants */
    --sidebar-width: 260px;
    --header-height: 70px;
    --sim-drawer-width: 380px;
}

/* DARK THEME TOKENS (DEFAULT) */
[data-theme="dark"] {
    --bg-app: hsl(222, 47%, 11%);
    --bg-surface: hsl(222, 47%, 15%);
    --bg-surface-glass: rgba(23, 32, 53, 0.7);
    --bg-surface-active: hsl(222, 47%, 20%);
    --bg-input: hsl(222, 47%, 9%);
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-strong: rgba(255, 255, 255, 0.15);
    
    --text-primary: hsl(210, 40%, 98%);
    --text-secondary: hsl(215, 20%, 75%);
    --text-muted: hsl(215, 15%, 55%);
    
    /* Core Brand Colors */
    --color-primary: hsl(250, 89%, 65%);
    --color-primary-hover: hsl(250, 89%, 70%);
    --color-primary-soft: rgba(99, 102, 241, 0.15);
    
    --color-accent: hsl(142, 70%, 45%); /* WhatsApp green */
    --color-accent-hover: hsl(142, 70%, 50%);
    --color-accent-soft: rgba(16, 185, 129, 0.15);

    --color-info: hsl(200, 95%, 50%);
    --color-warning: hsl(38, 92%, 50%);
    --color-danger: hsl(350, 89%, 60%);
    --color-danger-soft: rgba(239, 68, 68, 0.15);

    /* Message Bubbles Colors */
    --msg-inbound: hsl(222, 47%, 18%);
    --msg-outbound-agent: hsl(250, 80%, 30%);
    --msg-outbound-ai: hsl(142, 60%, 20%);
    --msg-outbound-auto: hsl(280, 60%, 25%);
    --msg-outbound-text: #fff;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
    --glow-primary: 0 8px 20px -6px hsla(250, 89%, 65%, 0.55);
    --glow-accent: 0 8px 20px -6px hsla(142, 70%, 45%, 0.5);
    --glass-blur: blur(12px);
}

/* LIGHT THEME TOKENS */
[data-theme="light"] {
    --bg-app: hsl(210, 40%, 96%);
    --bg-surface: hsl(0, 0%, 100%);
    --bg-surface-glass: rgba(255, 255, 255, 0.8);
    --bg-surface-active: hsl(210, 40%, 92%);
    --bg-input: hsl(210, 40%, 98%);
    
    --border-color: rgba(0, 0, 0, 0.08);
    --border-color-strong: rgba(0, 0, 0, 0.15);
    
    --text-primary: hsl(222, 47%, 12%);
    --text-secondary: hsl(215, 20%, 35%);
    --text-muted: hsl(215, 15%, 55%);
    
    --color-primary: hsl(250, 89%, 60%);
    --color-primary-hover: hsl(250, 89%, 55%);
    --color-primary-soft: rgba(99, 102, 241, 0.1);
    
    --color-accent: hsl(142, 70%, 40%);
    --color-accent-hover: hsl(142, 70%, 35%);
    --color-accent-soft: rgba(16, 185, 129, 0.1);

    --color-info: hsl(200, 95%, 40%);
    --color-warning: hsl(38, 92%, 45%);
    --color-danger: hsl(350, 89%, 55%);
    --color-danger-soft: rgba(239, 68, 68, 0.1);

    --msg-inbound: hsl(210, 40%, 90%);
    --msg-outbound-agent: hsl(250, 80%, 93%);
    --msg-outbound-ai: hsl(142, 60%, 92%);
    --msg-outbound-auto: hsl(280, 60%, 93%);
    /* Light theme's outbound bubbles are pale tints (93% lightness), not
       the dark/saturated colors dark theme uses — white text on them is
       almost unreadable. Use the same dark text as everything else. */
    --msg-outbound-text: hsl(222, 47%, 12%);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
    --glow-primary: 0 8px 20px -6px hsla(250, 89%, 60%, 0.35);
    --glow-accent: 0 8px 20px -6px hsla(142, 70%, 40%, 0.3);
    --glass-blur: blur(12px);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: inherit;
}

body {
    background-color: var(--bg-app);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: 15px;
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    transition: background-color var(--transition-normal);
}

/* Accessible keyboard focus (mouse/touch users never see this) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-item:focus-visible,
.kanban-card:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color-strong);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==========================================================================
   LAYOUT UTILITIES
   ========================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.app-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.app-main-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background-color: var(--bg-app);
}

.sub-view {
    animation: fadeIn var(--transition-normal) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   SIDEBAR COMPONENT
   ========================================================================== */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 10;
    flex-shrink: 0;
    transition: background-color var(--transition-normal);
}

.sidebar-brand {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.brand-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 18px;
    box-shadow: var(--glow-accent);
    flex-shrink: 0;
}

.brand-text h3 {
    font-size: 16px;
    font-weight: 600;
}

.brand-text span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.sidebar-menu {
    flex: 1;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    gap: 12px;
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item:hover {
    background-color: var(--bg-surface-active);
    color: var(--text-primary);
    padding-left: 20px;
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0.02) 100%);
    color: var(--color-primary);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px hsla(250, 89%, 65%, 0.15);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 4px;
    background-color: var(--color-primary);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 8px var(--color-primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: var(--glow-primary);
}

.user-info h4 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.user-info span {
    font-size: 11px;
    color: var(--text-muted);
}

.btn-logout {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all var(--transition-fast);
}

.btn-logout:hover {
    color: var(--color-danger);
    background-color: var(--color-danger-soft);
}

/* ==========================================================================
   APP HEADER COMPONENT
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-surface-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    gap: 12px;
    z-index: 20;
}

.header-left h2 {
    font-size: 20px;
    font-weight: 600;
}

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

/* ==========================================================================
   BUTTONS & INPUTS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover {
    filter: brightness(1.06);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.5);
}

.btn-accent {
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}
.btn-accent:hover {
    filter: brightness(1.06);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.5);
}

.btn-secondary {
    background-color: var(--bg-surface-active);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.btn-secondary:hover {
    background-color: var(--border-color-strong);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--color-danger) 0%, hsl(350, 89%, 48%) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}
.btn-danger:hover {
    filter: brightness(1.06);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.5);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color-strong);
    color: var(--text-primary);
}
.btn-outline:hover {
    background-color: var(--bg-surface-active);
    border-color: var(--color-primary);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-round {
    border-radius: 50%;
    width: 42px;
    height: 42px;
    padding: 0;
}

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

/* Leads bulk-action toolbar (multi-select assign/stage/export/delete). A
   dedicated block rather than reusing bare .form-control/.btn defaults —
   those have mismatched heights (selects ~40px, .btn-sm ~28px) which
   made this row look uneven. Everything here shares one fixed height so
   the two dropdowns and three buttons sit flush on one line. */
#leads-bulk-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: linear-gradient(135deg, hsla(250, 89%, 65%, 0.12) 0%, hsla(250, 89%, 65%, 0.04) 100%);
    border: 1px solid hsla(250, 89%, 65%, 0.35);
    border-left: 3px solid var(--color-primary);
}

#leads-bulk-toolbar .leads-bulk-count {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
}

#leads-bulk-toolbar .leads-bulk-count strong {
    color: var(--color-primary);
    font-size: 15px;
}

#leads-bulk-toolbar select.form-control,
#leads-bulk-toolbar .btn {
    height: 36px;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 13px;
}

#leads-bulk-toolbar select.form-control {
    padding-left: 12px;
    padding-right: 34px;
    background-position: right 10px center;
    background-size: 14px;
    border-radius: 8px;
    max-width: 170px;
}

#leads-bulk-toolbar .btn {
    border-radius: 8px;
    white-space: nowrap;
}

#leads-bulk-toolbar .leads-bulk-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    flex-shrink: 0;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background-color: var(--bg-surface-active);
    color: var(--text-primary);
}

.icon-btn-sm {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
}
.icon-btn-sm:hover {
    background-color: var(--bg-surface-active);
    color: var(--text-primary);
}

.link-btn {
    background: transparent;
    border: none;
    color: var(--color-primary);
    font-weight: 500;
    cursor: pointer;
    font-size: 13px;
}
.link-btn:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-control {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition-fast);
    width: 100%;
}
.form-control:focus {
    border-color: var(--color-primary);
}

textarea.form-control {
    resize: vertical;
}

/* Custom themed dropdown arrow — replaces the native browser arrow so
   <select> elements match the rest of the premium dark/light UI instead
   of falling back to OS-default styling. */
select.form-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 40px;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3E%3Cpath d='M5 7.5L10 12.5L15 7.5' stroke='%2394a3b8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
}
select.form-control:hover {
    border-color: var(--border-color-strong);
}
select.form-control:focus {
    border-color: var(--color-primary);
}
select.form-control option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

.input-icon-wrapper {
    position: relative;
    width: 100%;
}

.input-icon-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.input-icon-wrapper input {
    padding-left: 40px;
}

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

.radio-group {
    display: flex;
    gap: 16px;
}
.radio-group label {
    font-weight: normal;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ==========================================================================
   CARDS & GRIDS
   ========================================================================== */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: background-color var(--transition-normal), box-shadow var(--transition-fast), transform var(--transition-fast), border-color var(--transition-fast);
}

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

/* Table/list cards (.card-table) sit flush against surrounding content
   and hold a scrollable list, not a single glanceable stat — lifting
   them on hover reads as a layout jump rather than an affordance, so
   they opt back out of the generic .card hover above. */
.card-table:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--border-color);
}

.card-table {
    padding: 0;
    overflow: hidden;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card:has(.icon-blue):hover {
    box-shadow: 0 12px 30px rgba(59, 130, 246, 0.18), 0 0 12px rgba(59, 130, 246, 0.15);
    border-color: #3b82f6;
}

.stat-card:has(.icon-orange):hover {
    box-shadow: 0 12px 30px rgba(249, 115, 22, 0.18), 0 0 12px rgba(249, 115, 22, 0.15);
    border-color: #f97316;
}

.stat-card:has(.icon-red):hover {
    box-shadow: 0 12px 30px rgba(239, 68, 68, 0.18), 0 0 12px rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
}

.stat-card:has(.icon-green):hover {
    box-shadow: 0 12px 30px rgba(16, 185, 129, 0.18), 0 0 12px rgba(16, 185, 129, 0.15);
    border-color: #10b981;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.icon-blue { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.icon-orange { background: rgba(249, 115, 22, 0.15); color: #f97316; }
.icon-red { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.icon-green { background: rgba(16, 185, 129, 0.15); color: #10b981; }

.stat-content h3 {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.dashboard-charts-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.chart-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    flex: 1;
    min-width: 300px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.chart-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-color-strong);
}

.chart-card.flex-2 {
    flex: 2;
    min-width: 400px;
}

.card-header {
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chart-container {
    position: relative;
    height: 260px;
    width: 100%;
}

.stat-summary-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 10px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.summary-item span {
    color: var(--text-secondary);
}

.summary-item strong {
    font-size: 18px;
    color: var(--text-primary);
}

.summary-item.highlight {
    border-bottom: none;
    background: var(--color-primary-soft);
    padding: 12px;
    border-radius: 8px;
}

.summary-item.highlight span {
    color: var(--color-primary);
    font-weight: 600;
}
.summary-item.highlight strong {
    color: var(--color-primary);
    font-weight: 700;
}

/* ==========================================================================
   DATA TABLES & PACKAGES
   ========================================================================== */
.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.search-filters {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.sortable-th i.fa-sort {
    opacity: 0.4;
    margin-left: 4px;
    font-size: 11px;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th, .data-table td {
    padding: 14px 24px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table th {
    background-color: var(--bg-input);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 16px 24px;
    gap: 8px;
}

/* ==========================================================================
   BADGES & PILLS
   ========================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-primary { background-color: var(--color-primary-soft); color: var(--color-primary); }
.badge-accent { background-color: var(--color-accent-soft); color: var(--color-accent); }
.badge-danger { background-color: var(--color-danger-soft); color: var(--color-danger); }
.badge-warning { background-color: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-secondary { background-color: var(--bg-surface-active); color: var(--text-secondary); }
.badge-success { background-color: var(--color-accent-soft); color: var(--color-accent); }

/* Color utilities — referenced throughout inbox.js/contacts.js/automations.js
   for status icons (sent/delivered ticks, delete/archive actions, step
   type icons) but never had a defined rule. */
.text-green { color: var(--color-accent); }
.text-blue { color: var(--color-info); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }

.form-control-sm {
    padding: 6px 10px;
    font-size: 13px;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
}

/* ==========================================================================
   AGENT INBOX LAYOUT & VIEWS
   ========================================================================== */
.inbox-layout {
    display: flex;
    position: relative; /* anchors the profile panel overlay (.inbox-right) */
    height: calc(100vh - var(--header-height) - 48px); /* Account for padding */
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    background-color: var(--bg-surface);
}

/* Left panel: chats listing */
.inbox-left {
    width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background-color: var(--bg-surface);
}

.inbox-search {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.inbox-search i {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.inbox-search input {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    outline: none;
    color: var(--text-primary);
    padding: 10px 10px 10px 40px;
    border-radius: 10px;
    font-size: 14px;
}

.inbox-filters-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 4px;
    background-color: var(--bg-input);
    gap: 4px;
}

.filter-tab {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 0;
    cursor: pointer;
    border-radius: 6px;
    text-align: center;
    transition: all var(--transition-fast);
}

.filter-tab:hover {
    color: var(--text-primary);
}

.filter-tab.active {
    background-color: var(--bg-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

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

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

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

.chat-item.active {
    background-color: var(--color-primary-soft);
}

.chat-item.unread::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background-color: var(--color-primary);
    border-radius: 50%;
}

.chat-item-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--border-color-strong);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

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

.chat-item-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

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

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

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

.chat-item-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item-badge-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Center window: messages stream */
.inbox-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%; /* Propagate height from layout container */
    min-height: 0;
    background-color: var(--bg-input);
}

#chat-active-window {
    display: flex;
    flex-direction: column;
    height: 100%; /* Propagate height from inbox-center */
    min-height: 0;
}

.chat-header {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.chat-user-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.chat-title-info h3 {
    font-size: 15px;
    font-weight: 600;
}
.chat-title-info span {
    font-size: 12px;
    color: var(--text-muted);
}

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

.chat-messages-thread {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0; /* Constraints to enable scrolling */
}

/* Message Bubbles */
.msg-row {
    display: flex;
    width: 100%;
    animation: fadeInMsg 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-row.inbound {
    justify-content: flex-start;
}

.msg-row.outbound {
    justify-content: flex-end;
}

.msg-bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 16px;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: transform var(--transition-fast);
}

.msg-row.inbound .msg-bubble {
    background-color: var(--msg-inbound);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.msg-row.outbound .msg-bubble {
    border-bottom-right-radius: 4px;
}

.msg-row.outbound.sender-agent .msg-bubble {
    background: linear-gradient(135deg, var(--msg-outbound-agent) 0%, hsl(250, 80%, 35%) 100%);
    color: var(--msg-outbound-text);
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.2);
}

.msg-row.outbound.sender-ai .msg-bubble {
    background: linear-gradient(135deg, var(--msg-outbound-ai) 0%, hsl(142, 60%, 25%) 100%);
    color: var(--msg-outbound-text);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.2);
}

.msg-row.outbound.sender-automation .msg-bubble {
    background: linear-gradient(135deg, var(--msg-outbound-auto) 0%, hsl(280, 60%, 30%) 100%);
    color: var(--msg-outbound-text);
    box-shadow: 0 4px 14px rgba(168, 85, 247, 0.2);
}

.msg-content {
    font-size: 14px;
    word-break: break-word;
    white-space: pre-line;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    font-size: 10px;
    opacity: 0.7;
    margin-top: 2px;
}

.msg-row.outbound .msg-meta {
    color: var(--msg-outbound-text);
    opacity: 0.7;
}

.msg-row.inbound .msg-meta {
    color: var(--text-muted);
}

.msg-status-tick {
    display: inline-flex;
    font-size: 12px;
}

.msg-status-tick.blue {
    color: var(--color-info) !important;
}

.msg-sender-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
    opacity: 0.8;
}

/* Media previews inside messages */
.msg-media-preview {
    margin-bottom: 6px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 260px;
    border: 1px solid var(--border-color);
}

.msg-media-preview img {
    width: 100%;
    display: block;
    height: auto;
}

.audio-player-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    min-width: 200px;
}

.audio-player-wrapper button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: inherit;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.audio-waveform-sim {
    flex: 1;
    height: 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.audio-waveform-progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0%;
    background: currentColor;
    border-radius: 6px;
}

/* Composer */
.chat-composer {
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.composer-attachments {
    display: flex;
    gap: 8px;
    position: relative;
}

.composer-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.composer-preview {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer-preview-body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.composer-preview-body img {
    max-height: 96px;
    max-width: 140px;
    border-radius: 8px;
    object-fit: cover;
}

.composer-preview-body .composer-preview-file {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.composer-preview-body .composer-preview-file .file-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.composer-preview-body audio {
    flex: 1;
    height: 36px;
}

.composer-preview-caption {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 13px;
    outline: none;
}

.composer-preview-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.composer-input-wrapper textarea {
    flex: 1;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    resize: none;
    line-height: 20px;
    height: 40px;
    max-height: 120px;
}

.emoji-picker {
    position: absolute;
    bottom: 44px;
    left: 40px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color-strong);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    gap: 8px;
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.emoji-picker span {
    font-size: 20px;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.emoji-picker span:hover {
    transform: scale(1.2);
}

.quick-replies-wrapper {
    position: relative;
}

.quick-replies-dropdown {
    position: absolute;
    bottom: 36px;
    right: 0;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color-strong);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    width: 280px;
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
}

.reply-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color var(--transition-fast);
}
.reply-item:hover {
    background-color: var(--bg-surface-active);
}
.reply-item:last-child {
    border-bottom: none;
}

/* Right Panel: Customer Profile Details */
/* Contact info panel: like real WhatsApp Web, this is NOT a permanent
   third column. It stays hidden until the contact name/avatar in the
   chat header is clicked, then slides in as an overlay above the chat
   (never pushing the message column narrower), and closes via the X
   button, the Escape key, or a click on the backdrop. */
.inbox-right {
    width: 320px;
    max-width: 100%;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background-color: var(--bg-surface);
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform var(--transition-slow);
}

.inbox-right.open {
    transform: translateX(0);
}

/* Dims the chat behind the panel, and lets a click anywhere outside
   close it — same affordance WhatsApp Web uses. */
.inbox-right-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.28);
    z-index: 90;
}

.inbox-right-backdrop.open {
    display: block;
}

.chat-user-meta {
    cursor: pointer;
    border-radius: 10px;
    transition: background-color var(--transition-fast);
}

.chat-user-meta:hover {
    background-color: var(--bg-surface-active);
}

.profile-panel-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background-color: var(--bg-surface-active);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.profile-panel-close-btn:hover {
    background-color: var(--border-color-strong);
    color: var(--text-primary);
}

.profile-scroll {
    flex: 1;
    overflow-y: auto;
}

.profile-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 16px 20px;
    text-align: center;
    background:
        radial-gradient(120% 100% at 50% 0%, hsla(250, 89%, 65%, 0.16) 0%, transparent 60%),
        linear-gradient(180deg, hsla(250, 89%, 65%, 0.06) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-color);
}

.profile-avatar-ring {
    position: relative;
    width: 72px;
    height: 72px;
    margin-bottom: 14px;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--color-primary) 0%, hsl(265, 85%, 58%) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    box-shadow: var(--glow-primary), 0 0 0 3px var(--bg-surface);
    letter-spacing: 0.5px;
}

.profile-avatar-status {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--color-accent);
    border: 3px solid var(--bg-surface);
    box-shadow: 0 0 0 1px hsla(142, 70%, 45%, 0.4);
}

.profile-header h3 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    max-width: 100%;
    overflow-wrap: break-word;
}

.profile-company-badge {
    display: inline-flex;
    align-items: center;
    margin-top: 8px;
    padding: 3px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background-color: var(--bg-surface-active);
    border: 1px solid var(--border-color-strong);
    border-radius: 999px;
    letter-spacing: 0.2px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-section {
    padding: 18px 16px;
}

.border-top {
    border-top: 1px solid var(--border-color);
}

.profile-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.profile-section h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
}

/* Subtitle shown under the customer name (phone number, not a fake
   "Private Customer" placeholder) — only the real company badge shows
   when a contact actually has a company on file. */
.profile-subtitle-phone {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.profile-subtitle-phone i {
    color: var(--color-accent);
    font-size: 13px;
}

/* Collapsible accordion sections (Tags, Notes, Appointments, Orders,
   Activity) — premium compact panel instead of one long scroll. */
.profile-accordion {
    padding: 0;
}

.profile-accordion > summary {
    list-style: none;
    cursor: pointer;
    padding: 18px 16px;
    margin-bottom: 0;
    user-select: none;
    transition: background-color 0.15s ease;
}

.profile-accordion > summary::-webkit-details-marker {
    display: none;
}

.profile-accordion > summary:hover {
    background-color: var(--bg-surface-active);
}

.profile-accordion > summary h4 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile-accordion > summary h4 i {
    color: var(--color-primary);
    font-size: 12px;
    width: 14px;
    text-align: center;
}

.accordion-chevron {
    font-size: 11px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.profile-accordion[open] > summary .accordion-chevron {
    transform: rotate(180deg);
}

.profile-accordion > summary ~ * {
    padding-left: 16px;
    padding-right: 16px;
}

.profile-accordion > summary ~ *:last-child {
    padding-bottom: 18px;
}

.profile-tags-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    height: auto;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-primary);
    background: transparent;
    border: 1px dashed var(--border-color-strong);
    border-radius: 6px;
    padding: 4px 10px;
    margin-bottom: 8px;
    cursor: pointer;
}

.profile-tags-add-btn:hover {
    background-color: var(--bg-surface-active);
}

.profile-info-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}

.profile-info-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border-radius: 10px;
    transition: background-color var(--transition-fast);
}

.profile-info-list li:hover {
    background-color: var(--bg-surface-active);
}

.profile-info-list li i {
    color: var(--color-primary);
    background-color: var(--color-primary-soft);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.info-label {
    font-size: 10.5px;
    color: var(--text-muted);
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 1px;
}

/* Same size/color as .info-label but WITHOUT the uppercase transform —
   for rows that display real data (email, phone, agent name) rather than
   a section label. Using .info-label for both was forcing values like
   "talha@example.com" to render as "TALHA@EXAMPLE.COM". */
.info-row {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    margin-bottom: 1px;
}

.info-val {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.tag-pills-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-selector-wrapper {
    margin-top: 10px;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 8px;
    background-color: var(--bg-input);
}

.tag-checklist {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.tag-check-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.notes-feed {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 240px;
    overflow-y: auto;
}

.note-item {
    background-color: var(--bg-input);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.note-meta {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.note-body {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.chat-empty-state i {
    font-size: 64px;
    color: var(--border-color-strong);
    margin-bottom: 16px;
}

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

/* Typing loading state simulator */
.typing-indicator {
    align-self: flex-start;
    background-color: var(--msg-inbound);
    padding: 12px 18px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* ==========================================================================
   LEADS KANBAN BOARD SYSTEM
   ========================================================================== */
.kanban-board {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 12px;
    align-items: flex-start;
    height: calc(100vh - var(--header-height) - 120px);
}

.kanban-column {
    width: 280px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.kanban-column-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--border-color);
}

.kanban-column-header h4 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-primary);
}

.kanban-cards-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 150px;
}

.kanban-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    cursor: grab;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.kanban-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-4px) scale(1.01);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
}

.kanban-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.kanban-card-company {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.kanban-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 8px;
}

.kanban-card-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--color-accent);
}

.kanban-card-agent {
    font-size: 11px;
    color: var(--text-muted);
    background-color: var(--bg-surface-active);
    padding: 2px 6px;
    border-radius: 4px;
}

/* ==========================================================================
   AUTOMATION WORKFLOW BUILDER
   ========================================================================== */
.automations-list-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.automation-workflow-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color var(--transition-fast);
}
.automation-workflow-card:hover {
    border-color: var(--color-primary);
}

.workflow-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.workflow-card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.workflow-steps-summary {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--bg-input);
    padding: 12px;
    border-radius: 8px;
}

.workflow-step-summary-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.workflow-step-summary-item i {
    width: 14px;
    text-align: center;
}

.workflow-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

.switch-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.switch-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-toggle {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-color-strong);
    transition: .3s;
    border-radius: 34px;
}

.slider-toggle:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    transition: .3s;
    border-radius: 50%;
    background-color: #fff;
}

input:checked + .slider-toggle {
    background-color: var(--color-primary);
}

input:checked + .slider-toggle:before {
    transform: translateX(18px);
}

/* ==========================================================================
   SETTINGS COMPONENT
   ========================================================================== */
.settings-grid {
    display: flex;
    gap: 24px;
    height: calc(100vh - var(--header-height) - 90px);
}

.settings-nav-pane {
    width: 240px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: var(--bg-surface);
    padding: 16px 10px;
    /* On shorter viewports the fixed calc(100vh - header - 90px) height
       above underestimates real header height, so the pane can end up
       slightly taller than the visible area. The ancestor layout uses
       overflow:hidden, which silently clips the last tab button's
       rounded corner instead of scrolling. Scrolling internally (with
       min-height:0 so the flex item is actually allowed to shrink)
       keeps every tab reachable and its corners intact regardless of
       header height. */
    overflow-y: auto;
    min-height: 0;
}

.settings-tab-btn {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.settings-tab-btn:hover {
    background-color: var(--bg-surface-active);
    color: var(--text-primary);
}
.settings-tab-btn.active {
    background-color: var(--color-primary-soft);
    color: var(--color-primary);
    font-weight: 600;
}

.settings-content-pane {
    flex: 1;
    overflow-y: auto;
}

.settings-tab-content h3 {
    font-size: 18px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
    margin-bottom: 16px;
}

/* ==========================================================================
   MODAL DIALOG POPUPS
   ========================================================================== */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn var(--transition-fast) forwards;
}

.modal-dialog {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color-strong);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 40px);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: slideUp var(--transition-normal) forwards;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    max-height: 75vh;
    overflow-y: auto;
}

/* Every modal's action row (Save/Cancel, Confirm/Delete, ...) previously
   had no dedicated class, so each script styled its own buttons inline
   with slightly different spacing. This gives every popup a consistent,
   sticky footer: it stays pinned to the bottom of the dialog even when
   .modal-body scrolls, so the primary action is never scrolled out of
   view on a long form. */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background-color: var(--bg-surface);
    border-radius: 0 0 16px 16px;
}

.modal-footer.modal-footer-split {
    justify-content: space-between;
}

/* Confirmation dialog icon (Cancel follow-up / Cancel meeting / etc.) */
.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 22px;
}
.confirm-icon-danger {
    background-color: var(--color-danger-soft);
    color: var(--color-danger);
}

/* ==========================================================================
   WHATSAPP SIMULATION CONTROL PANEL DRAWER
   ========================================================================== */
.simulation-drawer {
    position: fixed;
    right: calc(-1 * var(--sim-drawer-width));
    top: 0;
    width: var(--sim-drawer-width);
    height: 100vh;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color-strong);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    display: flex;
    flex-direction: column;
    transition: right var(--transition-slow);
}

.simulation-drawer.open {
    right: 0;
}

.drawer-header {
    height: var(--header-height);
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-primary);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.sim-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ==========================================================================
   AUTHENTICATION VIEW STYLES
   ========================================================================== */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100vw;
    background-color: var(--bg-app);
    background-image: radial-gradient(circle at 15% 15%, var(--color-primary-soft), transparent 45%),
                       radial-gradient(circle at 85% 85%, var(--color-accent-soft), transparent 45%);
    overflow-y: auto;
    padding: 24px;
}

.auth-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    margin: auto;
}

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

.auth-logo i {
    font-size: 40px;
    width: 76px;
    height: 76px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-hover) 100%);
    color: #fff;
    box-shadow: var(--glow-accent);
    margin-bottom: 16px;
}

.auth-logo h2 {
    font-size: 24px;
    font-weight: 700;
}

.auth-logo p {
    font-size: 13px;
    color: var(--text-muted);
}

.error-msg {
    color: var(--color-danger);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 12px;
}

/* Notification Popups */
.bell-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background-color: var(--color-danger);
    border-radius: 50%;
}

.notification-bell-wrapper {
    position: relative;
}

.notification-dropdown {
    position: absolute;
    top: 44px;
    right: 0;
    width: 320px;
    max-width: calc(100vw - 24px);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color-strong);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: none;
    flex-direction: column;
}

.notification-dropdown.open {
    display: flex;
}

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

.dropdown-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.dropdown-list {
    max-height: 280px;
    overflow-y: auto;
}

.notification-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}
.notification-item:hover {
    background-color: var(--bg-surface-active);
}
.notification-item.unread {
    background-color: var(--color-primary-soft);
    font-weight: 500;
}
.notification-item-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
}

.empty-state {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Skeleton Loaders */
.skeleton-loader-chat {
    height: 76px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-surface-active) 50%, var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: loadingSkeleton 1.5s infinite;
}

@keyframes loadingSkeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Toast System */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
}

.toast {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color-strong);
    color: var(--text-primary);
    padding: 14px 20px;
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    max-width: 400px;
    transform: translateX(120%);
    animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideInToast {
    to { transform: translateX(0); }
}

.toast.toast-success { border-left: 4px solid var(--color-accent); }
.toast.toast-error { border-left: 4px solid var(--color-danger); }
.toast.toast-warning { border-left: 4px solid var(--color-warning); }
.toast.toast-info { border-left: 4px solid var(--color-info); }

/* Voice recording blinking animations */
.animate-pulse-voice {
    animation: pulseVoice 1.2s infinite ease-in-out;
}

@keyframes pulseVoice {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.15); color: hsl(350, 89%, 60%); }
}

.text-red {
    color: var(--color-danger) !important;
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET SUPPORT)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
    }
    
    .app-layout {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }
    
    .app-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-brand {
        height: 60px;
    }
    
    .sidebar-menu {
        flex-direction: row;
        overflow-x: auto;
        padding: 10px;
        gap: 8px;
    }
    
    .nav-item {
        padding: 8px 12px;
        font-size: 13px;
        white-space: nowrap;
    }
    
    .nav-item.active::before {
        left: 20%;
        top: auto;
        bottom: 0;
        width: 60%;
        height: 3px;
        border-radius: 4px 4px 0 0;
    }
    
    .sidebar-footer {
        display: none; /* Hide profile in sidebar footer on mobile */
    }
    
    .app-content-wrapper {
        height: auto;
        overflow: visible;
    }
    
    .app-main-content {
        padding: 12px;
        overflow-y: visible;
    }
    
    .inbox-layout {
        flex-direction: column;
        height: calc(100vh - 180px);
    }
    
    .inbox-left {
        width: 100%;
        height: 240px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .inbox-center {
        flex: 1;
    }
    
    .dashboard-charts-row {
        flex-direction: column;
    }
    
    .chart-card {
        width: 100% !important;
        min-width: 0 !important;
    }
    
    .settings-grid {
        flex-direction: column;
        height: auto;
    }
    
    .settings-nav-pane {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 8px;
    }
    
    .settings-tab-btn {
        white-space: nowrap;
    }
    
    .simulation-drawer {
        width: 100%;
        right: -100%;
    }

    .app-header {
        padding: 0 16px;
    }

    .header-right {
        gap: 8px;
    }

    .header-left h2 {
        font-size: 17px;
    }

    .view-header-row {
        align-items: stretch;
    }

    .view-header-row > .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Small phones: tighten spacing further and drop non-essential button labels */
@media (max-width: 480px) {
    .app-main-content {
        padding: 12px;
    }

    .analytics-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 12px;
    }

    .stat-card {
        padding: 14px;
        gap: 12px;
        border-radius: 14px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 17px;
    }

    .stat-value {
        font-size: 20px;
    }

    #toggle-sim-panel-btn .btn-label-text {
        display: none;
    }

    #toggle-sim-panel-btn {
        padding: 10px 12px;
    }

    .auth-card {
        padding: 28px 20px;
        border-radius: 16px;
    }

    .modal-header, .modal-body {
        padding: 16px;
    }

    .data-table th, .data-table td {
        padding: 12px 14px;
        font-size: 13px;
    }

    .kanban-column {
        width: 250px;
    }
}

/* Premium Segmented control buttons for Kanban / Table View */
.tabs-btn-group {
    background-color: var(--bg-surface-active);
    border: 1px solid var(--border-color);
    padding: 4px;
    border-radius: 12px;
    display: inline-flex;
    gap: 4px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background-color: var(--bg-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.view-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.mb-3 {
    margin-bottom: 16px !important;
}

/* ==========================================================================
   SPACING / LAYOUT UTILITIES
   Used throughout the JS-rendered modal forms (contacts, follow-ups,
   knowledge base, automations, campaigns, team, etc.) — kept centralized
   here so every view gets consistent spacing instead of each script
   re-declaring its own inline styles.
   ========================================================================== */
.mt-1 { margin-top: 4px !important; }
.mt-2 { margin-top: 8px !important; }
.mt-3 { margin-top: 16px !important; }
.mt-4 { margin-top: 24px !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-4 { margin-bottom: 24px !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.text-left { text-align: left !important; }
.d-flex { display: flex !important; }
.d-none { display: none !important; }

/* Follow-ups & Meetings additions */
.icon-purple { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }

.card-header.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-link-sm {
    font-size: 12px;
    color: var(--color-primary);
    text-decoration: none;
}

.btn-link-sm:hover {
    text-decoration: underline;
}

.flex-gap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.meeting-schedule-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.meeting-schedule-item:last-child {
    border-bottom: none;
}

.meeting-schedule-time {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 64px;
}

/* ==========================================================================
   TABLET BREAKPOINT (769px - 1024px)
   The app previously only had a desktop layout and a <=768px "mobile"
   layout (sidebar becomes a horizontal scrolling top bar). Everything
   in between — iPad-class tablets, small/split-screen laptop windows —
   fell back to the full desktop layout, where a fixed 260px sidebar eats
   a disproportionate share of a ~768-1024px viewport and squeezes
   grids/tables into a cramped middle column. This narrows the sidebar
   and lets grid components drop to fewer columns instead, while keeping
   the desktop (not horizontal-topbar) sidebar layout, which still fits
   comfortably at this width.
   ========================================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 210px;
    }

    .app-main-content {
        padding: 18px;
    }

    .sidebar-brand {
        padding: 16px;
    }

    .nav-item span {
        font-size: 13px;
    }

    .analytics-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 16px;
    }

    .dashboard-charts-row {
        flex-wrap: wrap;
    }

    .chart-card {
        min-width: 280px !important;
    }

    .modal-dialog {
        max-width: 90vw;
    }

    .simulation-drawer {
        width: min(var(--sim-drawer-width), 90vw);
    }
}

/* ==========================================================================
   POPUP / MODAL MOBILE POLISH
   The existing @media (max-width: 480px) block above already shrinks
   modal-header/modal-body padding, but left the dialog itself sized and
   positioned like a desktop popup (centered, rounded on all 4 corners,
   a fixed max-height that can strand a tall form's Save button below
   the fold with no way to reach it except scrolling the whole page
   behind the backdrop). On a phone a centered card is also the
   least ergonomic shape - a bottom/full sheet is far easier to reach
   one-handed and matches the native-app pattern people already know
   from WhatsApp itself.
   ========================================================================== */
@media (max-width: 640px) {
    .modal-backdrop {
        padding: 0;
        align-items: flex-end;
    }

    .modal-dialog {
        max-width: 100%;
        width: 100%;
        max-height: 92vh;
        border-radius: 20px 20px 0 0;
        border-bottom: none;
        animation: slideUpSheet var(--transition-normal) forwards;
    }

    @keyframes slideUpSheet {
        from { transform: translateY(100%); opacity: 0.4; }
        to { transform: translateY(0); opacity: 1; }
    }

    .modal-footer {
        border-radius: 0;
        /* Respect the home-indicator safe area on notched phones so the
           primary action button never sits underneath it. */
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .notification-dropdown {
        position: fixed;
        top: var(--header-height);
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
    }
}

/* ==========================================================================
   SPACING SCALE
   A formal scale to reach for in place of one-off pixel values —
   consistent 4px rhythm rather than the mix of 12/14/18/20/22px gaps
   scattered through component rules above. Additive: nothing existing
   was changed to use these, so there's zero risk of shifting any
   current layout; they're here for any new component/view going
   forward to stay visually consistent with the rest of the app.
   ========================================================================== */
:root {
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;
}
/* ==========================================================================
   URDU TEXT / RTL SUPPORT FIX
   ========================================================================== */
.urdu-text {
    direction: rtl !important;
    text-align: right !important;
    unicode-bidi: plaintext;
}

