/* ========================================
   ASK THE MESSAGE - UI STYLES
   Consolidated styles for the Ask the Message page
   ======================================== */

/* ========================================
   LAYOUT & STRUCTURE
   ======================================== */

main {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

#citationPanel {
    display: none;
    flex-direction: column;
}

#citationPanel:not(.hidden) {
    display: flex !important;
}

@media (min-width: 1024px) {
    /* Default: full width when citation panel is hidden */
    #chatMessages {
        max-width: 100%;
        flex: 1 1 auto;
    }

    /* Only constrain width when citation panel is visible */
    /* Note: :has() requires Safari 15.4+, Chrome 105+, Firefox 121+ */
    @supports selector(:has(*)) {
        #chatMessages:has(~ #citationPanel:not(.hidden)) {
            max-width: calc(100% - 24rem);
        }
    }

    /* Fallback for browsers without :has() - JS will add this class */
    #chatMessages.citation-panel-open {
        max-width: calc(100% - 24rem);
    }
}

/* Mobile-friendly citation panel - bottom sheet */
@media (max-width: 1023px) {
    #citationPanel:not(.hidden) {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        height: 60vh;
        max-height: 60vh;
        width: 100%;
        border-radius: 1rem 1rem 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1001;
        display: flex !important;
    }

    #citationPanel.open {
        transform: translateY(0);
    }

    /* Add drag handle for bottom sheet */
    #citationPanel::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
    }

    .dark #citationPanel::before {
        background: #4b5563;
    }
}

/* ========================================
   SKIP TO CONTENT - ACCESSIBILITY
   ======================================== */

.skip-to-content {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 9999;
    padding: 1rem;
    background: #3b82f6;
    color: white;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
}

.skip-to-content:focus {
    left: 0;
}

/* ========================================
   MOBILE HEADER
   ======================================== */

.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

.dark .mobile-header {
    background: #1f2937;
    border-color: #374151;
}

@media (min-width: 768px) {
    .mobile-header {
        display: none;
    }
}

@media (max-width: 767px) {
    .desktop-header {
        display: none !important;
    }
}

.mobile-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1f2937;
}

.dark .mobile-title {
    color: #f3f4f6;
}

.mobile-keyboard-toggle,
.mobile-sidebar-toggle,
.mobile-theme-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-keyboard-toggle:hover,
.mobile-sidebar-toggle:hover,
.mobile-theme-toggle:hover {
    color: #374151;
    background: #f3f4f6;
}

.dark .mobile-keyboard-toggle:hover,
.dark .mobile-sidebar-toggle:hover,
.dark .mobile-theme-toggle:hover {
    color: #e5e7eb;
    background: #374151;
}

/* ========================================
   CREDIT DISPLAY
   ======================================== */

.credit-display {
    color: #10b981;
    font-weight: 500;
}

.credit-display.credit-low {
    color: #f59e0b;
}

.credit-display.credit-empty {
    color: #ef4444;
}

.credit-display-desktop .bg-gray-100 {
    transition: all 0.3s ease;
}

.credit-display-desktop.credit-low .bg-gray-100 {
    background-color: #fef3c7;
    border-color: #fbbf24;
}

.credit-display-desktop.credit-empty .bg-gray-100 {
    background-color: #fee2e2;
    border-color: #f87171;
}

/* ========================================
   SERMON COUNT BADGES
   ======================================== */

.sermon-count-badge {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    background: #dbeafe;
    color: #1d4ed8;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.2s;
}

.sermon-count-badge:hover {
    background: #bfdbfe;
}

.dark .sermon-count-badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.dark .sermon-count-badge:hover {
    background: rgba(59, 130, 246, 0.3);
}

.sermon-count-badge-desktop {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: #f3f4f6;
    color: #374151;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.sermon-count-badge-desktop span:first-of-type {
    color: #3b82f6;
    font-weight: 600;
}

.dark .sermon-count-badge-desktop {
    background: #374151;
    color: #e5e7eb;
}

/* ========================================
   INPUT CONTEXT BADGES
   ======================================== */

.input-context-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background: #dbeafe;
    color: #1d4ed8;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
}

/* Ensure hidden class works on badges */
.input-context-badge.hidden {
    display: none !important;
}

.dark .input-context-badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

/* ========================================
   GUIDED PROMPTS DROPDOWN
   ======================================== */

.guided-prompts-dropdown {
    animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.guided-chevron.open {
    transform: rotate(180deg);
}

#guidedPromptsDropdown::-webkit-scrollbar {
    width: 6px;
}

#guidedPromptsDropdown::-webkit-scrollbar-track {
    background: transparent;
}

#guidedPromptsDropdown::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.dark #guidedPromptsDropdown::-webkit-scrollbar-thumb {
    background: #4b5563;
}

/* ========================================
   MOBILE SERMON FAB
   ======================================== */

.mobile-sermon-fab {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40;
}

.mobile-sermon-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}

.mobile-sermon-fab:active {
    transform: scale(0.95);
}

.fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 1024px) {
    .mobile-sermon-fab {
        display: none;
    }
}

/* Improved FAB positioning for small screens */
@media (max-width: 375px) {
    .mobile-sermon-fab {
        bottom: 80px;
        right: 12px;
        width: 48px;
        height: 48px;
    }

    .fab-badge {
        min-width: 18px;
        height: 18px;
        font-size: 10px;
    }
}

/* ========================================
   SERMON SIDEBAR ENHANCEMENTS
   ======================================== */

.sermon-sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 1023px) {
    .sermon-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        width: 300px !important;
    }

    .sermon-sidebar.mobile-sidebar-open {
        transform: translateX(0);
    }
}

/* Extra small screens - iPhone SE and similar */
@media (max-width: 375px) {
    .sermon-sidebar {
        width: 85vw !important;
        max-width: 280px;
    }
}

.sermon-list-container {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

.sermon-list-container::-webkit-scrollbar {
    width: 6px;
}

.sermon-list-container::-webkit-scrollbar-track {
    background: transparent;
}

.sermon-list-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.dark .sermon-list-container::-webkit-scrollbar-thumb {
    background: #4b5563;
}

/* Mobile sidebar overlay */
.mobile-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.mobile-sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

body.sidebar-open {
    overflow: hidden;
}

/* ========================================
   WELCOME MESSAGE
   ======================================== */

.welcome-message {
    animation: fadeInUp 0.5s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.example-question {
    cursor: pointer;
}

.example-question:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ========================================
   INPUT AREA ENHANCEMENTS
   ======================================== */

.input-wrapper {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.input-wrapper:focus-within {
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

#userInput {
    min-height: 60px;
    max-height: 200px;
}

#userInput:focus {
    box-shadow: none;
}

/* ========================================
   RESPONSE MESSAGE ENHANCEMENTS
   ======================================== */

.assistant-message {
    position: relative;
}

.response-actions {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.assistant-message:hover .response-actions {
    opacity: 1;
}

.response-action-btn {
    padding: 0.375rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.375rem;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.response-action-btn:hover {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.dark .response-action-btn {
    background: #374151;
    border-color: #4b5563;
    color: #9ca3af;
}

.dark .response-action-btn:hover {
    background: #4b5563;
    color: #e5e7eb;
}

/* Copy button success state */
.response-action-btn.copied {
    background: #dcfce7;
    border-color: #86efac;
    color: #16a34a;
}

/* ========================================
   FONT SIZE CONTROLS
   ======================================== */

.font-size-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: #f3f4f6;
    border-radius: 0.5rem;
}

.dark .font-size-controls {
    background: #374151;
}

.font-size-btn {
    padding: 0.25rem 0.5rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.font-size-btn:hover {
    background: #e5e7eb;
}

.dark .font-size-btn {
    background: #4b5563;
    border-color: #6b7280;
    color: #e5e7eb;
}

/* ========================================
   CITATION NOTIFICATION
   ======================================== */

.citation-notification {
    position: fixed;
    bottom: 100px;
    right: 20px;
    padding: 0.75rem 1rem;
    background: #3b82f6;
    color: white;
    border-radius: 0.75rem;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    animation: slideInRight 0.3s ease-out;
    z-index: 50;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.citation-notification:hover {
    background: #2563eb;
}

@media (min-width: 1024px) {
    .citation-notification {
        display: none;
    }
}

/* ========================================
   INLINE PROGRESS INDICATOR
   ======================================== */

#inlineProgress {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ========================================
   STUDY TOOLBAR ENHANCEMENTS
   ======================================== */

#studyToolbar {
    position: relative; /* For absolute positioned children like studyInfoPanel */
    flex-wrap: wrap;
    gap: 0.5rem;
}

#studyToolbar input,
#studyToolbar select {
    font-size: 0.875rem;
}

#studyInfoPanel {
    animation: dropdownFadeIn 0.15s ease-out;
}

/* ========================================
   FOCUS STATES - ACCESSIBILITY
   ======================================== */

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Remove focus outline for mouse users */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
select:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
    outline: none;
}

/* ========================================
   DARK MODE ADJUSTMENTS
   ======================================== */

.dark .desktop-header {
    background-color: #1f2937;
    border-color: #374151;
}

.dark .input-area-container {
    background: #111827;
}

.dark .input-wrapper {
    background: #1f2937;
    border-color: #374151;
}

.dark .input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */

@media (max-width: 640px) {
    .study-set-controls {
        flex-wrap: wrap;
    }

    #studySetName,
    #studySetSelect {
        width: 100%;
        min-width: unset;
    }

    .mobile-header {
        padding: 0.5rem 0.75rem;
    }

    .input-area-container {
        padding: 0.75rem;
    }

    #userInput {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    /* Improve chat message readability */
    #chatMessages {
        padding: 0.5rem;
    }

    .assistant-message {
        padding: 1rem;
        font-size: 0.9375rem;
        line-height: 1.5;
        margin: 0.75rem 0;
    }

    .assistant-message h1 {
        font-size: 1.125rem;
        margin-top: 1rem;
    }

    .assistant-message h2 {
        font-size: 1rem;
        margin-top: 0.875rem;
    }

    .assistant-message p {
        margin-bottom: 0.625rem;
    }
}

/* Extra small screens - optimize input and spacing */
@media (max-width: 375px) {
    .input-area-container {
        padding: 0.5rem;
    }

    #userInput {
        min-height: 50px;
        padding: 0.625rem;
        font-size: 16px;
    }

    .mobile-header {
        padding: 0.375rem 0.5rem;
    }

    #chatMessages {
        padding: 0.375rem;
    }

    .assistant-message {
        padding: 0.875rem;
        margin: 0.5rem 0;
    }

    /* Simplify mobile header - hide secondary items on very small screens */
    .mobile-keyboard-toggle {
        display: none;
    }

    /* Make credit display more compact */
    .credit-display {
        padding: 0.25rem 0.5rem;
        font-size: 0.625rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */

.animate-pulse-subtle {
    animation: pulseSublte 2s ease-in-out infinite;
}

@keyframes pulseSublte {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(
        90deg,
        #f3f4f6 25%,
        #e5e7eb 50%,
        #f3f4f6 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.dark .skeleton {
    background: linear-gradient(
        90deg,
        #374151 25%,
        #4b5563 50%,
        #374151 75%
    );
    background-size: 200% 100%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========================================
   SESSION STATS MODAL
   ======================================== */

#sessionStatsModal {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

#sessionStatsModal.hidden {
    display: none !important;
}

.stats-modal-content {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@media (max-width: 480px) {
    .stats-modal-content {
        max-width: 100%;
        max-height: 85vh;
        margin: 0.5rem;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

/* ========================================
   MOBILE STUDY MODE ACCESS
   ======================================== */

.mobile-study-trigger {
    display: none;
    position: fixed;
    bottom: 170px;
    right: 20px;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

@media (max-width: 767px) {
    .mobile-study-trigger {
        display: flex;
    }

    /* Hide desktop study toolbar on mobile */
    #studyToolbar {
        display: none !important;
    }
}

.mobile-study-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.5);
}

.mobile-study-trigger:active {
    transform: scale(0.95);
}

/* Mobile study panel */
.mobile-study-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1002;
    max-height: 70vh;
    overflow-y: auto;
}

.dark .mobile-study-panel {
    background: #1f2937;
    border-color: #374151;
}

.mobile-study-panel.open {
    transform: translateY(0);
}

/* Drag handle for mobile study panel */
.mobile-study-panel::before {
    content: '';
    position: sticky;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    display: block;
    margin: 0 auto 1rem;
}

.dark .mobile-study-panel::before {
    background: #4b5563;
}

.mobile-study-content {
    padding: 1.5rem 1rem 2rem;
}

@media (max-width: 375px) {
    .mobile-study-trigger {
        bottom: 140px;
        right: 12px;
        padding: 0.625rem 0.875rem;
        font-size: 0.8125rem;
    }
}

@media print {
    .mobile-header,
    .desktop-header,
    #studyToolbar,
    .input-area-container,
    .mobile-sermon-fab,
    .mobile-study-trigger,
    .mobile-study-panel,
    #citationPanel,
    .sermon-sidebar,
    #jump-to-latest {
        display: none !important;
    }

    #chatMessages {
        max-width: 100% !important;
        padding: 0 !important;
    }

    .assistant-message {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
