/**
 * style.css — Nexxus Medical CRM
 * Design System con Light/Dark Theme via CSS custom properties
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ==============================
   DESIGN TOKENS — LIGHT THEME
   ============================== */
:root {
    --accent:          #2563eb;
    --accent-hover:    #1d4ed8;
    --accent-light:    rgba(37, 99, 235, 0.08);

    --bg-base:         #f1f5f9;
    --bg-surface:      #ffffff;
    --bg-surface-2:    #f8fafc;
    --bg-sidebar:      #ffffff;
    --bg-chat:         #e5ddd5;

    --border:          #e2e8f0;
    --border-light:    #f1f5f9;

    --text-primary:    #0f172a;
    --text-secondary:  #475569;
    --text-muted:      #94a3b8;

    --bubble-user-bg:  #ffffff;
    --bubble-user-txt: #1e293b;
    --bubble-ai-bg:    #2563eb;
    --bubble-ai-txt:   #ffffff;

    --stat-card-bg:    #ffffff;
    --header-bg:       #ffffff;
    --input-bg:        #ffffff;
    --footer-bg:       #f8fafc;

    --shadow-sm:       0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:       0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --shadow-lg:       0 10px 40px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);

    --transition:      all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    --radius:          12px;
    --radius-sm:       8px;
    --radius-full:     9999px;
}

/* ==============================
   DESIGN TOKENS — DARK THEME
   ============================== */
[data-theme="dark"] {
    --accent:          #3b82f6;
    --accent-hover:    #60a5fa;
    --accent-light:    rgba(59, 130, 246, 0.12);

    --bg-base:         #0d1117;
    --bg-surface:      #161b22;
    --bg-surface-2:    #1c2330;
    --bg-sidebar:      #13181f;
    --bg-chat:         #1a2332;

    --border:          #21262d;
    --border-light:    #1c2330;

    --text-primary:    #e6edf3;
    --text-secondary:  #8b949e;
    --text-muted:      #6e7681;

    --bubble-user-bg:  #1c2330;
    --bubble-user-txt: #e6edf3;
    --bubble-ai-bg:    #2563eb;
    --bubble-ai-txt:   #ffffff;

    --stat-card-bg:    #161b22;
    --header-bg:       #13181f;
    --input-bg:        #1c2330;
    --footer-bg:       #13181f;

    --shadow-sm:       0 1px 3px rgba(0,0,0,0.30), 0 1px 2px rgba(0,0,0,0.20);
    --shadow-md:       0 4px 16px rgba(0,0,0,0.40), 0 2px 6px rgba(0,0,0,0.20);
    --shadow-lg:       0 10px 40px rgba(0,0,0,0.50), 0 4px 12px rgba(0,0,0,0.30);
}

/* ==============================
   BASE
   ============================== */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background-color: var(--bg-base);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }
h1,h2,h3,h4,h5,h6 { color: var(--text-primary); font-weight: 600; }

/* ==============================
   SIDEBAR
   ============================== */
#sidebar {
    width: 250px;
    height: 100vh;
    position: fixed;
    left: 0; top: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    z-index: 1000;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand-icon {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.sidebar-brand-text h6 {
    font-size: 14px; font-weight: 700; margin: 0;
    color: var(--text-primary);
}
.sidebar-brand-text span {
    font-size: 11px; color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 12px;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 16px 12px 6px;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 13.5px;
    transition: var(--transition);
    margin-bottom: 2px;
}

#sidebar .nav-link i {
    font-size: 15px;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

#sidebar .nav-link:hover {
    background: var(--accent-light);
    color: var(--accent);
}

#sidebar .nav-link.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37,99,235,0.30);
}
#sidebar .nav-link.active i { color: #fff; }

/* ==============================
   MAIN CONTENT
   ============================== */
#main-content {
    margin-left: 250px;
    min-height: 100vh;
    padding: 28px 32px;
    transition: margin-left 0.3s ease;
}

@media (max-width: 991.98px) {
    #sidebar { transform: translateX(-100%); }
    #sidebar.active { transform: translateX(0); }
    #main-content { margin-left: 0; }
}

/* ==============================
   TOPBAR
   ============================== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.topbar-title h4 {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.topbar-title p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Theme Toggle Button */
#theme-toggle {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: var(--transition);
}

#theme-toggle:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

.avatar-topbar {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    border: 2px solid var(--border);
    transition: var(--transition);
}
.avatar-topbar:hover { border-color: var(--accent); }

/* ==============================
   STAT CARDS
   ============================== */
.stat-card {
    background: var(--stat-card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.stat-icon.blue   { background: rgba(37,99,235,0.10); color: #2563eb; }
.stat-icon.green  { background: rgba(22,163,74,0.10);  color: #16a34a; }
.stat-icon.purple { background: rgba(139,92,246,0.10); color: #8b5cf6; }
.stat-icon.amber  { background: rgba(217,119,6,0.10);  color: #d97706; }

.stat-label {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.stat-trend {
    font-size: 11.5px;
    margin-top: 4px;
    font-weight: 500;
}
.stat-trend.up   { color: #16a34a; }
.stat-trend.info { color: var(--accent); }

/* ==============================
   CHAT MODULE
   ============================== */
.chat-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow: hidden;
    height: 640px;
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.chat-module-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Contacts Sidebar --- */
.contacts-sidebar {
    width: 300px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-surface);
}

.contacts-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.contacts-sidebar-header h6 {
    font-size: 13px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.contacts-list-scroll {
    flex: 1;
    overflow-y: auto;
}

.contacts-list-scroll::-webkit-scrollbar { width: 4px; }
.contacts-list-scroll::-webkit-scrollbar-track { background: transparent; }
.contacts-list-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Contact Item */
.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition);
    position: relative;
}

.contact-item:hover {
    background: var(--bg-surface-2);
}

.contact-item.active {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
}

.contact-avatar {
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
    flex-shrink: 0;
}

.contact-info { flex: 1; overflow: hidden; }
.contact-name {
    font-size: 13.5px; font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 2px;
}

.contact-preview {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.contact-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* --- Chat Main Area --- */
.chat-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Crect width='80' height='80' fill='none'/%3E%3Ccircle cx='5' cy='5' r='1' fill='%23000' fill-opacity='0.04'/%3E%3C/svg%3E");
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .chat-main-area {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Crect width='80' height='80' fill='none'/%3E%3Ccircle cx='5' cy='5' r='1' fill='%23fff' fill-opacity='0.03'/%3E%3C/svg%3E");
}

/* Chat Header */
#chat-active-header {
    padding: 12px 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 2;
}

.chat-header-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--text-muted);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px;
    flex-shrink: 0;
}

.chat-header-info { flex: 1; }
.chat-header-info h6 {
    font-size: 14px; font-weight: 700; margin: 0;
    color: var(--text-primary);
}
.chat-header-info small {
    font-size: 12px; color: var(--text-muted);
}

/* AI Toggle Badge */
.ai-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}

.ai-toggle-wrapper .form-check-input {
    cursor: pointer;
    margin: 0;
}

.ai-status-label { font-size: 11.5px; font-weight: 700; color: var(--accent); }

/* Chat Window */
.chat-window-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-window-scroll::-webkit-scrollbar { width: 4px; }
.chat-window-scroll::-webkit-scrollbar-track { background: transparent; }
.chat-window-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }
[data-theme="dark"] .chat-window-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.10); }

/* Chat Bubbles */
.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    position: relative;
    margin-bottom: 2px;
}

.msg-user {
    background: #ffffff; /* Gris muy claro / Blanco */
    color: #334155;
    border-bottom-left-radius: 4px;
    border: 1px solid #e2e8f0;
}

.msg-bot {
    background: #2563eb; /* Azul Nexxus */
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

[data-theme="dark"] .msg-user {
    background: #1c2330;
    color: #e2e8f0;
    border-color: #2d3748;
}

[data-theme="dark"] .msg-bot {
    background: #2563eb;
}

.bubble-time {
    font-size: 10.5px;
    opacity: 0.6;
    text-align: right;
    margin-top: 4px;
}

/* Chat Footer */
.chat-footer {
    padding: 12px 16px;
    background: var(--footer-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-footer .input-group {
    background: var(--input-bg);
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border);
    overflow: hidden;
    transition: var(--transition);
}

.chat-footer .input-group:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.chat-footer .form-control {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    padding: 10px 16px;
    box-shadow: none !important;
}

.chat-footer .form-control::placeholder {
    color: var(--text-muted);
}

.chat-footer .form-control:disabled {
    background: transparent;
    cursor: not-allowed;
}

.chat-footer #send-button {
    background: var(--accent);
    border: none;
    color: white;
    width: 42px;
    border-radius: 0 var(--radius-full) var(--radius-full) 0;
    flex-shrink: 0;
    transition: var(--transition);
}

.chat-footer #send-button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.chat-footer #send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Splash screen */
.chat-splash {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
}

.chat-splash i {
    font-size: 60px;
    opacity: 0.2;
    margin-bottom: 16px;
}

.chat-splash h5 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* ==============================
   BADGE
   ============================== */
.badge-counter {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-full);
}

/* ==============================
   DARK MODE OVERRIDES for Bootstrap
   ============================== */
[data-theme="dark"] .card,
[data-theme="dark"] .bg-light,
[data-theme="dark"] .bg-white,
[data-theme="dark"] .form-control,
[data-theme="dark"] .input-group-text {
    background-color: var(--bg-surface) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .text-dark {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .text-muted {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] .border,
[data-theme="dark"] .border-bottom,
[data-theme="dark"] .border-top,
[data-theme="dark"] .border-end {
    border-color: var(--border) !important;
}

[data-theme="dark"] .shadow-sm {
    box-shadow: var(--shadow-sm) !important;
}

/* ==============================
   UTILITY
   ============================== */
.rounded-4 { border-radius: 16px !important; }
