:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --bg-dark: #1e293b;
    --text-color: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --error-color: #dc2626;
    --success-color: #16a34a;
    --user-msg-bg: #dbeafe;
    --assistant-msg-bg: #f1f5f9;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* Auth Pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-container {
    background: white;
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    width: 100%;
    max-width: 400px;
}

.auth-title {
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-light);
    font-weight: normal;
    margin-bottom: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.auth-button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.auth-button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.auth-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-error {
    background: #fef2f2;
    color: var(--error-color);
    padding: 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-light);
}

.auth-link a {
    color: var(--primary-color);
    text-decoration: none;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* Chat Page */
.chat-page {
    display: flex;
    height: 100vh;
}

.chat-sidebar {
    width: 280px;
    background: var(--bg-dark);
    color: white;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h2 {
    font-size: 1rem;
    font-weight: 500;
}

.new-session-btn {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.new-session-btn:hover {
    background: var(--primary-hover);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.session-item {
    padding: 0.75rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    margin-bottom: 0.25rem;
    transition: background 0.2s;
}

.session-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.session-item.active {
    background: var(--primary-color);
}

.session-title {
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.375rem;
    cursor: pointer;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

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

.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-light);
}

.chat-welcome h1 {
    color: var(--text-color);
}

.start-btn {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 1rem;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Chat Messages */
.chat-message {
    max-width: 80%;
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 0.5rem;
}

.message-user {
    background: var(--user-msg-bg);
    margin-left: auto;
}

.message-assistant {
    background: var(--assistant-msg-bg);
}

.message-header {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.message-content {
    white-space: pre-wrap;
}

.message-sql {
    margin-top: 0.75rem;
}

.message-sql summary {
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--primary-color);
}

.message-sql pre {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: #1e293b;
    color: #e2e8f0;
    border-radius: 0.375rem;
    overflow-x: auto;
    font-size: 0.875rem;
}

/* Thinking Indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--text-light);
    font-style: italic;
}

.thinking-dots {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* SQL Preview */
.sql-preview {
    margin: 1rem;
    background: #1e293b;
    border-radius: 0.5rem;
    overflow: hidden;
}

.sql-preview-header {
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    color: #94a3b8;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.sql-preview-code {
    padding: 1rem;
    color: #e2e8f0;
    margin: 0;
    overflow-x: auto;
    font-family: monospace;
}

/* Results Table */
.results-container {
    padding: 1rem;
    max-height: 40vh;
    overflow: auto;
    border-top: 1px solid var(--border-color);
}

.results-table-wrapper {
    overflow-x: auto;
}

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

.results-table th,
.results-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.results-table th {
    background: #f1f5f9;
    font-weight: 600;
    position: sticky;
    top: 0;
}

.results-table tr:hover {
    background: #f8fafc;
}

.results-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
}

/* Chat Input */
.chat-input-form {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: white;
}

.chat-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 1rem;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chat-submit-btn {
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    cursor: pointer;
}

.chat-submit-btn:hover:not(:disabled) {
    background: var(--primary-hover);
}

.chat-submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Error */
.chat-error {
    margin: 1rem;
    padding: 1rem;
    background: #fef2f2;
    color: var(--error-color);
    border-radius: 0.375rem;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-sidebar {
        width: 60px;
    }

    .sidebar-header h2,
    .session-title,
    .logout-btn span {
        display: none;
    }

    .new-session-btn {
        padding: 0.5rem;
    }

    .session-item {
        padding: 0.75rem;
        text-align: center;
    }

    .chat-message {
        max-width: 95%;
    }
}
