/* ==========================================================================
   FILE: modern-style.css
   VERSION: 16.1.0
   DESCRIPTION: Full layout with Integrated Action Toolbar & Modern Account Modal.
   ========================================================================== */

#mh-crm-root {
    /* --- VARIABLES --- */
    --mh-primary: #008069;       /* WhatsApp Green */
    --mh-primary-dark: #005c4b;
    --mh-bg: #f0f2f5;
    --mh-white: #ffffff;
    --mh-border: #d1d7db;
    --mh-text-main: #111b21;
    --mh-text-sec: #667781;
    --mh-danger: #f44336;
    --mh-shadow: 0 2px 5px rgba(0,0,0,0.05);
    
    /* --- RESET & LAYOUT --- */
    font-family: 'Segoe UI', 'Heebo', 'Helvetica Neue', sans-serif;
    direction: rtl;
    background-color: var(--mh-bg);
    color: var(--mh-text-main);
    font-size: 14px;
    line-height: 1.5;
    
    /* Fixed Overlay Position (Full Screen) */
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: 99999; /* Ensure it's on top of theme elements */
    
    display: flex;
    flex-direction: column; /* Top: Header, Bottom: Content */
    overflow: hidden;
    box-sizing: border-box;
}

#mh-crm-root * { box-sizing: border-box; outline: none; }

/* --- WORDPRESS ADMIN BAR FIX --- */
body.admin-bar #mh-crm-root { top: 32px; height: calc(100vh - 32px); }
@media screen and (max-width: 782px) { 
    body.admin-bar #mh-crm-root { top: 46px; height: calc(100vh - 46px); } 
}

/* ==============================
   1. HEADER & TOOLBAR
   ============================== */
.mh-custom-header {
    height: 64px;
    background-color: var(--mh-bg);
    border-bottom: 1px solid var(--mh-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    flex-shrink: 0;
    z-index: 100;
}

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

/* Prevent Theme Styles from breaking Shortcodes */
.mh-shortcode-wrapper {
    display: flex;
    align-items: center;
}
.mh-shortcode-wrapper p { margin: 0 !important; }

/* --- NEW ACTION TOOLBAR --- */
.mh-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Icon Group (White container for icons) */
.mh-icon-group {
    display: flex;
    background-color: var(--mh-white);
    border: 1px solid var(--mh-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.mh-icon-btn {
    background: transparent;
    border: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--mh-text-sec);
    transition: all 0.2s;
    border-left: 1px solid var(--mh-border);
}
.mh-icon-btn:last-child { border-left: none; }
.mh-icon-btn:hover {
    background-color: #f5f6f6;
    color: var(--mh-primary);
}
.mh-icon-btn .material-icons { font-size: 20px; }

/* Primary Button (Add Contact) */
.mh-primary-btn {
    background-color: var(--mh-primary);
    color: white;
    border: none;
    height: 36px;
    padding: 0 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,128,105,0.2);
    transition: all 0.2s;
    white-space: nowrap;
}
.mh-primary-btn:hover {
    background-color: var(--mh-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,128,105,0.3);
}
.mh-primary-btn:active { transform: translateY(0); }
.mh-primary-btn .material-icons { font-size: 18px; }


/* ==============================
   2. MAIN LAYOUT GRID
   ============================== */
.mh-main-layout { 
    display: flex; 
    flex: 1; 
    overflow: hidden; 
    width: 100%; 
    position: relative; 
}

/* Column 1: Sources (Contacts List) */
.mh-col-sources { 
    width: 400px; 
    background: var(--mh-white); 
    border-left: 1px solid var(--mh-border); 
    display: flex; flex-direction: column; 
    z-index: 20; 
}

/* Column 2: Selected Items (Collapsible) */
.mh-col-selected { 
    width: 0; 
    opacity: 0; 
    overflow: hidden; 
    background: #f7f8fa; 
    border-left: 1px solid var(--mh-border); 
    display: flex; flex-direction: column; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    z-index: 15; 
}
#mh-crm-root.has-selection .mh-col-selected { width: 320px; opacity: 1; }

/* Column 3: Preview / Device */
.mh-col-preview { 
    flex: 1; 
    background: #efeae2; 
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center; 
    position: relative; 
}

/* ==============================
   3. COLUMN 1 COMPONENTS
   ============================== */
.mh-col-header {
    background: #f0f2f5;
    padding: 12px 15px;
    border-bottom: 1px solid var(--mh-border);
    display: flex; flex-direction: column; gap: 10px;
    flex-shrink: 0;
}

.mh-top-actions { display: flex; justify-content: space-between; align-items: center; }

/* Tabs */
.mh-tabs-nav { display: flex; background: #e9edef; padding: 4px; border-radius: 20px; gap: 4px; }
.mh-tab-btn {
    border: none; background: transparent; color: var(--mh-text-sec);
    width: 40px; height: 32px; border-radius: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: 0.2s;
}
.mh-tab-btn:hover { background: rgba(255,255,255,0.5); }
.mh-tab-btn.active { 
    background: var(--mh-white); color: var(--mh-primary); 
    font-weight: bold; box-shadow: 0 1px 2px rgba(0,0,0,0.1); 
}

/* Mini Tools (Filter Button) */
.mh-mini-tools { display: flex; gap: 5px; }
.mh-icon-action {
    background: transparent; border: none; cursor: pointer;
    color: var(--mh-text-sec); padding: 6px; border-radius: 50%;
}
.mh-icon-action:hover { background: rgba(0,0,0,0.05); color: var(--mh-text-main); }

/* Filters Panel */
.mh-filters-panel {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
    opacity: 0; display: flex; flex-direction: column; gap: 8px;
}
.mh-filters-panel.open { max-height: 200px; opacity: 1; padding-bottom: 5px; }

.mh-filter-row {
    background: var(--mh-white); border-radius: 8px; padding: 6px 10px;
    display: flex; align-items: center; border: 1px solid transparent;
}
.mh-filter-row:focus-within { border-color: var(--mh-primary); }
.mh-filter-row input { border: none; width: 100%; padding: 4px 8px; background: transparent; font-size: 14px; }

.mh-filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mh-filter-grid select {
    width: 100%; border: 1px solid var(--mh-border); border-radius: 6px;
    padding: 6px; background: var(--mh-white); cursor: pointer; font-size: 13px;
}

/* ==============================
   4. LISTS & ACTIONS (INNER)
   ============================== */
.mh-col-content { 
    flex: 1; overflow: hidden; display: flex; flex-direction: column; 
    background: var(--mh-white); position: relative;
}
.mh-tab-pane { display: none; height: 100%; flex-direction: column; }
.mh-tab-pane.active { display: flex; }

/* --- INNER ACTION TOOLBAR --- */
.mh-action-bar {
    padding: 10px 15px;
    background: #fff;
    border-bottom: 1px solid #eee;
    display: flex; justify-content: center;
}
.mh-action-group { display: flex; gap: 8px; width: 100%; }
.mh-action-btn {
    flex: 1; border: none; border-radius: 8px; height: 40px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: white; transition: transform 0.1s, opacity 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.mh-action-btn:hover { transform: translateY(-2px); opacity: 0.9; }
.mh-action-btn .material-icons { font-size: 20px; }

.mh-action-btn.red    { background: #f44336; } /* Trash */
.mh-action-btn.orange { background: #ff9800; } /* Event */
.mh-action-btn.purple { background: #9c27b0; } /* Tag */

/* --- SELECT ALL BAR --- */
.mh-select-all-bar {
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-size: 13px; font-weight: 600; color: #555;
    display: flex; align-items: center;
}
.mh-select-all-bar label { display: flex; align-items: center; gap: 10px; cursor: pointer; width: 100%; }
.mh-select-all-bar input { 
    transform: scale(1.3); accent-color: var(--mh-primary); margin: 0; 
}

/* --- SCROLL & ITEMS --- */
.mh-scroll-container { flex: 1; overflow-y: auto; padding-bottom: 20px; }

.mh-contact-item {
    display: flex; align-items: center; padding: 0 15px;
    border-bottom: 1px solid #f0f2f5; cursor: pointer; height: 72px;
    transition: background 0.1s;
}
.mh-contact-item:hover { background-color: #f5f6f6; }
.mh-contact-item.selected { background-color: #e7f5ff; }

.mh-avatar {
    width: 45px; height: 45px; border-radius: 50%;
    background: #dfe3e5; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 16px; margin-left: 15px; flex-shrink: 0;
}
.mh-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
.mh-name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mh-sub { font-size: 13px; color: var(--mh-text-sec); margin-top: 2px; }

.mh-checkbox-wrapper { margin-right: 12px; }
.mh-contact-item input { transform: scale(1.3); accent-color: var(--mh-primary); cursor: pointer; }

/* Generic Item (Tags/History/Events) */
.mh-generic-item {
    padding: 12px 15px; border-bottom: 1px solid #f0f2f5;
    display: flex; flex-direction: column; gap: 4px; cursor: pointer;
}
.mh-generic-item:hover { background: #f9f9f9; }

/* ==============================
   5. SELECTED PANEL & DEVICE
   ============================== */
.mh-selected-header { 
    padding: 15px; background: #fff; border-bottom: 1px solid #eee; flex-shrink: 0; 
}
.mh-flex-row-between { 
    display: flex; justify-content: space-between; align-items: center; 
}
.mh-selected-header h3 { margin: 0; font-size: 16px; }

.mh-selected-row {
    padding: 10px 15px;
    display: flex; justify-content: space-between; align-items: center;
    background: #fff; border-bottom: 1px solid #f0f0f0;
    animation: mhFadeIn 0.2s;
}
.mh-remove-sel { cursor: pointer; color: #ccc; padding: 5px; border-radius: 50%; } 
.mh-remove-sel:hover { color: var(--mh-danger); background: #ffebee; }

/* Device & Chat */
.mh-wa-device {
    width: 100%; max-width: 700px; height: 100%;
    background: #fff; display: flex; flex-direction: column;
    box-shadow: 0 0 30px rgba(0,0,0,0.05);
    border-left: 1px solid var(--mh-border);
    border-right: 1px solid var(--mh-border);
}
.mh-wa-header {
    background: #f0f2f5; height: 60px; display: flex; align-items: center;
    padding: 0 16px; border-bottom: 1px solid var(--mh-border); flex-shrink: 0;
}
.mh-wa-info { flex: 1; display: flex; flex-direction: column; margin-right: 15px; }
.mh-wa-name { font-weight: 600; font-size: 16px; }
.mh-wa-status { font-size: 13px; color: var(--mh-text-sec); }
.mh-wa-chat-area { flex: 1; padding: 20px 30px; overflow-y: auto; display: flex; flex-direction: column; }
.mh-wa-bubble {
    background: #d9fdd3; padding: 6px 9px; border-radius: 7.5px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); max-width: 70%;
    align-self: flex-end; position: relative; font-size: 14.2px; line-height: 19px;
    color: #111b21; margin-bottom: 10px; word-wrap: break-word;
}
.mh-wa-time { font-size: 11px; color: rgba(17, 27, 33, 0.5); float: left; margin-top: 4px; margin-right: 8px; }

/* Composer */
.mh-wa-composer { background: #f0f2f5; display: flex; flex-direction: column; flex-shrink: 0; border-top: 1px solid var(--mh-border); }
.mh-composer-tabs { display: flex; padding: 0 10px; border-bottom: 1px solid var(--mh-border); }
.mh-comp-tab { padding: 10px 16px; border: none; background: transparent; color: var(--mh-text-sec); font-weight: 500; cursor: pointer; border-bottom: 3px solid transparent; }
.mh-comp-tab.active { color: var(--mh-primary); border-bottom-color: var(--mh-primary); }
.mh-composer-panel { display: none; height: 140px; background: #fff; padding: 12px; overflow-y: auto; }
.mh-composer-panel.active { display: block; }
.mh-chat-textarea { width: 100%; height: 100%; border: none; resize: none; font-size: 16px; font-family: inherit; color: var(--mh-text-main); }
.mh-tags-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.mh-tag-insert { background: #fff; border: 1px solid var(--mh-border); padding: 6px 12px; border-radius: 20px; font-size: 13px; cursor: pointer; transition: 0.2s; }
.mh-tag-insert:hover { background: #e7f5ff; border-color: var(--mh-primary); color: var(--mh-primary); }
.mh-emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.mh-emoji-btn { font-size: 24px; cursor: pointer; padding: 4px; transition: 0.1s; }
.mh-emoji-btn:hover { transform: scale(1.2); }
.mh-composer-footer { display: flex; align-items: center; padding: 8px 16px; gap: 12px; min-height: 60px; }
.mh-send-btn { margin-right: auto; background: var(--mh-primary); color: white; border: none; padding: 10px 24px; border-radius: 24px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.mh-attach-wrapper { color: #54656f; transform: rotate(45deg); padding: 8px; cursor: pointer; }

/* ==============================
   7. MODALS & UTILS
   ============================== */
.mh-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 200000;
    display: none; align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
}
.mh-modal-overlay.visible { display: flex; animation: mhFadeIn 0.2s; }

.mh-modal-box {
    background: #fff; width: 90%; max-width: 400px;
    padding: 30px; border-radius: 12px; text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2); position: relative;
}

.mh-mini-btn {
    padding: 8px 16px; border-radius: 6px; border: 1px solid #ddd;
    background: #fff; cursor: pointer; font-size: 14px; transition: 0.2s;
}
.mh-mini-btn:hover { background: #f5f5f5; }

.mh-loader-spinner {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; margin-top: 20px; color: var(--mh-text-sec);
}
.mh-spin { animation: spin 1s linear infinite; }

/* ==========================================================================
   LEGACY SHORTCODE ADAPTER (V2 - Fix for Hiding Buttons)
   ========================================================================== */

/* 1. הסתרת כפתורים (WooCommerce + Group Send) - תיקון אגרסיבי */
.crm-actions-wrapper button[data-action="open-group-send-modal"],
.crm-actions-wrapper button[data-action="sync-woo-revenue"] {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 2. סידור מרווחים בקונטיינר */
.crm-actions-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    padding: 0;
}

.crm-actions-wrapper .control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

/* 3. עיצוב כפתורים משניים (אייקונים) - מראה נקי */
.crm-actions-wrapper .btn-secondary {
    background-color: var(--mh-white) !important;
    border: 1px solid #e0e0e0 !important; /* גבול עדין */
    color: #5f6368 !important; /* אפור כהה */
    border-radius: 8px !important;
    min-width: 40px !important; /* גודל אחיד */
    height: 40px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: none !important;
    transition: all 0.2s ease-in-out;
}

.crm-actions-wrapper .btn-secondary:hover {
    background-color: #e8f5e9 !important; /* ירוק בהיר מאוד */
    color: var(--mh-primary) !important;
    border-color: var(--mh-primary) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05) !important;
}

.crm-actions-wrapper .btn-secondary .material-icons {
    font-size: 20px !important;
    line-height: 1 !important;
}

/* 4. עיצוב כפתור ראשי (הוספת איש קשר) */
.crm-actions-wrapper .btn-primary {
    background-color: var(--mh-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 20px !important; /* Pill Shape */
    height: 40px !important;
    padding: 0 24px !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    letter-spacing: 0.3px;
    box-shadow: 0 4px 10px rgba(0, 128, 105, 0.25) !important;
    display: inline-flex !important;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.crm-actions-wrapper .btn-primary:hover {
    background-color: #006c59 !important; /* כהה יותר */
    box-shadow: 0 6px 12px rgba(0, 128, 105, 0.35) !important;
    transform: translateY(-1px);
}

.crm-actions-wrapper .btn-primary .material-icons {
    font-size: 18px !important;
}

/* 5. עיצוב כפתור פרופיל (Account Widget) - משתלב ברקע */
.crm-account-widget .profile-button {
    background: transparent !important;
    border: 1px solid transparent !important;
    box-shadow: none !important;
    padding: 4px 12px 4px 4px !important; /* ריווח פנימי מותאם */
    display: flex !important;
    align-items: center;
    gap: 12px;
    height: 44px !important;
    border-radius: 22px !important;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.crm-account-widget .profile-button:hover {
    background-color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05) !important;
}

/* אווטאר */
.crm-account-widget .default-avatar {
    width: 36px !important;
    height: 36px !important;
    background-color: #e0e0e0 !important;
    color: #757575 !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 20px !important;
}

/* טקסט */
.crm-account-widget .profile-text {
    font-size: 14px !important;
    font-weight: 500 !important;
    color: #333 !important;
}

/* ==========================================================================
   ACCOUNT MODAL & AVATAR STYLES
   ========================================================================== */

/* 1. Header Avatar Image */
.mh-header-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #25D366; /* Green border for connected state */
}

/* 2. Modal Profile Header */
.mh-account-profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--mh-border);
    margin-bottom: 20px;
}

.mh-profile-avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 10px;
    background: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.mh-profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mh-profile-avatar-large .material-icons {
    font-size: 40px;
    color: #999;
}

.mh-profile-info h3 {
    margin: 0 0 5px 0;
    font-size: 1.2rem;
    color: var(--mh-text-main);
}

.mh-status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}
.mh-status-badge.connected { background: #e8f5e9; color: #2e7d32; }
.mh-status-badge.disconnected { background: #ffebee; color: #c62828; }

/* ==========================================================================
   MODAL MENU STYLES (Live Links Version)
   ========================================================================== */

/* קו מפריד מעל התפריט */
.mh-account-menu-separator {
    height: 1px;
    background-color: #e0e0e0;
    margin: 20px 0 10px 0;
    width: 100%;
}

.mh-account-menu-wrapper {
    width: 100%;
    text-align: right;
    direction: rtl;
}

/* איפוס רשימות */
.mh-account-menu-wrapper ul,
.mh-modal-nav ul {
    list-style: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

.mh-account-menu-wrapper li,
.mh-modal-nav li {
    margin: 0 !important;
    padding: 0 !important;
    border-bottom: 1px solid #f5f5f5;
}

.mh-account-menu-wrapper li:last-child,
.mh-modal-nav li:last-child {
    border-bottom: none;
}

/* עיצוב הקישורים (a tags) */
.mh-account-menu-wrapper a,
.mh-modal-nav a {
    display: flex !important;
    align-items: center;
    justify-content: space-between; /* טקסט מימין, אייקון משמאל */
    padding: 12px 15px !important;
    color: #333 !important;
    text-decoration: none !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    transition: background-color 0.2s, color 0.2s;
    width: 100%;
    cursor: pointer !important; /* חזרה למצב לחיץ */
}

/* אפקט מעבר עכבר */
.mh-account-menu-wrapper a:hover,
.mh-modal-nav a:hover {
    background-color: #f0f7f5 !important; /* ירקרק עדין */
    color: #008069 !important; /* ירוק וואטסאפ */
}

/* הוספת חץ קטן בצד שמאל לכל קישור */
.mh-account-menu-wrapper a::after,
.mh-modal-nav a::after {
    content: 'chevron_left';
    font-family: 'Material Icons';
    font-size: 18px;
    color: #ccc;
    transition: transform 0.2s;
}

.mh-account-menu-wrapper a:hover::after,
.mh-modal-nav a:hover::after {
    color: #008069;
    transform: translateX(-3px); /* תזוזה קטנה שמאלה באפקט */
}

/* טיפול באייקונים שהוזרקו ע"י הפלאגין או התבנית בתוך ה-li */
.mh-account-menu-wrapper a .material-icons,
.mh-modal-nav a .material-icons {
    margin-left: 10px;
    font-size: 20px;
    color: #666;
}
/* ANIMATIONS */
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes mhFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Mobile */
@media (max-width: 900px) {
    .mh-col-sources { width: 100%; }
    .mh-col-selected, .mh-col-preview { display: none; }
    .mh-icon-btn { width: 32px; height: 32px; }
    .mh-primary-btn { padding: 0 12px; font-size: 13px; }
    .mh-primary-btn span:last-child { display: none; } /* Hide text on mobile */

/* ==========================================================================
   FILE: modern-style.css
   VERSION: 17.0.1 (FIXED LAYOUT)
   DESCRIPTION: Fixed Flexbox Layout, Hidden Panels & Unified Toolbar
   ========================================================================== */

#mh-crm-root {
    /* --- VARIABLES --- */
    --mh-primary: #008069;       /* WhatsApp Green */
    --mh-primary-dark: #005c4b;
    --mh-bg: #f0f2f5;
    --mh-white: #ffffff;
    --mh-border: #e0e0e0;
    --mh-text-main: #111b21;
    --mh-text-sec: #54656f;
    --mh-hover: #f5f6f6;
    
    /* --- RESET & LAYOUT --- */
    font-family: 'Segoe UI', 'Heebo', sans-serif;
    direction: rtl;
    background-color: var(--mh-bg);
    color: var(--mh-text-main);
    font-size: 14px;
    line-height: 1.5;
    
    /* FULL SCREEN LOCK */
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh; z-index: 99999;
    
    display: flex;
    flex-direction: column; /* Header Top, Content Bottom */
}

#mh-crm-root * { box-sizing: border-box; outline: none; }

/* Admin Bar Fix */
body.admin-bar #mh-crm-root { top: 32px; height: calc(100vh - 32px); }
@media screen and (max-width: 782px) { body.admin-bar #mh-crm-root { top: 46px; height: calc(100vh - 46px); } }

/* ==============================
   1. HEADER & TOOLBAR
   ============================== */
.mh-custom-header {
    height: 64px; 
    background: var(--mh-bg); 
    border-bottom: 1px solid var(--mh-border);
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 20px; 
    flex-shrink: 0; /* Don't shrink header */
}

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

/* --- UNIFIED BUTTONS --- */
.crm-actions-wrapper { display: flex; gap: 8px; margin: 0; padding: 0; }
.crm-actions-wrapper .control-group { display: flex; gap: 8px; margin: 0; }

/* Hide unwanted buttons explicitly */
.crm-actions-wrapper button[data-action="open-group-send-modal"],
.crm-actions-wrapper button[data-action="sync-woo-revenue"] {
    display: none !important;
}

/* Unified White Button Style */
.crm-actions-wrapper button {
    background-color: var(--mh-white) !important;
    border: 1px solid var(--mh-border) !important;
    color: var(--mh-text-sec) !important;
    border-radius: 8px !important;
    height: 36px !important;
    min-width: 36px !important;
    padding: 0 12px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500 !important;
    font-size: 13px !important;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
    transition: all 0.2s ease !important;
    cursor: pointer;
}

.crm-actions-wrapper button:hover {
    background-color: var(--mh-hover) !important;
    border-color: var(--mh-primary) !important;
    color: var(--mh-primary) !important;
    transform: translateY(-1px);
}

.crm-actions-wrapper button .material-icons {
    font-size: 18px !important;
    color: inherit !important;
    margin: 0 !important;
}

/* Account Widget */
.crm-account-widget .profile-button {
    background: transparent !important; border: none !important; box-shadow: none !important;
    padding: 4px !important; display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.crm-account-widget .default-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: #e0e0e0; 
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.crm-account-widget .profile-text { font-weight: 600; font-size: 14px; color: var(--mh-text-main); }

/* ==============================
   2. MAIN LAYOUT (CRITICAL FIX)
   ============================== */
.mh-main-layout { 
    display: flex; 
    flex: 1; /* Take remaining height */
    overflow: hidden; 
    width: 100%; 
    position: relative;
}

/* Column 1: Contacts List (Fixed Width) */
.mh-col-sources { 
    width: 400px; 
    min-width: 400px; /* Prevent squeezing */
    background: var(--mh-white); 
    border-left: 1px solid var(--mh-border); 
    display: flex; 
    flex-direction: column; 
    z-index: 20; 
    flex-shrink: 0; /* Don't shrink */
}

/* Column 2: Selected (Collapsible) */
.mh-col-selected { 
    width: 0; 
    opacity: 0; 
    overflow: hidden; 
    background: #f7f8fa; 
    border-left: 1px solid var(--mh-border); 
    display: flex; flex-direction: column; 
    transition: all 0.3s ease; 
    z-index: 15; 
    flex-shrink: 0;
}
#mh-crm-root.has-selection .mh-col-selected { width: 320px; opacity: 1; }

/* Column 3: Preview (Takes remaining space) */
.mh-col-preview { 
    flex: 1; 
    background: #efeae2; 
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    display: flex; 
    flex-direction: column; /* Fix for centered content */
    align-items: center; 
    justify-content: center; 
    position: relative;
    overflow: hidden;
}

/* ==============================
   3. COLUMN 1: LIST CONTENT
   ============================== */
.mh-col-header { background: #f0f2f5; padding: 10px 15px; border-bottom: 1px solid var(--mh-border); flex-shrink: 0; }
.mh-tabs-nav { display: flex; gap: 5px; margin-bottom: 10px; }
.mh-tab-btn { flex: 1; padding: 6px; background: transparent; border: none; border-radius: 16px; cursor: pointer; color: var(--mh-text-sec); transition: 0.2s; }
.mh-tab-btn.active { background: var(--mh-white); color: var(--mh-primary); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* Filters */
.mh-filters-panel {
    max-height: 0; overflow: hidden; transition: max-height 0.3s ease;
    opacity: 0; display: flex; flex-direction: column; gap: 8px;
}
.mh-filters-panel.open { max-height: 200px; opacity: 1; padding-bottom: 5px; }
.mh-filter-row { background: var(--mh-white); border-radius: 8px; padding: 6px 10px; display: flex; align-items: center; border: 1px solid #ddd; }
.mh-filter-row input { border: none; width: 100%; background: transparent; }
.mh-filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.mh-filter-grid select { width: 100%; padding: 5px; border-radius: 5px; border: 1px solid #ddd; }

.mh-col-content { flex: 1; overflow-y: auto; position: relative; }
.mh-tab-pane { display: none; height: 100%; flex-direction: column; }
.mh-tab-pane.active { display: flex; }

/* List Items */
.mh-contact-item {
    display: flex; align-items: center; padding: 12px 15px;
    border-bottom: 1px solid #f0f2f5; cursor: pointer;
    transition: background 0.2s;
    animation: slideInUp 0.3s ease-out forwards;
}
.mh-contact-item:hover { background-color: var(--mh-hover); }
.mh-contact-item.selected { background-color: #e7f5ff; }
.mh-item-new { animation: newContactFlash 2s ease-out forwards !important; }

.mh-avatar { width: 42px; height: 42px; border-radius: 50%; background: #dfe3e5; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; margin-left: 12px; flex-shrink: 0; }
.mh-info { flex: 1; overflow: hidden; }
.mh-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mh-sub { font-size: 13px; color: var(--mh-text-sec); }

/* ==============================
   4. PREVIEW DEVICE & COMPOSER (FIXED)
   ============================== */
.mh-wa-device {
    width: 100%; height: 100%; max-width: 100%; /* Full size in col */
    background: transparent; 
    display: flex; flex-direction: column;
}

.mh-wa-header { background: #f0f2f5; height: 60px; display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid var(--mh-border); flex-shrink: 0; }
.mh-wa-info { flex: 1; display: flex; flex-direction: column; margin-right: 15px; }
.mh-wa-name { font-weight: 600; font-size: 16px; }
.mh-wa-chat-area { flex: 1; padding: 20px 30px; overflow-y: auto; display: flex; flex-direction: column; }
.mh-wa-bubble { background: #d9fdd3; padding: 8px 12px; border-radius: 7.5px; box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); max-width: 70%; align-self: flex-end; margin-bottom: 10px; }

/* COMPOSER FIX */
.mh-wa-composer { 
    background: #f0f2f5; 
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0; /* Prevent squash */
    border-top: 1px solid var(--mh-border); 
}

.mh-composer-tabs { display: flex; padding: 0 10px; border-bottom: 1px solid #ddd; }
.mh-comp-tab { padding: 10px 16px; border: none; background: transparent; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 600; color: var(--mh-text-sec); }
.mh-comp-tab.active { color: var(--mh-primary); border-bottom-color: var(--mh-primary); }

/* PANELS - Hidden by default! */
.mh-composer-panel { 
    display: none; /* CRITICAL FIX */
    height: 150px; 
    background: #fff; 
    padding: 12px; 
    overflow-y: auto; 
}
.mh-composer-panel.active { display: block; }

.mh-chat-textarea { width: 100%; height: 100%; border: none; resize: none; font-size: 16px; font-family: inherit; }

/* Emoji Grid Fix */
.mh-emoji-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); 
    gap: 5px; 
}
.mh-emoji-btn { 
    font-size: 22px; cursor: pointer; text-align: center; padding: 5px; border-radius: 4px; 
}
.mh-emoji-btn:hover { background-color: #f0f0f0; }

/* Tags Grid */
.mh-tags-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.mh-tag-insert { background: #e7f5ff; color: var(--mh-primary); border: 1px solid var(--mh-primary); padding: 4px 10px; border-radius: 15px; cursor: pointer; font-size: 13px; font-weight: 500; }

.mh-composer-footer { display: flex; align-items: center; padding: 8px 16px; gap: 12px; min-height: 60px; }
.mh-send-btn { margin-right: auto; background: var(--mh-primary); color: white; border: none; padding: 8px 20px; border-radius: 24px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; }

/* ==============================
   5. MODALS & OVERLAYS
   ============================== */
.modal { background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 200000; }
.modal.visible { display: flex; animation: slideInUp 0.2s; }

.modal-content { background: #fff; width: 90%; max-width: 500px; border-radius: 16px !important; box-shadow: 0 10px 40px rgba(0,0,0,0.15) !important; border: none !important; overflow: hidden !important; display: flex; flex-direction: column; max-height: 90vh; }
.modal-header { background: var(--mh-primary) !important; color: #fff !important; padding: 15px 20px !important; border: none !important; display: flex; justify-content: space-between; align-items: center; }
.modal-header .modal-title { color: #fff !important; font-size: 18px !important; margin: 0; }
.modal-header .close { color: #fff !important; opacity: 0.8; background: transparent; border: none; font-size: 24px; cursor: pointer; }
.modal-body { padding: 25px !important; font-size: 15px; overflow-y: auto; flex: 1; }
.modal-footer { background: #fff !important; padding: 15px 25px !important; border-top: 1px solid #eee !important; display: flex; justify-content: flex-end; gap: 10px; }

.crm-input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 8px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 600; color: #666; }

/* Import Overlay */
#mh-import-progress-overlay { position: fixed; top:0; left:0; width:100%; height:100%; background: rgba(255,255,255,0.95); z-index: 200001; display: none; flex-direction: column; align-items: center; justify-content: center; }
#mh-import-progress-overlay.active { display: flex; }
.import-spinner { width: 50px; height: 50px; border: 4px solid #eee; border-top-color: var(--mh-primary); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20px; }
.import-status-text { font-size: 18px; font-weight: bold; }
.import-current-name { font-size: 14px; color: #666; margin-top: 5px; }

/* Animations */
@keyframes spin { 100% { transform: rotate(360deg); } }
@keyframes slideInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes newContactFlash { 0% { background-color: #dcf8c6; } 100% { background-color: transparent; } }

/* Account Styles */
.mh-header-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 2px solid #25D366; }
.mh-account-menu-separator { height: 1px; background: #eee; margin: 15px 0; }
.mh-account-menu-wrapper a { display: flex; justify-content: space-between; padding: 10px; color: #333; text-decoration: none; border-bottom: 1px solid #f9f9f9; }
.mh-account-menu-wrapper a:hover { background: #f0f7f5; color: var(--mh-primary); }
}