:root {
    --app-primary: #6366f1;
    --app-primary-dark: #4f46e5;
    --app-secondary: #374151;
    --app-accent: #c084fc;
    --app-surface: #1f2937;
    --app-background: #111827;
    --app-card: #1e293b;
    --app-text: #f3f4f6;
    --app-text-muted: #9ca3af;
    --app-border: rgba(255, 255, 255, 0.1);
    --app-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --app-transition: all 0.3s ease;
    --app-header-bg: #1a1f2c;
    --app-header-border: rgba(255, 255, 255, 0.05);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    background-color: var(--app-background);
    color: var(--app-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Prevent dark mode from forcing light iframe backgrounds (e.g., Razorpay Checkout) */
iframe[src*="razorpay"] {
    color-scheme: light;
}

/* ===== Typography ===== */
.app-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    background: linear-gradient(90deg, var(--app-primary) 0%, var(--app-accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ===== Header and Navigation ===== */
.main-header {
    background-color: var(--app-header-bg);
    border-bottom: 1px solid var(--app-header-border);
    padding: 0.75rem 0;
    margin-bottom: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.navbar-brand {
    display: flex;
    align-items: center;
}

.navbar-brand .brand-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.navbar-brand .app-title {
    font-size: 1.6rem;
    line-height: 1.1;
    margin-bottom: 0.2rem;
}

.navbar-brand .navbar-tagline {
    font-size: 0.75rem;
    color: var(--app-text-muted);
    letter-spacing: 0.03em;
    opacity: 0.8;
    font-weight: 300;
}

.navbar-logo {
    height: 60px; /* Increased by 50% from 40px to 60px */
    width: auto;
    display: block;
    transition: transform 0.3s ease;
    margin-right: 12px;
}

.navbar-nav .nav-link {
    color: var(--app-text-muted);
    transition: var(--app-transition);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    margin: 0 0.25rem;
}

.navbar-nav .nav-link:hover, 
.navbar-nav .nav-link:focus,
.navbar-nav .nav-link.active {
    color: var(--app-text);
    background-color: rgba(255, 255, 255, 0.05);
}

.navbar-nav .nav-link.active {
    position: relative;
}

.navbar-nav .nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1rem;
    right: 1rem;
    height: 2px;
    background: linear-gradient(90deg, var(--app-primary) 0%, var(--app-accent) 100%);
    border-radius: 1px;
}

.dropdown-menu .logout-item {
    border: 1px solid rgba(248, 113, 113, 0.22);
    border-radius: var(--radius-md);
    margin: 0.25rem 0.5rem 0.5rem;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
    transition: var(--app-transition);
    width: calc(100% - 1rem);
    box-sizing: border-box;
}

.dropdown-menu .logout-item:hover,
.dropdown-menu .logout-item:focus {
    border-color: rgba(248, 113, 113, 0.6);
    background-color: rgba(248, 113, 113, 0.08);
}

/* ===== Legal Footer ===== */
.legal-footer {
    margin-top: 2rem;
    padding: 0.85rem 1rem 1.05rem;
    border-top: 1px solid var(--app-header-border);
}

.legal-footer-inner {
    max-width: 1140px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    flex-wrap: nowrap;
    font-size: 0.84rem;
    line-height: 1.25;
    color: var(--app-text-muted);
}

.legal-footer-links {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}

.legal-footer-link,
.legal-footer-separator {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.legal-footer-link {
    color: var(--app-text-muted);
    text-decoration: none;
    transition: var(--app-transition);
}

.legal-footer-link:hover,
.legal-footer-link:focus {
    color: var(--app-text);
    text-decoration: underline;
}

.legal-footer-separator {
    font-size: 0.78rem;
    opacity: 0.6;
}

.legal-footer-copy {
    display: inline;
    font-size: inherit;
    white-space: nowrap;
    line-height: 1.25;
    opacity: 0.8;
    letter-spacing: 0.01em;
}

@media (max-width: 576px) {
    .legal-footer {
        margin-top: 1.5rem;
        padding: 0.7rem 0.75rem 0.95rem;
    }

    .legal-footer-inner {
        flex-wrap: wrap;
        gap: 0.35rem;
        font-size: 0.8rem;
    }

    .legal-footer-copy-divider {
        display: none;
    }
}

/* ===== Layout ===== */
.container {
    max-width: 1140px;
    width: 100%;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

/* ===== Cards and Containers ===== */
.setup-card {
    background-color: var(--app-card);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--app-shadow);
    overflow: hidden;
    transition: var(--app-transition);
}

.modal-blur {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background-color: rgba(30, 41, 59, 0.95);
    border: 1px solid var(--app-border);
}

/* ===== Setup Steps ===== */
.setup-step {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-md);
    position: relative;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    background-color: var(--app-primary);
    color: white;
    border-radius: 50%;
    font-weight: bold;
    flex-shrink: 0;
}

.step-content {
    flex-grow: 1;
}

/* ===== Setup Wizard V2 ===== */
.setup-wizard-v2 .setup-card {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.92) 0%, rgba(17, 24, 39, 0.96) 100%);
    border: 1px solid rgba(139, 127, 217, 0.22);
    border-radius: 1rem;
}

.setup-wizard-v2 .wizard-header .card-title {
    margin-bottom: 0.5rem;
}

.setup-wizard-v2 .wizard-step-indicator {
    position: relative;
}

.setup-wizard-v2 .wizard-step-progress {
    position: absolute;
    top: 1rem;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(255, 255, 255, 0.12);
    z-index: 1;
    display: none;
}

.setup-wizard-v2 .wizard-step-progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #8b7fd9 0%, #6366f1 100%);
    transition: width 0.35s ease;
}

.setup-wizard-v2 .wizard-step-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    z-index: 2;
}

.setup-wizard-v2 .wizard-step-item {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
}

.setup-wizard-v2 .wizard-step-circle {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(31, 41, 55, 0.9);
    color: #9ca3af;
    font-size: 0.9rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: all 0.25s ease;
}

.setup-wizard-v2 .wizard-step-label {
    color: #9ca3af;
    font-size: 0.85rem;
    font-weight: 500;
    transition: color 0.25s ease;
}

.setup-wizard-v2 .wizard-step-detail {
    color: #8b7fd9;
    font-size: 0.72rem;
    min-height: 1rem;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.setup-wizard-v2 .wizard-step-item.is-active .wizard-step-circle {
    border-color: #8b7fd9;
    color: #8b7fd9;
    box-shadow: 0 0 0 3px rgba(139, 127, 217, 0.2);
}

.setup-wizard-v2 .wizard-step-item.is-active .wizard-step-label {
    color: #e5e7eb;
}

.setup-wizard-v2 .wizard-step-item.is-complete .wizard-step-circle {
    border-color: transparent;
    color: #fff;
    background: linear-gradient(135deg, #8b7fd9 0%, #6366f1 100%);
}

.setup-wizard-v2 .wizard-step-item.is-complete .wizard-step-label {
    color: #e5e7eb;
}

.setup-wizard-v2 .wizard-panel {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.9rem;
    background: rgba(17, 24, 39, 0.5);
    padding: 1.25rem;
}

.setup-wizard-v2 .wizard-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.setup-wizard-v2 .wizard-panel-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.setup-wizard-v2 .wizard-back-btn {
    border-color: rgba(148, 163, 184, 0.35);
    color: #cbd5e1;
    background: rgba(30, 41, 59, 0.35);
    padding: 0.3rem 0.75rem;
}

.setup-wizard-v2 .wizard-back-btn:hover,
.setup-wizard-v2 .wizard-back-btn:focus {
    border-color: rgba(129, 140, 248, 0.55);
    color: #f8fafc;
    background: rgba(79, 70, 229, 0.28);
}

.setup-wizard-v2 .wizard-ready-header {
    display: flex;
    justify-content: flex-start;
}

.setup-wizard-v2 .wizard-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    width: 100%;
}

.setup-wizard-v2 .wizard-loading-state .spinner-container {
    margin-left: auto;
    margin-right: auto;
}

.setup-wizard-v2 .wizard-loading-state .loading-text {
    margin-left: auto;
    margin-right: auto;
}

.setup-wizard-v2 .wizard-loading-state .loading-subtext {
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

.setup-wizard-v2 .wizard-ready-badge {
    width: 3rem;
    height: 3rem;
    margin-left: auto;
    margin-right: auto;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #8b7fd9 0%, #6366f1 100%);
    color: #fff;
    font-size: 1.15rem;
}

.setup-wizard-v2 .wizard-story-dropzone {
    border: 1px dashed rgba(148, 163, 184, 0.55);
    border-radius: 0.85rem;
    background: rgba(15, 23, 42, 0.45);
    padding: 1.15rem 1rem;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.setup-wizard-v2 .wizard-story-dropzone:hover {
    border-color: rgba(129, 140, 248, 0.85);
    background: rgba(30, 41, 59, 0.62);
}

.setup-wizard-v2 .wizard-story-dropzone.is-dragover {
    border-color: rgba(129, 140, 248, 0.95);
    background: rgba(79, 70, 229, 0.18);
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.2);
    transform: translateY(-1px);
}

.setup-wizard-v2 .wizard-story-dropzone:focus-visible {
    outline: 0;
    border-color: rgba(129, 140, 248, 0.95);
    box-shadow: 0 0 0 0.22rem rgba(99, 102, 241, 0.25);
}

.setup-wizard-v2 .wizard-story-dropzone-icon {
    color: #a5b4fc;
    font-size: 1.6rem;
    line-height: 1;
    margin-bottom: 0.55rem;
}

.setup-wizard-v2 .wizard-story-dropzone-title {
    color: #e5e7eb;
    font-size: 0.98rem;
    font-weight: 600;
}

.setup-wizard-v2 .wizard-story-dropzone-subtitle {
    color: #cbd5e1;
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

.setup-wizard-v2 .wizard-story-dropzone-hint {
    color: #94a3b8;
    font-size: 0.75rem;
    margin-top: 0.65rem;
}

.setup-wizard-v2 .wizard-advanced {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 0.85rem;
    background: rgba(15, 23, 42, 0.5);
    padding: 0.8rem 1rem;
}

.setup-wizard-v2 #prompt-file-group {
    display: none;
}

.setup-wizard-v2 #prompt-file-group.wizard-visible {
    display: block;
}

.setup-wizard-v2 .wizard-advanced-summary {
    cursor: pointer;
    color: #cbd5e1;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.setup-wizard-v2 .wizard-advanced-summary i {
    color: #94a3b8;
}

.setup-wizard-v2 .wizard-advanced-summary::-webkit-details-marker {
    display: none;
}

.setup-wizard-v2 .wizard-advanced-summary::after {
    content: "\25BE";
    margin-left: auto;
    font-size: 0.75rem;
    color: #94a3b8;
}

.setup-wizard-v2 .wizard-advanced[open] .wizard-advanced-summary::after {
    content: "\25B4";
}

.setup-wizard-v2 .wizard-advanced-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.setup-wizard-v2 .wizard-prompt-mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(15, 23, 42, 0.65);
}

.setup-wizard-v2 .wizard-prompt-mode-btn {
    border: 1px solid transparent;
    color: #cbd5e1;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.45rem 1rem;
    min-width: 7rem;
}

.setup-wizard-v2 .wizard-prompt-mode-btn:hover {
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.32);
    background: rgba(30, 41, 59, 0.75);
}

.setup-wizard-v2 .wizard-prompt-mode-btn.is-active {
    color: #ffffff;
    border-color: rgba(129, 140, 248, 0.85);
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.55), rgba(99, 102, 241, 0.75));
}

.setup-wizard-v2 .wizard-prompt-mode-btn:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.35);
}

.setup-wizard-v2 .wizard-prompt-custom-upload {
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    padding-top: 0.9rem;
}

.setup-wizard-v2 .wizard-prompt-upload-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
}

.setup-wizard-v2 .wizard-prompt-upload-btn {
    min-width: 8rem;
    flex: 0 0 auto;
}

.setup-wizard-v2 .wizard-prompt-filename {
    flex: 1 1 auto;
    min-width: 0;
    min-height: calc(1.5em + 1.5rem + 2px);
    display: flex;
    align-items: center;
    background-color: rgba(17, 24, 39, 0.8);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    color: #94a3b8;
    font-size: 0.92rem;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.setup-wizard-v2 #scenes-container .scene-card {
    background: rgba(31, 41, 55, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.setup-wizard-v2 #scenes-container .scene-card .card-title {
    color: #e5e7eb !important;
}

.setup-wizard-v2 #scenes-container .scene-card .card-text {
    color: #9ca3af !important;
}

.setup-wizard-v2 #scenes-container .scene-card.border-primary {
    border-color: #8b7fd9 !important;
    background: rgba(139, 127, 217, 0.15) !important;
}

.setup-wizard-v2 #scenes-container .scene-card.border-primary .card-title {
    color: #d9d2ff !important;
}

.setup-wizard-v2 #scenes-container .scene-card.border-primary .card-text {
    color: #e5e7eb !important;
}

@media (max-width: 768px) {
    .setup-wizard-v2 .wizard-step-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        row-gap: 1rem;
    }

    .setup-wizard-v2 .wizard-prompt-mode-toggle {
        width: 100%;
    }

    .setup-wizard-v2 .wizard-prompt-mode-btn {
        flex: 1 1 50%;
        min-width: 0;
    }

    .setup-wizard-v2 .wizard-prompt-upload-row {
        flex-direction: column;
        align-items: stretch;
    }

    .setup-wizard-v2 .wizard-prompt-upload-btn {
        width: 100%;
    }

    .setup-wizard-v2 .wizard-panel-header {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ===== Forms ===== */
.form-control {
    background-color: rgba(17, 24, 39, 0.8);
    border: 1px solid var(--app-border);
    color: var(--app-text);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    transition: var(--app-transition);
}

.form-control:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.25);
    background-color: rgba(17, 24, 39, 0.9);
}

.form-control[type="file"] {
    position: relative;
    z-index: 2;
    pointer-events: auto;
}

.form-control[type="file"]::file-selector-button,
.form-control[type="file"]::-webkit-file-upload-button {
    pointer-events: auto;
}

textarea {
    resize: none;
    min-height: 2.5rem;
    max-height: 8rem;
    overflow-y: auto;
}

/* ===== Buttons ===== */
.btn {
    border-radius: var(--radius-md);
    padding: 0.5rem 1.25rem;
    font-weight: 500;
    transition: var(--app-transition);
}

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

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--app-primary-dark);
    border-color: var(--app-primary-dark);
}

.btn-secondary {
    background-color: var(--app-secondary);
    border-color: var(--app-secondary);
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    background-color: var(--app-surface);
    color: var(--app-text);
    border: 1px solid var(--app-border);
    transition: var(--app-transition);
}

.btn-icon:hover {
    background-color: var(--app-secondary);
    color: white;
}

.btn-send {
    background-color: var(--app-primary);
    color: white;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    width: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send:hover {
    background-color: var(--app-primary-dark);
}

.start-btn {
    min-width: 180px;
    background: linear-gradient(90deg, var(--app-primary) 0%, var(--app-accent) 100%);
    border: none;
    border-radius: var(--radius-lg);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Support Button */
.support-button {
    background-color: rgba(217, 70, 239, 0.2);
    color: white;
    border: 1px solid rgba(217, 70, 239, 0.4);
    border-radius: var(--radius-lg);
    padding: 0.5rem 1rem;
    transition: var(--app-transition);
}

.support-button:hover {
    background-color: rgba(217, 70, 239, 0.3);
    border-color: rgba(217, 70, 239, 0.5);
    color: white;
}

/* ===== Feedback Button ===== */
.feedback-button {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-accent) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: none;
    transition: var(--app-transition);
}

.feedback-button:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.feedback-button i {
    font-size: 1.2rem;
}

/* ===== Character Selection ===== */
.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}

.character-item {
    background-color: var(--app-surface);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    cursor: pointer;
    transition: var(--app-transition);
    border: 2px solid transparent;
}

.character-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.character-item.selected {
    border-color: var(--app-primary);
    background-color: rgba(99, 102, 241, 0.1);
}

.character-description {
    font-size: 0.875rem;
    color: var(--app-text-muted);
    margin-top: var(--spacing-sm);
}

/* ===== Chat Interface ===== */
.chat-header {
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--app-border);
}

.chat-header-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "left center right";
    align-items: center;
    column-gap: var(--spacing-sm);
}

.chat-header-left {
    grid-area: left;
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-header-center {
    grid-area: center;
    justify-self: center;
    min-width: 0;
}

.chat-header-right {
    grid-area: right;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.message-usage-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--app-border);
    background-color: var(--app-surface);
    color: var(--app-text-muted);
    font-size: 0.75rem;
    line-height: 1;
    white-space: nowrap;
}

.message-usage-badge strong {
    color: var(--app-text);
    font-weight: 600;
}

.message-usage-label {
    color: var(--app-text-muted);
}

.character-badge {
    background-color: var(--app-surface);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    border: 1px solid var(--app-border);
    max-width: min(56vw, 36rem);
    overflow: hidden;
}

#character-info span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-container {
    background-color: var(--app-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    max-height: calc(100vh - 220px);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    border: 1px solid var(--app-border);
}

.message {
    display: flex;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out;
    margin-bottom: var(--spacing-md);
}

.user-message {
    align-self: flex-end;
    margin-left: auto;
    background: linear-gradient(135deg, var(--app-primary) 0%, var(--app-primary-dark) 100%);
    color: white;
    border-radius: 1.5rem 1.5rem 0 1.5rem;
    padding: 0.75rem 1rem;
}

.assistant-message {
    align-self: flex-start;
    background-color: var(--app-card);
    color: var(--app-text);
    border-radius: 1.5rem 1.5rem 1.5rem 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--app-border);
    position: relative;
}

.message-content {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.5;
}

/* Message actions styling */
.message-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    /* Always visible */
    opacity: 1;
}

/* Regenerate button styling */
.regenerate-btn {
    width: 1.8rem;
    height: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: rgba(99, 102, 241, 0.1);
    color: var(--app-primary);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 0;
    transition: all 0.2s ease;
}

.regenerate-btn:hover {
    background-color: rgba(99, 102, 241, 0.2);
    transform: rotate(45deg);
}

.regenerate-btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.25);
    outline: none;
}

.welcome-message {
    text-align: center;
    padding: var(--spacing-xl);
    margin: auto;
}

.message-input-container {
    margin-bottom: var(--spacing-md);
}

.message-input-group {
    border: 1px solid var(--app-border);
    background-color: var(--app-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.message-input-group .form-control {
    border: none;
    background-color: transparent;
}

/* ===== QR Code ===== */
.qr-code {
    max-width: 200px;
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    background-color: white;
}

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

/* ===== Loading Indicator ===== */
#loading-indicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.3) 0%, rgba(192, 132, 252, 0.3) 100%);
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 
                0 0 40px rgba(192, 132, 252, 0.4);
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.custom-spinner {
    width: 40px;
    height: 40px;
    position: relative;
}

.custom-spinner-circle {
    width: 100%;
    height: 100%;
    position: absolute;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.8));
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* ===== Error Message Styling ===== */
.error-message {
    background-color: rgba(239, 68, 68, 0.1);
    border-left: 4px solid rgb(239, 68, 68);
    padding: var(--spacing-md);
    margin: var(--spacing-sm) 0;
    border-radius: var(--radius-sm);
}

.error-title {
    color: rgb(239, 68, 68);
    font-weight: bold;
    margin-bottom: var(--spacing-sm);
}

.error-suggestion {
    color: rgb(245, 158, 11);
    font-style: italic;
    margin: var(--spacing-sm) 0;
}

.error-details, .error-timestamp {
    font-size: 0.8rem;
    color: var(--app-text-muted);
    margin: var(--spacing-xs) 0;
}

/* ===== Responsive Styles ===== */
@media (max-width: 767.98px) {
    #setup-section {
        overflow-y: auto;
        padding-bottom: 100px;
    }
    
    .character-grid {
        grid-template-columns: 1fr;
    }
    
    #chat-container {
        max-height: calc(100vh - 200px);
        padding: var(--spacing-sm);
    }
    
    .message {
        max-width: 90%;
    }
    
    .app-title {
        font-size: 1.5rem;
    }
    
    .step-number {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.9rem;
    }
    
    .setup-step {
        gap: var(--spacing-sm);
    }

    .chat-header-layout {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "left right"
            "center center";
        row-gap: var(--spacing-sm);
    }

    .chat-header-center {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .chat-header-right {
        gap: 0.375rem;
    }

    .message-usage-badge {
        font-size: 0.7rem;
        padding: 0.35rem 0.55rem;
    }

    .message-usage-label {
        display: none;
    }

    .character-badge {
        max-width: min(100%, 26rem);
        font-size: 0.8125rem;
        padding: 0.45rem 0.75rem;
    }
}

/* ===== Modal Background Blur ===== */
/* Apply consistent background blur to all modals across all pages */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.3s ease;
}

.modal-backdrop.subscription-status-backdrop {
    background-color: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Additional blur for page content when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Ensure blur is applied to the main content when modal is active */
body.modal-open .main-content,
body.modal-open .container,
body.modal-open main,
body.modal-open .main-header,
body.modal-open .navbar {
    filter: blur(3px);
    -webkit-filter: blur(3px);
    transition: filter 0.3s ease;
}

/* Keep modals sharp and unblurred */
body.modal-open .modal,
body.modal-open .modal-dialog,
body.modal-open .modal-content {
    filter: none;
    -webkit-filter: none;
}

/* Enhanced modal styling with consistent blur effects */
.modal-content {
    background-color: rgba(31, 41, 55, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

/* Modal content blur class for specific modal styling */
.modal-blur {
    background-color: rgba(31, 41, 55, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Ensure backdrop blur is visible on all browsers */
@supports not (backdrop-filter: blur(8px)) {
    .modal-backdrop {
        background-color: rgba(0, 0, 0, 0.7);
    }
}

@supports not (backdrop-filter: blur(10px)) {
    .modal-content,
    .modal-blur {
        background-color: rgba(31, 41, 55, 0.98);
    }
}

/* ===== Preference Switches ===== */
.preferences-container .form-switch .pref-switch-input,
.chat-settings-panel .form-switch .pref-switch-input {
    width: 2.35rem;
    height: 1.2rem;
    margin-top: 0;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 999px;
    background-color: rgba(15, 23, 42, 0.9);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23f8fafc'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: left 2px center;
    background-size: 0.95rem 0.95rem;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, background-position 0.2s ease, box-shadow 0.2s ease;
}

.preferences-container .form-switch .pref-switch-input:checked,
.chat-settings-panel .form-switch .pref-switch-input:checked {
    background-color: #6d28d9;
    border-color: rgba(167, 139, 250, 0.95);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23f8fafc'/%3e%3c/svg%3e");
    background-position: right 2px center;
}

.preferences-container .form-switch .pref-switch-input:focus,
.chat-settings-panel .form-switch .pref-switch-input:focus {
    border-color: rgba(167, 139, 250, 0.95);
    box-shadow: 0 0 0 0.2rem rgba(168, 85, 247, 0.24);
}
