/* ============================================
   MedKnowledgeAgent - Clinical Precision Theme
   ============================================ */

:root {
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-hover: #f6f7f9;
    --bg-code: #f1f5f9;

    --text-primary: #1a2332;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --accent: #0891b2;
    --accent-dark: #0e7490;
    --accent-light: #cffafe;
    --accent-bg: #ecfeff;

    --user-bg: #1a2332;
    --user-text: #ffffff;
    --ai-bg: #ffffff;
    --ai-border: #e2e8f0;

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.06);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.06), 0 2px 4px -2px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.06), 0 4px 6px -4px rgb(0 0 0 / 0.06);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --font-display: 'Crimson Pro', Georgia, 'Times New Roman', 'Songti SC', serif;
    --font-body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Subtle dot grid background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: 0.25;
    pointer-events: none;
    z-index: 0;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* Header */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--ai-border);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0.3;
}

.header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.logo {
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(8, 145, 178, 0.2));
}

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.brand-text span {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.02em;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-hover);
    border-radius: 100px;
    border: 1px solid var(--ai-border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    position: relative;
}

.status-dot.online {
    background: var(--success);
}

.status-dot.online::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid var(--success);
    opacity: 0.4;
    animation: pulse-ring 2s ease-out infinite;
}

.status-dot.offline {
    background: var(--error);
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(2); opacity: 0; }
}

.status-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    scroll-behavior: smooth;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Welcome */
.welcome {
    text-align: center;
    padding: 48px 20px;
    animation: fadeInUp 0.8s ease-out;
}

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

.welcome-badge {
    margin-bottom: 24px;
    display: inline-flex;
    padding: 16px;
    background: var(--accent-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.welcome-title {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

.welcome-desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 520px;
    margin: 0 auto 12px;
    line-height: 1.7;
}

.welcome-hint {
    color: var(--accent);
    font-size: 0.85rem;
    max-width: 520px;
    margin: 0 auto 28px;
    line-height: 1.6;
    background: var(--accent-bg);
    padding: 10px 16px;
    border-radius: var(--radius);
    border-left: 3px solid var(--accent);
    text-align: left;
}

.ecg-divider {
    max-width: 320px;
    margin: 0 auto 28px;
    height: 40px;
    opacity: 0.6;
}

.ecg-line {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    animation: drawEcg 3s ease-in-out forwards;
}

@keyframes drawEcg {
    to { stroke-dashoffset: 0; }
}

.suggested-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 500;
}

.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.suggestion-chip {
    padding: 10px 18px;
    background: var(--bg-card);
    border: 1.5px solid var(--ai-border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: var(--shadow-sm);
}

.suggestion-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Suggestion Categories */
.suggestion-category {
    margin-top: 16px;
}

.category-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 100px;
    margin-bottom: 10px;
    letter-spacing: 0.04em;
}

.category-tag.usage {
    background: #dbeafe;
    color: #1e40af;
}

.category-tag.caution {
    background: #fef3c7;
    color: #92400e;
}

.category-tag.interaction {
    background: #fce7f3;
    color: #9d174d;
}

.category-tag.indication {
    background: #dcfce7;
    color: #166534;
}

.category-tag.storage {
    background: #e0e7ff;
    color: #3730a3;
}

.category-tag.special {
    background: #ffedd5;
    color: #9a3412;
}

.category-tag.miss {
    background: #f3e8ff;
    color: #6b21a8;
}

.category-tag.overdose {
    background: #fee2e2;
    color: #991b1b;
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    gap: 6px;
    animation: messageIn 0.4s ease-out;
    max-width: 85%;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.message-system {
    align-self: center;
    align-items: center;
    max-width: 90%;
}

.message-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    padding: 0 4px;
}

.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    line-height: 1.7;
    word-break: break-word;
    box-shadow: var(--shadow);
}

.message-user .message-bubble {
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: var(--radius-sm);
}

.message-assistant .message-bubble {
    background: var(--ai-bg);
    color: var(--text-primary);
    border: 1px solid var(--ai-border);
    border-bottom-left-radius: var(--radius-sm);
}

.message-system .message-bubble {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
    font-size: 0.875rem;
    text-align: center;
}

/* Markdown in assistant messages */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
    font-family: var(--font-display);
    color: var(--text-primary);
    margin: 16px 0 10px;
    line-height: 1.3;
}

.message-bubble h1 { font-size: 1.25rem; }
.message-bubble h2 { font-size: 1.15rem; }
.message-bubble h3 { font-size: 1.05rem; }

.message-bubble p {
    margin-bottom: 10px;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin: 5px 0;
}

.message-bubble code {
    background: var(--bg-code);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.85em;
    color: var(--accent-dark);
}

.message-bubble pre {
    background: var(--bg-code);
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--ai-border);
}

.message-bubble pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.message-bubble strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message-bubble blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message-bubble hr {
    border: none;
    border-top: 1px solid var(--ai-border);
    margin: 16px 0;
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.9em;
}

.message-bubble th,
.message-bubble td {
    border: 1px solid var(--ai-border);
    padding: 8px 12px;
    text-align: left;
}

.message-bubble th {
    background: var(--bg-hover);
    font-weight: 600;
}

/* Sources */
.sources {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--ai-border);
}

.sources-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sources-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 14px;
    background: var(--accent);
    border-radius: 2px;
}

.source-item {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 5px 0;
    border-bottom: 1px dashed #e2e8f0;
}

.source-item:last-child {
    border-bottom: none;
}

/* Loading */
.loading-bubble {
    display: flex;
    align-items: center;
    min-width: 80px;
    min-height: 48px;
}

.typing-indicator {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 4px 8px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite both;
}

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

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

/* Back Home Button */
.back-home-btn {
    flex-shrink: 0;
    display: none;
    align-items: center;
    gap: 2px;
    padding: 7px 12px 7px 8px;
    border: 1px solid rgba(8, 145, 178, 0.2);
    border-radius: 999px;
    background: var(--accent-bg);
    color: var(--accent-dark);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.back-home-btn.visible {
    display: inline-flex;
}

.back-home-icon {
    flex-shrink: 0;
    margin-left: -1px;
}

.back-home-btn:hover {
    background: var(--accent-light);
    border-color: rgba(8, 145, 178, 0.4);
    color: var(--accent);
}

.back-home-btn:active {
    transform: scale(0.97);
}

.back-home-btn:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 2px;
}

/* Input Panel */
.input-panel {
    flex-shrink: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--ai-border);
    padding: 16px 24px 20px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
    position: relative;
    z-index: 10;
}

.input-inner {
    max-width: 900px;
    margin: 0 auto;
}

.input-box {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-body);
    border: 1.5px solid var(--ai-border);
    border-radius: var(--radius-xl);
    padding: 6px 6px 6px 18px;
    transition: all 0.25s ease;
}

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

.question-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
    resize: none;
    min-height: 24px;
    max-height: 160px;
    padding: 10px 0;
    line-height: 1.5;
}

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

.send-button {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.send-button:hover:not(:disabled) {
    background: var(--accent-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}

.input-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 10px;
    letter-spacing: 0.02em;
}

/* Responsive */
@media (max-width: 768px) {
    .header-inner {
        padding: 12px 16px;
    }

    .brand-text h1 {
        font-size: 1.1rem;
    }

    .brand-text span {
        display: none;
    }

    .chat-messages {
        padding: 20px 16px;
        gap: 16px;
    }

    .message {
        max-width: 92%;
    }

    .welcome {
        padding: 32px 16px;
    }

    .welcome-title {
        font-size: 1.4rem;
    }

    .suggested-questions {
        gap: 8px;
    }

    .suggestion-chip {
        padding: 8px 14px;
        font-size: 0.8rem;
    }

    .input-panel {
        padding: 12px 16px 16px;
    }

    .back-home-btn {
        padding: 6px 10px 6px 6px;
        font-size: 0.78rem;
    }

    .input-box {
        padding: 4px 4px 4px 14px;
    }
}
