:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --bg-main: #f3f2f1;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --accent: #ef4444;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --glass: rgba(255, 255, 255, 0.7);
    --radius: 12px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    padding: 40px 20px;
    max-width: 1000px;
    margin: 0 auto;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, #1e293b 0%, #3b82f6 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.025em;
}

.health-info {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 30px;
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
}

.health-info h3 {
    margin-bottom: 12px;
    color: var(--text-main);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-container {
    background: var(--bg-card);
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    margin-bottom: 40px;
    border: 1px solid var(--border);
    overflow: visible; /* allow help tooltips to escape the container */
}

.search-form {
    display: flex;
    gap: 12px;
}

.search-form input[type="text"] {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.2s;
    outline: none;
}

.search-form input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.search-form button {
    padding: 14px 28px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.search-form button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.options {
    margin-top: 20px;
    display: flex;
    gap: 24px;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.results {
    display: grid;
    gap: 20px;
}

.result-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    transition: transform 0.2s, box-shadow 0.2s;
    animation: fadeIn 0.4s ease-out forwards;
}

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

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

.result-card h3 {
    font-size: 1.25rem;
    margin-bottom: 12px;
    color: var(--text-main);
    font-weight: 700;
}

.result-card .meta {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-card .meta span {
    background: var(--bg-main);
    padding: 4px 10px;
    border-radius: 6px;
    color: var(--text-muted);
}

.result-card .score {
    color: var(--accent) !important;
}

.result-card .content {
    font-size: 0.9375rem;
    color: #475569;
    line-height: 1.7;
    margin-bottom: 20px;
    white-space: pre-wrap;
    background: #fbfcfd;
    padding: 16px;
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.result-card .content a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
}

.result-card .content a:hover {
    color: var(--primary-hover);
}

.actions {
    display: flex;
    gap: 16px;
}

.actions a {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
}

.actions a:hover {
    text-decoration: underline;
}

.related {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.related h4 {
    font-size: 0.8125rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 0.05em;
}

.related-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.related-item {
    background: #f1f5f9;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

mark {
    background: rgba(254, 240, 138, 0.6);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.loading {
    display: flex;
    justify-content: center;
    padding: 40px;
    color: var(--text-muted);
    font-weight: 600;
    animation: pulse 2s infinite ease-in-out;
}

.error {
    color: var(--accent);
    padding: 12px;
    background: #fef2f2;
    border-radius: 8px;
    font-size: 0.875rem;
}

/* AI Assistant & RAG Styles */
.mode-toggle {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 10px;
    gap: 4px;
}

.mode-toggle button {
    padding: 6px 16px;
    border: none;
    background: transparent;
    border-radius: 7px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-toggle button.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.ai-response-container {
    margin-bottom: 30px;
    animation: fadeIn 0.5s ease-out;
}

.ai-bubble {
    background: linear-gradient(135deg, #ffffff 0%, #f8faff 100%);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.ai-bubble::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), #a855f7);
}

.ai-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.ai-content {
    color: #334155;
    line-height: 1.8;
    font-size: 1.05rem;
}

.ai-content p {
    margin-bottom: 16px;
}

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

.ai-content ul, .ai-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.ai-content li {
    margin-bottom: 8px;
}

.ai-content code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Cascadia Code', 'Source Code Pro', monospace;
    font-size: 0.9em;
    color: var(--primary);
}

.ai-content pre {
    background: #1e293b;
    color: #f8fafc;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.ai-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}

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

.ai-content a {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-style: italic;
}

.typing-indicator::after {
    content: '...';
    animation: dots 1.5s steps(5, end) infinite;
    width: 20px;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60% { content: '...'; }
    80%, 100% { content: ''; }
}

.results h2 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin: 40px 0 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.results h2::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Help tip tooltip */
.help-tip {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    vertical-align: middle;
    cursor: default;
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    font-style: normal;
    line-height: 1;
    transition: background 0.2s;
}

.help-tip:hover .help-icon {
    background: var(--primary);
    color: #fff;
}

.help-tooltip {
    /* Always out of flow and invisible; revealed on hover via opacity/visibility */
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    background: var(--bg-card);   /* was --surface (undefined) */
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.78rem;
    color: var(--text-main);      /* was --text-light (undefined) */
    line-height: 1.5;
    white-space: normal;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    /* Hidden by default — visibility+opacity avoids label text-flow issues */
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Arrow */
.help-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border);
}

.help-tip:hover .help-tooltip {
    visibility: visible;
    opacity: 1;
}
