/* ================================================================
   ACE Crop Insurance Assistant — Design System
   Modern, clean UI with emerald accents
   ================================================================ */

/* ── Design Tokens ── */
:root {
    --primary: #10b981;
    --primary-hover: #059669;
    --primary-light: #d1fae5;
    --primary-subtle: #ecfdf5;
    --primary-glow: rgba(16, 185, 129, 0.15);

    --secondary: #6366f1;
    --accent: #f59e0b;

    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --gray-950: #020617;

    --white: #ffffff;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning-bg: #fef3c7;
    --warning-border: #fcd34d;

    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-2xl: 1.25rem;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-width: 300px;
    --header-height: 56px;
    --input-max-width: 48rem;
    --content-max-width: 48rem;
}

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

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: var(--gray-50);
    color: var(--gray-800);
    font-size: 15px;
    line-height: 1.6;
}

h1:focus { outline: none; }

a, .btn-link {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover { color: var(--primary-hover); }

/* ── Layout Utilities ── */
.h-screen { height: 100vh; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.gap-4 { gap: 1rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.m-0 { margin: 0; }
.w-full { width: 100%; }
.max-w-4xl { max-width: var(--content-max-width); }
.mx-auto { margin-left: auto; margin-right: auto; }
.overflow-y-auto { overflow-y: auto; }
.overflow-hidden { overflow: hidden; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.pt-4 { padding-top: 1rem; }
.py-12 { padding-top: 3rem; padding-bottom: 3rem; }
.bg-gray-50 { background-color: var(--gray-50); }
.bg-gray-100 { background-color: var(--gray-100); }
.bg-white { background-color: var(--white); }
.bg-primary { background-color: var(--primary); }
.text-gray-500 { color: var(--gray-500); }
.text-gray-600 { color: var(--gray-600); }
.text-gray-800 { color: var(--gray-800); }
.text-white { color: var(--white); }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-xl { font-size: 1.25rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.prose { line-height: 1.7; }
.rounded { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.border { border: 1px solid var(--gray-200); }
.border-t { border-top: 1px solid var(--gray-200); }
.border-b { border-bottom: 1px solid var(--gray-200); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow { box-shadow: var(--shadow-md); }

/* ── Buttons ── */
.btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
    border: none;
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.3);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #047857 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background-color: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.btn-secondary:hover {
    background-color: var(--gray-50);
    border-color: var(--gray-300);
}

/* ── Inputs ── */
.input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--white);
    color: var(--gray-800);
    transition: all var(--transition-fast);
}
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
.input::placeholder {
    color: var(--gray-400);
}

/* ================================================================
   App Header
   ================================================================ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: var(--header-height);
    background: var(--gray-900);
    color: var(--gray-100);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.header-title {
    font-weight: 700;
    font-size: 1.125rem;
    background: linear-gradient(135deg, var(--primary) 0%, #34d399 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
    letter-spacing: -0.02em;
}
.header-title:hover {
    opacity: 0.9;
}

.header-subtitle {
    font-size: 0.8rem;
    color: var(--gray-400);
    font-weight: 400;
    padding-left: 0.625rem;
    border-left: 1px solid var(--gray-700);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-nav .nav-link {
    color: var(--gray-400);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}
.header-nav .nav-link:hover {
    color: var(--gray-100);
    background: rgba(255, 255, 255, 0.06);
}

/* ── Login Display ── */
.auth-user-name {
    font-size: 0.8125rem;
    color: var(--gray-400);
}

.btn-login, .btn-logout {
    font-size: 0.8rem;
    padding: 0.35rem 0.875rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    border: 1px solid var(--gray-700);
    background: transparent;
    color: var(--gray-300);
    font-weight: 500;
    transition: all var(--transition-fast);
}
.btn-login:hover, .btn-logout:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gray-600);
    color: var(--white);
}

/* ================================================================
   Three-Column Layout
   ================================================================ */

.app-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
    background-color: var(--gray-50);
}

/* ── Sidebars ── */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--white);
    overflow-y: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: var(--radius-full);
}

.sidebar-left {
    border-right: 1px solid var(--gray-200);
    padding: 1.5rem;
}

.sidebar-right {
    border-left: 1px solid var(--gray-200);
    padding: 1.5rem;
    transition: transform var(--transition-slow);
}

.sidebar-right.hidden {
    transform: translateX(100%);
    position: absolute;
    right: 0;
    height: 100%;
    z-index: 30;
}

@media (max-width: 1280px) {
    .sidebar-left { display: none; }
}

@media (max-width: 1024px) {
    .sidebar-right {
        position: fixed;
        right: 0;
        top: var(--header-height);
        height: calc(100% - var(--header-height));
        z-index: 30;
        box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
    }
    .sidebar-right.hidden {
        transform: translateX(100%);
    }
}

.sidebar-overlay { display: none; }

@media (max-width: 1024px) {
    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        top: var(--header-height);
        background: rgba(15, 23, 42, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 20;
        animation: fadeIn var(--transition-fast) ease-out;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    background: var(--gray-50);
}

.content-header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0.875rem 1.5rem;
}

.header-inner {
    max-width: var(--content-max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-text h1 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.02em;
}

.header-text p {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin: 0.125rem 0 0 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-sidebar-toggle {
    display: none;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    background: var(--white);
    cursor: pointer;
    color: var(--gray-500);
    transition: all var(--transition-fast);
}
.btn-sidebar-toggle:hover {
    background-color: var(--gray-50);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

@media (max-width: 1024px) {
    .btn-sidebar-toggle { display: flex; }
}

.btn-api-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.625rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    background: var(--white);
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--gray-500);
    transition: all var(--transition-fast);
    font-family: inherit;
}
.btn-api-toggle .icon { width: 14px; height: 14px; }
.btn-api-toggle .api-toggle-label {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.btn-api-toggle:hover {
    background-color: var(--gray-50);
    border-color: var(--gray-300);
}
.btn-api-toggle.active {
    background-color: rgba(99, 102, 241, 0.08);
    border-color: var(--secondary);
    color: var(--secondary);
}
.btn-api-toggle.active:hover {
    background-color: rgba(99, 102, 241, 0.12);
}

/* ── Conversation Area ── */
.conversation-area {
    flex: 1;
    overflow: hidden;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.conversation-area-inner {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}
.conversation-area-inner::-webkit-scrollbar { width: 5px; }
.conversation-area-inner::-webkit-scrollbar-track { background: transparent; }
.conversation-area-inner::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: var(--radius-full);
}

/* ================================================================
   Message Bubbles
   ================================================================ */

.message {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-xl);
    animation: messageSlideIn var(--transition-slow) ease-out;
}

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

.message-user {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
    margin-left: auto;
    max-width: 75%;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.message-assistant {
    background: var(--white);
    border: 1px solid var(--gray-200);
    max-width: 85%;
    box-shadow: var(--shadow-sm);
}

.agent-name-label {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-hover);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ── Loading ── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.animate-pulse { animation: pulse 2s infinite; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-indicator {
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-lg);
}

.loading-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.loading-spinner {
    width: 1.125rem;
    height: 1.125rem;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.loading-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.loading-primary {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-700);
}

.loading-secondary {
    font-size: 0.75rem;
    color: var(--gray-400);
}

/* ── Response Metadata ── */
.response-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--gray-100);
}

.agent-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.agent-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    font-weight: 500;
    background: var(--primary-subtle);
    color: var(--primary-hover);
    border: 1px solid var(--primary-light);
}

.processing-time {
    font-size: 0.6875rem;
    color: var(--gray-400);
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

.tool-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-full);
    font-size: 0.625rem;
    font-weight: 500;
    background: rgba(99, 102, 241, 0.08);
    color: var(--secondary);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

/* ── Message Timestamps ── */
.message-timestamp {
    font-size: 0.6875rem;
    color: var(--gray-400);
    margin-bottom: 0.25rem;
}

/* ── Message Action Bar (copy, regenerate, feedback) ── */
.message-actions {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--gray-400);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    color: var(--gray-600);
    border-color: var(--gray-200);
    background: var(--gray-50);
}

.action-btn:active {
    transform: scale(0.92);
}

.action-divider {
    width: 1px;
    height: 16px;
    background: var(--gray-200);
    margin: 0 0.25rem;
}

.feedback-status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-left: 0.25rem;
}

.feedback-positive {
    color: var(--primary);
}

.feedback-negative {
    color: var(--gray-500);
}

/* ── Feedback Comment Box ── */
.feedback-comment-box {
    margin-top: 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-50);
}

.feedback-textarea {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: inherit;
    resize: vertical;
    background: var(--white);
    color: var(--gray-800);
    transition: border-color var(--transition-fast);
}

.feedback-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.feedback-comment-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.375rem;
}

.feedback-comment-btn {
    padding: 0.25rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.feedback-comment-cancel {
    background: transparent;
    color: var(--gray-500);
}

.feedback-comment-cancel:hover {
    color: var(--gray-700);
}

.feedback-comment-submit {
    background: var(--primary);
    color: var(--white);
}

.feedback-comment-submit:hover {
    background: var(--primary-hover);
}

/* ── Theme Toggle ── */
.theme-toggle {
    border: none;
    background: none;
    cursor: pointer;
    padding: 0.25rem;
}

/* ── Agent Response Sections ── */
.agent-detail-section {
    border-color: var(--gray-200);
}

details.agent-response {
    margin-bottom: 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    overflow: hidden;
}

details.agent-response summary {
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-700);
    background: var(--gray-50);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    -webkit-user-select: none;
    user-select: none;
    transition: background var(--transition-fast);
}
details.agent-response summary::-webkit-details-marker { display: none; }
details.agent-response summary::before {
    content: '\25B6';
    font-size: 0.55rem;
    transition: transform var(--transition-fast);
    color: var(--gray-400);
}
details.agent-response[open] summary::before {
    transform: rotate(90deg);
}
details.agent-response summary:hover {
    background: var(--gray-100);
}
details.agent-response .agent-response-content {
    padding: 0.75rem;
    font-size: 0.8125rem;
    border-top: 1px solid var(--gray-200);
    max-height: 500px;
    overflow-y: auto;
}

/* ── Card ── */
.card {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    padding: 1rem;
}

/* ── Blazor Error UI ── */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-family: inherit;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred." }

/* ── Loading Progress ── */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}
.loading-progress circle {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}
.loading-progress circle:last-child {
    stroke: var(--primary);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}
.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

code { color: #c02d76; }

/* ── Error Banner ── */
.error-banner {
    background: var(--danger-light);
    border-bottom: 1px solid #fecaca;
    color: #b91c1c;
    padding: 0.625rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8125rem;
    animation: slideDown var(--transition-fast) ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.error-dismiss {
    background: none;
    border: none;
    color: #b91c1c;
    cursor: pointer;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}
.error-dismiss:hover { background: #fee2e2; }

/* ── Error Boundary Container ── */
.error-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: var(--gray-50);
}

.error-content {
    background: var(--white);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    padding: 2.5rem;
    max-width: 28rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.error-content h2 {
    color: var(--danger);
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}
.error-content p {
    color: var(--gray-500);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.error-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.error-details {
    margin-top: 1.5rem;
    text-align: left;
}
.error-details summary {
    cursor: pointer;
    color: var(--gray-500);
    font-size: 0.8125rem;
}
.error-details pre {
    background: var(--gray-100);
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 0.5rem;
}

/* ── Icons ── */
.icon { width: 1.25rem; height: 1.25rem; }
.icon-sm { width: 1rem; height: 1rem; }
.icon-xs { width: 0.75rem; height: 0.75rem; }
.icon-large { width: 3rem; height: 3rem; color: var(--gray-300); }

/* ================================================================
   Example Queries Component
   ================================================================ */

.example-queries {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.example-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.example-header .icon { color: var(--gray-500); }
.example-header h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.01em;
}

.example-description {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin: 0;
    line-height: 1.5;
}

.category {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.category-title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--gray-400);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.category-questions {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.example-button {
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    background: var(--white);
    text-align: left;
    font-size: 0.8125rem;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    line-height: 1.4;
}
.example-button:hover {
    background: var(--primary-subtle);
    border-color: var(--primary);
    color: var(--primary-hover);
    transform: translateX(2px);
}

/* ================================================================
   Welcome / Empty State (Conversation Thread)
   ================================================================ */

.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    animation: fadeIn var(--transition-slow) ease-out;
}

.welcome-icon {
    width: 4rem;
    height: 4rem;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--primary-subtle) 0%, rgba(99, 102, 241, 0.08) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.welcome-icon svg {
    width: 2rem;
    height: 2rem;
    color: var(--primary);
}

.welcome-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0 0 0.5rem;
    background: linear-gradient(135deg, var(--gray-900) 0%, var(--gray-600) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-subtitle {
    font-size: 0.9375rem;
    color: var(--gray-500);
    margin: 0 0 2rem;
    max-width: 24rem;
    line-height: 1.5;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    max-width: 32rem;
    width: 100%;
}

.welcome-suggestion {
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    background: var(--white);
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}
.welcome-suggestion:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px var(--primary-glow);
    transform: translateY(-2px);
}

.welcome-suggestion-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.welcome-suggestion-text {
    font-size: 0.8125rem;
    color: var(--gray-600);
    line-height: 1.4;
}

@media (max-width: 640px) {
    .welcome-suggestions {
        grid-template-columns: 1fr;
    }
}

/* ================================================================
   Query Input
   ================================================================ */

.query-input-container {
    padding: 0.75rem 1.5rem 1.25rem;
    background: var(--gray-50);
}

.query-input-inner {
    max-width: var(--input-max-width);
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-2xl);
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.query-input-inner:focus-within {
    border-color: var(--primary);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--primary-glow);
}

.query-textarea {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--gray-800);
    background: transparent;
    resize: none;
    min-height: 1.5rem;
    max-height: 8rem;
    padding: 0.375rem 0;
    line-height: 1.5;
}
.query-textarea::placeholder {
    color: var(--gray-400);
}

.query-submit {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-xl);
    border: none;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition-fast);
    box-shadow: 0 1px 3px rgba(16, 185, 129, 0.3);
}
.query-submit:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #047857 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
    transform: scale(1.05);
}
.query-submit:active { transform: scale(0.98); }
.query-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.query-submit svg {
    width: 1.125rem;
    height: 1.125rem;
}

.query-loading-indicator {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.query-loading-dot {
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: var(--white);
    animation: dotBounce 1.4s ease-in-out infinite;
}
.query-loading-dot:nth-child(2) { animation-delay: 0.16s; }
.query-loading-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotBounce {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ================================================================
   Chat History Component
   ================================================================ */

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.header-title .icon { color: var(--gray-500); }
.header-title h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.01em;
}

.btn-new-chat {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
    font-size: 0.8125rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.2);
}
.btn-new-chat:hover {
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.35);
    transform: translateY(-1px);
}

.conversations-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toggle-conversations {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0;
    background: none;
    border: none;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    font-family: inherit;
    transition: color var(--transition-fast);
}
.toggle-conversations:hover { color: var(--gray-900); }

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--radius-md);
    background: var(--gray-50);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}
.conversation-item:hover {
    background: var(--gray-100);
}
.conversation-item.active {
    background: var(--primary-subtle);
    border-color: var(--primary);
    border-left: 3px solid var(--primary);
}
.conversation-item.active .conv-title {
    color: var(--primary-hover);
    font-weight: 600;
}

.conversation-button {
    flex: 1;
    min-width: 0;
    padding: 0;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.conv-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.active-indicator {
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
    box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
}

.conv-meta {
    display: block;
    font-size: 0.6875rem;
    color: var(--gray-500);
}

.conversation-actions {
    display: flex;
    gap: 0.125rem;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.conversation-item:hover .conversation-actions { opacity: 1; }

.btn-icon {
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.btn-icon:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}
.btn-icon.success:hover {
    background: var(--primary-light);
    color: var(--primary-hover);
}
.btn-icon.danger:hover {
    background: #fee2e2;
    color: var(--danger);
}

.edit-form {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.375rem;
}

.edit-input {
    flex: 1;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: inherit;
    background: var(--white);
}
.edit-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.divider {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 0.5rem 0;
}

.current-chat {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.current-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.current-header h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-600);
    margin: 0;
}

.export-buttons {
    display: flex;
    gap: 0.25rem;
}

.message-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    max-height: 24rem;
    overflow-y: auto;
}

.message-preview {
    display: flex;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    background: var(--white);
    transition: all var(--transition-fast);
}
.message-preview:hover {
    border-color: var(--primary);
    box-shadow: 0 1px 4px var(--primary-glow);
}

.message-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--primary-subtle);
    flex-shrink: 0;
}
.message-icon .icon-sm { color: var(--primary); }

.message-content {
    flex: 1;
    min-width: 0;
}

.message-query {
    font-size: 0.8125rem;
    color: var(--gray-800);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.message-meta {
    font-size: 0.6875rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.export-actions {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.5rem;
}

.btn-export {
    flex: 1;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
    background: var(--white);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}
.btn-export:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.empty-state {
    padding: 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    background: var(--white);
    text-align: center;
}
.empty-state h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-800);
    margin: 0.75rem 0 0.375rem;
}
.empty-state p {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin: 0;
}

/* ================================================================
   About Page
   ================================================================ */

.about-page {
    min-height: calc(100vh - var(--header-height));
    background: var(--gray-50);
    padding: 2rem;
}

.about-content {
    max-width: 42rem;
    margin: 0 auto;
    background: var(--white);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    padding: 2.5rem;
    box-shadow: var(--shadow-sm);
}

.about-content h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
    letter-spacing: -0.03em;
}

.about-content .subtitle {
    font-size: 1rem;
    color: var(--gray-500);
    margin: 0.5rem 0 2rem;
}

.about-section {
    margin-bottom: 2rem;
}
.about-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 0.75rem;
    letter-spacing: -0.01em;
}
.about-section p {
    color: var(--gray-600);
    line-height: 1.7;
    margin: 0;
}

.program-list, .agent-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.program-list li, .agent-list li {
    padding: 0.75rem;
    border-radius: var(--radius-md);
    background: var(--gray-50);
    margin-bottom: 0.375rem;
    border: 1px solid var(--gray-100);
    transition: border-color var(--transition-fast);
}
.program-list li:hover, .agent-list li:hover {
    border-color: var(--gray-200);
}
.program-list li strong, .agent-list li strong {
    display: block;
    color: var(--gray-800);
    font-size: 0.875rem;
}
.program-list li span {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.about-section.disclaimer {
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}
.about-section.disclaimer h2 { color: #92400e; }
.about-section.disclaimer p {
    color: #78350f;
    font-size: 0.8125rem;
}

.back-link {
    margin-top: 2rem;
    text-align: center;
}
.back-link a {
    color: var(--primary);
    font-weight: 500;
    text-decoration: none;
    font-size: 0.875rem;
}
.back-link a:hover { text-decoration: underline; }

/* ================================================================
   Citation Styles
   ================================================================ */

.citation-item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem;
    padding: 0.25rem 0;
}

.citation-number {
    font-weight: 600;
    color: var(--gray-500);
    flex-shrink: 0;
    font-size: 0.75rem;
}

.citation-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8125rem;
    transition: color var(--transition-fast);
}
.citation-link:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.citation-title {
    color: var(--gray-700);
    font-weight: 500;
    font-size: 0.8125rem;
}

.citation-type {
    color: var(--gray-400);
    font-size: 0.6875rem;
}

/* ================================================================
   Prose (Markdown Content)
   ================================================================ */

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--gray-900);
    letter-spacing: -0.01em;
}
.prose h1 { font-size: 1.375rem; }
.prose h2 { font-size: 1.125rem; }
.prose h3 { font-size: 1rem; }

.prose p { margin-bottom: 0.75rem; }

.prose ul, .prose ol {
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}
.prose ul { list-style-type: disc; }
.prose ol { list-style-type: decimal; }
.prose li { margin-bottom: 0.25rem; }

.prose pre {
    background: var(--gray-900);
    color: var(--gray-100);
    padding: 1rem;
    border-radius: var(--radius-lg);
    overflow-x: auto;
    margin-bottom: 0.75rem;
    font-size: 0.8125rem;
}

.prose code {
    background: var(--gray-100);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    color: var(--gray-700);
}

.prose pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.prose blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 1rem;
    margin-left: 0;
    margin-bottom: 0.75rem;
    color: var(--gray-600);
    font-style: italic;
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}
.prose th, .prose td {
    border: 1px solid var(--gray-200);
    padding: 0.5rem 0.75rem;
    text-align: left;
}
.prose th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
}

.prose a {
    color: var(--primary);
    text-decoration: none;
}
.prose a:hover { text-decoration: underline; }

/* ================================================================
   Streaming
   ================================================================ */

.streaming-text {
    font-family: inherit;
    font-size: inherit;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: inherit;
}

.streaming-cursor {
    animation: blink 1s step-end infinite;
    font-weight: bold;
    color: var(--primary);
}

@keyframes blink { 50% { opacity: 0; } }

/* ================================================================
   Authentication Pages
   ================================================================ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.auth-message {
    text-align: center;
    max-width: 400px;
    padding: 2rem;
}
.auth-message h2 {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
    color: var(--gray-800);
    letter-spacing: -0.02em;
}
.auth-message p {
    color: var(--gray-500);
    margin: 0 0 1.5rem;
    font-size: 0.9rem;
}
.auth-message .btn-primary {
    display: inline-block;
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
}
.auth-message .btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #047857 100%);
}

.auth-error h2 { color: var(--danger); }

.auth-loading {
    text-align: center;
    padding: 2rem;
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* ================================================================
   Agent Selector
   ================================================================ */

.agent-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--gray-700);
    background: var(--white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 0.625rem center;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 10rem;
}
.agent-select:hover {
    border-color: var(--gray-300);
}
.agent-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Admin Dashboard ── */

.admin-layout {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.admin-nav {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: 0.5rem;
}

.admin-nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    color: var(--gray-600);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.admin-nav-link:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.admin-nav-link.active {
    background: var(--primary);
    color: white;
}

.admin-content {
    min-height: 400px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin: 0;
}

.admin-filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.admin-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: white;
    color: var(--gray-700);
    cursor: pointer;
}

.admin-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.admin-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    min-width: 250px;
}

.admin-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.admin-checkbox {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.875rem;
    color: var(--gray-600);
    cursor: pointer;
}

.admin-loading {
    text-align: center;
    padding: 3rem;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.admin-error {
    text-align: center;
    padding: 2rem;
    color: var(--danger, #ef4444);
    background: #fef2f2;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
}

.admin-empty {
    text-align: center;
    padding: 3rem;
    color: var(--gray-400);
}

.admin-result-count {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-bottom: 0.75rem;
}

.admin-section {
    margin-top: 2rem;
}

.admin-section h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--gray-800);
    margin: 0 0 1rem;
}

/* Metric Cards */

.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-cards-secondary {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.metric-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.metric-card-sm {
    padding: 1rem;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.metric-card-sm .metric-value {
    font-size: 1.5rem;
}

.metric-label {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
    font-weight: 500;
}

.metric-sub {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}

.metric-success {
    color: var(--primary);
}

.metric-danger {
    color: var(--danger, #ef4444);
}

/* Admin Table */

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.admin-table th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.admin-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}

.admin-table tbody tr {
    cursor: pointer;
    transition: background var(--transition-fast);
}

.admin-table tbody tr:hover {
    background: var(--gray-50);
}

.admin-table .row-error {
    background: #fef2f2;
}

.admin-table .row-error:hover {
    background: #fee2e2;
}

.admin-table .row-expanded {
    background: var(--gray-50);
}

.admin-table .row-detail {
    cursor: default;
}

.admin-table .row-detail td {
    padding: 1rem;
    background: var(--gray-50);
}

.query-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.monospace {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 0.8125rem;
}

/* Status Badges */

.admin-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-700);
}

.status-success {
    color: var(--primary);
    font-weight: 600;
}

.status-error {
    color: var(--danger, #ef4444);
    font-weight: 600;
}

.text-muted {
    color: var(--gray-400);
}

/* Detail View */

.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.detail-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--gray-500);
    margin: 0 0 0.375rem;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.detail-text {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.8125rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    font-family: inherit;
}

.error-text {
    color: var(--danger, #ef4444);
    border-color: #fecaca;
}

.detail-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.agents-used-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.agent-used-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: var(--gray-800);
    border-radius: 0.375rem;
    font-size: 0.8rem;
}

.agent-role {
    color: var(--gray-400);
}

.aip-label {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.agent-time {
    color: var(--gray-500);
    font-size: 0.75rem;
}

/* Pagination */

.admin-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 1rem;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.btn-page {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    background: white;
    color: var(--gray-700);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-page:hover:not(:disabled) {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.btn-page:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Chart */

.admin-chart {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 200px;
    padding: 1rem 0;
    border-bottom: 1px solid var(--gray-200);
}

.chart-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    cursor: pointer;
}

.chart-bar {
    width: 100%;
    max-width: 40px;
    background: var(--primary);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    position: relative;
    min-height: 2px;
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

.chart-bar-wrapper:hover .chart-bar {
    opacity: 1;
}

.chart-bar-error {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--danger, #ef4444);
    border-radius: 0;
}

.chart-label {
    font-size: 0.625rem;
    color: var(--gray-400);
    margin-top: 0.375rem;
    white-space: nowrap;
}

/* Agent Cards */

.agent-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.agent-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.agent-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.agent-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.agent-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.agent-stat {
    display: flex;
    flex-direction: column;
}

.agent-stat-value {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--gray-800);
}

.agent-stat-label {
    font-size: 0.6875rem;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Feedback Cards */

.feedback-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.feedback-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.feedback-card:hover {
    box-shadow: var(--shadow-sm);
}

.feedback-positive {
    border-left: 3px solid var(--primary);
}

.feedback-negative {
    border-left: 3px solid var(--danger, #ef4444);
}

.feedback-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.feedback-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.feedback-positive .feedback-icon {
    background: #d1fae5;
    color: var(--primary);
}

.feedback-negative .feedback-icon {
    background: #fee2e2;
    color: var(--danger, #ef4444);
}

.feedback-agent {
    font-weight: 600;
    color: var(--gray-700);
}

.feedback-category {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    background: var(--gray-100);
    border-radius: 9999px;
    color: var(--gray-500);
}

.feedback-time {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--gray-400);
}

.feedback-comment {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--gray-600);
    line-height: 1.5;
}

.feedback-detail {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-100);
}

/* Responsive */

@media (max-width: 768px) {
    .admin-layout {
        padding: 1rem;
    }

    .admin-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .admin-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .metric-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .agent-cards {
        grid-template-columns: 1fr;
    }

    .admin-table {
        display: block;
        overflow-x: auto;
    }
}

/* ================================================================
   Dark Mode
   Triggered by .dark class on <html> element
   ================================================================ */
html.dark {
    --primary: #34d399;
    --primary-hover: #6ee7b7;
    --primary-light: #064e3b;
    --primary-subtle: #022c22;
    --primary-glow: rgba(52, 211, 153, 0.15);

    --secondary: #818cf8;
    --accent: #fbbf24;

    --gray-50: #0f172a;
    --gray-100: #1e293b;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-400: #94a3b8;
    --gray-500: #cbd5e1;
    --gray-600: #e2e8f0;
    --gray-700: #f1f5f9;
    --gray-800: #f8fafc;
    --gray-900: #ffffff;
    --gray-950: #ffffff;

    --white: #0f172a;
    --danger: #f87171;
    --danger-light: #450a0a;
    --warning-bg: #422006;
    --warning-border: #a16207;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

    color-scheme: dark;
}

html.dark body {
    background: #020617;
    color: #e2e8f0;
}

html.dark .app-header {
    background: #0f172a;
    border-bottom-color: #1e293b;
}

html.dark .message-assistant {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .message-user {
    background: linear-gradient(135deg, #065f46, #064e3b);
    color: #d1fae5;
}

html.dark .prose {
    color: #e2e8f0;
}

html.dark .prose code {
    background: #334155;
    color: #e2e8f0;
}

html.dark .prose pre {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .content-header {
    background: #0f172a;
    border-bottom-color: #1e293b;
}

html.dark .sidebar {
    background: #0f172a;
    border-color: #1e293b;
}

html.dark .conversation-area {
    background: #020617;
}

html.dark .welcome-suggestion {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .welcome-suggestion:hover {
    border-color: #34d399;
    background: #0f172a;
}

html.dark .query-input-container {
    background: #0f172a;
    border-top-color: #1e293b;
}

html.dark .query-textarea {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .query-textarea:focus {
    border-color: #34d399;
}

html.dark .agent-select {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .action-btn:hover {
    color: #e2e8f0;
    border-color: #475569;
    background: #334155;
}

html.dark .feedback-comment-box {
    background: #1e293b;
    border-color: #334155;
}

html.dark .feedback-textarea {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .error-container {
    background: #0f172a;
}

/* Dark mode admin pages */
html.dark .admin-layout {
    background: #020617;
}

html.dark .admin-nav {
    background: #0f172a;
    border-color: #1e293b;
}

html.dark .admin-nav-link {
    color: #94a3b8;
}

html.dark .admin-nav-link:hover,
html.dark .admin-nav-link.active {
    color: #34d399;
    background: #1e293b;
}

html.dark .metric-card {
    background: #1e293b;
    border-color: #334155;
}

html.dark .admin-table th {
    background: #1e293b;
    color: #94a3b8;
}

html.dark .admin-table td {
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .admin-table tr:hover td {
    background: #1e293b;
}

html.dark .admin-select,
html.dark .admin-input {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .agent-card {
    background: #1e293b;
    border-color: #334155;
}

html.dark .feedback-card {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .feedback-positive .feedback-icon {
    background: #064e3b;
}

html.dark .feedback-negative .feedback-icon {
    background: #450a0a;
}

html.dark .feedback-detail {
    border-top-color: #334155;
}

html.dark .detail-text {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .btn-page {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .btn-page:hover:not(:disabled) {
    background: #334155;
    border-color: #475569;
}

html.dark .admin-section h2 {
    color: #e2e8f0;
}
