/* ============================================
   Meta Business Suite Analytics - Main Styles
   ============================================ */

:root {
    --primary: #1877f2;
    --primary-dark: #166fe5;
    --secondary: #42b72a;
    --danger: #e74c3c;
    --warning: #f39c12;
    --info: #3498db;
    --dark: #1c1e21;
    --gray-100: #f0f2f5;
    --gray-200: #e4e6eb;
    --gray-300: #dadde1;
    --gray-500: #8a8d91;
    --gray-700: #65676b;
    --gray-900: #1c1e21;
    --sidebar-width: 260px;
    --sidebar-collapsed: 60px;
    --header-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --transition: 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--dark);
    line-height: 1.5;
    min-height: 100vh;
}

/* ========== LOGIN PAGE ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1877f2 0%, #0c5dbf 100%);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

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

.login-icon {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 15px;
}

.login-header h1 {
    font-size: 24px;
    color: var(--dark);
    margin-bottom: 5px;
}

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

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--gray-700);
    font-size: 14px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 15px;
    transition: border-color var(--transition);
    outline: none;
}

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

.form-select {
    padding: 8px 12px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    background: white;
    cursor: pointer;
    outline: none;
}

.form-select:focus {
    border-color: var(--primary);
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 10px;
    display: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--dark);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

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

.btn-danger:hover {
    background: #c0392b;
}

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

.btn-block {
    width: 100%;
    justify-content: center;
}

/* ========== APP LAYOUT ========== */
#app {
    display: flex;
    min-height: 100vh;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: width var(--transition);
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    white-space: nowrap;
}

.sidebar-logo i {
    font-size: 24px;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--gray-700);
    cursor: pointer;
    padding: 4px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-200);
}

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

.user-info {
    overflow: hidden;
    white-space: nowrap;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: var(--gray-700);
    text-transform: capitalize;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.nav-section {
    padding: 12px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--gray-500);
    letter-spacing: 0.5px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--dark);
}

.nav-item.active {
    background: #e7f3ff;
    color: var(--primary);
    font-weight: 500;
}

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

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.alert-badge {
    background: var(--warning);
}

.sidebar-footer {
    border-top: 1px solid var(--gray-200);
    padding: 8px 0;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    transition: margin-left var(--transition);
    min-height: 100vh;
}

.sidebar.collapsed + .main-content {
    margin-left: var(--sidebar-collapsed);
}

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

.page-title {
    font-size: 24px;
    font-weight: 700;
}

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

/* ========== CARDS ========== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

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

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

/* ========== STATS GRID ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

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

.stat-icon.blue { background: #e7f3ff; color: var(--primary); }
.stat-icon.green { background: #e8f5e9; color: var(--secondary); }
.stat-icon.red { background: #fde8e8; color: var(--danger); }
.stat-icon.yellow { background: #fef3e2; color: var(--warning); }
.stat-icon.purple { background: #f3e8ff; color: #8b5cf6; }

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 13px;
    color: var(--gray-700);
    margin-top: 2px;
}

.stat-change {
    font-size: 12px;
    font-weight: 500;
    margin-top: 4px;
}

.stat-change.up { color: var(--secondary); }
.stat-change.down { color: var(--danger); }

/* ========== CHARTS ========== */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

.chart-container-sm {
    height: 200px;
}

/* ========== TABLE ========== */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    font-size: 14px;
}

th {
    font-weight: 600;
    color: var(--gray-700);
    background: var(--gray-100);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover td {
    background: var(--gray-100);
}

/* ========== BADGES ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-warning { background: #fef3e2; color: #e65100; }
.badge-danger { background: #fde8e8; color: #c62828; }
.badge-info { background: #e7f3ff; color: #1565c0; }

/* ========== ALERTS LIST ========== */
.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--gray-100);
    transition: background 0.2s;
}

.alert-item:hover {
    background: var(--gray-200);
}

.alert-item.critical { border-left: 3px solid var(--danger); }
.alert-item.warning { border-left: 3px solid var(--warning); }
.alert-item.info { border-left: 3px solid var(--info); }

.alert-icon {
    font-size: 18px;
    margin-top: 2px;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    font-size: 14px;
}

.alert-message {
    font-size: 13px;
    color: var(--gray-700);
    margin-top: 2px;
}

.alert-time {
    font-size: 11px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* ========== LOADING ========== */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--gray-700);
    font-size: 16px;
    gap: 10px;
}

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-wide {
    max-width: 860px;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-700);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ========== CONVERSATIONS ========== */
.conversation-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.conversation-user img,
.conversation-user span {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
}

.conversation-user img {
    object-fit: cover;
}

.conversation-user span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    font-weight: 600;
}

.conversation-preview {
    max-width: 360px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    margin-top: 4px;
    color: var(--gray-500);
    font-size: 12px;
}

.thread-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 16px;
}

.thread-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.thread-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 4px;
}

.message-bubble {
    max-width: 72%;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--gray-100);
}

.message-bubble.from-page {
    align-self: flex-end;
    background: #e7f3ff;
}

.message-bubble.from-user {
    align-self: flex-start;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.message-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-time {
    margin-top: 6px;
    font-size: 11px;
    color: var(--gray-500);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-collapsed);
    }
    
    .sidebar .sidebar-title,
    .sidebar .user-info,
    .sidebar .nav-item span,
    .sidebar .nav-section {
        display: none;
    }
    
    .main-content {
        margin-left: var(--sidebar-collapsed);
    }
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========== UTILITY ========== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
