/* ═══════════════════════════════════════════
   WACoPilot — Estilos principales
   ═══════════════════════════════════════════ */

:root {
    --primary:       #25D366;
    --primary-dark:  #128C7E;
    --primary-light: #dcf8c6;
    --secondary:     #34B7F1;
    --accent:        #5B5EA6;
    --danger:        #e74c3c;
    --warning:       #f39c12;
    --success:       #27ae60;

    --bg:            #f0f2f5;
    --bg-sidebar:    #111b21;
    --bg-chat:       #efeae2;
    --bg-white:      #ffffff;
    --bg-input:      #f0f2f5;
    --bg-msg-out:    #d9fdd3;
    --bg-msg-in:     #ffffff;

    --text-primary:  #111b21;
    --text-secondary:#667781;
    --text-muted:    #aab8c2;
    --text-white:    #ffffff;

    --border:        #e9edef;
    --shadow:        0 1px 3px rgba(0,0,0,0.12);
    --radius:        8px;
    --radius-sm:     4px;
    --radius-lg:     16px;

    --font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono:     'Courier New', monospace;

    --sidebar-w:     70px;
    --list-w:        360px;
    --copilot-w:     300px;
    --header-h:      60px;
}

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

html, body { height: 100%; overflow: hidden; font-family: var(--font); font-size: 14px; color: var(--text-primary); background: var(--bg); }

/* ─── Layout ──────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

.app-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 16px; color: var(--text-secondary); }

/* Sidebar izquierda (íconos) */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    gap: 4px;
    flex-shrink: 0;
}
.sidebar-logo { width: 40px; height: 40px; margin-bottom: 8px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.sidebar-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100%; padding: 10px 0; cursor: pointer; gap: 3px; border: none;
    background: transparent; color: var(--text-muted); font-size: 10px;
    transition: color 0.15s, background 0.15s; border-left: 3px solid transparent;
}
.sidebar-btn:hover, .sidebar-btn.active {
    color: var(--primary); background: rgba(255,255,255,0.05); border-left-color: var(--primary);
}
.sidebar-btn svg { width: 22px; height: 22px; }
.sidebar-bottom { margin-top: auto; width: 100%; }
.sidebar-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; cursor: pointer; }

/* Lista de conversaciones */
.conversation-list {
    width: var(--list-w);
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.list-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list-header h2 { font-size: 18px; font-weight: 600; }
.list-search { padding: 8px 12px; background: var(--bg-input); }
.list-search input { width: 100%; padding: 8px 12px; border: none; border-radius: 20px; background: var(--border); outline: none; font-size: 13px; }
.list-filters { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.filter-btn { padding: 4px 12px; border-radius: 20px; border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 12px; color: var(--text-secondary); transition: all 0.15s; }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.conv-items { flex: 1; overflow-y: auto; }

/* Item de conversación */
.conv-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.1s;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #f0f2f5; }
.conv-avatar { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--primary); display: flex; align-items: center; justify-content: center; color: white; font-weight: 600; font-size: 18px; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 14px; }
.conv-preview { color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.conv-time { color: var(--text-muted); font-size: 11px; }
.conv-badge { background: var(--primary); color: white; border-radius: 10px; padding: 2px 6px; font-size: 11px; min-width: 18px; text-align: center; }

/* Área de chat principal */
.chat-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-chat); }
.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-secondary); gap: 12px; }
.chat-empty svg { opacity: 0.3; }

/* Header del chat */
.chat-header {
    background: var(--bg-white); padding: 10px 16px;
    display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name { font-weight: 600; font-size: 15px; }
.chat-header-status { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 8px; }
.icon-btn { background: transparent; border: none; cursor: pointer; padding: 6px; border-radius: 50%; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.icon-btn:hover { background: var(--bg-input); color: var(--text-primary); }

/* Mensajes */
.messages-container { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 4px; }
.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

/* Burbuja de mensaje */
.msg { display: flex; flex-direction: column; max-width: 65%; gap: 2px; }
.msg.out { align-self: flex-end; }
.msg.in  { align-self: flex-start; }
.msg-bubble {
    padding: 8px 12px; border-radius: var(--radius-lg);
    position: relative; word-break: break-word;
}
.msg.out .msg-bubble { background: var(--bg-msg-out); border-bottom-right-radius: 2px; }
.msg.in  .msg-bubble { background: var(--bg-msg-in); border-bottom-left-radius: 2px; box-shadow: var(--shadow); }
.msg-text { font-size: 14px; line-height: 1.4; }
.msg-meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 2px; }
.msg-time { font-size: 10px; color: var(--text-muted); }
.msg-status { font-size: 12px; }
.msg-status.sent     { color: var(--text-muted); }
.msg-status.delivered{ color: var(--text-muted); }
.msg-status.read     { color: var(--secondary); }
.msg-status.failed   { color: var(--danger); }

/* Media en burbuja */
.msg-image { max-width: 280px; max-height: 200px; border-radius: var(--radius); cursor: pointer; display: block; }
.msg-video { max-width: 280px; border-radius: var(--radius); }
.msg-audio-player { display: flex; align-items: center; gap: 8px; min-width: 200px; }
.msg-audio-player audio { flex: 1; height: 32px; }
.msg-document { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 4px 0; }
.msg-document-icon { font-size: 28px; }
.msg-document-info { flex: 1; min-width: 0; }
.msg-document-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-document-size { font-size: 11px; color: var(--text-secondary); }
.msg-location { display: flex; align-items: center; gap: 8px; color: var(--primary-dark); cursor: pointer; }
.msg-sticker { max-width: 150px; background: transparent !important; box-shadow: none !important; }
.msg-reaction { font-size: 18px; background: transparent; padding: 2px 6px; border-radius: 12px; border: 1px solid var(--border); display: inline-block; }
.msg-reply { background: rgba(0,0,0,0.05); border-left: 3px solid var(--primary); border-radius: 4px; padding: 4px 8px; margin-bottom: 4px; font-size: 12px; color: var(--text-secondary); cursor: pointer; }
.msg-system { align-self: center; background: rgba(0,0,0,0.06); padding: 4px 12px; border-radius: 8px; font-size: 12px; color: var(--text-secondary); }

/* Input de chat */
.chat-input-area {
    background: var(--bg-white); padding: 10px 16px;
    border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-input-reply { background: var(--bg); border-left: 3px solid var(--primary); padding: 6px 10px; margin-bottom: 6px; border-radius: 4px; display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--text-secondary); }
.chat-input-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-input-box { flex: 1; position: relative; }
.chat-input-box textarea {
    width: 100%; min-height: 42px; max-height: 150px; padding: 10px 48px 10px 16px;
    border: none; border-radius: 21px; background: var(--bg-input);
    resize: none; outline: none; font-size: 14px; font-family: var(--font); line-height: 1.4;
    overflow-y: auto;
}
.chat-input-emoji-btn { position: absolute; right: 12px; bottom: 10px; background: transparent; border: none; cursor: pointer; font-size: 20px; opacity: 0.6; }
.chat-input-actions { display: flex; align-items: flex-end; gap: 4px; }
.send-btn { background: var(--primary); color: white; border: none; width: 42px; height: 42px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.15s; flex-shrink: 0; }
.send-btn:hover { background: var(--primary-dark); }
.send-btn svg { width: 20px; height: 20px; }
.rec-btn { background: var(--danger); color: white; border: none; width: 42px; height: 42px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.recording-indicator { display: flex; align-items: center; gap: 8px; flex: 1; color: var(--danger); font-size: 13px; }
.recording-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* CoPilot panel */
.copilot-panel {
    width: var(--copilot-w); background: var(--bg-white);
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
    flex-shrink: 0; transition: width 0.2s;
}
.copilot-panel.collapsed { width: 0; overflow: hidden; }
.copilot-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.copilot-header h3 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.copilot-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.copilot-suggestion {
    background: #f8f9ff; border: 1px solid #e0e4ff;
    border-radius: var(--radius); padding: 12px;
}
.copilot-suggestion textarea { width: 100%; border: none; background: transparent; resize: none; font-size: 13px; line-height: 1.5; color: var(--text-primary); outline: none; min-height: 80px; font-family: var(--font); }
.copilot-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.copilot-history { border-top: 1px solid var(--border); padding-top: 10px; }
.copilot-history-item { font-size: 12px; color: var(--text-secondary); padding: 6px 8px; border-radius: 4px; cursor: pointer; transition: background 0.1s; }
.copilot-history-item:hover { background: var(--bg); }
.copilot-loading { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 13px; }

/* Config panel */
.config-page { flex: 1; overflow-y: auto; padding: 24px; background: var(--bg); }
.config-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.config-tab { padding: 10px 20px; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 14px; transition: all 0.15s; }
.config-tab.active { color: var(--primary-dark); border-bottom-color: var(--primary-dark); font-weight: 600; }
.config-panel { background: white; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); max-width: 720px; }
.config-panel h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* Formularios */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; outline: none;
    background: white; transition: border-color 0.15s; font-family: var(--font);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--primary-dark); }
.form-group textarea { min-height: 80px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* Botones */
.btn { padding: 8px 16px; border-radius: var(--radius-sm); border: none; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary-dark); color: white; }
.btn-primary:hover { background: #0d6b61; }
.btn-secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Marketing */
.marketing-page { flex: 1; overflow-y: auto; padding: 24px; background: var(--bg); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.campaigns-table { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.campaigns-table table { width: 100%; border-collapse: collapse; }
.campaigns-table th, .campaigns-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.campaigns-table th { background: var(--bg); font-weight: 600; color: var(--text-secondary); }

/* Billing */
.billing-page { flex: 1; overflow-y: auto; padding: 24px; background: var(--bg); }
.plan-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.plan-card { background: white; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); border: 2px solid transparent; transition: border-color 0.15s; }
.plan-card.current { border-color: var(--primary); }
.plan-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.plan-price { font-size: 32px; font-weight: 700; color: var(--primary-dark); }
.plan-price span { font-size: 14px; color: var(--text-secondary); }
.plan-features { list-style: none; margin: 16px 0; display: flex; flex-direction: column; gap: 6px; }
.plan-features li { font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.plan-features li::before { content: '✓'; color: var(--primary); font-weight: 700; }

/* Toast */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius); color: white; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.2s ease; min-width: 200px; max-width: 350px; }
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--accent); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay.hidden { display: none; }
.modal-content { background: white; border-radius: var(--radius); padding: 24px; min-width: 360px; max-width: 560px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; font-weight: 600; }

/* Toggle switch */
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 24px; cursor: pointer; transition: background 0.2s; }
.toggle-slider::before { position: absolute; content: ''; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: transform 0.2s; }
input:checked + .toggle-slider { background: var(--primary); }
input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Spinner */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login / Auth */
.auth-page { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.auth-card { background: white; border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,0.08); }
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; }
.auth-logo h1 { font-size: 22px; font-weight: 700; color: var(--primary-dark); }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; margin: 16px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Status badge */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-open     { background: #e3f2fd; color: #1565c0; }
.badge-pending  { background: #fff3e0; color: #e65100; }
.badge-resolved { background: #e8f5e9; color: #2e7d32; }
.badge-bot      { background: #f3e5f5; color: #6a1b9a; }
.badge-active   { background: #e8f5e9; color: #2e7d32; }
.badge-inactive { background: #fce4ec; color: #c62828; }

/* Users table */
.users-table table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; }
.users-table th { font-weight: 600; color: var(--text-secondary); background: var(--bg); }
.user-row { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--primary); display: flex; align-items: center; justify-content: center; color: white; font-size: 13px; font-weight: 600; flex-shrink: 0; }

/* Onboarding steps */
.onboarding { flex: 1; overflow-y: auto; padding: 32px; display: flex; flex-direction: column; align-items: center; }
.onboarding-steps { display: flex; gap: 0; margin-bottom: 32px; }
.step-indicator { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.step-circle { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--text-muted); background: white; }
.step-circle.done { background: var(--primary); border-color: var(--primary); color: white; }
.step-circle.current { border-color: var(--primary-dark); color: var(--primary-dark); }
.step-label { font-size: 11px; color: var(--text-secondary); white-space: nowrap; }
.step-line { width: 60px; height: 2px; background: var(--border); margin-top: 14px; }
.step-line.done { background: var(--primary); }

/* Scrollbars */
.conv-items::-webkit-scrollbar, .messages-container::-webkit-scrollbar, .copilot-body::-webkit-scrollbar { width: 4px; }
.conv-items::-webkit-scrollbar-thumb, .messages-container::-webkit-scrollbar-thumb, .copilot-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 2px; }

/* Date separator */
.date-separator { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 12px; padding: 8px 0; }
.date-separator::before, .date-separator::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Inbox empty state */
.inbox-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; color: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
    :root { --list-w: 100%; --copilot-w: 100%; }
    .conversation-list { display: none; }
    .conversation-list.mobile-show { display: flex; position: fixed; inset: 0; z-index: 100; }
    .copilot-panel { display: none; }
}
