* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #242581; height: 100vh; overflow: hidden; }

/* LOGIN */
.login-screen { display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #242581 0%, #5b2c85 100%); }
.login-box { background: #fff; border-radius: 16px; padding: 40px 30px; width: 320px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.login-logo { font-size: 32px; font-weight: 800; color: #5b2c85; margin-bottom: 4px; letter-spacing: 2px; }
.login-sub { font-size: 13px; color: #656D78; margin-bottom: 24px; }
.login-input { width: 100%; padding: 12px 16px; border: 2px solid #E6E9ED; border-radius: 10px; font-size: 15px; margin-bottom: 12px; outline: none; transition: border 0.2s; }
.login-input:focus { border-color: #5b2c85; }
.login-btn { width: 100%; padding: 13px; border: none; border-radius: 10px; background: #5b2c85; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; transition: background 0.2s; }
.login-btn:hover { background: #4a2470; }
.login-btn:disabled { background: #AAB2BD; cursor: not-allowed; }
.login-error { color: #E9573F; font-size: 13px; margin-top: 10px; min-height: 20px; }

/* CHAT */
.chat-screen { display: flex; flex-direction: column; height: 100vh; background: #F5F7FA; }
.chat-header { background: #242581; color: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.chat-header-title { font-size: 20px; font-weight: 700; color: #fff; letter-spacing: 1px; }
.chat-header-client { font-size: 12px; color: #fff; opacity: 0.85; }
.chat-header-usage { font-size: 10px; color: #fff; opacity: 0.75; margin-top: 2px; font-family: monospace; }
.chat-back { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; padding: 4px 8px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-input-area { display: flex; gap: 8px; padding: 10px 12px; background: #fff; border-top: 1px solid #E6E9ED; align-items: center; }
.chat-input { flex: 1; padding: 12px 16px; border: 2px solid #E6E9ED; border-radius: 24px; font-size: 15px; outline: none; }
.chat-input:focus { border-color: #5b2c85; }
.btn-circle { width: 44px; height: 44px; border-radius: 50%; border: none; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-mic { background: #E6E9ED; color: #656D78; }
.btn-mic.active { background: #E9573F; color: #fff; animation: pulse 1s infinite; }
.btn-send { background: #5b2c85; color: #fff; }
.btn-send:hover { background: #4a2470; }
.btn-pdf { background: #E6E9ED; color: #656D78; font-size: 16px; }
.btn-pdf:hover { background: #3BAFDA; color: #fff; }
.btn-img { background: #E6E9ED; color: #656D78; font-size: 16px; }
.btn-img:hover { background: #5b2c85; color: #fff; }
.btn-img.loading { background: #F6BB42; color: #fff; animation: pulse 1s infinite; }
.btn-web { background: #E6E9ED; color: #656D78; font-size: 14px; }
.btn-web:hover { background: #242581; color: #fff; }
.btn-web.active { background: #242581; color: #fff; }
.btn-pdf.loading { background: #F6BB42; color: #fff; animation: pulse 1s infinite; }
.pdf-badge { display: inline-block; background: #3BAFDA; color: white; padding: 3px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; margin-bottom: 6px; }
.pdf-info { background: #f0f8ff; border: 1px solid #bbdefb; border-radius: 6px; padding: 8px; margin-bottom: 8px; font-size: 11px; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* MENSAJES */
.msg { max-width: 85%; padding: 12px 16px 16px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-wrap: break-word; position: relative; }
.msg-hora { display: block; font-size: 10px; color: rgba(0,0,0,0.45); text-align: right; margin-top: 4px; font-weight: 500; line-height: 1; user-select: none; }
.msg-user .msg-hora { color: rgba(255,255,255,0.75); }
.msg-user { align-self: flex-end; background: #5b2c85; color: #fff; border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; background: #fff; color: #333; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.msg-bot table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; font-variant-numeric: tabular-nums; font-family: "Consolas", "Menlo", "Courier New", monospace; }
.msg-bot th, .msg-bot td { border: 1px solid #c8cce4; padding: 6px 10px; vertical-align: top; }
.msg-bot th { background: #242581; color: #fff; text-align: left; font-weight: 600; }
.msg-bot td { background: #fff; }
.msg-bot tr:nth-child(even) td { background: #F5F7FA; }
.msg-bot strong, .msg-bot b { color: #5b2c85; }
.msg-typing { align-self: flex-start; background: #fff; padding: 16px 20px; border-radius: 16px; }
.msg-typing span { display: inline-block; width: 8px; height: 8px; background: #5b2c85; border-radius: 50%; margin: 0 2px; animation: bounce 1.4s infinite; }
.msg-typing span:nth-child(2) { animation-delay: 0.2s; }
.msg-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }

/* MENU */
.chat-menu { position: absolute; top: 40px; right: 0; background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); min-width: 200px; z-index: 100; overflow: hidden; }
.chat-menu-item { padding: 12px 16px; cursor: pointer; font-size: 14px; color: #242581; border-bottom: 1px solid #F5F7FA; }
.chat-menu-item:hover { background: #F5F7FA; color: #5b2c85; }
.chat-menu-separator { height: 1px; background: #E6E9ED; }

/* SPEAKING BAR */
.speaking-bar { display: none; background: #242581; padding: 10px 16px; align-items: center; justify-content: space-between; }
.speaking-bar.active { display: flex; }
.speaking-waves span { display: inline-block; width: 3px; height: 16px; background: #5b2c85; margin: 0 2px; animation: wave 0.6s infinite; }
.speaking-waves span:nth-child(2) { animation-delay: 0.1s; }
.speaking-waves span:nth-child(3) { animation-delay: 0.2s; }
.speaking-waves span:nth-child(4) { animation-delay: 0.3s; }
.speaking-waves span:nth-child(5) { animation-delay: 0.4s; }
@keyframes wave { 0%,100% { height: 8px; } 50% { height: 20px; } }
.speaking-text { color: #5b2c85; font-size: 13px; }
.speaking-stop { background: #E9573F; color: #fff; border: none; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }

/* MSG ACTIONS */
.msg-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.msg-actions button { background: #E6E9ED; border: none; padding: 4px 10px; border-radius: 6px; font-size: 11px; cursor: pointer; color: #242581; }
.msg-actions button:hover { background: #5b2c85; color: #fff; }

/* CHART */
.chart-container { background: #fff; border-radius: 10px; padding: 10px; margin-top: 8px; max-width: 100%; }

/* INFORMES HTML */
.informe-html { max-width: 100%; overflow-x: auto; }
.informe-html h2 { color: #5b2c85; margin: 12px 0 8px; font-size: 18px; }
.informe-html h3 { color: #242581; margin: 10px 0 6px; font-size: 15px; }
.informe-html table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; }
.informe-html th { background: #242581; color: #fff; padding: 6px 8px; text-align: left; }
.informe-html td { padding: 5px 8px; border-bottom: 1px solid #E6E9ED; }
.informe-html tr:nth-child(even) { background: #F5F7FA; }
.crt-mode .informe-html h2 { color: #ff8c00 !important; }
.crt-mode .informe-html h3 { color: #ffaa33 !important; }
.crt-mode .informe-html th { background: #ff8c00 !important; color: #0a0a0a !important; }
.crt-mode .informe-html td { border-color: #ff8c0030 !important; color: #ff8c00 !important; }
.crt-mode .informe-html tr:nth-child(even) { background: #1a1200 !important; }

.hidden { display: none !important; }

/* SIDEBAR DE CONVERSACIONES */
.conv-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--conv-w, 300px); background: #fff; box-shadow: 2px 0 12px rgba(0,0,0,0.15); z-index: 300; display: flex; flex-direction: column; transform: translateX(-100%); transition: transform 0.22s ease; }
.conv-resizer { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; background: transparent; z-index: 310; }
.conv-resizer:hover, .conv-resizer.dragging { background: rgba(91,44,133,0.25); }
.conv-sidebar:not(.hidden) { transform: translateX(0); }
.conv-sidebar-header { background: linear-gradient(135deg, #242581, #5b2c85); color: #fff; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; }
.conv-sidebar-title { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }
.conv-close { background: rgba(255,255,255,0.2); color: #fff; border: none; width: 28px; height: 28px; border-radius: 50%; font-size: 18px; cursor: pointer; line-height: 1; }
.conv-close:hover { background: rgba(255,255,255,0.35); }
.conv-new-btn { margin: 12px; padding: 10px 14px; background: linear-gradient(135deg, #242581, #5b2c85); color: #fff; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.conv-new-btn:hover { opacity: 0.92; }
.conv-search-wrap { padding: 0 12px 8px; }
.conv-search { width: 100%; box-sizing: border-box; padding: 8px 12px; border: 1px solid #c8cce4; border-radius: 8px; font-size: 13px; color: #242581; outline: none; background: #fff; }
.conv-search:focus { border-color: #5b2c85; box-shadow: 0 0 0 2px rgba(91,44,133,0.15); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.conv-item { padding: 10px 12px; border-radius: 8px; margin-bottom: 4px; cursor: pointer; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; transition: background 0.12s; }
.conv-item:hover { background: #f3f0fa; }
.conv-item.active { background: #eae3f6; }
.conv-item .ci-main { flex: 1; min-width: 0; }
.conv-item .ci-titulo { font-size: 13px; font-weight: 600; color: #242581; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .ci-ordinal { color: #5b2c85; font-weight: 700; margin-right: 2px; }
.conv-item .ci-meta { font-size: 10px; color: #888; }
.conv-item .ci-actions { opacity: 0; display: flex; gap: 3px; flex-shrink: 0; transition: opacity 0.12s; }
.conv-item:hover .ci-actions { opacity: 1; }
.conv-item .ci-actions button { background: none; border: none; cursor: pointer; font-size: 13px; padding: 2px 4px; color: #888; border-radius: 4px; }
.conv-item .ci-actions button:hover { background: #fff; color: #5b2c85; }
.conv-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.35); z-index: 290; }
.btn-sidebar { margin-right: 4px; }

/* HISTORIAL */
.historial-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; justify-content: center; align-items: center; }
.historial-panel { background: #fff; border-radius: 12px; padding: 20px; width: 90%; max-width: 400px; max-height: 70vh; overflow-y: auto; }
.historial-panel h3 { color: #242581; margin-bottom: 12px; }
.historial-dia { padding: 10px; border-bottom: 1px solid #E6E9ED; cursor: pointer; color: #242581; }
.historial-dia:hover { background: #F5F7FA; color: #5b2c85; }
