/* Nova Application Main Styles */

/* Layout Structure - Using Bootstrap flex utilities where possible */
body {
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 0;
    /* This forces the flex item to respect flex: 1 properly */
    overflow: hidden;
}

/* Chat page layout - full height with internal scrolling */
.main-container>.container-fluid {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* Configuration/settings pages - allow full page scrolling */
.main-container>.container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================
   MOBILE UNIFIED NAVBAR STYLES
   ============================================ */

/* Mobile navbar - compact unified design */
.mobile-navbar {
    min-height: 44px;
    max-height: 48px;
}

.mobile-navbar .navbar-brand {
    font-size: 1rem;
}

.mobile-navbar .navbar-brand img {
    height: 20px;
}

.mobile-nav-btn {
    padding: 0.25rem 0.5rem;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-nav-btn i {
    font-size: 1.1rem;
}

/* Remove dropdown caret on mobile user button for cleaner look */
.mobile-navbar .dropdown-toggle::after {
    display: none;
}

/* Main content area height calculation - use flex instead of fixed vh */
.main-content-row {
    flex: 1;
    min-height: 0;
    height: 100%;
    flex-wrap: nowrap;
    overflow: hidden;
}

/* Ensure message container fills available space and positions input at bottom */
#message-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

#message-container>.d-flex.flex-column.h-100 {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* ============================================
   TOUCH-FRIENDLY IMPROVEMENTS
   ============================================ */

@media (hover: none) and (pointer: coarse) {

    /* Standard touch targets but allow smaller for specific UI elements */
    .btn:not(.btn-sm):not(.mobile-nav-btn) {
        min-height: 44px;
        min-width: 44px;
    }

    .file-item-content {
        padding: 0.5rem;
        min-height: 40px;
    }

    .auto-resize-textarea {
        font-size: 16px;
        /* Prevents zoom on iOS */
        min-height: 40px;
    }

    .file-item-actions {
        opacity: 1;
        /* Always show on touch devices */
    }

    .file-delete-btn {
        padding: 4px 6px;
        min-height: 28px;
        min-width: 28px;
    }
}

/* ============================================
   MOBILE PADDING & SPACING OPTIMIZATIONS
   ============================================ */

@media (max-width: 575.98px) {

    /* Compact message cards on mobile */
    .message {
        margin-bottom: 0.5rem !important;
    }

    .message .card-body {
        padding: 0.5rem 0.75rem !important;
    }

    /* Hide context indicator on mobile - accessible via long press */
    .message .card-footer {
        display: none !important;
    }

    /* ============================================
       CHAT BUBBLE STYLING (Mobile only)
       ============================================ */

    /* User messages - right-aligned bubble */
    .message .card.border-primary {
        border: none !important;
        border-radius: 16px 16px 4px 16px;
        background-color: var(--bs-primary);
        color: white;
        margin-left: 15%;
    }

    .message .card.border-primary .card-body {
        color: white;
    }

    .message .card.border-primary .card-body strong.text-primary {
        color: white !important;
    }

    .message .card.border-primary .text-muted {
        color: rgba(255, 255, 255, 0.8) !important;
    }

    /* Agent messages - left-aligned bubble */
    .message .card.border-secondary {
        border: none !important;
        border-radius: 16px 16px 16px 4px;
        background-color: var(--bs-light);
        margin-right: 10%;
    }

    /* Interaction cards - keep minimal border for distinction */
    .message .card.border-warning,
    .message .card.border-success {
        border-width: 1px !important;
        border-radius: 12px;
    }

    /* System messages - subtle styling */
    .message .card.border-light {
        border: none !important;
        background-color: transparent;
    }

}

/* Desktop Layout Responsive Columns */
@media (min-width: 992px) {

    /* Default state: threads (2 cols) + messages (8 cols) + files (2 cols) */
    #message-area[data-files-visible="true"] {
        flex: 0 0 66.666667%;
        /* col-lg-8 equivalent */
        max-width: 66.666667%;
    }

    /* Files hidden state: threads (2 cols) + messages (10 cols) */
    #message-area[data-files-visible="false"] {
        flex: 0 0 83.333333%;
        /* col-lg-10 equivalent */
        max-width: 83.333333%;
    }

    /* Smooth transition for layout changes */
    #message-area {
        transition: flex 0.3s ease, max-width 0.3s ease;
    }

    #files-sidebar {
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* Hidden files sidebar */
    #files-sidebar.files-hidden {
        opacity: 0;
        transform: translateX(100%);
        pointer-events: none;
    }
}

/* Message Area */
#message-area {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex-grow: 1;
}

/* File sidebar containers - scrollable */
#files-sidebar,
#file-sidebar-content,
#file-sidebar-content-mobile {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Sidebar flex containers - ensure proper height constraints */
#threads-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* Thread containers: scrollable within flex parent */
#threads-container,
#mobile-threads-container {
    flex: 1 1 0;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Files sidebar */
#files-sidebar {
    min-height: 0;
    overflow: hidden;
}

/* Ensure file tree container allows proper scrolling */
#file-tree-container {
    min-height: 0;
    height: 100%;
}

/* Load more button container */
#load-more-container,
#mobile-load-more-container {
    padding: 0.75rem;
    text-align: center;
}

/* Message Input Area */
.message-input-area {
    flex-shrink: 0;
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-light);
    padding-bottom: 0;
}

.message-input-area .input-group {
    margin-bottom: 0;
}

/* Form Controls */
.auto-resize-textarea {
    min-height: 38px;
    max-height: 200px;
    overflow-y: auto;
    resize: none;
}

/* Progress Indicators */
#progress-logs {
    transition: opacity 0.3s ease;
}

.updating #progress-logs {
    opacity: 0.5;
}

/* File Panel Styles */
.file-item-content {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    white-space: nowrap;
    min-width: max-content;
}

.file-item-content:hover {
    background-color: var(--bs-light);
}

.file-item-icon {
    margin-right: 8px;
    color: var(--bs-secondary);
}

.file-item-name {
    flex: 1;
    font-size: 14px;
    color: var(--bs-body-color);
}

.file-item-actions {
    margin-left: 8px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Desktop with mouse: show actions on hover */
@media (hover: hover) and (pointer: fine) {
    .file-item-content:hover .file-item-actions {
        opacity: 1;
    }
}

.file-delete-btn {
    padding: 2px 6px;
    border: none;
    background: transparent;
    color: var(--bs-danger);
    border-radius: 3px;
    transition: all 0.2s ease;
}

.file-delete-btn:hover {
    background-color: var(--bs-danger);
    color: white;
    transform: scale(1.1);
}

.file-delete-btn i {
    font-size: 12px;
}

.file-tree-list {
    list-style: none;
    margin: 0;
    padding: 0;
    min-width: max-content;
}

/* Ensure file tree root container handles overflow properly */
.file-tree-list.root {
    overflow-x: auto;
    overflow-y: visible;
}

/* Ensure file names don't break on long paths */
.file-item-name,
.file-download-link {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* On hover, show full name */
.file-item-name:hover,
.file-download-link:hover {
    overflow: visible;
    max-width: none;
    background-color: var(--bs-dark);
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    position: relative;
    z-index: 10;
}

.file-tree-item.selected .file-item-content {
    background-color: var(--bs-primary);
    color: white;
}

.file-tree-item.selected .file-item-icon,
.file-tree-item.selected .file-item-name {
    color: white;
}

/* Upload Progress Bar */
#upload-progress {
    margin: 10px 0;
    padding: 0 10px;
}

#upload-progress .progress {
    height: 20px;
    background-color: var(--bs-gray-200);
    border-radius: 10px;
    overflow: hidden;
}

#upload-progress .progress-bar {
    background-color: var(--bs-primary);
    color: white;
    font-size: 12px;
    line-height: 20px;
    text-align: center;
    transition: width 0.3s ease;
    border-radius: 10px;
}

#upload-progress .progress-bar:empty::after {
    content: "0%";
}

/* Agent selector button */
.agent-selector-btn {
    padding: 0.25rem 0.5rem;
    min-width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-selector-btn i {
    font-size: 1.2rem;
}

/* Tooltip styling (Bootstrap handles the display) */
.tooltip-inner {
    max-width: 200px;
    text-align: center;
}

/* Mobile adjustments: Ensure button is touch-friendly */
@media (hover: none) and (pointer: coarse) {
    .agent-selector-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Preview mode: hide sidebars and expand message area for split preview */
.preview-active #threads-sidebar,
.preview-active #files-sidebar {
    display: none !important;
}

@media (min-width: 992px) {

    /* When preview is active, central column takes full width */
    .preview-active #message-area {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Hide "Messages" toolbar row inside message area to maximize space */
    .preview-active #message-area>.d-lg-flex {
        display: none !important;
    }
}

/* Accessibility: make resizer more visible on focus */
#split-resizer:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

/* ============================================
   MOBILE MESSAGE CONTEXT MENU (Action Sheet)
   ============================================ */

/* Action sheet offcanvas styling */
#messageContextMenu {
    --bs-offcanvas-height: auto;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
}

#messageContextMenu .offcanvas-body {
    padding: 0.5rem;
}

/* Action sheet buttons */
.action-sheet-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--bs-body-color);
    font-size: 1rem;
    text-align: left;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.action-sheet-btn:hover,
.action-sheet-btn:focus {
    background-color: var(--bs-light);
}

.action-sheet-btn i {
    font-size: 1.25rem;
    margin-right: 0.75rem;
    width: 24px;
    text-align: center;
}

.action-sheet-btn.text-danger:hover,
.action-sheet-btn.text-danger:focus {
    background-color: rgba(220, 53, 69, 0.1);
}

/* Context info in action sheet */
.context-info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: var(--bs-light);
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.context-info-label {
    font-size: 0.875rem;
    color: var(--bs-secondary);
}

.context-info-value {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Visual feedback during long press */
.message.long-press-active .card {
    transform: scale(0.98);
    transition: transform 0.15s ease-out;
}

/* Divider in action sheet */
.action-sheet-divider {
    height: 1px;
    background-color: var(--bs-border-color);
    margin: 0.5rem 0;
}