/* Ensure parent containers don't clip dropdown */
.model-selector-container,
.header-controls,
.chat-header {
    overflow: visible !important;
    position: relative;
}

/* Model Selector Button */
:root {
    /* Typography Variables */
    --mobile-font-xs: 0.6875rem;     /* 11px - Extra small text */
    --mobile-font-xs-plus: 0.75rem;  /* 12px - Very small text */
    --mobile-font-small: 0.875rem;   /* 14px - Secondary text */
    --mobile-font-small-plus: 0.9375rem; /* 15px - Small plus text */
    --mobile-font-base: 1rem;        /* 16px - Base font size */
    --mobile-font-large: 1.125rem;   /* 18px - Large text */
    --mobile-font-weight-normal: 400;
}
.model-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e6e6e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: var(--mobile-font-small);
    font-weight: 500;
    color: #2c2c2c;
    /* Ensure dropdown positioning works correctly */
    z-index: 1;
    overflow: visible;
}

.model-selector:hover {
    border-color: #c93891;
    background: rgba(201, 56, 145, 0.02);
}

.model-selector.open {
    border-color: #c93891;
    background: rgba(201, 56, 145, 0.04);
}

.model-selector .fa-chevron-down {
    font-size: var(--mobile-font-xs-plus);
    color: #666;
    transition: transform 0.2s ease;
}

.model-selector.open .fa-chevron-down {
    transform: rotate(180deg);
}

/* Loading state for model selector */
.model-selector.loading {
    opacity: 0.6;
    pointer-events: none;
}

.model-selector.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top: 2px solid #c93891;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Model Dropdown */
.model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: white;
    border: 1px solid #e6e6e6;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: none;
    z-index: 1000;
    min-width: 320px;
    max-height: 344px;
    overflow-y: auto;
    padding: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    /* Hide scrollbar */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
}

/* Hide scrollbar for Webkit browsers */
.model-dropdown::-webkit-scrollbar {
    display: none;
}

.model-dropdown .mobile-handle {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: #e6e6e6;
    margin: 12px auto;
    width: 40px;
    border-radius: 2px;
    z-index: 1001;
    cursor: grab;
    background-color: #ddd;
}

.model-dropdown.position-top {
    top: auto;
    bottom: calc(100% + 8px);
    transform-origin: bottom center;
    /* Ensure proper positioning when dropdown opens upward */
    overflow-y: auto;
}

.model-dropdown.show {
    display: block;
    animation: modelDropdownFadeIn 0.2s ease;
}

.model-dropdown.position-top.show {
    animation: modelDropdownFadeInTop 0.2s ease;
}

@keyframes modelDropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Model Sections */
.model-section {
    padding: 8px;
}

.model-section:last-child {
    padding-bottom: 8px;
    margin-bottom: 0;
}

.model-section-content {
    padding-bottom: 0;
    margin-bottom: 0;
}

.model-section-title {
    font-size: var(--mobile-font-xs-plus);
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding: 0 8px;
}

/* Model Options */
.model-option {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    gap: 12px;
    margin-bottom: 2px;
}

.model-option:last-child {
    margin-bottom: 0;
}

.model-option:hover {
    background: rgba(201, 56, 145, 0.04);
}

.model-option.selected {
    background: rgba(201, 56, 145, 0.08);
    border: 1px solid rgba(201, 56, 145, 0.2);
}

.model-info {
    flex: 1;
    min-width: 0;
}

.model-name {
    font-weight: 500;
    color: #2c2c2c;
    font-size: var(--mobile-font-small);
    margin-bottom: 2px;
}

.model-description {
    color: #666;
    font-size: var(--mobile-font-xs-plus);
    line-height: 1.3;
}

/* Model Status */
.model-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--mobile-font-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.status-running {
    background: #28a745;
    box-shadow: 0 0 4px rgba(40, 167, 69, 0.4);
}

.status-dot.status-stopped {
    background: #dc3545;
}

.status-dot.status-starting {
    background: #ffc107;
    animation: pulse 1.5s infinite;
}

.status-dot.status-stopping {
    background: #fd7e14;
    animation: pulse 1.5s infinite;
}

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

.status-text {
    color: #666;
}

/* Model Action Button */
.model-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.model-action-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.05);
}

.model-action-btn i {
    font-size: var(--mobile-font-xs-plus);
    color: #666;
}

.model-selected-icon {
    color: #007AFF;
    font-size: var(--mobile-font-base);
    flex-shrink: 0;
}

/* Error states */
.model-option.error {
    background: rgba(220, 53, 69, 0.05);
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.model-option.error .model-name {
    color: #dc3545;
}

.model-option.error .status-dot {
    background: #dc3545;
}

/* Dark mode styles */
[data-theme="dark"] .model-selector {
    background: #1e1e1e;
    border: 1px solid #333333;
    color: #e0e0e0;
}

[data-theme="dark"] .model-selector:hover {
    border-color: #c93891;
    background: rgba(201, 56, 145, 0.05);
}

[data-theme="dark"] .model-selector.open {
    border-color: #c93891;
    background: rgba(201, 56, 145, 0.08);
}

[data-theme="dark"] .model-selector .fa-chevron-down {
    color: #888888;
}

[data-theme="dark"] .model-dropdown {
    background: #1e1e1e;
    border: 1px solid #333333;
}

[data-theme="dark"] .model-section-title {
    color: #888888;
}

[data-theme="dark"] .model-option {
    color: #e0e0e0;
}

[data-theme="dark"] .model-option:hover {
    background: rgba(201, 56, 145, 0.1);
}

[data-theme="dark"] .model-option.selected {
    background: rgba(201, 56, 145, 0.15);
    border: 1px solid rgba(201, 56, 145, 0.3);
}

[data-theme="dark"] .model-name {
    color: #e0e0e0;
}

[data-theme="dark"] .model-description {
    color: #888888;
}

[data-theme="dark"] .status-text {
    color: #888888;
}

[data-theme="dark"] .model-action-btn {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .model-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .model-action-btn i {
    color: #e0e0e0;
}

[data-theme="dark"] .model-option.error {
    background: rgba(220, 53, 69, 0.1);
}

[data-theme="dark"] .model-option.error .model-name {
    color: #ff6b6b;
}

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    .model-dropdown {
        position: fixed;
        bottom: -100%;
        left: 0;
        right: 0;
        top: auto;
        width: 100%;
        min-width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        transition: bottom 0.3s ease-in-out;
        z-index: 1001;
        background: #f8f9fa;
        padding: 0;
        display: flex;
        flex-direction: column;
                overflow: scroll;
                height: 100%;
    }
    
    .model-dropdown .mobile-handle {
        display: block;
        width: 40px;
        height: 4px;
        background: #e0e0e0;
        border-radius: 2px;
        margin: 8px auto 16px;
        flex-shrink: 0;
    }
    .model-dropdown.show {
        bottom: 0;
        animation: none;
        height: 100%;
        overflow: scroll;
        display: flex;
        flex-direction: column;
    }

    .model-section {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: scroll;
    }

    .model-section-title {
        padding: 5px 5px 5px 20px;
        font-size: var(--mobile-font-large);
        font-weight: 600;
        color: #1a1a1a;
        text-transform: none;
        letter-spacing: normal;
        background: #f8f9fa;
        flex-shrink: 0;
    
    }

    .model-section-content {
        padding: 0 16px;
        overflow-y: auto;
        flex-grow: 1;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .model-option {
        margin: 8px 0;
        padding: 20px;
        border: 1px solid #e6e6e6;
        border-radius: 16px;
        background: white;
        display: flex;
        align-items: flex-start;
    }

    .model-option:hover {
        border-color: #007AFF;
        background: white;
    }

    .model-option.selected {
        border-color: #007AFF;
        background: white;
    }

    .model-name {
        font-size: var(--mobile-font-small);
        font-weight: 500;
        margin-bottom: 6px;
        color: #1a1a1a;
    }

    .model-description {
        font-size: var(--mobile-font-small-plus);
        color: #666;
        line-height: 1.4;
        margin: 0;
    }

    .model-selected-icon {
        margin-left: auto;
        margin-top: 4px;
    }

    /* Dark mode adjustments for mobile */
    [data-theme="dark"] .model-dropdown {
        background: #1a1a1a;
    }

    [data-theme="dark"] .model-dropdown .mobile-handle {
        background: #666;
    }

    [data-theme="dark"] .model-section-title {
        color: #ffffff;
        background: #1a1a1a;
    }

    [data-theme="dark"] .model-option {
        background: #2a2a2a;
        border-color: #404040;
    }

    [data-theme="dark"] .model-option:hover {
        border-color: #007AFF;
        background: #2a2a2a;
    }

    [data-theme="dark"] .model-option.selected {
        border-color: #007AFF;
        background: #2a2a2a;
    }

    [data-theme="dark"] .model-name {
        color: #ffffff;
    }

    [data-theme="dark"] .model-description {
        color: #888;
    }
}
@media(max-width: 768px){
    .selected-model-name{
        font-size: var(--mobile-font-base);
        font-weight: var(--mobile-font-weight-normal);
        margin-bottom: 0px;
        color: #1a1a1a;
        white-space: nowrap;
        max-width: 95px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .model-selector{
        padding: 3px 6px !important;
        border-radius: 18px !important;
    }
}