/* Pharmacopilot Chat Widget */

:root {
    --pp-primary: #1a6b54;
    --pp-primary-hover: #145a46;
    --pp-primary-light: #e8f5f0;
    --pp-bg: #ffffff;
    --pp-bg-alt: #f7f8fa;
    --pp-text: #1e293b;
    --pp-text-muted: #64748b;
    --pp-border: #e2e8f0;
    --pp-shadow: 0 4px 24px rgba(0,0,0,0.12);
    --pp-radius: 12px;
    --pp-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --pp-transition: 0.2s ease;
}

/* ─── Launcher button ─────────────────────────────────────── */

#pp-chat-launcher {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--pp-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--pp-shadow);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--pp-transition), background var(--pp-transition);
}

#pp-chat-launcher:hover {
    transform: scale(1.08);
    background: var(--pp-primary-hover);
}

#pp-chat-launcher svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* ─── Chat window ─────────────────────────────────────────── */

#pp-chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 480px;
    height: 680px;
    max-height: calc(100vh - 120px);
    background: var(--pp-bg);
    border-radius: var(--pp-radius);
    box-shadow: var(--pp-shadow);
    z-index: 99998;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--pp-font);
    border: 1px solid var(--pp-border);
}

#pp-chat-window.pp-open {
    display: flex;
}

/* ─── Header ──────────────────────────────────────────────── */

.pp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--pp-primary);
    color: #fff;
    flex-shrink: 0;
}

.pp-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pp-header-icon {
    width: 28px;
    height: 28px;
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.pp-header-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.pp-header-subtitle {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 1px;
}

.pp-header-actions {
    display: flex;
    gap: 4px;
}

.pp-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--pp-transition);
    font-size: 14px;
}

.pp-header-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ─── Auth screen ─────────────────────────────────────────── */

.pp-auth {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
}

.pp-auth-logo {
    font-size: 40px;
    margin-bottom: 16px;
}

.pp-auth h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--pp-text);
    margin: 0 0 8px;
}

.pp-auth p {
    font-size: 13px;
    color: var(--pp-text-muted);
    margin: 0 0 24px;
    line-height: 1.5;
}

.pp-auth-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--pp-border);
    border-radius: 8px;
    font-size: 15px;
    font-family: var(--pp-font);
    text-align: center;
    letter-spacing: 1px;
    outline: none;
    transition: border-color var(--pp-transition);
}

.pp-auth-input:focus {
    border-color: var(--pp-primary);
}

.pp-auth-input::placeholder {
    letter-spacing: 0;
    color: var(--pp-text-muted);
}

.pp-auth-btn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    background: var(--pp-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--pp-font);
    transition: background var(--pp-transition);
}

.pp-auth-btn:hover {
    background: var(--pp-primary-hover);
}

.pp-auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.pp-auth-error {
    color: #dc2626;
    font-size: 13px;
    margin-top: 12px;
}

/* ─── Messages area ───────────────────────────────────────── */

.pp-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.pp-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    position: relative;
}

.pp-msg-user {
    align-self: flex-end;
    background: var(--pp-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.pp-msg-assistant {
    align-self: flex-start;
    background: var(--pp-bg-alt);
    color: var(--pp-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--pp-border);
}

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

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

.pp-msg-assistant strong {
    font-weight: 600;
}

.pp-msg-assistant code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
}

/* ─── Sources badge ───────────────────────────────────────── */

.pp-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--pp-border);
}

.pp-source-tag {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--pp-primary-light);
    color: var(--pp-primary);
    border-radius: 4px;
    font-weight: 500;
}

/* ─── Feedback ────────────────────────────────────────────── */

.pp-feedback {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.pp-feedback-btn {
    background: none;
    border: 1px solid var(--pp-border);
    border-radius: 6px;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 14px;
    transition: all var(--pp-transition);
    color: var(--pp-text-muted);
}

.pp-feedback-btn:hover {
    border-color: var(--pp-primary);
    color: var(--pp-primary);
}

.pp-feedback-btn.pp-active {
    background: var(--pp-primary-light);
    border-color: var(--pp-primary);
    color: var(--pp-primary);
}

/* ─── Typing indicator ───────────────────────────────────── */

.pp-typing {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    align-self: flex-start;
}

.pp-typing-dot {
    width: 6px;
    height: 6px;
    background: var(--pp-text-muted);
    border-radius: 50%;
    animation: pp-bounce 1.4s infinite ease-in-out both;
}

.pp-typing-dot:nth-child(1) { animation-delay: 0s; }
.pp-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.pp-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes pp-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ─── Input area ──────────────────────────────────────────── */

.pp-input-area {
    display: flex;
    align-items: flex-end;
    padding: 12px 16px;
    border-top: 1px solid var(--pp-border);
    background: var(--pp-bg);
    gap: 8px;
    flex-shrink: 0;
}

.pp-input-field {
    flex: 1;
    border: 1px solid var(--pp-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--pp-font);
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 40px;
    line-height: 1.4;
    transition: border-color var(--pp-transition);
}

.pp-input-field:focus {
    border-color: var(--pp-primary);
}

.pp-input-field::placeholder {
    color: var(--pp-text-muted);
}

.pp-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--pp-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--pp-transition), opacity var(--pp-transition);
}

.pp-send-btn:hover {
    background: var(--pp-primary-hover);
}

.pp-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pp-send-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ─── Status bar ──────────────────────────────────────────── */

.pp-status {
    font-size: 11px;
    color: var(--pp-text-muted);
    text-align: center;
    padding: 4px;
    background: var(--pp-bg-alt);
    flex-shrink: 0;
}

/* ─── Welcome message ─────────────────────────────────────── */

.pp-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--pp-text-muted);
    font-size: 13px;
    line-height: 1.6;
}

.pp-welcome-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.pp-welcome strong {
    color: var(--pp-text);
    display: block;
    font-size: 15px;
    margin-bottom: 4px;
}

.pp-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* ─── Mobile responsive ──────────────────────────────────── */

@media (max-width: 480px) {
    #pp-chat-window {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }

    #pp-chat-launcher {
        bottom: 16px;
        right: 16px;
    }
}

/* ─── Context bar ─────────────────────────────────────────── */

.pp-context-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    background: var(--pp-bg-alt);
    border-bottom: 1px solid var(--pp-border);
    font-size: 12px;
    flex-shrink: 0;
    min-height: 32px;
}

.pp-ctx-label {
    color: var(--pp-text-muted);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.pp-ctx-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
}

.pp-ctx-country {
    background: #dbeafe;
    color: #1e40af;
}

.pp-ctx-lang {
    background: #e0e7ff;
    color: #3730a3;
}

.pp-ctx-product {
    background: var(--pp-primary-light);
    color: var(--pp-primary);
}

.pp-ctx-ingredient {
    background: #fef3c7;
    color: #92400e;
}

.pp-ctx-type {
    background: #f3e8ff;
    color: #6b21a8;
}

.pp-ctx-dosage {
    background: #fce7f3;
    color: #9d174d;
}

/* ─── Clarification message ───────────────────────────────── */

.pp-msg-clarification {
    border-left: 3px solid #f59e0b;
    background: #fffbeb !important;
}