/* Modern LLM-style chatbot UI — colorful and polished */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #06b6d4;
    --accent-soft: rgba(6, 182, 212, 0.15);
    --sidebar-bg: linear-gradient(180deg, #1e1b4b 0%, #312e81 50%, #3730a3 100%);
    --sidebar-surface: rgba(255, 255, 255, 0.06);
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-text: #e0e7ff;
    --sidebar-text-dim: #a5b4fc;
    --chat-bg: #f8fafc;
    --chat-bg-pattern: radial-gradient(ellipse at top left, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
                      radial-gradient(ellipse at bottom right, rgba(6, 182, 212, 0.05) 0%, transparent 50%);
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --success: #10b981;
    --success-soft: rgba(16, 185, 129, 0.12);
    --error: #ef4444;
    --error-soft: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --user-bubble: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --user-bubble-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    --bot-bubble-bg: #ffffff;
    --bot-bubble-border: rgba(99, 102, 241, 0.12);
    --bot-bubble-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --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.05);
    --transition: 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--chat-bg);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ——— Login screen ——— */
.login-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #3730a3 100%);
    z-index: 2000;
}
.login-container[hidden],
body.auth-disabled .login-container {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 2.5rem;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    text-align: center;
}

.login-subtitle {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: center;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.login-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 1rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.login-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.login-error {
    font-size: 0.875rem;
    color: var(--error);
    margin: 0;
}

.login-submit {
    margin-top: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--user-bubble);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: transform var(--transition), box-shadow var(--transition);
}

.login-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.login-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ——— Sidebar ——— */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-database {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-database label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sidebar-text-dim);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sidebar-section {
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
}

.sidebar-section-history {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-section-settings {
    flex-shrink: 0;
}

.sidebar-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--sidebar-text);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background var(--transition);
}

.sidebar-section-toggle:hover {
    background: var(--sidebar-surface);
}

.sidebar-section-toggle .sidebar-section-chevron {
    font-size: 0.7rem;
    color: var(--sidebar-text-dim);
    transition: transform 0.2s ease;
}

.sidebar-section-toggle.collapsed .sidebar-section-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-content.collapsed,
.sidebar-section-content[hidden] {
    display: none !important;
}

.sidebar-section-history .sidebar-section-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-section-settings .sidebar-section-content {
    max-height: 300px;
    overflow-y: auto;
}

.sidebar-section-settings .sidebar-section-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-section-settings .sidebar-section-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
}

.btn-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: calc(100% - 2rem);
    margin: 0.75rem 1rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--sidebar-text);
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-new-chat:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 0.75rem 1rem;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-full);
}

.chat-list-item {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0.25rem;
    font-size: 0.8125rem;
    text-align: left;
    color: var(--sidebar-text-dim);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all var(--transition);
}

.chat-list-item:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-surface);
}

.chat-list-item.active {
    background: rgba(99, 102, 241, 0.25);
    color: #fff;
    font-weight: 500;
}

.chat-list-empty {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: var(--sidebar-text-dim);
}

.settings-section {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--sidebar-border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--sidebar-text-dim);
    margin-bottom: 0.5rem;
}

.sidebar .setting-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--sidebar-surface);
    color: var(--sidebar-text);
    transition: border-color var(--transition);
}

.sidebar .setting-input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 2px rgba(129, 140, 248, 0.2);
}

.sidebar .btn-secondary {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sidebar-text);
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.sidebar .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
    font-size: 0.8125rem;
    color: var(--sidebar-text-dim);
    margin-bottom: 0.5rem;
}

.btn-logout {
    width: 100%;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--sidebar-text);
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.1);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    color: var(--sidebar-text-dim);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sidebar-text-dim);
    animation: pulse 2s infinite;
}

.status-dot.connecting {
    background: var(--warning);
}

.status-dot.connected {
    background: var(--success);
    animation: none;
    box-shadow: 0 0 0 2px var(--success-soft);
}

.status-dot.error {
    background: var(--error);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ——— Chat area ——— */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--chat-bg);
    background-image: var(--chat-bg-pattern);
}

.chat-header {
    padding: 1.25rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.chat-header h1 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    letter-spacing: -0.02em;
}

.chat-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ——— Messages ——— */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageIn 0.35s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.bot-message {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    line-height: 1.55;
}

.user-message .message-content {
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: var(--user-bubble-shadow);
}

.bot-message .message-content {
    background: var(--bot-bubble-bg);
    color: var(--text-primary);
    border: 1px solid var(--bot-bubble-border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--bot-bubble-shadow);
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 0.8125rem;
    margin: 0.75rem 0;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.message-content code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}

/* Response blocks */
.response-explanation {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-weight: 500;
}

.response-summary {
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.04) 0%, rgba(6, 182, 212, 0.03) 100%);
}

.response-summary-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: background var(--transition);
}

.response-summary-toggle:hover {
    background: rgba(99, 102, 241, 0.06);
}

.response-summary-label {
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
}

.response-summary-preview {
    flex: 1;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.response-summary-chevron {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
}

.response-summary-toggle.response-summary-expanded .response-summary-chevron {
    transform: rotate(180deg);
}

.response-summary-content {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.6);
}

.response-bottom {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.response-sql-section {
    margin-bottom: 1rem;
}

.response-sql-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.response-sql-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-copy-sql {
    flex-shrink: 0;
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-copy-sql:hover {
    background: rgba(99, 102, 241, 0.18);
    border-color: var(--primary);
}

.sql-rejected-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--error);
    margin-left: 0.5rem;
    padding: 0.2rem 0.5rem;
    background: var(--error-soft);
    border-radius: 4px;
}

.sql-rejected {
    color: var(--error);
    font-weight: 600;
    background: var(--error-soft);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

.response-validation-error {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--error);
    font-weight: 500;
}

.response-blocked-details {
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.response-blocked-details summary {
    cursor: pointer;
    font-weight: 500;
}

.response-tables-section {
    margin-top: 0.75rem;
}

.response-tables-title {
    margin-bottom: 0.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.response-tables-hint {
    font-weight: normal;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tables-list-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.table-detail-link {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--transition);
}

.table-detail-link.table-in-query {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.table-detail-link.table-in-query:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    color: #fff;
}

.table-detail-link.table-checked-only {
    background: var(--border);
    color: var(--text-secondary);
}

.table-detail-link.table-checked-only:hover {
    background: var(--text-secondary);
    color: var(--surface);
}

/* ——— Chat input ——— */
.chat-input-container {
    padding: 1.25rem 2rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    max-width: 900px;
    margin: 0 auto;
}

.chat-input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-xl);
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input::placeholder {
    color: var(--text-secondary);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
}

.send-button {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--user-bubble);
    color: #fff;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: transform var(--transition), box-shadow var(--transition);
}

.send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ——— Progress (streaming) ——— */
.progress-container {
    padding: 1rem 1.25rem;
    background: var(--bot-bubble-bg);
    border: 1px solid var(--bot-bubble-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--bot-bubble-shadow);
}

.progress-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 0.9375rem;
}

.progress-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-step {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: 0.5rem 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--border);
    background: rgba(99, 102, 241, 0.04);
    font-size: 0.875rem;
}

.progress-step-running {
    border-left-color: var(--primary);
    animation: pulse-border 1.2s ease-in-out infinite;
}

.progress-step-done {
    border-left-color: var(--success);
}

.progress-step-icon {
    font-weight: bold;
    color: var(--text-secondary);
    line-height: 1.4;
}

.progress-step-running .progress-step-icon {
    color: var(--primary);
}

.progress-step-done .progress-step-icon {
    color: var(--success);
}

.progress-step-name {
    font-weight: 600;
    color: var(--text-primary);
}

.progress-step-duration {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.progress-step-message {
    grid-column: 2 / -1;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.4;
}

@keyframes pulse-border {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.loading-indicator {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ——— Details (expandable summary) ——— */
.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.detail-item {
    background: rgba(255, 255, 255, 0.7);
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    border: 1px solid var(--border);
}

.detail-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.detail-value {
    color: var(--text-primary);
}

.agent-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.step-item {
    background: rgba(255, 255, 255, 0.7);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
}

.step-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.step-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.step-duration {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.step-details {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.performance-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.metric-item {
    background: rgba(255, 255, 255, 0.7);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    text-align: center;
    border: 1px solid var(--border);
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.metric-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* ——— Table detail modal ——— */
.table-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.table-detail-overlay.table-detail-modal-visible {
    opacity: 1;
    visibility: visible;
}

.table-detail-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    background: var(--surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.table-detail-modal.table-detail-modal-visible {
    opacity: 1;
    visibility: visible;
}

.table-detail-modal-inner {
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.table-detail-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, transparent 100%);
}

.table-detail-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.table-detail-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.table-detail-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

.table-detail-content {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    font-size: 0.875rem;
}

.table-detail-content p {
    margin-bottom: 0.5rem;
}

.table-detail-content ul {
    margin-left: 1.25rem;
    margin-bottom: 0.75rem;
}

.table-detail-columns {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    margin-top: 0.5rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.table-detail-columns th,
.table-detail-columns td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table-detail-columns th {
    font-weight: 600;
    background: rgba(99, 102, 241, 0.06);
    color: var(--text-secondary);
}

.table-detail-loading,
.table-detail-error {
    color: var(--text-secondary);
}

.table-detail-error {
    color: var(--error);
    font-weight: 500;
}

/* ——— Feedback and Actions ——— */
.response-actions {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.response-feedback {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.feedback-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.btn-feedback {
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-feedback:hover {
    background: var(--border);
    transform: scale(1.1);
}

.btn-feedback.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.btn-add-golden {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-add-golden:hover {
    background: rgba(99, 102, 241, 0.18);
    border-color: var(--primary);
}

.btn-add-golden:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ——— Golden Queries Sidebar (latest 5) ——— */
.golden-queries-sidebar-list,
.golden-queries-list {
    max-height: 280px;
    overflow-y: auto;
}

.golden-queries-empty,
.golden-queries-error {
    padding: 0.75rem;
    text-align: center;
    color: var(--sidebar-text-dim);
    font-size: 0.8125rem;
}

.btn-view-all-golden {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-light);
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(129, 140, 248, 0.3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-view-all-golden:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: var(--primary-light);
    color: var(--sidebar-text);
}

.golden-query-sidebar-item {
    padding: 0.6rem 0.75rem;
    margin-bottom: 0.4rem;
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.golden-query-sidebar-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-light);
}

.golden-query-sidebar-title {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--sidebar-text);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.golden-query-sidebar-preview {
    font-size: 0.75rem;
    color: var(--sidebar-text-dim);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.golden-query-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--sidebar-surface);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.golden-query-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-light);
}

.golden-query-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.golden-query-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--sidebar-text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.golden-query-actions {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
}

.btn-golden-view,
.btn-golden-edit,
.btn-golden-delete {
    padding: 0.25rem 0.4rem;
    font-size: 0.75rem;
    background: transparent;
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--sidebar-text-dim);
}

.btn-golden-view:hover,
.btn-golden-edit:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary-light);
    color: var(--sidebar-text);
}

.btn-golden-delete:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--error);
    color: var(--error);
}

.golden-query-preview {
    font-size: 0.75rem;
    color: var(--sidebar-text-dim);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ——— Golden Query Modal ——— */
.golden-query-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    padding: 1rem;
}

.golden-query-modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.golden-query-modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.06) 0%, transparent 100%);
}

.golden-query-modal-header h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.golden-query-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.golden-query-modal-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

.golden-query-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.golden-query-field {
    margin-bottom: 1.25rem;
}

.golden-query-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.golden-query-value {
    padding: 0.75rem;
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.golden-query-input,
.golden-query-textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.875rem;
    font-family: 'Courier New', monospace;
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: all var(--transition);
}

.golden-query-input:focus,
.golden-query-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.golden-query-textarea {
    resize: vertical;
    min-height: 100px;
}

.golden-query-field pre {
    margin: 0;
    padding: 0.75rem;
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.6;
}

.golden-query-field code {
    font-family: 'Courier New', monospace;
    color: var(--text-primary);
}

.golden-query-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.golden-query-modal-actions .btn-primary,
.golden-query-modal-actions .btn-secondary {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    border: none;
}

.golden-query-modal-actions .btn-primary {
    background: var(--primary);
    color: white;
}

.golden-query-modal-actions .btn-primary:hover {
    background: var(--primary-dark);
}

.golden-query-modal-actions .btn-secondary {
    background: var(--border);
    color: var(--text-primary);
}

.golden-query-modal-actions .btn-secondary:hover {
    background: #d1d5db;
}

/* ——— Dedicated Golden Queries Page ——— */
.golden-queries-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    background: var(--chat-bg);
    background-image: var(--chat-bg-pattern);
}

.golden-queries-page-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.golden-queries-page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem 0;
}

.golden-queries-page-header p {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin: 0;
}

.btn-back-to-chat {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-back-to-chat:hover {
    background: rgba(99, 102, 241, 0.18);
    border-color: var(--primary);
}

.golden-queries-page-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.golden-queries-page-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 900px;
    margin: 0 auto;
}

.golden-queries-page-empty,
.golden-queries-page-error {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
    font-size: 1rem;
}

.golden-query-page-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all var(--transition);
}

.golden-query-page-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(99, 102, 241, 0.2);
}

.golden-query-page-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.04) 0%, transparent 100%);
}

.golden-query-page-card-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.golden-query-page-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.golden-query-page-card-actions .btn-golden-view,
.golden-query-page-card-actions .btn-golden-edit,
.golden-query-page-card-actions .btn-golden-delete {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 600;
    background: var(--chat-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-primary);
}

.golden-query-page-card-actions .btn-golden-view:hover,
.golden-query-page-card-actions .btn-golden-edit:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.golden-query-page-card-actions .btn-golden-delete:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
    color: var(--error);
}

.golden-query-page-card-question {
    padding: 1rem 1.5rem;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.golden-query-page-card-sql {
    margin: 0;
    padding: 1rem 1.5rem;
    font-size: 0.8125rem;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--chat-bg);
    overflow-x: auto;
    white-space: pre;
}

.golden-query-page-card-sql code {
    font-family: inherit;
}
