/* ============================================================
   SOFIACHAT — Design System
   Modern WhatsApp-style chat interface
   ============================================================ */

:root {
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --primary-bg: rgba(124, 58, 237, 0.08);
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;
    --info: #3b82f6;

    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-chat: #efeae2;
    --bg-chat-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d5cfc6' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    --bg-bubble-in: #ffffff;
    --bg-bubble-out: #d9fdd3;
    --bg-input: #ffffff;
    --bg-header: #ffffff;

    --border-light: #e5e7eb;
    --border-default: #d1d5db;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --text-on-primary: #ffffff;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);

    --font-sans: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-sans); background: var(--bg-body); color: var(--text-primary); line-height: 1.5; min-height: 100vh; overflow: hidden; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* LOGIN */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #0c0a1a; background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124,58,237,0.15), transparent); }
.login-container { width: 100%; max-width: 400px; padding: 2rem; }
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo h1 { font-size: 2rem; font-weight: 800; color: #fff; }
.login-logo h1 span { color: var(--primary); }
.login-logo p { color: #64748b; font-size: 0.9rem; margin-top: 0.25rem; }
.login-card { background: rgba(23,28,38,0.85); backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,0.07); border-radius: var(--radius-lg); padding: 2rem; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.login-card .form-input { background: rgba(15,18,25,0.7); border-color: rgba(255,255,255,0.08); color: #e2e8f0; }
.login-card .form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }
.login-card .form-input::placeholder { color: #475569; }
.login-card .form-label { color: #94a3b8; }

/* FORMS */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.3rem; }
.form-input { width: 100%; padding: 0.6rem 0.85rem; background: var(--bg-input); border: 1px solid var(--border-light); border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-sans); font-size: 0.9rem; outline: none; transition: all 0.15s; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.form-input::placeholder { color: var(--text-muted); }
.form-select { width: 100%; padding: 0.6rem 0.85rem; background: var(--bg-input); border: 1px solid var(--border-light); border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-sans); font-size: 0.9rem; outline: none; cursor: pointer; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.55rem 1rem; font-family: var(--font-sans); font-size: 0.875rem; font-weight: 600; border: none; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--text-on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border-light); }
.btn-secondary:hover:not(:disabled) { background: #f9fafb; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* LAYOUT — 3 columns: sidebar | chat list | chat view */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* LEFT SIDEBAR (narrow — icons + logo) */
.app-sidebar { width: 60px; background: var(--primary); display: flex; flex-direction: column; align-items: center; padding: 1rem 0; flex-shrink: 0; }
.app-sidebar-logo { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 1rem; margin-bottom: 1.5rem; cursor: pointer; }
.app-sidebar-nav { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; flex: 1; }
.app-sidebar-btn { width: 40px; height: 40px; border-radius: 10px; border: none; background: transparent; color: rgba(255,255,255,0.6); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.15s; }
.app-sidebar-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.app-sidebar-btn.active { background: rgba(255,255,255,0.2); color: #fff; }
.app-sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; }
.app-sidebar-avatar { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.75rem; color: #fff; cursor: pointer; }

/* CHAT LIST (middle column) */
.chat-list-panel { width: 340px; background: var(--bg-sidebar); border-right: 1px solid var(--border-light); display: flex; flex-direction: column; flex-shrink: 0; }
.chat-list-header { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; gap: 0.75rem; }
.chat-list-header h2 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.chat-list-search { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border-light); }
.chat-list-search input { width: 100%; padding: 0.5rem 0.75rem; background: var(--bg-body); border: none; border-radius: 8px; font-size: 0.85rem; outline: none; color: var(--text-primary); }
.chat-list-search input::placeholder { color: var(--text-muted); }
.chat-list-body { flex: 1; overflow-y: auto; }
.chat-list-empty { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }

.chat-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; cursor: pointer; border-bottom: 1px solid rgba(0,0,0,0.04); transition: background 0.1s; }
.chat-item:hover { background: #f5f5f5; }
.chat-item.active { background: var(--primary-bg); }
.chat-item-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--primary-bg); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem; flex-shrink: 0; }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-name { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.chat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; flex-shrink: 0; }
.chat-item-time { font-size: 0.7rem; color: var(--text-muted); }
.chat-item-badge { min-width: 18px; height: 18px; border-radius: 9px; background: var(--primary); color: #fff; font-size: 0.65rem; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

/* CHAT VIEW (right column) */
.chat-view { flex: 1; display: flex; flex-direction: column; background: var(--bg-chat); background-image: var(--bg-chat-pattern); }
.chat-view-header { padding: 0.65rem 1rem; background: var(--bg-header); border-bottom: 1px solid var(--border-light); display: flex; align-items: center; gap: 0.75rem; box-shadow: var(--shadow-sm); z-index: 10; }
.chat-view-header-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-bg); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; }
.chat-view-header-info { flex: 1; }
.chat-view-header-name { font-weight: 600; font-size: 0.95rem; }
.chat-view-header-status { font-size: 0.75rem; color: var(--text-muted); }

.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.25rem; }

.msg-row { display: flex; margin-bottom: 2px; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }
.msg-bubble { max-width: 65%; padding: 0.5rem 0.65rem; border-radius: 8px; font-size: 0.9rem; line-height: 1.45; position: relative; box-shadow: 0 1px 1px rgba(0,0,0,0.06); word-wrap: break-word; white-space: pre-wrap; }
.msg-row.in .msg-bubble { background: var(--bg-bubble-in); border-top-left-radius: 2px; }
.msg-row.out .msg-bubble { background: var(--bg-bubble-out); border-top-right-radius: 2px; }
.msg-time { font-size: 0.65rem; color: rgba(0,0,0,0.4); text-align: right; margin-top: 3px; }
.msg-status { font-size: 0.6rem; color: rgba(0,0,0,0.35); margin-left: 4px; }
.msg-template-badge { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.68rem; color: var(--primary); font-weight: 600; margin-bottom: 0.25rem; }

/* Empty chat view */
.chat-view-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); background: var(--bg-body); }
.chat-view-empty-icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.3; }
.chat-view-empty h3 { font-size: 1.2rem; font-weight: 700; color: var(--text-secondary); margin-bottom: 0.5rem; }

/* CHAT INPUT */
.chat-input-bar { padding: 0.6rem 1rem; background: var(--bg-header); border-top: 1px solid var(--border-light); display: flex; align-items: flex-end; gap: 0.6rem; }
.chat-input-bar textarea { flex: 1; resize: none; border: none; outline: none; font-family: var(--font-sans); font-size: 0.9rem; padding: 0.6rem 0.85rem; background: var(--bg-body); border-radius: 20px; max-height: 120px; min-height: 40px; line-height: 1.4; color: var(--text-primary); }
.chat-input-bar textarea::placeholder { color: var(--text-muted); }
.chat-send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background 0.15s; }
.chat-send-btn:hover { background: var(--primary-hover); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* MODAL */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; animation: fadeIn 0.15s; padding: 1rem; }
.modal { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-light); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.3rem; line-height: 1; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0.85rem 1.25rem; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 0.6rem; }

/* TOAST */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: 0.75rem 1rem; min-width: 260px; box-shadow: var(--shadow-md); animation: slideUp 0.25s; display: flex; align-items: center; gap: 0.6rem; }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast-message { flex: 1; font-size: 0.875rem; font-weight: 500; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; }

/* SPINNER */
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-light); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 3rem; }

/* BADGE */
.badge { display: inline-flex; align-items: center; padding: 0.15rem 0.5rem; border-radius: 4px; font-size: 0.73rem; font-weight: 600; }
.badge-success { background: rgba(34,197,94,0.1); color: var(--success); }
.badge-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.1); color: var(--info); }
.badge-warning { background: rgba(234,179,8,0.1); color: var(--warning); }

/* CONNECTIONS PAGE */
.page-container { max-width: 900px; margin: 0 auto; padding: 2rem; }
.page-title { font-size: 1.4rem; font-weight: 800; margin-bottom: 0.5rem; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.card { background: var(--bg-card); border: 1px solid var(--border-light); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden; }
.card-body { padding: 1.25rem; }

/* WEBHOOK URL BOX */
.webhook-box { background: var(--bg-body); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 0.6rem 0.85rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--primary); word-break: break-all; display: flex; align-items: center; gap: 0.5rem; }
.webhook-box button { flex-shrink: 0; }

/* UTILITY */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* DATE SEPARATOR */
.msg-date-sep { text-align: center; padding: 0.5rem 0; }
.msg-date-sep span { background: rgba(255,255,255,0.9); color: var(--text-muted); font-size: 0.72rem; font-weight: 600; padding: 0.25rem 0.75rem; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* WINDOW EXPIRED BANNER */
.window-expired { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; padding: 0.6rem 1rem; font-size: 0.82rem; display: flex; align-items: center; gap: 0.5rem; }
