/* Global Variables & Colors (Classic Blue & White Theme) */
:root {
    --primary-color: #1a73e8;
    --primary-hover: #1557b0;
    --primary-light: #e8f0fe;
    --bg-color: #f8f9fa;
    --bg-white: #ffffff;
    --border-color: #dadce0;
    --border-light: #f1f3f4;
    --text-main: #202124;
    --text-body: #3c4043;
    --text-muted: #5f6368;
    --danger-color: #d93025;
    --danger-light: #fce8e6;
    --success-color: #137333;
    --success-light: #e6f4ea;
    --shadow-sm: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-body);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
    outline: none;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--bg-white);
}

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

.btn-primary:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-body);
}

.btn-outline:hover {
    background-color: var(--border-light);
    border-color: var(--text-muted);
}

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

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

/* Spinner */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

.btn-outline .spinner {
    border-top-color: var(--primary-color);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
}

.badge-success {
    background-color: var(--success-light);
    color: var(--success-color);
}

.badge-danger {
    background-color: var(--danger-color);
    color: var(--bg-white);
}

/* Login Page Styles */
.login-body {
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background-color: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 30px;
    border: 1px solid var(--border-color);
}

.login-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-header h2 {
    font-size: 24px;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-body);
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--bg-white);
}

.form-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.login-error {
    background-color: var(--danger-light);
    color: var(--danger-color);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid rgba(217, 48, 37, 0.2);
}

/* Dashboard Layout */
.dashboard-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    background-color: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    height: 60px;
    flex-shrink: 0;
}

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

.header-logo h1 {
    font-size: 20px;
    color: var(--primary-color);
}

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

.header-user .username {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-body);
}

.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar Navigation */
.app-sidebar {
    width: 240px;
    background-color: var(--bg-white);
    border-right: 1px solid var(--border-color);
    padding: 20px 0;
    flex-shrink: 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-body);
    cursor: pointer;
    border-left: 3px solid transparent;
    text-align: left;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.nav-item:hover {
    background-color: var(--border-light);
    color: var(--text-main);
}

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

.nav-item .badge {
    font-size: 10px;
}

/* Main Content Views */
.app-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background-color: var(--bg-color);
    position: relative;
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.section-header {
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 22px;
    color: var(--text-main);
}

/* Card Styles */
.card {
    background-color: var(--bg-white);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.card-header h4 {
    font-size: 16px;
    color: var(--text-main);
}

.card-body {
    padding: 20px;
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stats-card {
    margin-bottom: 0;
}

.stats-card .card-label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    display: block;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-card .card-value {
    font-size: 32px;
    color: var(--primary-color);
    font-weight: 700;
}

/* Chart Styles */
.chart-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 350px;
}

.chart-body {
    flex: 1;
    position: relative;
    height: 100%;
    min-height: 300px;
}

/* Table Card */
.table-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.table-actions {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-white);
}

.search-box input {
    width: 100%;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--primary-color);
}

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

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

.leads-table th {
    background-color: var(--border-light);
    color: var(--text-main);
    font-weight: 600;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
}

.leads-table td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-body);
    vertical-align: middle;
}

.leads-table tr:last-child td {
    border-bottom: none;
}

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

.leads-table tr.empty-row td {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}

/* Chat Layout */
.chat-layout {
    display: flex;
    background-color: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    height: calc(100vh - 130px);
    overflow: hidden;
}

.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.chat-search {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.chat-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
}

.chat-search input:focus {
    border-color: var(--primary-color);
}

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

.chat-thread {
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background-color 0.2s;
}

.chat-thread:hover {
    background-color: var(--border-light);
}

.chat-thread.active {
    background-color: #f0f2f5;
}

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

.thread-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

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

.thread-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.thread-snippet {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.chat-thread.active .thread-snippet {
    color: var(--text-body);
}

.thread-unread-badge {
    background-color: #25d366; /* WhatsApp Green */
    color: var(--bg-white);
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.chat-thread-list .empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f0f2f5;
}

.chat-window.empty {
    justify-content: center;
    align-items: center;
    background-color: var(--bg-white);
}

.chat-empty-state {
    color: var(--text-muted);
    font-size: 15px;
}

.chat-active-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-window-header {
    background-color: #f0f2f5;
    border-bottom: 1px solid #e9edef;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    height: 59px;
    flex-shrink: 0;
}

.chat-lead-info h4 {
    font-size: 15px;
    color: var(--text-main);
    margin-bottom: 2px;
}

.chat-lead-info span {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-messages-log {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: #efeae2; /* WhatsApp Classic Background */
}

/* Message Bubbles - WhatsApp Style */
.message-bubble {
    max-width: 70%;
    padding: 6px 10px 8px 12px;
    border-radius: 8px;
    font-size: 14.2px;
    line-height: 19px;
    color: #111b21;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(11,20,26,0.13);
    word-break: break-word;
    white-space: pre-wrap;
    display: flex;
    flex-direction: column;
}

.message-bubble.incoming {
    align-self: flex-start;
    background-color: #ffffff;
    border-top-left-radius: 0;
}

.message-bubble.outgoing {
    align-self: flex-end;
    background-color: #d9fdd3; /* WhatsApp Green */
    border-top-right-radius: 0;
}

.message-time {
    display: block;
    text-align: right;
    font-size: 11px;
    color: #667781;
    margin-top: 2px;
    align-self: flex-end;
}

.chat-window-warning {
    background-color: var(--danger-light);
    color: var(--danger-color);
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    border-top: 1px solid rgba(217, 48, 37, 0.1);
    border-bottom: 1px solid rgba(217, 48, 37, 0.1);
}

.chat-window-footer {
    background-color: #f0f2f5;
    border-top: 1px solid #e9edef;
    padding: 10px 16px;
    flex-shrink: 0;
}

#chatMessageForm {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#chatMessageInput {
    flex: 1;
    border: 1px solid #dadce0;
    background-color: #ffffff;
    border-radius: 24px; /* Pill shaped professional input */
    padding: 10px 18px;
    font-size: 14.5px;
    outline: none;
    resize: none;
    max-height: 120px;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

#chatMessageInput:focus {
    border-color: var(--primary-color);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05), 0 0 0 3px var(--primary-light);
}

/* Page Loader Overlay */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.page-loader .spinner {
    width: 40px;
    height: 40px;
    border-width: 4px;
    border-top-color: var(--primary-color);
}

/* Helper Classes */
.mobile-only {
    display: none !important;
}

/* Hide empty state if chat is active */
.chat-window:not(.empty) .chat-empty-state {
    display: none !important;
}

.chat-window.empty .chat-active-container {
    display: none !important;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .app-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 8px 0;
    }
    
    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
    }
    
    .nav-item {
        padding: 8px 12px;
        border-left: none;
        border-bottom: 3px solid transparent;
        justify-content: center;
    }
    
    .nav-item.active {
        border-bottom-color: var(--primary-color);
    }
    
    .chat-layout {
        height: calc(100dvh - 170px);
    }
    
    .chat-sidebar {
        width: 100%;
    }
    
    /* Toggle active chat view on mobile */
    .chat-layout.chat-active .chat-sidebar {
        display: none;
    }
    
    .chat-layout.chat-active .chat-window {
        display: flex;
        flex: 1;
    }
    
    .chat-window {
        display: none;
    }
    
    .mobile-only {
        display: inline-flex !important;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 8px 16px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .header-logo h1 {
        font-size: 16px;
        white-space: nowrap;
    }
    
    .header-logo .badge {
        font-size: 9px;
        padding: 2px 6px;
    }
    
    .header-user {
        gap: 8px;
    }
    
    .header-user .username {
        font-size: 13px;
    }
    
    .btn-sm {
        padding: 4px 8px;
        font-size: 12px;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .app-content {
        padding: 12px;
    }
    
    .stats-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}
