:root {
    /* CAMBIO DE FUENTE: Inter es excelente para legibilidad en interfaces densas */
    --font-heading: 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --color-bg: #f8f9fa; 
    --color-container-bg: #FFFFFF;
    --color-sidebar-bg: #FFFFFF;
    --color-text: #5D5C61;
    --color-text-light: #7e7c82;
    --color-primary: #81B29A; 
    --color-secondary: #E07A5F;
    --color-accent: #F2CC8F;
    --color-border: #EAE6E1;
    --color-shadow: rgba(93, 92, 97, 0.08);
    --color-danger: #dc3545;
    --color-danger-hover: #c82333;
    --color-success: #28a745;
    --color-success-hover: #218838;
    --color-subtle-bg: #f0f0f0;
    --color-subtle-text: #7e7c82;
    --color-subtle-hover-bg: #e0e0e0;
    --color-bubble-sent-bg: #dcf8c6;
    --color-bubble-sent-text: #303030;
    --color-bubble-received-bg: #FFFFFF;
    --color-bubble-received-text: #303030;
    --border-radius-sm: 6px;
    --border-radius-md: 10px;
    --border-radius-lg: 15px;
}

/* --- TOKYO NIGHT THEME --- */
body.dark-mode {
    --color-bg: #1a1b26; /* Fondo principal oscuro profundo */
    --color-container-bg: #24283b; /* Fondo de contenedores/tarjetas */
    --color-sidebar-bg: #16161e; /* Fondo de la barra lateral un poco más oscuro */
    --color-text: #ffffff; /* Texto principal blanco/neón brillante */
    --color-text-light: #c0caf5; /* Texto secundario más brillante */
    
    /* Ajuste de colores primarios al estilo Tokyo Night */
    --color-primary: #7aa2f7; /* Azul Tokyo */
    --color-secondary: #bb9af7; /* Magenta suave */
    --color-accent: #e0af68; /* Naranja/Dorado suave */
    
    --color-border: #414868; /* Bordes azul grisáceo */
    --color-shadow: rgba(0, 0, 0, 0.3); /* Sombras más fuertes */
    
    --color-danger: #f7768e; /* Rojo Tokyo */
    --color-danger-hover: #db4b4b;
    --color-success: #9ece6a; /* Verde Tokyo */
    --color-success-hover: #73d029;
    
    --color-subtle-bg: #292e42;
    --color-subtle-text: #787c99;
    --color-subtle-hover-bg: #3b4261;
    
    /* Burbujas de Chat */
    --color-bubble-sent-bg: #3d59a1; /* Azul más intenso para enviados */
    --color-bubble-sent-text: #ffffff;
    --color-bubble-received-bg: #292e42; /* Gris azulado para recibidos */
    --color-bubble-received-text: #ffffff;
}

body { font-family: var(--font-body); background-color: var(--color-bg); color: var(--color-text); font-size: 14px; overflow: hidden; transition: background-color 0.3s ease, color 0.3s ease; }
body.modal-open { overflow: hidden; }
h1, h2, h3, h4, h5, h6 { font-family: var(--font-heading); color: var(--color-text); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #dcdcdc; border-radius: 3px; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #414868; }
::-webkit-scrollbar-thumb:hover { background: #c5c5c5; }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: #565f89; }

/* CORRECCIÓN AQUÍ: Se agrega !important para asegurar que oculte los elementos */
.hidden { display: none !important; }
.note-actions-visible { display: none; }
.sidebar-note:hover .note-actions-visible { display: flex !important; }

input[type="file"], input[type="color"] { display: none; }
.btn { font-family: var(--font-heading); font-weight: 600; padding: 8px 18px; border: none; border-radius: var(--border-radius-md); cursor: pointer; font-size: 0.9rem; transition: all 0.2s ease; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:disabled { background-color: #cccccc; color: #666666; cursor: not-allowed; opacity: 0.7; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); }
.btn:active:not(:disabled) { transform: translateY(0px); box-shadow: none; }
.btn-sm { padding: 5px 12px; font-size: 0.85rem; }
.btn-icon { padding: 8px; font-size: 1rem; }
.btn-primary { background-color: var(--color-primary); color: white; }
.btn-primary:hover:not(:disabled) { background-color: #70a087; }
body.dark-mode .btn-primary { color: #1a1b26; font-weight: 700; } /* Texto oscuro en botón primario brillante */
body.dark-mode .btn-primary:hover:not(:disabled) { background-color: #5d8ae8; }

.btn-secondary { background-color: var(--color-secondary); color: white; }
.btn-secondary:hover:not(:disabled) { background-color: #d8684a; }
.btn-danger { background-color: var(--color-danger); color: white; }
.btn-danger:hover:not(:disabled) { background-color: #c82333; }
.btn-success { background-color: var(--color-success); color: white; }
.btn-success:hover:not(:disabled) { background-color: var(--color-success-hover); }
.btn-subtle { background-color: var(--color-subtle-bg); color: var(--color-subtle-text); }
.btn-subtle:hover { background-color: var(--color-subtle-hover-bg); color: var(--color-primary); }

input[type="email"], input[type="password"], input[type="text"], input[type="number"], input[type="tel"], textarea, select { width: 100%; padding: 10px 15px; margin-bottom: 15px; border: 1px solid var(--color-border); border-radius: var(--border-radius-md); font-family: var(--font-body); font-size: 0.95rem; color: var(--color-text); background-color: #f7f9fc; transition: all 0.2s ease; }
body.dark-mode input[type="email"], body.dark-mode input[type="password"], body.dark-mode input[type="text"], body.dark-mode input[type="number"], body.dark-mode input[type="tel"], body.dark-mode textarea, body.dark-mode select {
    background-color: #1f2335;
    color: #c0caf5;
}

input:focus, textarea:focus, select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(129, 178, 154, 0.2); }
body.dark-mode input:focus, body.dark-mode textarea:focus, body.dark-mode select:focus { box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.2); }

/* --- AD REFERRAL BANNER --- */
.ad-referral-banner {
    background: linear-gradient(135deg, #fff9c4 0%, #fffde7 100%);
    border-bottom: 1px solid #fff59d;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideDown 0.3s ease-out;
}

.ad-referral-icon {
    width: 36px;
    height: 36px;
    background: #fbc02d;
    color: white;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 4px rgba(251, 192, 45, 0.3);
}

.ad-referral-content {
    flex-grow: 1;
}

.ad-referral-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    color: #f57f17;
    margin: 0;
    letter-spacing: 0.5px;
}

.ad-referral-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #424242;
    margin: 1px 0 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ad-referral-link {
    color: #fbc02d;
    font-size: 1.1rem;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
}

.ad-referral-link:hover {
    background: rgba(251, 192, 45, 0.1);
    transform: scale(1.1);
}

@keyframes slideDown {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

input:disabled { background-color: #f0f2f5; cursor: not-allowed; }
#search-contacts-input { margin-bottom: 0; background-color: var(--color-container-bg); }
#search-contacts-input.pr-8 { padding-right: 2.5rem; } /* Asegura espacio para el botón */
#app-header { background-color: var(--color-container-bg); border-bottom: 1px solid var(--color-border); transition: background-color 0.3s ease; }
#app-header h1 { color: var(--color-primary); }
body.dark-mode #user-info { color: #c0caf5; }
#contacts-panel { background-color: #f8f9fa; border-right: 1px solid var(--color-border); transition: background-color 0.3s ease; }
body.dark-mode #contacts-panel { background-color: #1a1b26; }

.contact-item { transition: all 0.2s ease; border-left: 8px solid transparent; }
.contact-item:hover { background-color: #eef2f7; }
body.dark-mode .contact-item:hover { background-color: #292e42; }

/* Efecto de aro pulsante para chats con IA */
.contact-item.ai-active .rounded-full:first-child,
.contact-item.ai-active img.rounded-full:first-child {
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    animation: pulse-green 2s infinite;
    border: 2px solid #28a745;
}

@keyframes pulse-green {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

@keyframes mesh-flow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.contact-item.selected { background-image: linear-gradient(to right, var(--color-primary) 80%, var(--color-container-bg)); border-left-color: var(--color-primary); }
.contact-item.selected h3, .contact-item.selected p { color: white !important; }
body.dark-mode .contact-item.selected h3, body.dark-mode .contact-item.selected p { color: #ffffff !important; font-weight: 700; text-shadow: 0 0 5px rgba(255,255,255,0.3); }

.contact-item.selected .unread-badge { background-color: white; color: var(--color-primary); }
body.dark-mode .contact-item.selected .unread-badge { background-color: #ffffff; color: #1a1b26; box-shadow: 0 0 8px rgba(255,255,255,0.6); }

.contact-item.selected .fas, .contact-item.selected .far { color: white !important; }
body.dark-mode .contact-item.selected .fas, body.dark-mode .contact-item.selected .far { color: #ffffff !important; text-shadow: 0 0 5px rgba(255,255,255,0.4); }

.contact-item.campaign-mode { cursor: default; }
.contact-item.campaign-mode:hover { background-color: transparent; }
.unread-badge { background-color: var(--color-primary); color: white; font-size: 0.7rem; font-weight: 700; padding: 2px 7px; border-radius: 12px; min-width: 20px; text-align: center; line-height: 1.2; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
body.dark-mode .unread-badge { color: #1a1b26; background-color: #00ffcc; box-shadow: 0 0 8px rgba(0, 255, 204, 0.6); }

.contact-time-label { font-size: 0.7rem; font-weight: 500; color: #6b7280; }
body.dark-mode .contact-time-label { color: #a9b1d6; }
.contact-item.selected .contact-time-label { color: rgba(255, 255, 255, 0.85); }

.order-badge {
    background-color: var(--color-accent);
    color: var(--color-text);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}
body.dark-mode .order-badge { color: #1a1b26; background-color: #ff9e64; box-shadow: 0 0 8px rgba(255, 158, 100, 0.6); }

/* Badge de pedidos diarios en el header */
.orders-badge {
    background-color: #81B29A; /* Verde salvia pacífico (Sage Green) */
    color: white;
    font-size: 0.95rem; /* Casi el doble de grande (era 0.65rem) */
    font-weight: 700;
    min-width: 30px; /* Más grande */
    height: 30px; /* Más grande */
    padding: 0 10px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    z-index: 10;
    border: 2px solid var(--color-container-bg);
    animation: badge-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: default;
}

body.dark-mode .orders-badge {
    background-color: #5d8e76; /* Versión un poco más profunda para modo oscuro */
    border-color: var(--color-container-bg);
}

@keyframes badge-pop {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

#chat-panel { 
    background-color: #e5ddd5;
    position: relative;
    z-index: 1;
}

#chat-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    z-index: -1;
    opacity: 0.8;
}

body.dark-mode #chat-panel { 
    background-color: #16161e; 
}

body.dark-mode #chat-panel::before {
    filter: invert(1) hue-rotate(180deg) brightness(0.6) contrast(0.9);
}


.chat-header { background-color: #f8f9fa; border-bottom: 1px solid var(--color-border); transition: background-color 0.3s ease; }
body.dark-mode .chat-header { background-color: #1a1b26; }

.chat-footer { background-color: #f8f9fa; padding: 8px 16px; transition: background-color 0.3s ease; }
body.dark-mode .chat-footer { background-color: #1a1b26; }

#message-input { 
    background-color: var(--color-container-bg); 
    border-radius: 20px; 
    padding: 12px 20px; 
    border: 1px solid var(--color-border); 
    font-size: 0.9rem; 
    min-height: 44px;
    max-height: 120px;
    overflow-y: auto;
    resize: none;
    line-height: 1.4;
}
#message-input:focus { 
    outline: none; 
    border-color: var(--color-primary); 
    box-shadow: 0 0 0 2px rgba(129, 178, 154, 0.2); 
}
body.dark-mode #message-input:focus { box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.2); }

.chat-icon-btn { color: var(--color-text-light); transition: color 0.2s ease; }
.chat-icon-btn:hover { color: var(--color-primary); }

.message-group {
    display: flex;
    margin: 1px 0;
    position: relative;
    align-items: center;
    user-select: none; /* Prevent text selection on the group container */
}
.message-group.sent { justify-content: flex-end; }
.message-group.received { justify-content: flex-start; }

.message-bubble { 
    position: relative; 
    padding: 6px 12px; 
    border-radius: var(--border-radius-md); 
    box-shadow: 0 1px 1px rgba(0,0,0,0.05); 
    max-width: 60%; 
    user-select: text; /* Allow text selection inside the bubble */
}
.message-bubble.sent { background-color: var(--color-bubble-sent-bg); color: var(--color-bubble-sent-text); border-bottom-right-radius: 4px; }
.message-bubble.received { background-color: var(--color-bubble-received-bg); color: var(--color-bubble-received-text); border-bottom-left-radius: 4px; }

/* Styles for links in dark mode */
.chat-link { text-decoration: underline; }
body.dark-mode .chat-link { color: #7aa2f7 !important; }
body.dark-mode .message-bubble.sent .chat-link { color: #7dcfff !important; font-weight: 500; }
body.dark-mode .message-bubble.received .chat-link { color: #7aa2f7 !important; font-weight: 500; }

.message-bubble.message-queued { background-color: #dbeafe; color: #1e40af; border-bottom-right-radius: 4px; }
body.dark-mode .message-bubble.message-queued { background-color: #3b4261; color: #c0caf5; }

/* --- Correction Start: Styles for the message actions menu --- */
/* The menu is positioned absolutely inside the message bubble, which has position: relative. */
.message-actions {
    display: flex;
    align-items: center;
    position: absolute;
    top: 50%;
    z-index: 10;
    background-color: white;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    padding: 2px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%) scale(0.9);
    transition: all 0.15s ease-in-out;
}
body.dark-mode .message-actions { background-color: #292e42; border: 1px solid #414868; }

/* The menu appears on hovering over the message bubble, not the entire group. */
.message-bubble:hover .message-actions {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) scale(1);
}
/* For sent messages, the menu is positioned to the left of the bubble. */
.message-group.sent .message-actions {
    right: 100%;
    margin-right: 8px;
}
/* For received messages, the menu is positioned to the right of the bubble. */
.message-group.received .message-actions {
    left: 100%;
    margin-left: 8px;
}
.reaction-bar {
    display: flex;
    align-items: center;
    border-right: 1px solid var(--color-border);
    padding-right: 4px;
    margin-right: 4px;
}
.reaction-emoji-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    transition: transform 0.1s ease;
}
.reaction-emoji-btn:hover {
    transform: scale(1.3);
}
.message-action-btn {
    background: none; border: none; cursor: pointer; color: var(--color-text-light); padding: 6px; display: flex; align-items: center; justify-content: center;
}
.message-action-btn:hover {
    color: var(--color-primary);
}
/* --- Correction End --- */

.reactions-container { position: absolute; bottom: -10px; right: 10px; background-color: white; border-radius: 10px; padding: 2px 5px; font-size: 0.8rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
body.dark-mode .reactions-container { background-color: #414868; }
.reactions-container.received-reaction { left: 10px; right: auto; }
.reply-preview { background-color: rgba(0,0,0,0.05); padding: 8px; margin: 0 0 8px 0; border-left: 3px solid var(--color-primary); border-radius: var(--border-radius-sm); }
body.dark-mode .reply-preview { background-color: rgba(255,255,255,0.05); }
.reply-preview p { margin: 0; font-size: 0.85rem; }
.reply-preview .reply-author { font-weight: 600; color: var(--color-primary); }
.reply-preview .reply-text { color: var(--color-text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#reply-context-bar { background-color: #f0f2f5; padding: 8px 16px; border-top: 1px solid var(--color-border); position: relative; }
body.dark-mode #reply-context-bar { background-color: #1f2335; }
#cancel-reply-btn { position: absolute; top: 4px; right: 8px; background: none; border: none; font-size: 1.2rem; color: #999; cursor: pointer; }
.message-status-icon { vertical-align: middle; }

.message-bubble img, .message-bubble video { border-radius: var(--border-radius-sm); }
.drag-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(255, 255, 255, 0.85); border: 3px dashed var(--color-primary); border-radius: 0.5rem; display: flex; align-items: center; justify-content: center; z-index: 20; pointer-events: none; }
body.dark-mode .drag-overlay { background-color: rgba(26, 27, 38, 0.85); }
.drag-overlay-content { color: var(--color-primary); font-family: var(--font-heading); font-size: 1.5rem; font-weight: 600; text-align: center; }
#file-preview-container { background-color: #f8f9fa; padding: 10px 12px; border-bottom: 1px solid var(--color-border); }
body.dark-mode #file-preview-container { background-color: #1a1b26; }
.file-preview-grid { display: flex; gap: 10px; overflow-x: auto; padding: 4px 0; }
.file-preview-item { position: relative; display: flex; flex-direction: column; align-items: center; background-color: var(--color-container-bg); border-radius: var(--border-radius-md); padding: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); min-width: 90px; max-width: 110px; flex-shrink: 0; }
body.dark-mode .file-preview-item { background-color: #292e42; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.file-thumb { width: 80px; height: 80px; border-radius: var(--border-radius-sm); object-fit: cover; display: block; }
.file-thumb-icon { display: flex; align-items: center; justify-content: center; background-color: #e2e8f0; color: #64748b; font-size: 1.5rem; }
.file-thumb-icon.video { background-color: #dbeafe; color: #3b82f6; }
.file-thumb-icon.audio { background-color: #fce7f3; color: #ec4899; }
.file-thumb-icon.doc { background-color: #fef3c7; color: #f59e0b; }
body.dark-mode .file-thumb-icon { background-color: #3b4261; color: #a9b1d6; }
.file-preview-info { margin-top: 6px; text-align: center; width: 100%; overflow: hidden; }
.file-preview-name { display: block; font-size: 0.7rem; font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview-size { display: block; font-size: 0.65rem; color: var(--color-text-light); }
.file-remove-btn { position: absolute; top: -6px; right: -6px; background-color: var(--color-danger); color: white; border: 2px solid white; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.2); transition: all 0.15s ease; z-index: 2; padding: 0; }
.file-remove-btn:hover { background-color: var(--color-danger-hover); transform: scale(1.1); }
body.dark-mode .file-remove-btn { border-color: #1a1b26; }
/* Keep old cancel-file-btn styles for RemoteFilePreviewTemplate */
.file-preview-content { position: relative; display: inline-flex; align-items: center; background-color: var(--color-container-bg); border-radius: var(--border-radius-md); padding: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.file-preview-content img, .file-preview-content video { max-height: 60px; max-width: 60px; border-radius: var(--border-radius-sm); object-fit: cover; }
#cancel-file-btn { position: absolute; top: -8px; right: -8px; background-color: var(--color-danger); color: white; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: background-color 0.2s ease; }
#cancel-file-btn:hover { background-color: var(--color-danger-hover); }
.date-separator { text-align: center; margin: 16px auto 12px; padding: 5px 12px; background-color: #e1f3fb; color: var(--color-text); border-radius: var(--border-radius-md); box-shadow: 0 1px 1px rgba(0,0,0,0.05); font-size: 0.8rem; font-weight: 600; max-width: fit-content; }
body.dark-mode .date-separator { background-color: #292e42; color: #a9b1d6; }
#sticky-date-header { position: absolute; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 10; transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out; opacity: 0; pointer-events: none; }
#sticky-date-header.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.chat-image-preview { width: 250px; height: 250px; object-fit: cover; border-radius: var(--border-radius-sm); display: block; cursor: pointer; }
.chat-sticker-preview { width: 75px; height: 75px; object-fit: contain; }
.message-bubble video { 
    max-width: 100%; 
    height: auto; 
    border-radius: 8px; 
}
.chat-audio-player { width: 250px; min-width: 250px; height: 45px; }

.message-bubble.has-image, .message-bubble.has-video { 
    padding: 5px; 
    max-width: 270px; 
}
.time-overlay { position: absolute; bottom: 5px; right: 8px; background-color: rgba(0, 0, 0, 0.4); color: white !important; padding: 1px 6px; border-radius: 10px; font-size: 0.7rem; display: inline-flex; align-items: center; gap: 4px; }
.time-overlay .fas { color: white !important; }
.image-modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.75); z-index: 998; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.image-modal-backdrop.visible { opacity: 1; pointer-events: all; }
.image-modal-content { position: relative; transform: scale(0.9); transition: transform 0.3s ease; }
.image-modal-backdrop.visible .image-modal-content { transform: scale(1); }
.image-modal-content img { max-width: 90vw; max-height: 85vh; border-radius: var(--border-radius-md); }
.image-modal-close { position: absolute; top: -15px; right: -15px; width: 35px; height: 35px; background-color: white; color: black; border-radius: 50%; border: none; font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.document-link { display: flex; align-items: center; gap: 10px; color: var(--color-text); padding: 8px; text-decoration: none; }
.document-icon { font-size: 1.8rem; color: var(--color-primary); }
.document-text { font-weight: 600; }

.sticker-fallback {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: #f0f2f5;
    padding: 8px 12px;
    border-radius: 18px;
    font-style: italic;
    color: #54656f;
    font-weight: 500;
}
body.dark-mode .sticker-fallback { background-color: #3b4261; color: #a9b1d6; }

.filter-btn { background-color: #e2e8f0; color: #4a5568; font-weight: 600; padding: 5px 10px; border-radius: 9999px; font-size: 0.75rem; transition: all 0.2s ease; cursor: pointer; border: none; }
body.dark-mode .filter-btn { background-color: #414868; color: #a9b1d6; }
.filter-btn.active { background-color: var(--color-primary); color: white; }
body.dark-mode .filter-btn.active { color: #1a1b26; }

.tag-dropdown-wrapper { position: relative; display: inline-block; }
.tag-dropdown-toggle { display: flex; align-items: center; gap: 4px; }
.tag-dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; background: white; border: 1px solid #e2e8f0; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 50; min-width: 160px; padding: 4px 0; }
body.dark-mode .tag-dropdown-menu { background: #24283b; border-color: #414868; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.tag-dropdown-menu.hidden { display: none; }
.tag-dropdown-item { display: flex; align-items: center; width: 100%; padding: 8px 14px; font-size: 0.8rem; font-weight: 500; color: #4a5568; background: none; border: none; cursor: pointer; text-align: left; transition: background 0.15s ease; }
.tag-dropdown-item:hover { background-color: #f1f5f9; }
body.dark-mode .tag-dropdown-item { color: #a9b1d6; }
body.dark-mode .tag-dropdown-item:hover { background-color: #414868; }
.tag-dropdown-item.active { color: var(--color-primary); font-weight: 700; }

.tab-btn { position: relative; padding: 6px 14px; font-weight: 600; color: var(--color-text-light); border-bottom: 3px solid transparent; transition: all 0.2s ease; font-size: 0.9rem; }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.note-count-badge { position: absolute; top: 2px; right: 2px; background-color: var(--color-secondary); color: white; font-size: 0.65rem; font-weight: 700; border-radius: 50%; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }
body.dark-mode .note-count-badge { color: #1a1b26; }

.note-item { background-color: #fffbeb; border-left: 4px solid #facc15; padding: 12px; border-radius: var(--border-radius-md); margin-bottom: 10px; }
body.dark-mode .note-item { background-color: #2e2c22; border-left-color: #e0af68; }

/* Animación de glow en movimiento para la zona de notas en el sidebar */
@keyframes sidebar-glow {
    0% { background-position: 0% 50%; box-shadow: 0 0 10px rgba(242, 204, 143, 0.2); }
    50% { background-position: 100% 50%; box-shadow: 0 0 20px rgba(242, 204, 143, 0.4); }
    100% { background-position: 0% 50%; box-shadow: 0 0 10px rgba(242, 204, 143, 0.2); }
}

.notes-glow {
    background: linear-gradient(-45deg, #fffbeb, #fef3c7, #fff9db, #fffbeb);
    background-size: 400% 400%;
    animation: sidebar-glow 5s ease infinite;
    border-radius: var(--border-radius-lg);
}

body.dark-mode .notes-glow {
    background: linear-gradient(-45deg, #2e2c22, #3d3a2b, #2e2c22, #1f1d16);
    background-size: 400% 400%;
    box-shadow: 0 0 15px rgba(224, 175, 104, 0.1);
}
.note-item p { margin: 0; white-space: pre-wrap; }
.note-item .note-meta { font-size: 0.75rem; color: var(--color-text-light); margin-top: 8px; display: flex; justify-content: space-between; align-items: center; }
.note-actions button { background: none; border: none; color: var(--color-text-light); cursor: pointer; padding: 4px; }
.note-actions button:hover { color: var(--color-primary); }
#emoji-picker { position: absolute; bottom: 60px; left: 10px; background: white; border-radius: var(--border-radius-lg); box-shadow: 0 5px 15px rgba(0,0,0,0.15); z-index: 30; width: 300px; }
body.dark-mode #emoji-picker { background-color: #24283b; border: 1px solid #414868; }
.picker-header { padding: 8px; border-bottom: 1px solid var(--color-border); }
.picker-content { padding: 8px; max-height: 200px; overflow-y: auto; }
.emoji-category { font-weight: bold; margin-top: 8px; margin-bottom: 4px; font-size: 0.9rem; }
.emoji, .quick-reply-item { cursor: pointer; padding: 5px; border-radius: 5px; display: inline-block; font-size: 1.2rem; }
.emoji:hover, .quick-reply-item:hover { background-color: #f0f0f0; }
body.dark-mode .emoji:hover, body.dark-mode .quick-reply-item:hover { background-color: #414868; }

.picker-container { position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 8px; background: white; border-radius: var(--border-radius-md); box-shadow: 0 -5px 15px rgba(0,0,0,0.1); z-index: 30; max-height: 250px; overflow-y: auto; }
body.dark-mode .picker-container { background-color: #24283b; border: 1px solid #414868; }
.picker-item { display: block; width: 100%; text-align: left; font-size: 0.9rem; padding: 10px 15px; cursor: pointer; border-bottom: 1px solid var(--color-border); }
.picker-item:last-child { border-bottom: none; }
.picker-item:hover, .picker-item.selected { background-color: #eef2ff; }
body.dark-mode .picker-item:hover, body.dark-mode .picker-item.selected { background-color: #3b4261; }
.picker-item strong { color: var(--color-primary); }
.picker-add-btn { display: block; width: 100%; text-align: left; font-size: 0.9rem; padding: 10px 15px; cursor: pointer; color: var(--color-primary); font-weight: 600; }
.picker-add-btn:hover { background-color: #f7f9fc; }
body.dark-mode .picker-add-btn:hover { background-color: #1a1b26; }
.template-item .template-category { font-size: 0.75rem; background-color: var(--color-subtle-bg); color: var(--color-subtle-text); padding: 2px 6px; border-radius: 9999px; text-transform: uppercase; font-weight: 600; }

.modal-backdrop, .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 998; display: flex; align-items: center; justify-content: center; }
body.dark-mode .modal-overlay { background-color: rgba(0, 0, 0, 0.8); }

.modal-content {
    background-color: var(--color-container-bg);
    padding: 30px 40px;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transition: all 0.3s ease;
}
.modal-content h2 { margin-top: 0; margin-bottom: 20px; font-size: 1.5rem; }
.modal-content label { display: block; font-weight: 600; margin-bottom: 8px; }
.media-preview { margin-top: 10px; max-height: 100px; border-radius: var(--border-radius-md); }

#contact-details-panel { width: 0; transition: width 0.3s ease-in-out; background-color: var(--color-container-bg); border-left: 1px solid var(--color-border); flex-shrink: 0; }
#contact-details-panel.open { width: 320px; }

.status-btn-group { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn { 
    padding: 3px 10px; font-size: 0.7rem; border-radius: 9999px; 
    border: 1px solid color-mix(in srgb, var(--btn-color) 50%, transparent); 
    font-weight: 600; cursor: pointer; transition: all 0.2s ease; 
    background-color: color-mix(in srgb, var(--btn-color) 20%, transparent); 
    color: var(--btn-color);
}
.status-btn.active { 
    background-color: var(--btn-color); 
    color: white; 
    border-color: var(--btn-color);
}
.status-btn:hover:not(.active) { transform: translateY(-1px); }

/* Ensure inactive tags remain readable on dark mode backgrounds */
body.dark-mode .status-btn:not(.active) {
    background-color: color-mix(in srgb, var(--btn-color) 25%, transparent);
    color: color-mix(in srgb, var(--btn-color) 40%, white);
    border-color: color-mix(in srgb, var(--btn-color) 30%, white);
}

.status-dropdown-wrapper { position: relative; display: inline-block; }
.status-dropdown-menu { position: absolute; top: calc(100% + 6px); left: 0; background: white; border: 1px solid #e2e8f0; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 50; min-width: 150px; padding: 4px 0; }
body.dark-mode .status-dropdown-menu { background: #24283b; border-color: #414868; box-shadow: 0 4px 16px rgba(0,0,0,0.4); }
.status-dropdown-menu.hidden { display: none; }
.status-dropdown-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 14px; font-size: 0.75rem; font-weight: 500; color: #4a5568; background: none; border: none; cursor: pointer; text-align: left; transition: background 0.15s ease; }
.status-dropdown-item:hover { background-color: #f1f5f9; }
body.dark-mode .status-dropdown-item { color: #a9b1d6; }
body.dark-mode .status-dropdown-item:hover { background-color: #414868; }
.status-dropdown-item.active { font-weight: 700; color: var(--btn-color); }
.status-dropdown-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

#main-sidebar { background-color: var(--color-sidebar-bg); border-right: 1px solid var(--color-border); width: 280px; transition: width 0.3s ease-in-out; flex-shrink: 0; }
#main-sidebar.collapsed { width: 80px; }
#main-sidebar.collapsed .sidebar-text { display: none; }
#main-sidebar.collapsed .nav-item { justify-content: center; }
.nav-item { display: flex; align-items: center; padding: 12px 16px; border-radius: var(--border-radius-md); margin-bottom: 6px; transition: background-color 0.2s ease, color 0.2s ease; cursor: pointer; font-weight: 600; color: var(--color-text-light); }
.nav-item:hover { background-color: #f0f2f5; color: var(--color-text); }
body.dark-mode .nav-item:hover { background-color: #24283b; }
.nav-item.active { background-color: #eef2ff; color: #4338ca; }
body.dark-mode .nav-item.active { background-color: #3b4261; color: #c0caf5; }
.nav-item i { width: 24px; text-align: center; margin-right: 12px; font-size: 1.1rem; }
#main-sidebar.collapsed .nav-item i { margin-right: 0; }
.rotate-180 { transform: rotate(180deg); }

.view-container { padding: 2rem; background-color: var(--color-container-bg); height: 100%; overflow-y: auto; }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.view-header h1 { font-size: 1.8rem; font-weight: 700; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--color-border); }
.table th { font-weight: 600; color: var(--color-text-light); font-size: 0.8rem; text-transform: uppercase; }
.table tr:hover { background-color: #f8f9fa; }
body.dark-mode .table tr:hover { background-color: #292e42; }
.tag-color-cell { display: flex; align-items: center; gap: 10px; }
.tag-color-swatch { width: 24px; height: 24px; border-radius: 50%; }
.actions-cell button, .actions-cell a { color: var(--color-text-light); }
.actions-cell button:hover, .actions-cell a:hover { color: var(--color-primary); }

.campaign-form-section { margin-bottom: 2rem; }
.campaign-form-section label { display: block; font-weight: 600; margin-bottom: 0.5rem; }
#recipient-count-display { margin-top: 0.5rem; font-style: italic; color: var(--color-text-light); }

#app-body { display: flex; flex: 1; overflow: hidden; }
#main-view-container { flex: 1; min-width: 0; }
#chat-view { display: flex; flex: 1; min-width: 0; height: 100%; }
#contacts-panel { flex-shrink: 0; }
#chat-panel { flex-grow: 1; min-width: 0; }
#contact-details-panel { flex-shrink: 0; }

.color-picker-label { display: inline-block; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; border: 2px solid var(--color-border); }

.draggable-row { cursor: grab; }
.draggable-row:active { cursor: grabbing; }
.drag-handle { cursor: grab; padding: 0 10px; color: #a0aec0; }
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { background-color: #eef2ff; opacity: 0.7; }
body.dark-mode .sortable-ghost { background-color: #3b4261; }
.sortable-drag { background-color: #ffffff; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
body.dark-mode .sortable-drag { background-color: #24283b; }

.pipeline-container { display: flex; gap: 1rem; padding: 1rem; padding-right: 2rem; overflow-x: auto; height: 100%; align-items: flex-start; }
.pipeline-column { flex: 0 0 300px; width: 300px; background-color: #f1f2f4; border-radius: var(--border-radius-lg); display: flex; flex-direction: column; max-height: 100%; }
body.dark-mode .pipeline-column { background-color: #16161e; border: 1px solid #414868; }
.pipeline-header { padding: 1rem; font-weight: 600; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; gap: 8px; }
.pipeline-header .tag-color-swatch { flex-shrink: 0; }
.pipeline-cards { padding: 0.5rem; overflow-y: auto; min-height: 100px; flex-grow: 1; }
.pipeline-card { background-color: white; border-radius: var(--border-radius-md); padding: 0.8rem; margin-bottom: 0.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.08); cursor: pointer; border-left: 4px solid; transition: box-shadow 0.2s ease; }
body.dark-mode .pipeline-card { background-color: #24283b; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.pipeline-card:hover { box-shadow: 0 4px 8px rgba(0,0,0,0.12); }
.pipeline-card:active { cursor: grabbing; }
.pipeline-card .contact-name { font-weight: 600; }
.pipeline-card .last-message { font-size: 0.8rem; color: var(--color-text-light); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sortable-ghost.pipeline-card { opacity: 0.5; background: #cce5ff; }
body.dark-mode .sortable-ghost.pipeline-card { background: #414868; }

#loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: var(--color-bg); display: flex; justify-content: center; align-items: center; z-index: 9999; transition: opacity 0.5s ease; }
.login-container { background-color: var(--color-container-bg); padding: 40px; border-radius: var(--border-radius-lg); box-shadow: 0 5px 25px var(--color-shadow); text-align: center; max-width: 420px; width: 100%; }
.login-container h1 { margin-bottom: 25px; font-size: 1.8em; color: var(--color-primary); }
.login-container button { width: 100%; }
#login-error-message { margin-top: 15px; color: var(--color-danger); font-weight: 600; min-height: 1.2em; }

.toggle-switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 28px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--color-primary); }
input:checked + .slider:before { transform: translateX(22px); }
.settings-card { background-color: var(--color-container-bg); border: 1px solid var(--color-border); border-radius: var(--border-radius-lg); padding: 1.5rem; }

/* Styles for Reply with Media Preview */
.reply-media-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.reply-thumbnail {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-sm);
    object-fit: cover;
    background-color: #e2e8f0; /* gray-200 */
}
body.dark-mode .reply-thumbnail { background-color: #414868; }

.reply-media-text {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.reply-media-icon {
    font-size: 0.8rem;
    line-height: 1;
}

.reply-media-caption {
    font-size: 0.85rem;
    color: var(--color-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Estilos para la vista de métricas */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}
.chart-container {
    background-color: var(--color-container-bg);
    padding: 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 4px 12px var(--color-shadow);
}
.chart-container h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.session-expired-banner {
    background-color: #fffbeb; /* yellow-100 */
    color: #92400e; /* yellow-800 */
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid #fef3c7; /* yellow-200 */
}
body.dark-mode .session-expired-banner { background-color: #422e05; color: #fcd34d; border-bottom-color: #5c4208; }

/* Styles for disabled chat input elements */
textarea:disabled {
    background-color: #f3f4f6; /* gray-100 */
    cursor: not-allowed;
}
body.dark-mode textarea:disabled { background-color: #1f2335; }

.disabled-icon {
    color: #d1d5db !important; /* gray-300 */
    cursor: not-allowed;
}
body.dark-mode .disabled-icon { color: #414868 !important; }

label.disabled-icon {
    pointer-events: none;
}

/* --- START: STYLES FOR NEW ORDER MODAL --- */
#new-order-modal .modal-content {
    max-width: 750px;
    padding: 30px 40px;
}
#nuevoPedidoContainer h2, #editPedidoContainer h2 {
    text-align: center;
    font-size: 1.5em;
    color: var(--color-secondary);
    margin-bottom: 25px;
}
#formularioNuevoPedido .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px 25px;
    margin-bottom: 25px;
}
.form-item-full {
    grid-column: 1 / -1;
}
#formularioNuevoPedido .form-actions, #edit-order-form .form-actions {
    text-align: right;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

#new-order-modal select, #order-edit-modal select {
    width: 100%;
    height: 44px;
    padding: 10px 15px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    background-color: #f7f9fc;
    color: var(--color-text);
    font-size: 0.95rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%237e7c82' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    transition: all 0.2s ease;
}

#new-order-modal select:focus, #order-edit-modal select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(129, 178, 154, 0.2);
}

body.dark-mode #new-order-modal select, body.dark-mode #order-edit-modal select {
    background-color: #1f2335;
    color: #c0caf5;
    border-color: #414868;
}

#new-order-modal button, #order-edit-modal button {
    font-family: var(--font-heading);
    font-weight: 600;
    padding: 12px 25px;
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 1rem;
    margin-top: 10px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 12px;
}

#btnGuardarPedido, #order-update-btn {
    background-color: var(--color-secondary) !important;
    color: white !important;
}

#btnGuardarPedido:hover, #order-update-btn:hover {
    background-color: #d8684a !important;
}

#new-order-modal button:not([type="submit"]), #order-edit-modal button:not([type="submit"]):not(#order-update-btn) {
    background-color: #f0f0f0;
    color: var(--color-text-light);
}
#new-order-modal button:not([type="submit"]):hover, #order-edit-modal button:not([type="submit"]):not(#order-update-btn):hover {
    background-color: #e0e0e0;
    color: var(--color-text);
}
#new-order-modal .modal-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 2.5rem;
    font-weight: 300;
    color: var(--color-text-light);
    cursor: pointer;
}
#new-order-modal .modal-close-btn:hover {
    color: var(--color-secondary);
}


/* Photo Upload Styling */
#new-order-modal .file-input-container, #order-edit-modal .file-input-container {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 15px;
    margin-bottom: 18px;
    transition: all 0.3s ease;
    outline: none;
}
#new-order-modal .file-input-container:focus-within, #order-edit-modal .file-input-container:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(129, 178, 154, 0.2);
}
#new-order-modal .file-input-container.drag-over, #order-edit-modal .file-input-container.drag-over {
    border-color: var(--color-primary);
    background-color: rgba(129, 178, 154, 0.1);
}
#new-order-modal .file-input-header, #order-edit-modal .file-input-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}
#new-order-modal .custom-file-upload, #order-edit-modal .custom-file-upload {
    display: inline-block;
    background-color: var(--color-secondary);
    color: white;
    padding: 10px 20px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1rem;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
#new-order-modal .custom-file-upload:hover {
    background-color: #6aa88d;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
#new-order-modal .previews-container, #order-edit-modal .previews-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 50px;
}
#new-order-modal .preview-thumbnail, #order-edit-modal .preview-thumbnail {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 2px solid transparent;
    background-color: #f0f2f5;
    cursor: grab;
    transition: border-color 0.2s ease, opacity 0.2s ease;
}
body.dark-mode #new-order-modal .preview-thumbnail, body.dark-mode #order-edit-modal .preview-thumbnail { background-color: #1a1b26; }
#new-order-modal .preview-thumbnail.dragging, #order-edit-modal .preview-thumbnail.dragging {
    opacity: 0.4;
    cursor: grabbing;
}
#new-order-modal .preview-thumbnail.selected, #order-edit-modal .preview-thumbnail.selected {
    border-color: var(--color-secondary);
    box-shadow: 0 0 8px var(--color-secondary);
}
#new-order-modal .preview-thumbnail img, #order-edit-modal .preview-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#new-order-modal .preview-thumbnail .delete-photo-btn, #order-edit-modal .preview-thumbnail .delete-photo-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.8em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    z-index: 2;
}
#new-order-modal .preview-thumbnail .delete-photo-btn:hover, #order-edit-modal .preview-thumbnail .delete-photo-btn:hover {
    background-color: var(--color-danger);
    transform: scale(1.1);
}

/* Checkbox Style */
#new-order-modal .checkbox-container, #order-edit-modal .checkbox-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
#new-order-modal .checkbox-container input[type="checkbox"], #order-edit-modal .checkbox-container input[type="checkbox"] {
    width: auto;
    margin-bottom: 0;
    flex-shrink: 0;
}
#new-order-modal .checkbox-container label, #order-edit-modal .checkbox-container label {
    margin-bottom: 0;
    font-weight: normal;
    font-size: 0.9em;
    color: var(--color-text-light);
    cursor: pointer;
}

#order-error-message {
    margin-top: 15px;
    color: var(--color-danger);
    font-weight: 600;
    min-height: 1.2em;
    text-align: center;
    font-size: 0.9em;
    background-color: rgba(220, 53, 69, 0.1);
    border-radius: var(--border-radius-sm);
    padding: 8px;
}
#order-error-message:empty {
    display: none;
}


#order-product-other {
    margin-top: 8px;
}
/* --- END: STYLES FOR NEW ORDER MODAL --- */

/* --- START: Conversation Preview Modal Styles --- */

/* Estilo para el ícono del ojo en la lista de contactos */
.contact-item .preview-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-light);
    padding: 4px;
    border-radius: 50%;
    opacity: 0; /* Oculto por defecto */
    transition: opacity 0.2s ease-in-out, background-color 0.2s ease-in-out;
    margin-right: 4px; /* Espacio entre el ojo y la hora */
}

.contact-item:hover .preview-icon {
    opacity: 1; /* Visible al pasar el mouse sobre el item */
}

.contact-item .preview-icon:hover {
    background-color: #e2e8f0; /* Un fondo sutil al pasar el mouse sobre el ícono */
    color: var(--color-primary);
}
body.dark-mode .contact-item .preview-icon:hover { background-color: #414868; }

.contact-item .contact-meta {
    min-width: 60px; /* Asegura espacio para que aparezca el ícono sin empujar la hora */
    display: flex;
    justify-content: flex-end;
    align-items: center;
}


/* Estilos para el modal de previsualización */
#conversation-preview-modal .modal-content {
    display: flex;
    flex-direction: column;
    height: 85vh; /* Altura del modal */
    max-height: 800px;
}

#preview-messages-container {
    background-color: #e5ddd5; /* Fondo tipo WhatsApp */
    position: relative;
    z-index: 1;
}

#preview-messages-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    z-index: -1;
    opacity: 0.8;
}

body.dark-mode #preview-messages-container {
    background-color: #16161e;
}

body.dark-mode #preview-messages-container::before {
    filter: invert(1) hue-rotate(180deg) brightness(0.6) contrast(0.9);
}

/* El spinner de carga dentro del modal */
#preview-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

/* Usamos las mismas burbujas de mensaje que el chat principal, pero dentro del contenedor del preview */
#preview-messages-content .message-bubble {
    max-width: 80%; /* Un poco más anchas en el modal */
}

#preview-messages-content .message-bubble .message-actions {
    display: none; /* Ocultar acciones de responder/reaccionar en la previsualización */
}

/* --- END: Conversation Preview Modal Styles --- */

/* --- START: STYLES FOR ORDER EDIT MODAL (to match pedidos.html) --- */
#order-edit-modal.modal-overlay {
    display: flex;
    background-color: rgba(40, 40, 40, 0.7);
    padding: 20px;
}

#order-edit-modal .modal-content {
    padding: 30px 40px;
    max-width: 750px;
}

#order-edit-modal .modal-close-btn {
    position: absolute; top: 10px; right: 15px; background: transparent;
    border: none; font-size: 2.5rem; font-weight: 300;
    color: var(--color-text-light); cursor: pointer; line-height: 1;
    padding: 0 5px; margin: 0; transition: color 0.2s ease;
}
#order-edit-modal .modal-close-btn:hover { color: var(--color-secondary); transform: none; box-shadow: none; }

#order-edit-modal h2 {
    text-align: center;
    font-size: 1.5em;
    color: var(--color-primary); /* Use primary from style.css which is the green from estilos.css */
    margin-bottom: 25px;
}

#order-edit-form .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px 25px;
    margin-bottom: 25px;
}

#order-edit-form .form-item-full {
    grid-column: 1 / -1;
}

#order-edit-form .form-actions {
    text-align: right;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

#order-edit-form .form-actions button {
    margin-left: 12px;
}

#order-edit-form .file-input-container {
    border: 2px dashed var(--color-border);
    border-radius: var(--border-radius-md);
    padding: 15px;
    margin-bottom: 18px;
    transition: all 0.3s ease;
    outline: none;
}
#order-edit-form .file-input-container:focus-within,
#order-edit-form .file-input-container.drag-over {
    border-color: var(--color-primary);
    background-color: rgba(129, 178, 154, 0.1);
}

#order-edit-form .file-input-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}

#order-edit-form .custom-file-upload {
    display: inline-block;
    background-color: var(--color-primary);
    color: white;
    padding: 10px 20px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1rem;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
body.dark-mode #order-edit-form .custom-file-upload { color: #1a1b26; }
#order-edit-form .custom-file-upload:hover {
    background-color: #70a087;
}

#order-edit-form .previews-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 50px;
}

#order-edit-form .preview-thumbnail {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 2px solid transparent;
    background-color: #f0f2f5;
    cursor: grab;
    transition: border-color 0.2s ease, opacity 0.2s ease;
}
#order-edit-form .preview-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#order-edit-form .preview-thumbnail .delete-photo-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.8em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    z-index: 2;
}
#order-edit-form .preview-thumbnail .delete-photo-btn:hover {
    background-color: var(--color-danger);
    transform: scale(1.1);
}

#order-edit-form .checkbox-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
#order-edit-form .checkbox-container input[type="checkbox"] {
    width: auto;
    margin-bottom: 0;
    flex-shrink: 0;
}
#order-edit-form .checkbox-container label {
    margin-bottom: 0;
    font-weight: normal;
    font-size: 0.9em;
    color: var(--color-text-light);
    cursor: pointer;
}

#edit-order-error-message {
     margin-top: 15px; color: var(--color-danger); font-weight: 600; min-height: 1.2em; text-align: center; font-size: 0.9em;
     background-color: rgba(220, 53, 69, 0.1); border-radius: var(--border-radius-sm); padding: 8px; display: block;
}
#edit-order-error-message:empty {
    display: none;
}
/* --- END: STYLES FOR ORDER EDIT MODAL --- */


/* --- START: Order History Styles --- */
.order-history-item {
    display: flex;
    flex-direction: column; /* Cambiado a columna */
    padding: 8px 12px;
    background-color: #f7f9fc;
    border-radius: var(--border-radius-md);
    font-size: 0.85rem;
    gap: 4px; /* Espacio entre filas */
}
body.dark-mode .order-history-item { background-color: #1f2335; }

.order-history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.order-history-item.loading, .order-history-item.empty {
    flex-direction: row; /* Mantener horizontal para mensajes de carga/vacío */
    justify-content: center;
    font-style: italic;
    color: var(--color-text-light);
}
.order-history-item .order-number {
    font-weight: 600;
    color: var(--color-primary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-align: left;
}
.order-history-item .order-product {
    color: var(--color-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    font-weight: 500;
}
.order-history-item .order-date {
    font-size: 0.8rem;
    color: var(--color-text-light);
    flex-shrink: 0;
}

.order-history-status-select {
    width: 100%; /* Ocupar todo el ancho disponible */
    padding: 4px 8px;
    border-radius: 9999px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    border: 1px solid transparent;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 8px 8px;
    padding-right: 26px; /* Space for the arrow */
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.order-history-status-select option {
    background-color: var(--color-container-bg);
    color: var(--color-text);
}

.order-history-status-select:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* --- END: Order History Styles --- */

.drag-overlay-footer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(238, 242, 255, 0.9);
    border: 3px dashed var(--color-primary);
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
    pointer-events: all;
}
body.dark-mode .drag-overlay-footer { background-color: rgba(36, 40, 59, 0.9); }

.drag-overlay-footer .drag-overlay-content {
    color: var(--color-primary);
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 600;
    text-align: center;
}

 /* Custom Select Dropdown */
 .custom-select-wrapper { 
         position: relative; 
         width: 100%; 
 } 
 
 .custom-select-button { 
         display: flex; 
         justify-content: space-between; 
         align-items: center; 
         width: 100%; 
         padding: 10px 15px; 
         border: 1px solid var(--color-border); 
         border-radius: var(--border-radius-md); 
         background-color: #f7f9fc; 
         cursor: pointer; 
         text-align: left; 
         font-size: 0.95rem; 
         font-family: var(--font-body); 
         color: var(--color-text); 
 }
 body.dark-mode .custom-select-button { background-color: #1f2335; }
 
 .custom-select-button:focus, .custom-select-button.open { 
         outline: none; 
         border-color: var(--color-primary); 
         box-shadow: 0 0 0 3px rgba(129, 178, 154, 0.2); 
 } 
 
 .custom-select-arrow { 
         transition: transform 0.2s ease; 
 } 
 
 .custom-select-button.open .custom-select-arrow { 
         transform: rotate(180deg); 
 } 
 
 .custom-select-options { 
         position: absolute; 
         top: calc(100% + 4px); 
         left: 0; 
         right: 0; 
         z-index: 1000; 
         background-color: var(--color-container-bg); 
         border: 1px solid var(--color-border); 
         border-radius: var(--border-radius-md); 
         box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); 
         max-height: 200px; 
         overflow-y: auto; 
 } 
 
 .custom-select-option { 
         display: flex; 
         align-items: center; 
         padding: 10px 15px; 
         cursor: pointer; 
         transition: background-color 0.2s ease; 
         font-size: 0.95rem; 
 } 
 
 .custom-select-option:hover { 
         background-color: #eef2ff; 
 }
 body.dark-mode .custom-select-option:hover { background-color: #3b4261; }
 
 .custom-select-option .color-circle { 
         width: 12px; 
         height: 12px; 
         border-radius: 50%; 
         margin-right: 12px; 
         flex-shrink: 0; 
 }

/* --- Simulator Message Delete Button --- */
.sim-msg-delete {
    display: none;
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background-color: #ef4444;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    font-size: 9px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 5;
    padding: 0;
    line-height: 1;
    transition: transform 0.15s ease, background-color 0.15s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.sim-msg-bubble:hover .sim-msg-delete {
    display: flex;
}
.sim-msg-delete:hover {
    background-color: #dc2626;
    transform: scale(1.15);
}
/* Adjust position for sent messages (right-aligned) */
.sim-msg-wrapper.flex.justify-end .sim-msg-delete {
    right: auto;
    left: -8px;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Mobile & Tablet)
   ========================================================================== */

@media (max-width: 1024px) {
   .metrics-grid {
       grid-template-columns: 1fr;
   }
   
   .view-container {
       padding: 1.25rem;
   }
}

@media (max-width: 768px) {
    /* General Layout */
    #app-header {
        padding: 0.75rem 1rem;
    }

    #main-sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        height: 100vh;
        z-index: 1000 !important;
        box-shadow: 10px 0 30px rgba(0,0,0,0.1);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background-color: var(--color-sidebar-bg) !important;
    }

    #main-sidebar.mobile-open {
        left: 0;
    }

    /* Overlay for mobile sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0,0.4);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Chat View Responsiveness */
    #chat-view {
        flex-direction: column;
        position: relative;
        overflow: hidden;
    }

    #contacts-panel {
        width: 100% !important;
        display: flex;
    }

    #chat-panel {
        position: absolute;
        top: 0;
        left: 100%;
        width: 100%;
        height: 100%;
        background: var(--color-bg);
        z-index: 20;
        transition: left 0.3s ease;
    }

    #chat-view.contact-selected #chat-panel {
        left: 0;
    }

    #chat-view.contact-selected #contacts-panel {
        visibility: hidden;
    }

    #contact-details-panel {
        position: fixed !important;
        top: 0;
        right: -100%;
        width: 100% !important;
        height: 100%;
        z-index: 1100 !important;
        transition: right 0.3s ease;
        box-shadow: -5px 0 20px rgba(0,0,0,0.1);
        background-color: var(--color-container-bg);
    }

    #contact-details-panel.open {
        right: 0;
    }

    /* Tables */
    .table-responsive-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
        border-radius: 8px;
        border: 1px solid var(--color-border);
    }

    table.table {
        white-space: nowrap;
        min-width: 600px;
    }

    /* Buttons / Touch Targets */
    .btn, .nav-item, .chat-icon-btn, .status-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-item {
        padding: 0.75rem 1rem;
    }

    .chat-header {
        padding: 0.5rem 0.75rem;
    }

    /* Back button for chat */
    #chat-back-btn {
        display: flex !important;
        margin-right: 0.5rem;
        padding: 0.5rem;
        font-size: 1.25rem;
        color: var(--color-text);
        background: none;
        border: none;
        cursor: pointer;
    }

    /* Modales responsivos */
    .modal-content {
        width: 96% !important;
        max-width: 500px !important; /* Cap on mobile for readability */
        margin: 20px auto !important;
        padding: 1.25rem !important;
    }
    
    .view-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .metrics-grid {
        gap: 1rem;
    }

    /* Quick Replies / Emoji pickers on mobile */
    .picker-container {
        width: 100% !important;
        max-height: 50vh !important;
        bottom: 0 !important;
        left: 0 !important;
        border-radius: 12px 12px 0 0 !important;
        position: fixed !important;
        z-index: 2000;
    }
}

/* Helper for Desktop-First override to ensure desktop is untouched */
@media (min-width: 769px) {
    #chat-back-btn {
        display: none !important;
    }
    
    #main-sidebar.collapsed {
        width: 80px;
    }
}
