:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --success-dark: #059669;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s ease;
}

/* Dark mode (default) */
[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #94a3b8;
    --success: #10b981;
    --success-dark: #059669;
    --background: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* Light mode */
[data-theme="light"] {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --success-dark: #059669;
    --background: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
}

.card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

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

.project-card {
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.project-card .card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
}

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

.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 0.5rem 1rem;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline-primary {
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn-outline-primary:hover {
    background-color: var(--primary);
    color: white;
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: var(--success-dark);
}

.navbar {
    box-shadow: var(--shadow);
}

.navbar-brand {
    color: var(--text) !important;
    font-size: 1.25rem;
}

.progress-tracker {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.progress-step::after {
    content: '';
    position: absolute;
    left: 1.25rem;
    top: 2.5rem;
    width: 2px;
    height: calc(100% + 0.5rem);
    background: var(--border);
    z-index: 0;
}

.progress-step:last-child::after {
    display: none;
}

.step-circle {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    position: relative;
    z-index: 1;
    transition: var(--transition);
}

.step-circle.completed {
    background-color: var(--success);
    color: white;
}

.step-circle.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.2);
    }
}

.step-circle.pending {
    background-color: var(--background);
    color: var(--text-muted);
    border: 2px solid var(--border);
}

.step-content {
    flex: 1;
}

.step-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.step-description {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
    min-height: 600px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Ensure container uses full height - ONLY for chat interface */
body:has(.chat-container) .container-fluid {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

body:has(.chat-container) .container-fluid > .row {
    flex: 1;
    min-height: 0;
    display: flex;
}

body:has(.chat-container) .container-fluid > .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Fallback for browsers that don't support :has() */
.chat-page .container-fluid {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-page .container-fluid > .row {
    flex: 1;
    min-height: 0;
    display: flex;
}

.chat-page .container-fluid > .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--background);
}

.chat-message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-bubble {
    max-width: 80%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    word-wrap: break-word;
}

.message-bubble.user {
    background-color: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message-bubble.assistant {
    background-color: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

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

.message-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.chat-input-container {
    padding: 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.chat-input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    resize: none;
    transition: var(--transition);
    font-family: inherit;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-send-btn {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
}

.loading {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.library-card {
    transition: var(--transition);
    height: 100%;
}

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

.library-card .card-body {
    display: flex;
    flex-direction: column;
}

.library-card .badge {
    margin-top: auto;
    align-self: flex-start;
}

.badge {
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.75rem;
}

.text-muted {
    color: var(--text-muted) !important;
}

.bg-light {
    background-color: var(--background) !important;
}

.border {
    border-color: var(--border) !important;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

@media (max-width: 768px) {
    .message-bubble {
        max-width: 90%;
    }
    
    .progress-tracker {
        padding: 1rem;
    }
    
    .chat-container {
        height: calc(100vh - 100px);
        min-height: 500px;
    }
}

.auto-save-indicator {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
    box-shadow: var(--shadow);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.auto-save-indicator.show {
    opacity: 1;
}

.auto-save-indicator.saving {
    color: var(--primary);
}

.auto-save-indicator.saved {
    color: var(--success);
}

.auto-save-indicator.error {
    color: #ef4444;
}

/* Quick Reply Buttons */
.quick-reply-container {
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: none;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.quick-reply-container.show {
    display: flex;
}

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

.quick-reply-btn {
    padding: 0.625rem 1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    flex: 0 0 auto;
    min-width: fit-content;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.quick-reply-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.quick-reply-btn:active {
    transform: translateY(0);
}

.quick-reply-btn .btn-icon {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Mobile responsive quick reply buttons */
@media (max-width: 768px) {
    .quick-reply-container {
        padding: 0.5rem;
        gap: 0.375rem;
        max-height: 150px;
    }
    
    .quick-reply-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
        flex: 1 1 auto;
        min-width: calc(50% - 0.25rem);
        max-width: 100%;
        white-space: normal;
        word-wrap: break-word;
        text-align: center;
        justify-content: center;
    }
    
    .quick-reply-btn .btn-icon {
        display: none;
    }
}

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
}

.theme-toggle:hover {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}

.theme-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Navbar dark mode adjustments */
[data-theme="dark"] .navbar {
    background-color: var(--surface) !important;
    border-bottom-color: var(--border) !important;
}

[data-theme="dark"] .navbar-light {
    background-color: var(--surface) !important;
}

[data-theme="dark"] .navbar-brand {
    color: var(--text) !important;
}

[data-theme="dark"] .nav-link {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .nav-link:hover {
    color: var(--text) !important;
}

/* Bootstrap overrides for dark mode */
[data-theme="dark"] .bg-white {
    background-color: var(--surface) !important;
}

[data-theme="dark"] .text-muted {
    color: var(--text-muted) !important;
}

[data-theme="dark"] .border-bottom {
    border-bottom-color: var(--border) !important;
}

[data-theme="dark"] .modal-content {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

[data-theme="dark"] .modal-header {
    border-bottom-color: var(--border);
}

[data-theme="dark"] .modal-footer {
    border-top-color: var(--border);
}

[data-theme="dark"] .btn-close {
    filter: invert(1);
}

/* Progress Bar Styling for VSL List */
.project-card .progress {
    background-color: var(--border);
    overflow: hidden;
}

.project-card .progress-bar {
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    transition: width 0.3s ease;
}

[data-theme="dark"] .project-card .progress {
    background-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .project-card .progress-bar {
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
}

/* Rate Limit Error UI */
.rate-limit-error {
    margin: 1rem 0;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.rate-limit-message {
    display: flex;
    align-items: center;
    color: #ef4444;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.rate-limit-info {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.rate-limit-actions {
    display: flex;
    justify-content: flex-end;
}

.rate-limit-resend {
    min-width: 100px;
}

.rate-limit-resend:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

[data-theme="dark"] .rate-limit-error {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
}

[data-theme="dark"] .rate-limit-message {
    color: #f87171;
}
