/**
 * File: main.css
 * Description: Complete & Optimized Styles for M.H CRM (Legacy + Modern Integration).
 * Version: 36.0.0 (Full Merge)
 */

@import url('https://fonts.googleapis.com/css2?family=Heebo:wght@400;500;700&display=swap');

:root {
    /* --- Modern Color Palette --- */
    --primary-color: #008069;       /* WhatsApp Green */
    --primary-hover: #006c59;
    --primary-light: #e8f5e9;
    
    --secondary-color: #111b21;     /* Dark Text */
    --text-secondary: #54656f;      /* Grey Text */
    --text-tertiary: #8696a0;
    
    --bg-body: #efeae2;             /* WhatsApp Web BG or Neutral Grey */
    --bg-card: #ffffff;
    --bg-hover: #f5f6f6;
    
    --border-color: #e9edef;
    --border-focus: #00a884;
    
    --danger-color: #ea0038;
    --success-color: #25d366;
    --warning-color: #ff9900;

    /* --- Spacing & Radius --- */
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    /* --- Shadows --- */
    --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 25px rgba(0,0,0,0.15);
    
    /* --- Layout --- */
    --header-height: 64px;
    --input-height: 40px;
}

/* ===================================================================
   1. BASE LAYOUT & RESET
   =================================================================== */

#crm-app-wrapper {
    font-family: 'Heebo', sans-serif;
    color: var(--secondary-color);
    background-color: transparent;
    margin: 20px auto;
    padding: 0;
    direction: rtl;
    box-sizing: border-box;
    max-width: 1200px;
    width: 100%;
}

#crm-app-wrapper * { box-sizing: border-box; outline: none; }

.hidden { display: none !important; }

/* ===================================================================
   2. MODERN HEADER (Integrated)
   =================================================================== */

.mh-custom-header {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    height: var(--header-height);
}

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

/* Account Widget */
.crm-account-widget .profile-button {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 12px 4px 4px;
    display: flex; align-items: center; gap: 10px;
    height: 40px; border-radius: 20px;
    transition: all 0.2s ease;
    cursor: pointer; color: var(--secondary-color);
}

.crm-account-widget .profile-button:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-color);
}

.crm-account-widget .default-avatar {
    width: 32px; height: 32px;
    background-color: #e9edef; color: #aebac1;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; overflow: hidden;
}

.crm-account-widget .profile-text {
    font-size: 14px; font-weight: 600;
}

/* ===================================================================
   3. APP CONTAINER & TABS
   =================================================================== */

.app-main {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

.content-area {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
}

/* Tabs */
.view-tabs {
    display: flex;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px 0;
    gap: 6px;
    overflow-x: auto;
    flex-shrink: 0;
}

.view-tab {
    padding: 10px 18px;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    transition: all 0.2s;
    border-radius: 8px 8px 0 0;
    position: relative;
    top: 1px;
    white-space: nowrap;
}

.view-tab:hover {
    background-color: rgba(255,255,255,0.6);
    color: var(--primary-color);
}

.view-tab.active {
    background-color: #fff;
    color: var(--primary-color);
    border-color: var(--border-color);
    font-weight: 700;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.02);
}

.tab-counter {
    background-color: #e9edef;
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75em;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}
.view-tab.active .tab-counter {
    background-color: var(--primary-light);
    color: var(--primary-color);
}

/* ===================================================================
   4. TOOLBARS & BUTTONS
   =================================================================== */

.view-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.table-controls {
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* Inputs */
.search-container, 
.sort-container select, 
.bulk-actions-container select,
.bulk-actions-container button,
.crm-input {
    height: var(--input-height);
    box-sizing: border-box;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background-color: #fff;
    transition: all 0.2s;
}

.search-container {
    flex-grow: 1;
    display: flex; align-items: center;
    background: #f0f2f5; border: none;
    padding: 0 12px;
}
.search-container:focus-within {
    background: #fff;
    box-shadow: 0 0 0 2px rgba(0,128,105,0.2);
    border: 1px solid var(--border-focus);
}
.search-container input {
    border: none; background: transparent; width: 100%; height: 100%;
    padding: 0 8px; outline: none; font-family: inherit;
}
.search-container .material-icons { color: var(--text-secondary); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    cursor: pointer; font-weight: 500; transition: all 0.2s ease;
    border: 1px solid transparent; outline: none; font-family: inherit;
    height: var(--input-height);
    border-radius: 20px;
    padding: 0 20px;
    font-size: 14px;
    white-space: nowrap;
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); box-shadow: 0 2px 5px rgba(0,0,0,0.15); }

.btn-secondary { background-color: transparent; color: var(--text-secondary); border-color: var(--border-color); }
.btn-secondary:hover { background-color: var(--bg-hover); color: var(--secondary-color); border-color: var(--text-secondary); }

.btn-danger { background-color: #fce8e6; color: var(--danger-color); border-color: transparent; }
.btn-danger:hover { background-color: #f8d7da; border-color: #f5c6cb; }

/* Small buttons */
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 6px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 50%; background: transparent; color: var(--text-secondary); border: none; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.btn-icon:hover { background-color: var(--bg-hover); color: var(--primary-color); }

/* ===================================================================
   5. MODERN LISTS & TABLES
   =================================================================== */

.mh-modern-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background-color: #fff;
}

.mh-scroll-container {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* --- Classic Table (Contacts) --- */
.table-container { width: 100%; overflow-x: auto; flex: 1; }
table#contactsTable { width: 100%; border-collapse: collapse; min-width: 800px; }
table#contactsTable thead th {
    background-color: #f9fafb; color: var(--text-secondary); font-weight: 600;
    font-size: 0.85rem; text-align: right; padding: 14px 20px;
    border-bottom: 1px solid var(--border-color); position: sticky; top: 0;
}
table#contactsTable tbody tr { border-bottom: 1px solid var(--bg-hover); transition: background 0.1s; }
table#contactsTable tbody tr:hover { background-color: var(--bg-hover); }
table#contactsTable td { padding: 12px 20px; vertical-align: middle; color: var(--secondary-color); }

/* --- Modern Group Cards (Group Manager) --- */
.gm-group-card {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}
.gm-group-card:hover { background-color: #fcfcfc; }

.gm-card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
}
.gm-group-info { display: flex; align-items: center; gap: 15px; }
.gm-icon { 
    background: #e9edef; color: var(--text-secondary);
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.gm-name { font-weight: 600; font-size: 15px; color: var(--secondary-color); }

.contact-editor-wrapper {
    background-color: #f9f9f9;
    border-top: 1px solid var(--border-color);
    padding: 0;
    animation: slideDown 0.2s ease-out;
}
.contact-editor-content { padding: 20px; }

/* --- Modern History List --- */
.mh-list-header {
    display: flex; align-items: center;
    background: #f8f9fa; border-bottom: 1px solid var(--border-color);
    padding: 10px 20px; font-weight: 600; color: var(--text-secondary); font-size: 13px;
    flex-shrink: 0;
}

.mh-history-row {
    display: flex; align-items: center;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    transition: background 0.1s;
}
.mh-history-row:hover { background-color: #fdfdfd; }

.mh-col-check { width: 40px; text-align: center; }
.mh-col-content { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.message-text { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90%; }
.mh-history-meta { display: flex; gap: 10px; font-size: 12px; color: var(--text-tertiary); }
.mh-col-stats { width: 120px; text-align: center; }
.mh-col-actions { width: 100px; text-align: left; }

/* Badges */
.status-badge { padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; display: inline-block; }
.status-badge.success { background: #dcf8c6; color: #075e54; }
.status-badge.error { background: #f8d7da; color: #842029; }
.status-badge.total { background: #e9edef; color: #54656f; }

/* ===================================================================
   6. MODALS (Fixed)
   =================================================================== */

.modal {
    display: none !important;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 999999;
    align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
}
.modal.visible { display: flex !important; animation: fadeIn 0.2s; }

.modal-content {
    background: #fff; width: 90%; max-width: 500px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    max-height: 90vh; overflow: hidden;
    position: relative;
}
.modal-content.large { max-width: 900px; }

.modal-header {
    padding: 16px 24px; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    background: #fff; flex-shrink: 0;
}
.modal-title { margin: 0; font-size: 1.2rem; font-weight: 700; }
.close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-tertiary); }
.close:hover { color: var(--secondary-color); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 16px 24px; background: var(--bg-hover);
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; max-height: 0; } to { opacity: 1; max-height: 500px; } }

/* ===================================================================
   7. RESPONSIVE
   =================================================================== */

@media (max-width: 768px) {
    .mh-custom-header { height: auto; flex-direction: column-reverse; gap: 15px; align-items: stretch; }
    .mh-header-section { justify-content: center; }
    
    .view-tab span:not(.material-icons) { display: none; }
    .view-tab { justify-content: center; padding: 10px; }
    
    .table-controls { flex-direction: column; align-items: stretch; }
    .search-container { width: 100%; }
    
    .mh-list-header { display: none; }
    .mh-history-row { flex-direction: column; align-items: flex-start; gap: 10px; }
    .mh-col-check { position: absolute; top: 10px; left: 10px; }
    .mh-col-content { padding-left: 30px; width: 100%; }
    .mh-col-stats, .mh-col-actions { width: 100%; text-align: left; padding-left: 30px; }
    
    .gm-card-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .gm-actions { width: 100%; justify-content: space-between; }
}