/**
 * crm.css - Text-World Enterprise CRM & Support Suite
 * Ultra-fast, zero-overhead CSS with modern design tokens, Swiss/Bento grids, and responsive layout.
 */

:root {
    --primary: #16a34a; /* Text-World WhatsApp Green */
    --primary-hover: #15803d;
    --primary-dark: #064e3b;
    --primary-light: #dcfce7;
    --meta-blue: #0080fb;
    --meta-blue-light: #eff6ff;

    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    --danger: #ef4444;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --info: #0284c7;
    --info-light: #e0f2fe;

    --sidebar-width: 250px;
    --topbar-height: 60px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--slate-50);
    color: var(--slate-800);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.crm-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.crm-sidebar {
    width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--slate-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 40;
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--slate-200);
    gap: 10px;
}

.brand-logo {
    max-height: 32px;
    width: auto;
    object-fit: contain;
}

.mbp-badge-pill {
    display: inline-flex;
    align-items: center;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 9999px;
    gap: 4px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-title {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--slate-400);
    letter-spacing: 0.06em;
    padding: 10px 12px 4px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: var(--slate-600);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.15s ease;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--slate-100);
    color: var(--slate-900);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
}

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

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--slate-200);
    background: #ffffff;
}

.user-status-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--slate-50);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
}

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

.user-avatar-circle {
    width: 30px;
    height: 30px;
    border-radius: 9999px;
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.user-details {
    display: flex;
    flex-direction: column;
    font-size: 12px;
}

.user-name {
    font-weight: 600;
    color: var(--slate-800);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role-text {
    font-size: 10.5px;
    color: var(--slate-500);
}

.availability-toggle {
    cursor: pointer;
    background: none;
    border: none;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 9999px;
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 0 2px #dcfce7; }
.status-dot.offline { background: var(--slate-400); }

/* Main Content Area */
.crm-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--slate-50);
}

/* Topbar */
.crm-topbar {
    height: var(--topbar-height);
    background: #ffffff;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.page-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--slate-900);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline {
    background: #ffffff;
    border: 1px solid var(--slate-300);
    color: var(--slate-700);
}
.btn-outline:hover { background: var(--slate-50); border-color: var(--slate-400); }

.btn-danger { background: var(--danger); color: #ffffff; }
.btn-danger:hover { background: #dc2626; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* View Container */
.crm-view {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.metric-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
}

.metric-card.warning::before { background: var(--warning); }
.metric-card.danger::before { background: var(--danger); }
.metric-card.blue::before { background: var(--meta-blue); }
.metric-card.purple::before { background: #8b5cf6; }

.metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.metric-title { font-size: 12.5px; font-weight: 500; color: var(--slate-500); }
.metric-icon { font-size: 15px; color: var(--slate-400); }
.metric-value { font-size: 22px; font-weight: 700; color: var(--slate-900); margin-bottom: 2px; }
.metric-caption { font-size: 11px; color: var(--slate-500); }

/* Content Card & Tables */
.content-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-toolbar {
    padding: 12px 18px;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

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

.search-input {
    padding: 6px 12px 6px 30px;
    font-size: 12.5px;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius);
    width: 220px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') no-repeat 9px center;
}

.select-filter {
    padding: 6px 10px;
    font-size: 12.5px;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius);
    background-color: #ffffff;
    color: var(--slate-700);
}

.table-responsive { overflow-x: auto; }

.crm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    text-align: left;
}

.crm-table th {
    background: var(--slate-50);
    color: var(--slate-600);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--slate-200);
    white-space: nowrap;
}

.crm-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--slate-100);
    vertical-align: middle;
}

.crm-table tr:hover { background: #f8fafc; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-source-whatsapp { background: #dcfce7; color: #15803d; }
.badge-source-indiamart { background: #ffedd5; color: #c2410c; }
.badge-source-justdial { background: #fef3c7; color: #b45309; }
.badge-source-facebook { background: #dbeafe; color: #1d4ed8; }
.badge-source-website { background: #f3e8ff; color: #7e22ce; }
.badge-source-manual { background: var(--slate-100); color: var(--slate-700); }

.badge-status-new { background: #fee2e2; color: #b91c1c; }
.badge-status-contacted { background: #fef3c7; color: #b45309; }
.badge-status-qualified { background: #e0f2fe; color: #0369a1; }
.badge-status-proposal-sent { background: #f3e8ff; color: #7e22ce; }
.badge-status-negotiation { background: #fef3c7; color: #92400e; }
.badge-status-won { background: #dcfce7; color: #15803d; }
.badge-status-lost { background: var(--slate-200); color: var(--slate-600); }

.sla-pill {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 4px;
}
.sla-pill.breached { background: #fee2e2; color: #b91c1c; }
.sla-pill.normal { background: #f1f5f9; color: var(--slate-600); }

/* -------------------------------------------------------------
 * KANBAN PIPELINE BOARD
 * ------------------------------------------------------------- */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(7, minmax(260px, 1fr));
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 20px;
    align-items: start;
}

.kanban-column {
    background: var(--slate-100);
    border-radius: var(--radius);
    border: 1px solid var(--slate-200);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 140px);
}

.kanban-header {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--slate-300);
    background: #ffffff;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}

.kanban-col-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--slate-800);
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.kanban-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: 6px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kanban-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.kanban-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-900);
    margin-bottom: 2px;
}

.kanban-card-company {
    font-size: 11.5px;
    color: var(--slate-500);
    margin-bottom: 8px;
}

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

/* -------------------------------------------------------------
 * LIVE WHATSAPP INBOX
 * ------------------------------------------------------------- */
.wa-chat-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 120px);
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    overflow: hidden;
}

.wa-chat-sidebar {
    border-right: 1px solid var(--slate-200);
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

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

.wa-chat-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--slate-100);
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    gap: 10px;
    align-items: center;
}

.wa-chat-item:hover, .wa-chat-item.active {
    background: #f0fdf4;
}

.wa-chat-main {
    display: flex;
    flex-direction: column;
    background: #efeae2; /* Authentic WhatsApp chat wallpaper background */
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

.wa-chat-header {
    background: #ffffff;
    border-bottom: 1px solid var(--slate-200);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wa-message-feed {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wa-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    position: relative;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

.wa-bubble.inbound {
    align-self: flex-start;
    background: #ffffff;
    border-top-left-radius: 0;
}

.wa-bubble.outbound {
    align-self: flex-end;
    background: #d9fdd3;
    border-top-right-radius: 0;
}

.wa-bubble-time {
    font-size: 10px;
    color: var(--slate-400);
    text-align: right;
    margin-top: 4px;
}

.wa-chat-footer {
    background: #ffffff;
    border-top: 1px solid var(--slate-200);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* -------------------------------------------------------------
 * KRA & KPI DASHBOARD
 * ------------------------------------------------------------- */
.kra-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kra-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--slate-200);
    border-radius: 9999px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

/* Slide-Over Drawer */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 50;
    display: none;
    justify-content: flex-end;
}
.drawer-backdrop.active { display: flex; }

.drawer-panel {
    width: 620px;
    max-width: 90vw;
    background: #ffffff;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 25px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

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

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

/* Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-backdrop.active { display: flex; }

.modal-card {
    background: #ffffff;
    border-radius: var(--radius);
    width: 580px;
    max-width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--slate-200);
    background: var(--slate-50);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 12px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
}

.input-control {
    padding: 7px 10px;
    font-size: 13px;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius);
    font-family: inherit;
    outline: none;
}
.input-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* Proposal Builder embed */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}

.plan-card-selectable {
    border: 2px solid var(--slate-200);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.plan-card-selectable:hover { border-color: var(--primary); }
.plan-card-selectable.selected { border-color: var(--primary); background: #f0fdf4; }

/* Timeline */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    padding-left: 18px;
    margin-top: 14px;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 5px;
    width: 2px;
    background: var(--slate-200);
}

.timeline-item { position: relative; font-size: 12px; }
.timeline-dot {
    position: absolute;
    left: -18px;
    top: 3px;
    width: 10px;
    height: 10px;
    border-radius: 9999px;
    background: var(--primary);
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px var(--slate-300);
}

/* -------------------------------------------------------------
 * NOTIFICATION BELL & DROPDOWN
 * ------------------------------------------------------------- */
.notif-bell-btn {
    position: relative;
    padding: 6px 10px;
    color: var(--slate-700);
}

.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    min-width: 17px;
    height: 17px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    padding: 0 3px;
    animation: pulseBadge 2s infinite;
}

@keyframes pulseBadge {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.notif-dropdown-card {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 340px;
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
    z-index: 1000;
    overflow: hidden;
}

.notif-dropdown-header {
    padding: 10px 14px;
    background: var(--slate-50);
    border-bottom: 1px solid var(--slate-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notif-items-list {
    max-height: 380px;
    overflow-y: auto;
}

.notif-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--slate-100);
    cursor: pointer;
    transition: background 0.15s ease;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #f0fdf4; }
.notif-item.unread::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: 5px;
    flex-shrink: 0;
}

.notif-item-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-900);
    margin-bottom: 2px;
}

.notif-item-msg {
    font-size: 11px;
    color: var(--slate-600);
    margin-bottom: 4px;
    line-height: 1.35;
}

.notif-item-time {
    font-size: 10px;
    color: var(--slate-400);
}

/* Floating Real-time Toast Alerts */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast-card {
    pointer-events: auto;
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-left: 4px solid var(--primary);
    border-radius: 8px;
    padding: 12px 16px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    width: 320px;
    max-width: 90vw;
    animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

@keyframes slideInToast {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-card-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--slate-900);
    margin-bottom: 2px;
}

.toast-card-msg {
    font-size: 11.5px;
    color: var(--slate-600);
}

/* Teams Pod Cards */
.team-pod-card {
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

.team-pod-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.badge-status-demo {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}
