/**
 * Enterprise WhatsApp CRM - Main Stylesheet
 * Custom styles on top of Bootstrap 5
 */

/* ===== CSS Variables ===== */
:root {
    --primary: #075e54;
    --primary-dark: #054d44;
    --primary-light: #128c7e;
    --secondary: #25d366;
    --secondary-light: #dcf8c6;
    --accent: #34b7f1;
    --sidebar-bg: #1a1a2e;
    --sidebar-hover: #16213e;
    --sidebar-active: #0f3460;
    --sidebar-text: #a3a8b8;
    --sidebar-width: 260px;
    --header-height: 60px;
    --border-color: #e2e8f0;
    --bg-light: #f8f9fa;
    --text-muted: #6c757d;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-light);
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    color: var(--primary);
    transition: var(--transition);
}

a:hover {
    color: var(--primary-dark);
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1040;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-brand img {
    width: 36px;
    height: 36px;
}

.sidebar-brand h5 {
    color: #fff;
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.sidebar-nav {
    padding: 16px 0;
    list-style: none;
    margin: 0;
}

.sidebar-nav .nav-section {
    padding: 12px 24px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(163,168,184,0.6);
    font-weight: 600;
}

.sidebar-nav .nav-item {
    margin: 2px 12px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    transition: var(--transition);
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-nav .nav-link i {
    font-size: 18px;
    width: 22px;
    text-align: center;
}

.sidebar-nav .nav-badge {
    margin-left: auto;
    background: var(--secondary);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

/* ===== Top Header ===== */
.top-header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1030;
    box-shadow: var(--shadow-sm);
}

.top-header .page-title {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

.top-header .header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-actions .btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    position: relative;
    transition: var(--transition);
}

.header-actions .btn-icon:hover {
    background: #fff;
    border-color: var(--primary);
    color: var(--primary);
}

.header-actions .btn-icon .badge-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: #dc3545;
    border-radius: 50%;
    border: 2px solid #fff;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.user-menu-btn:hover {
    background: var(--bg-light);
}

.user-menu-btn .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

/* ===== Page Content ===== */
.page-content {
    padding: 24px;
}

/* ===== Cards ===== */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
}

.card-body {
    padding: 20px;
}

/* ===== Stat Cards ===== */
.stat-card {
    border: none;
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 8px 0 4px;
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
}

.stat-card .stat-change {
    font-size: 12px;
    font-weight: 600;
}

.stat-card .stat-change.positive {
    color: #10b981;
}

.stat-card .stat-change.negative {
    color: #ef4444;
}

/* ===== Tables ===== */
.table-responsive {
    border-radius: var(--radius);
}

.table {
    margin-bottom: 0;
}

.table th {
    background: var(--bg-light);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom-width: 1px;
    padding: 12px 16px;
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    vertical-align: middle;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
    background: rgba(7,94,84,0.02);
}

/* ===== Buttons ===== */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-success {
    background: var(--secondary);
    border-color: var(--secondary);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn {
    font-weight: 500;
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 13.5px;
    transition: var(--transition);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12.5px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

/* ===== Forms ===== */
.form-control, .form-select {
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    font-size: 14px;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(7,94,84,0.1);
}

.form-label {
    font-weight: 600;
    font-size: 13px;
    color: #374151;
    margin-bottom: 6px;
}

/* ===== Badges ===== */
.badge {
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 11.5px;
}

/* ===== Chat Styles ===== */
.chat-container {
    display: flex;
    height: calc(100vh - var(--header-height));
}

.chat-sidebar {
    width: 360px;
    border-right: 1px solid var(--border-color);
    background: #fff;
    display: flex;
    flex-direction: column;
}

.chat-sidebar .search-box {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
}

.chat-item:hover, .chat-item.active {
    background: rgba(7,94,84,0.04);
}

.chat-item .contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-item .chat-info {
    flex: 1;
    min-width: 0;
}

.chat-item .chat-name {
    font-weight: 600;
    font-size: 14px;
    color: #1a1a1a;
    margin: 0;
}

.chat-item .chat-preview {
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.chat-item .chat-meta {
    text-align: right;
    flex-shrink: 0;
}

.chat-item .chat-time {
    font-size: 11px;
    color: var(--text-muted);
}

.chat-item .unread-badge {
    background: var(--secondary);
    color: #fff;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
    display: inline-block;
    margin-top: 4px;
}

/* Chat Messages Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4d4d4' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-header {
    background: #fff;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.message-bubble {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    position: relative;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-bubble.outbound {
    background: var(--secondary-light);
    margin-left: auto;
    border-bottom-right-radius: 2px;
}

.message-bubble.inbound {
    background: #fff;
    margin-right: auto;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.message-bubble .message-time {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
}

.message-bubble .message-status {
    margin-left: 4px;
}

.message-bubble .message-status .bi-check2-all {
    color: var(--accent);
}

/* Chat Input */
.chat-input {
    background: #fff;
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-input .form-control {
    border-radius: 20px;
    padding: 10px 18px;
}

.chat-input .btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ===== Auth Pages ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 20px;
}

.auth-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    padding: 40px;
}

.auth-card .auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-card .auth-logo h3 {
    color: var(--primary);
    font-weight: 700;
    margin-top: 12px;
}

.auth-card .auth-logo i {
    font-size: 48px;
    color: var(--primary);
}

/* ===== Status Badges ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.active, .status-badge.sent, .status-badge.delivered {
    background: #dcfce7;
    color: #166534;
}

.status-badge.inactive, .status-badge.failed {
    background: #fef2f2;
    color: #991b1b;
}

.status-badge.pending, .status-badge.queued {
    background: #fef9c3;
    color: #854d0e;
}

.status-badge.read {
    background: #dbeafe;
    color: #1e40af;
}

/* ===== Progress Bar ===== */
.campaign-progress {
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: #e5e7eb;
}

.campaign-progress .progress-bar {
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

/* ===== Responsive ===== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .chat-sidebar {
        width: 100%;
    }

    .chat-main {
        display: none;
    }

    .chat-main.active {
        display: flex;
    }
}

@media (max-width: 767.98px) {
    .page-content {
        padding: 16px;
    }

    .stat-card .stat-value {
        font-size: 22px;
    }

    .message-bubble {
        max-width: 85%;
    }
}

/* ===== Loading Spinner ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state i {
    font-size: 64px;
    color: var(--border-color);
    margin-bottom: 16px;
}

.empty-state h5 {
    color: #374151;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    max-width: 400px;
    margin: 0 auto 20px;
}

/* ===== WhatsApp Connect Button ===== */
.btn-whatsapp-connect {
    background: var(--secondary);
    color: #fff;
    border: none;
    padding: 14px 28px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}

.btn-whatsapp-connect:hover {
    background: #20bd5a;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ===== Connection Status Card ===== */
.connection-card {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    transition: var(--transition);
}

.connection-card.connected {
    border-color: var(--secondary);
    border-style: solid;
    background: rgba(37,211,102,0.02);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
