/* ── CSS Variables ── */
:root {
    --bg: #f7f8fa;
    --bg-card: #ffffff;
    --primary: #1a7a8a;
    --primary-light: #e6f4f7;
    --primary-fg: #ffffff;
    --text: #1a1f30;
    --text-muted: #6b7280;
    --border: #d5dce8;
    --success: #3fa667;
    --success-light: #e8f5ee;
    --warning: #e5a100;
    --warning-light: #fff7e0;
    --muted: #f1f3f7;
    --radius: 0.75rem;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
}

nav { max-width: 768px; margin: 0 auto; padding: 0.75rem 1rem; }
nav a { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: inherit; }

.nav-icon {
    width: 40px; height: 40px;
    background: var(--primary);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.nav-icon svg { width: 22px; height: 22px; }

.nav-text h1 { font-size: 1.15rem; font-weight: 700; line-height: 1.2; }
.nav-text p { font-size: 0.8rem; color: var(--text-muted); }

/* ── Main ── */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 768px;
    width: 100%;
    margin: 0 auto;
    position: relative;
}

/* ── Footer ── */
footer {
    text-align: center;
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* ── Chat Container ── */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

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

/* ── Empty State ── */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem;
    animation: fadeIn .4s ease-out;
}

.empty-state-icon {
    width: 56px; height: 56px;
    background: var(--muted);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.empty-state-icon svg { width: 28px; height: 28px; color: var(--text-muted); }

.empty-state h2 { font-size: 1.35rem; font-weight: 600; text-align: center; }
.empty-state p { color: var(--text-muted); font-size: 0.9rem; text-align: center; max-width: 400px; }

.example-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.5rem;
}

.example-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: all .15s;
}
.example-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: var(--shadow);
}

/* ── Messages ── */
.message { display: flex; gap: 0.5rem; animation: slideUp .3s ease-out; }
.message-user { justify-content: flex-end; }
.message-assistant { justify-content: flex-start; }

.message-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--muted);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.message-user .message-avatar { background: var(--primary); color: var(--primary-fg); }
.message-avatar svg { width: 16px; height: 16px; }

.message-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.6;
}

.message-user .message-bubble {
    background: var(--primary);
    color: var(--primary-fg);
    border-bottom-right-radius: 0.35rem;
}

.message-assistant .message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 0.35rem;
    max-width: 90%;
}

/* ── Loading dots ── */
.loading-dots { display: flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0; }
.loading-dots span {
    width: 7px; height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

/* ── ICD Result Cards ── */
.results-section { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }

.results-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.icd-card {
    background: var(--muted);
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    transition: box-shadow .15s;
}
.icd-card:hover { box-shadow: var(--shadow); }

.icd-info { flex: 1; min-width: 0; }

.icd-code {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary);
}

.icd-name { font-size: 0.85rem; margin-top: 0.15rem; }
.icd-notes { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; }

.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: 0.35rem;
    transition: color .15s;
    flex-shrink: 0;
}
.copy-btn:hover { color: var(--primary); }
.copy-btn svg { width: 16px; height: 16px; }

/* ── Clarification ── */
.clarification {
    background: var(--warning-light);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
}
.clarification-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--warning);
    margin-bottom: 0.35rem;
    display: flex; align-items: center; gap: 0.35rem;
}
.clarification-title svg { width: 16px; height: 16px; }
.clarification-question { font-size: 0.88rem; margin-bottom: 0.5rem; }

/* ── Reasoning ── */
.reasoning {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-style: italic;
}

/* ── Error Message ── */
.error-bubble {
    background: #fef2f2 !important;
    border-color: #fca5a5 !important;
}

.error-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #dc2626;
}

.error-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.75rem;
    padding: 0.4rem 0.85rem;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: opacity 0.15s;
}

.retry-btn:hover { opacity: 0.9; }
.retry-btn svg { width: 14px; height: 14px; }

/* ── Chat Input ── */
.chat-input-wrapper {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem 1rem;
}

.chat-input-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem 0.6rem;
    box-shadow: var(--shadow);
    transition: border-color .15s;
}
.chat-input-card:focus-within { border-color: var(--primary); }

.chat-input-card textarea {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    padding: 0;
    max-height: 150px;
    background: transparent;
    color: var(--text);
}
.chat-input-card textarea::placeholder { color: var(--text-muted); }

.input-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.6rem;
}

.model-select {
    padding: 0.4rem 0.7rem;
    background: var(--muted);
    border: 1px solid transparent;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    outline: none;
    transition: all .15s;
}
.model-select:hover { background: var(--border); }
.model-select:focus { border-color: var(--primary); }

.send-btn {
    width: 36px; height: 36px;
    background: var(--primary);
    color: var(--primary-fg);
    border: none;
    border-radius: 0.65rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: opacity .15s;
}
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }
.send-btn.retry-mode { background: #dc2626; }

/* ── New Search Button ── */
.new-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    margin: 1rem auto 0;
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 2rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s;
}
.new-search-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.new-search-btn svg { width: 16px; height: 16px; }

.input-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}
