/* CRM Application Modern Design System */

:root {
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #0f172a;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.4;
    font-size: 0.8125rem;
    min-height: 100vh;
    display: flex;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--primary-hover);
}

/* Icon System */
.icon {
    width: 1.15rem;
    height: 1.15rem;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.badge-icon {
    width: 0.85rem;
    height: 0.85rem;
    margin-right: 0.35rem;
    display: inline-block;
    vertical-align: middle;
}

.alert-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.65rem;
    flex-shrink: 0;
}

/* Layout Architecture (Fixed Sidebar & Topbar, Scrollable Content) */
.app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Fixed Sidebar Component */
.sidebar {
    width: 200px;
    height: 100vh;
    background-color: var(--bg-sidebar);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.22s ease-in-out;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    padding: 1rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 800;
    font-size: 1.2rem;
    color: #ffffff;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #1e293b;
    position: sticky;
    top: 0;
    background-color: var(--bg-sidebar);
    z-index: 10;
    white-space: nowrap;
}

.sidebar-brand .brand-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: #818cf8;
}

.sidebar-nav {
    padding: 0.75rem 0.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-section-title {
    font-size: 0.675rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    padding: 0.65rem 0.5rem 0.25rem 0.5rem;
    white-space: nowrap;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.65rem;
    color: #94a3b8;
    font-size: 0.785rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
    white-space: nowrap;
}

.sidebar-link:hover, .sidebar-link.active {
    color: #ffffff;
    background-color: #1e293b;
}

.sidebar-link.active {
    background-color: var(--primary);
    color: #ffffff;
}

.sidebar-footer {
    padding: 0.75rem 0.5rem;
    border-top: 1px solid #1e293b;
    font-size: 0.725rem;
    color: #64748b;
    text-align: center;
    background-color: var(--bg-sidebar);
    white-space: nowrap;
}

/* Sidebar Toggle Button in Topbar */
.sidebar-toggle-btn {
    background: #ffffff;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
    background-color: #f1f5f9;
    color: var(--text-primary);
    border-color: #cbd5e1;
}

/* Collapsed Sidebar Rules */
.sidebar-collapsed .sidebar {
    width: 68px;
}

.sidebar-collapsed .sidebar-brand span,
.sidebar-collapsed .sidebar-section-title,
.sidebar-collapsed .sidebar-link span:not(.icon):not(.badge),
.sidebar-collapsed .sidebar-footer {
    display: none !important;
}

.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 1.25rem 0.5rem;
}

.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 0.75rem 0.5rem;
    position: relative;
}

.sidebar-collapsed .sidebar-link .icon {
    width: 1.3rem;
    height: 1.3rem;
}

.sidebar-collapsed .sidebar-link .badge {
    position: absolute;
    top: 4px;
    right: 6px;
    margin-left: 0 !important;
    font-size: 0.6rem;
    padding: 0.1rem 0.3rem;
}

/* Hover Tooltips for Collapsed Sidebar Links */
.sidebar-collapsed .sidebar-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    background-color: #0f172a;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.65rem;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 999;
}

.sidebar-collapsed .sidebar-link:hover::after {
    opacity: 1;
}

/* Main Content Wrapper */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
}

/* Fixed Topbar Header */
.topbar {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.65rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    min-height: 58px;
    flex-shrink: 0;
    z-index: 90;
}

.topbar-search {
    position: relative;
    width: 320px;
}

.topbar-search .icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    width: 1.1rem;
    height: 1.1rem;
    pointer-events: none;
}

.topbar-search input {
    width: 100%;
    padding: 0.55rem 0.85rem 0.55rem 2.4rem;
    font-size: 0.875rem;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #f8fafc;
    color: #0f172a;
    transition: all 0.15s ease;
}

.topbar-search input:focus {
    outline: none;
    background-color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

/* Notification Bell Dropdown */
.notif-wrapper {
    position: relative;
}

.notif-bell-btn {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.notif-bell-btn:hover {
    background-color: #eef2ff;
    color: var(--primary);
    border-color: #c7d2fe;
}

.notif-bell-btn .icon {
    width: 1.25rem;
    height: 1.25rem;
}

.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: var(--danger);
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 1.15rem;
    height: 1.15rem;
    padding: 0 0.2rem;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.notif-dropdown {
    position: absolute;
    right: 0;
    top: 2.5rem;
    width: 320px;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 500;
    overflow: hidden;
}

.notif-dropdown.active {
    display: block;
}

.notif-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.85rem;
    background-color: #f8fafc;
}

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

.notif-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: block;
    color: var(--text-primary);
    font-size: 0.825rem;
    transition: background 0.15s ease;
}

.notif-item:hover {
    background-color: #f8fafc;
}

.notif-item.unread {
    background-color: #eef2ff;
}

/* Page Container (Scrollable Content Body) */
.content-body {
    padding: 1.15rem 1.25rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Card Component */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #ffffff;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-body {
    padding: 1.5rem;
}

/* Stats Cards Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    }
}

.stat-card {
    background: #ffffff;
    padding: 0.85rem 0.9rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    border-color: #c7d2fe;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.08);
}

.stat-icon-wrapper {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-wrapper.indigo { background: #e0e7ff; color: #4338ca; }
.stat-icon-wrapper.cyan { background: #cffafe; color: #0891b2; }
.stat-icon-wrapper.amber { background: #fef3c7; color: #d97706; }
.stat-icon-wrapper.emerald { background: #dcfce7; color: #16a34a; }
.stat-icon-wrapper.rose { background: #ffe4e6; color: #dc2626; }

.stat-val {
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-lbl {
    font-size: 0.775rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Pill Badges & Phase 1 Extensions */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    text-transform: capitalize;
}

.badge-admin { background-color: #e0e7ff; color: #3730a3; }
.badge-manager { background-color: #dbeafe; color: #1e40af; }
.badge-agent { background-color: #f1f5f9; color: #334155; border: 1px solid #cbd5e1; }

.badge-status-new { background-color: #dbeafe; color: #1e40af; }
.badge-status-contacted { background-color: #e0e7ff; color: #3730a3; }
.badge-status-follow-up { background-color: #fef3c7; color: #92400e; }
.badge-status-interested { background-color: #cffafe; color: #155e75; }
.badge-status-closed { background-color: #dcfce7; color: #166534; }
.badge-status-lost { background-color: #ffe4e6; color: #991b1b; }

.badge-score-hot { background-color: #ffe4e6; color: #991b1b; font-weight: 700; }
.badge-score-warm { background-color: #fef3c7; color: #92400e; font-weight: 700; }
.badge-score-cold { background-color: #dbeafe; color: #1e40af; font-weight: 700; }

.badge-duplicate { background-color: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }

.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.45rem;
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 0.69rem;
    font-weight: 500;
    line-height: 1.25;
}

/* Source Channel Badges */
.source-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.725rem;
    font-weight: 600;
    line-height: 1.2;
    border: 1px solid transparent;
}
.source-google { background-color: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.source-whatsapp { background-color: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.source-meta { background-color: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
.source-call { background-color: #fcf4ff; color: #7e22ce; border-color: #f5d0fe; }
.source-manual { background-color: #f8fafc; color: #475569; border-color: #cbd5e1; }
.source-default { background-color: #f1f5f9; color: #334155; border-color: #cbd5e1; }

/* Bulk Action Toolbar */
.bulk-toolbar {
    background-color: #eef2ff;
    border: 1px solid #c7d2fe;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

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

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
}

.table th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    padding: 0.55rem 0.5rem;
    font-size: 0.725rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 0.55rem 0.5rem;
    font-size: 0.785rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color 0.12s ease;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-primary { background-color: var(--primary); color: #ffffff; }
.btn-primary:hover { background-color: var(--primary-hover); color: #ffffff; }
.btn-secondary { background-color: #ffffff; border-color: var(--border-color); color: var(--text-primary); }
.btn-secondary:hover { background-color: #f1f5f9; }
.btn-success { background-color: var(--success); color: #ffffff; }
.btn-success:hover { background-color: #15803d; }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.75rem; white-space: nowrap; }
.btn-block { width: 100%; }

/* Form Controls */
.form-group { margin-bottom: 0.85rem; }
.form-label { display: block; font-weight: 600; font-size: 0.775rem; color: var(--text-primary); margin-bottom: 0.25rem; white-space: nowrap; }
.input-icon-group {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.input-icon-group .icon-left {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    z-index: 2;
    width: 1.1rem;
    height: 1.1rem;
}

.input-icon-group .btn-eye-toggle {
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 0.3rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.input-icon-group .btn-eye-toggle:hover {
    color: var(--text-primary);
    background-color: #f1f5f9;
}

.form-input, .form-select {
    width: 100%;
    padding: 0.45rem 0.65rem;
    font-size: 0.8125rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all 0.15s ease;
}

.input-icon-group .form-input {
    padding-left: 2.35rem;
}

.input-icon-group .form-input.has-toggle {
    padding-right: 2.6rem;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* Modals Architecture (Fixed Height & Internal Scrolling) */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 1.5rem;
}
.modal-backdrop.active {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}
.modal {
    background: #ffffff;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}
.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.modal-title { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
.modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1;
    max-height: 65vh;
}
.modal-footer {
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background-color: #f8fafc;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Tabs Component (Single Line Compact Layout) */
.tab-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.775rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
    text-decoration: none;
}
.tab-link:hover, .tab-link.active {
    background-color: var(--primary-light);
    color: var(--primary);
}

.nav-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: #ffffff;
    padding: 0 1rem;
    gap: 1rem;
    overflow-x: auto;
}
.tab-btn {
    padding: 0.65rem 0;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
}
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-content { display: none; padding: 1.5rem; }
.tab-content.active { display: block; }

/* WhatsApp Chat Interface */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 420px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: #efeae2;
    overflow: hidden;
}
.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.chat-bubble {
    max-width: 75%;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    line-height: 1.4;
    position: relative;
}
.chat-bubble.outbound {
    align-self: flex-end;
    background-color: #d9fdd3;
    color: #111b21;
    border-top-right-radius: 0;
}
.chat-bubble.inbound {
    align-self: flex-start;
    background-color: #ffffff;
    color: #111b21;
    border-top-left-radius: 0;
}
.chat-time {
    font-size: 0.675rem;
    color: #667781;
    text-align: right;
    margin-top: 0.25rem;
}
.chat-input-area {
    padding: 0.75rem;
    background-color: #f0f2f5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Timeline Feed */
.timeline {
    position: relative;
    padding-left: 1.5rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--border-color);
}
.timeline-item {
    position: relative;
    margin-bottom: 1.25rem;
}
.timeline-dot {
    position: absolute;
    left: -1.5rem;
    top: 0.2rem;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    background-color: var(--primary);
    border: 2px solid #ffffff;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #ffffff;
}

@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; }
}
