/* ============================================
   CATBOX - Dr. CatBox Chat Interface
   v14.0.0 - Structure Maquette JSX
   ============================================ */

/* ========== VARIABLES - Palette Maquette ========== */
#screen-chat {
    --accent: #2D7A6D;
    --accent-light: rgba(45, 122, 109, 0.12);
    --accent-hover: rgba(45, 122, 109, 0.04);
    --bg: #FAFAF7;
    --surface: #FFFFFF;
    --text: #2C2620;
    --text-light: #F5F2ED;
    --muted: #A09888;
    --muted-light: #B5AEA2;
    --border: #EDE8E0;
    --border-light: #F0EDE6;
    --user-bubble: #2C2620;
    --danger: #D4645A;
    --danger-bg: #FEF2F2;
}

/* ========== SCREEN VISIBILITY ========== */
#screen-chat.active {
    display: flex !important;
}

/* ========== MAIN CONTAINER ========== */
#screen-chat {
    flex-direction: column;
    height: calc((var(--vh, 1vh) * 100) - var(--header-h, 56px) - var(--nav-h, 72px));
    height: calc(100dvh - var(--header-h, 56px) - var(--nav-h, 72px));
    padding: 0 !important;
    overflow: hidden;
    background: var(--bg);
    position: relative;
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
}

/* ========== HEADER V2 - Style Maquette ========== */
.chat-header-v2 {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

/* Avatar avec dot online */
.chat-avatar-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.chat-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: cover;
    background: var(--border-light);
}

.chat-avatar-online {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 6px;
    background: var(--accent);
    border: 2px solid var(--bg);
}

/* Info chat */
.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-info h4 {
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
}

.chat-header-info p {
    font-size: 11px;
    color: var(--muted);
    margin: 2px 0 0 0;
    font-weight: 600;
}

/* Header actions */
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Bouton Terminer V2 */
.chat-end-btn-v2 {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 8px;
    background: var(--danger-bg);
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: var(--danger);
    flex-shrink: 0;
    transition: background 0.15s;
}

.chat-end-btn-v2:active {
    background: #FECACA;
}

/* Bouton menu V2 */
.chat-menu-btn-v2 {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--border-light);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--muted);
    transition: background 0.15s;
}

.chat-menu-btn-v2:active {
    background: var(--border);
}

.chat-menu-btn-v2 i {
    font-size: 18px;
}

/* Menu dropdown */
#screen-chat .chat-menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 16px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    display: none;
    min-width: 180px;
    z-index: 100;
    overflow: hidden;
    border: 1px solid var(--border);
}

#screen-chat .chat-menu-dropdown.active {
    display: block;
    animation: menuSlide 0.2s ease;
}

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

#screen-chat .chat-menu-dropdown button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    border: none;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

#screen-chat .chat-menu-dropdown button:active {
    background: var(--border-light);
}

#screen-chat .chat-menu-dropdown button i {
    font-size: 16px;
    color: var(--muted);
}

/* ========== SCROLLABLE AREA ========== */
#screen-chat .chat-messages {
    position: absolute;
    top: 66px;
    bottom: 68px;
    left: 0;
    right: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 16px 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

#screen-chat .chat-messages::-webkit-scrollbar { width: 0; }

/* ========== ÉTAT WELCOME (avant conversation) ========== */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 28px 0 0;
}

/* Icône stéthoscope dans carré */
.chat-welcome-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--accent-light);
    border: 1.5px solid rgba(45, 122, 109, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}

.chat-welcome-icon i {
    font-size: 26px;
    color: var(--accent);
}

.chat-welcome-title {
    font-size: 18px;
    font-weight: 900;
    color: var(--text);
    margin: 0;
}

.chat-welcome-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin: 4px 0 0;
    font-weight: 500;
}

/* Crédits V2 avec dots */
.chat-credits-v2 {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 14px;
    border-radius: 20px;
    background: var(--border-light);
    margin-top: 12px;
}

.chat-credits-v2.premium {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.chat-credits-v2.premium .chat-credits-text {
    color: #92400e;
}

.chat-credits-dot {
    width: 7px;
    height: 7px;
    border-radius: 4px;
    background: #DDD8CF;
    transition: background 0.3s;
}

.chat-credits-dot.active {
    background: var(--accent);
}

.chat-credits-text {
    font-size: 11px;
    color: #8A8478;
    font-weight: 600;
    margin-left: 2px;
}

/* Section titre quick actions */
.chat-welcome-section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--muted-light);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 24px 0 12px;
    text-align: left;
    width: 100%;
}

/* ========== QUICK ACTIONS - LISTE VERTICALE ========== */
.chat-quick-actions-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Quick Action Card */
.qa-card {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
    transition: all 0.15s ease;
}

.qa-card:active {
    transform: scale(0.98);
}

/* Icône colorée */
.qa-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.qa-card-icon i {
    font-size: 18px;
}

/* Contenu */
.qa-card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.qa-card-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 3px;
    line-height: 1.2;
}

.qa-card-desc {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
    font-weight: 500;
}

/* Chevron */
.qa-card-chevron {
    flex-shrink: 0;
    margin-top: 8px;
    color: #D0C8BC;
    font-size: 16px;
}

/* ========== MESSAGES V2 ========== */
.chat-message-v2 {
    margin-bottom: 10px;
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Bot message V2 */
.chat-message-v2.bot {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.chat-bot-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 10px;
    background: var(--accent-light);
    border: 1px solid rgba(45, 122, 109, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-bot-avatar i {
    font-size: 15px;
    color: var(--accent);
}

.chat-message-v2.bot .chat-bubble-v2 {
    padding: 11px 14px;
    max-width: 80%;
    border-radius: 4px 16px 16px 16px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.65;
    font-weight: 500;
}

/* User message V2 */
.chat-message-v2.user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.chat-message-v2.user .chat-bubble-v2 {
    padding: 11px 14px;
    max-width: 75%;
    border-radius: 16px 16px 4px 16px;
    background: var(--user-bubble);
    color: var(--text-light);
    font-size: 13px;
    line-height: 1.65;
    font-weight: 500;
}

/* Bubble content */
.chat-bubble-content {
    /* For HTML content */
}

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

.chat-message-v2.user .chat-bubble-time {
    color: var(--text-light);
}

.chat-message-v2.bot .chat-bubble-time {
    color: var(--muted);
}

/* ========== TYPING INDICATOR ========== */
#screen-chat .chat-typing-bubble {
    display: none;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    animation: msgIn 0.3s ease;
}

#screen-chat .chat-typing-bubble.active {
    display: flex;
}

#screen-chat .chat-typing-bubble .chat-bot-avatar {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: var(--accent-light);
    border: 1px solid rgba(45, 122, 109, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
}

#screen-chat .chat-typing-bubble .chat-bot-avatar i {
    font-size: 15px;
    color: var(--accent);
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: 4px 16px 16px 16px;
    border: 1px solid var(--border);
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 3px;
    background: var(--muted);
    opacity: 0.4;
    animation: typingDot 1.2s ease infinite;
}

.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ========== DRAWER QUICK ACTIONS (mode chat) ========== */
.chat-drawer {
    position: absolute;
    bottom: 68px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: none;
    flex-direction: column;
    z-index: 5;
}

/* Drawer toggle button */
.chat-drawer-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: #8A8478;
    transition: color 0.2s;
}

.chat-drawer-toggle:hover {
    color: var(--accent);
}

.chat-drawer-toggle i {
    font-size: 14px;
}

.chat-drawer-chevron {
    transition: transform 0.3s ease;
}

/* Drawer content */
.chat-drawer-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-drawer.open .chat-drawer-content {
    max-height: 300px;
    overflow-y: auto;
    padding: 0 16px 10px;
}

/* Quick actions compactes dans drawer */
.chat-quick-actions-compact {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.qa-compact {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s ease;
}

.qa-compact:active {
    transform: scale(0.98);
}

.qa-compact-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.qa-compact-icon i {
    font-size: 16px;
}

.qa-compact-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* ========== INPUT BAR V2 ========== */
.chat-input-container-v2 {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: var(--bg);
    padding: 8px 16px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Input wrapper style pill */
.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border-radius: 24px;
    padding: 4px 4px 4px 6px;
    border: 1.5px solid var(--border);
    transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent);
}

/* Bouton camera */
.chat-camera-btn {
    width: 34px;
    height: 34px;
    border-radius: 17px;
    background: var(--border-light);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--muted);
    transition: background 0.15s;
}

.chat-camera-btn:active {
    background: var(--border);
}

.chat-camera-btn i {
    font-size: 16px;
}

/* Input text V2 */
.chat-input-v2 {
    flex: 1;
    border: none;
    outline: none;
    font-size: 13.5px;
    color: var(--text);
    background: transparent;
    font-family: inherit;
    font-weight: 500;
    min-width: 0;
    padding: 8px 4px;
    resize: none;
}

.chat-input-v2::placeholder {
    color: var(--muted-light);
}

/* Bouton send */
.chat-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 17px;
    background: var(--user-bubble);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    transition: background 0.2s;
}

.chat-send-btn.has-text {
    background: var(--accent);
}

.chat-send-btn i {
    font-size: 14px;
}

/* ========== AI MESSAGE CONTENT ========== */
.chat-bubble-v2 .ai-msg,
#screen-chat .ai-msg {
    font-size: 13px;
    line-height: 1.65;
    color: var(--text);
}

.ai-msg > *:first-child { margin-top: 0 !important; }
.ai-msg > *:last-child { margin-bottom: 0 !important; }

.ai-msg p {
    margin: 0 0 8px 0;
}

.ai-msg p:last-child { margin-bottom: 0; }

.ai-msg strong {
    font-weight: 700;
    color: var(--text);
}

.ai-msg em {
    font-style: italic;
    color: var(--muted);
}

.ai-msg ul,
.ai-msg ol {
    margin: 6px 0;
    padding-left: 0;
    list-style: none;
}

.ai-msg li {
    position: relative;
    padding-left: 14px;
    margin-bottom: 4px;
    line-height: 1.55;
}

.ai-msg ul > li::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 8px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
}

.ai-msg blockquote {
    margin: 6px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--accent);
    background: var(--accent-light);
    border-radius: 0 8px 8px 0;
    font-size: 12px;
}

/* ========== MODIFICATION CARDS ========== */
.ai-modifications-container {
    margin: 12px 0 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ai-mod-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-mod-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-mod-icon.vaccine { background: #d1fae5; color: #059669; }
.ai-mod-icon.weight { background: #fef3c7; color: #d97706; }
.ai-mod-icon.visit { background: #dbeafe; color: #2563eb; }
.ai-mod-icon.treatment { background: #ede9fe; color: #7c3aed; }

.ai-mod-content { flex: 1; min-width: 0; }
.ai-mod-field { font-size: 9px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.ai-mod-new { font-size: 12px; font-weight: 600; color: var(--text); }

.ai-mod-actions { display: flex; gap: 4px; }
.ai-mod-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
}
.ai-mod-btn.accept { background: #dcfce7; color: #16a34a; }
.ai-mod-btn.reject { background: #fee2e2; color: #dc2626; }

/* ========== ONBOARDING MODAL ========== */
.chat-onboarding-modal {
    max-width: 340px !important;
    text-align: center;
    padding: 28px 20px !important;
}

.onboarding-mascot {
    width: 80px;
    height: 80px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.onboarding-mascot i {
    font-size: 36px;
    color: white;
}

.onboarding-slide h2 {
    font-size: 20px;
    font-weight: 800;
    color: #2C2620;
    margin: 0 0 10px;
}

.onboarding-slide p {
    font-size: 14px;
    color: #A09888;
    line-height: 1.6;
}

/* ========== END CONVERSATION MODAL ========== */
.extracted-observations {
    margin-top: 16px;
    max-height: 280px;
    overflow-y: auto;
}

.observation-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: #FAFAF7;
    border-radius: 10px;
    margin-bottom: 8px;
    border: 1px solid #EDE8E0;
}

.observation-item input[type="checkbox"] {
    accent-color: #2D7A6D;
    width: 18px;
    height: 18px;
}

.observation-content strong {
    font-size: 14px;
    color: #2C2620;
}

.observation-content p {
    font-size: 13px;
    color: #A09888;
    margin: 4px 0 0;
}

/* ========== RESPONSIVE ========== */
@media (max-height: 600px) {
    .chat-welcome {
        padding-top: 16px;
    }
    .chat-welcome-icon {
        width: 48px;
        height: 48px;
    }
    .chat-welcome-icon i {
        font-size: 22px;
    }
    .chat-welcome-section-title {
        margin-top: 16px;
    }
}

/* Ajuster la zone de messages quand le drawer est ouvert */
#screen-chat .chat-drawer.open ~ .chat-messages {
    bottom: 138px;
}
