.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.5s ease;
}

.loading-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(0, 221, 255, 0.3);
    border-top: 4px solid #00ddff;
    border-radius: 50%;
    animation: loadingSpin 1s linear infinite;
}

@keyframes loadingSpin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-family: "Orbitron", monospace;
    font-size: 16px;
    color: #00ddff;
    font-weight: 600;
}

/* =========================================
   RESPONSIVE DESIGN
   ========================================= */

/* Large desktop */
@media (max-width: 1400px) {
    #app {
        grid-template-columns: minmax(220px, 260px) 1fr minmax(350px, 500px);
        gap: 10px;
        padding: 10px;
    }
}

/* Small desktop / Large tablet landscape */
@media (max-width: 1200px) {
    #app {
        grid-template-columns: 240px 1fr 300px;
        gap: 10px;
        padding: 10px;
    }

    .mode-label {
        font-size: 8px;
    }
}

/* Tablet portrait */
@media (max-width: 1024px) {
    #app {
        grid-template-columns: 200px 1fr 260px;
        gap: 8px;
        padding: 8px;
    }

    .mode-tab {
        padding: 4px 6px;
        min-width: 38px;
    }

    .mode-icon {
        font-size: 16px;
    }

    .mode-label {
        font-size: 7px;
    }
}

/* iPad / Small tablet */
@media (max-width: 900px) {
    #app {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr;
        gap: 10px;
        padding: 10px;
    }

    .workspace-panel {
        grid-column: 1 / 2;
        height: auto;
        min-height: 250px;
        max-height: 50vh;
    }

    .orb-wrapper {
        grid-column: 2 / 3;
        grid-row: 1 / 2;
    }

    .output-panel {
        grid-column: 1 / -1;
        grid-row: 2 / 3;
        height: auto;
        min-height: 400px;
    }
}

/* Phone landscape / Small tablet */
@media (max-width: 768px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        gap: 8px;
        padding: 8px;
    }

    .workspace-panel {
        grid-column: 1;
        height: auto;
        min-height: 200px;
    }

    .orb-wrapper {
        grid-column: 1;
        padding: 16px;
    }

    .ai-orb {
        width: 120px;
        height: 120px;
    }

    .output-panel {
        grid-column: 1;
        height: auto;
        min-height: 350px;
    }

    /* Stack mode tabs horizontally with scroll */
    .mode-tabs {
        justify-content: flex-start;
        gap: 4px;
        padding: 8px;
    }

    .mode-tab {
        padding: 8px 12px;
    }
}

/* Phone portrait */
@media (max-width: 480px) {
    .service-toolbar {
        height: 36px;
        padding: 0 8px;
    }

    #app {
        margin-top: 36px;
        height: calc(100vh - 36px);
        padding: 6px;
        gap: 6px;
    }

    /* Icon-only mode tabs */
    .mode-label {
        display: none;
    }

    .mode-tab {
        min-width: 36px;
        padding: 8px;
    }

    .mode-icon {
        font-size: 20px;
    }

    /* Full-width input */
    .command-input-wrapper {
        flex-direction: row;
    }

    .command-input-wrapper textarea {
        font-size: 16px;
        /* Prevent iOS zoom */
    }

    /* Smaller orb on mobile */
    .ai-orb {
        width: 100px;
        height: 100px;
    }

    .orb-wrapper {
        padding: 12px;
    }

    /* Compact output panel */
    .output-panel {
        min-height: 300px;
    }

    .panel-tab {
        font-size: 11px;
        padding: 8px;
    }
}

@media (max-width: 400px) {
    .service-toolbar {
        padding: 0 10px;
    }

    .toolbar-left,
    .toolbar-right {
        gap: 8px;
    }

    .model-switcher {
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .model-switcher select {
        font-size: 10px;
        padding: 3px 6px;
    }

    .model-status {
        font-size: 9px;
    }

    .service-indicators {
        gap: 5px;
    }

    .service-indicator {
        padding: 3px 5px;
    }

    .indicator-label {
        display: none;
    }
}

/* =========================================
   ENHANCED OUTPUT PANEL STYLES (Appended)
   ========================================= */

.output-panel {
    background: rgba(15, 15, 15, 0.98);
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 8px;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 0 20px rgba(255, 147, 41, 0.05), inset 0 0 0 1px rgba(255, 147, 41, 0.1);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    overflow: hidden;
}

.output-panel:hover {
    box-shadow: 0 0 25px rgba(255, 147, 41, 0.1), inset 0 0 0 1px rgba(255, 147, 41, 0.2);
}

.output-panel.active-response {
    box-shadow: 0 0 30px rgba(255, 147, 41, 0.2), inset 0 0 0 1px rgba(255, 147, 41, 0.4);
    border-color: rgba(255, 147, 41, 0.5);
    animation: responsePulse 1.5s infinite alternate;
}

@keyframes responsePulse {
    from {
        box-shadow: 0 0 20px rgba(255, 147, 41, 0.15), inset 0 0 0 1px rgba(255, 147, 41, 0.2);
    }

    to {
        box-shadow: 0 0 40px rgba(255, 147, 41, 0.4), inset 0 0 0 1px rgba(255, 147, 41, 0.6);
    }
}

.output-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

/* Scoped Log Entries */
.log-entry {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 2px;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.log-entry:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateX(1px);
}

.log-entry.user-query {
    border-left-color: #4a9eff;
    background: rgba(74, 158, 255, 0.04);
}

.log-entry.system-response {
    border-left-color: #ff9329;
    background: rgba(255, 147, 41, 0.04);
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    padding-bottom: 4px;
}

.log-timestamp {
    font-size: 8px;
    color: #666;
    font-family: monospace;
}

.log-type-badge {
    font-size: 8px;
    text-transform: uppercase;
    font-weight: bold;
    color: #888;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 4px;
    border-radius: 2px;
}

.log-content {
    font-size: 11px;
    color: #ddd;
    line-height: 1.5;
    font-family: 'Inter', sans-serif;
}

.panel-title {
    color: #eee;
    /* Brighter title */
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* Message Stream Footer and Actions */
.msg-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.msg-read-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 10px;
    opacity: 0.5;
    transition: opacity 0.2s;
    padding: 2px 4px;
}

.msg-read-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* =========================================
   OUTPUT PANEL TABS
   ========================================= */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.panel-tabs {
    display: flex;
    gap: 0;
}

.panel-tab {
    background: transparent;
    border: none;
    color: #666;
    font-size: 10px;
    font-family: monospace;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.panel-tab:hover {
    color: #aaa;
    background: rgba(255, 255, 255, 0.02);
}

.panel-tab.active {
    color: #ff9329;
    border-bottom-color: #ff9329;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Compact selectors for output panel */
.model-select-compact,
.lang-selector-compact {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 147, 41, 0.3);
    border-radius: 4px;
    color: #ff9329;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    outline: none;
}

.model-select-compact {
    min-width: 100px;
}

.lang-selector-compact {
    min-width: 50px;
}

.model-select-compact:hover,
.lang-selector-compact:hover {
    border-color: #ff9329;
}

.model-select-compact option,
.lang-selector-compact option {
    background: #1a1a1a;
    color: #ddd;
}

.panel-btn {
    background: transparent;
    border: none;
    color: #555;
    font-size: 14px;
    padding: 6px 8px;
    cursor: pointer;
    transition: color 0.15s ease;
}

.panel-btn:hover {
    color: #ff9329;
}

.output-tab-content {
    display: none;
    height: 100%;
    overflow: hidden;
}

.output-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* =========================================
   TERMINAL TAB
   ========================================= */
.terminal-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.term-btn {
    background: rgba(255, 147, 41, 0.1);
    border: 1px solid rgba(255, 147, 41, 0.2);
    color: #ff9329;
    font-size: 10px;
    padding: 6px 10px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.term-btn:hover {
    background: rgba(255, 147, 41, 0.2);
}

.term-select {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #aaa;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    outline: none;
}

.terminal-container {
    flex: 1;
    background: #0d1117;
    overflow: hidden;
    padding: 4px;
}

/* xterm.js overrides */
.terminal-container .xterm {
    height: 100%;
}

.terminal-container .xterm-viewport {
    background: #0d1117 !important;
}

/* =========================================
   CODE EDITOR TAB
   ========================================= */
.code-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.code-select {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #aaa;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    outline: none;
}

.code-btn {
    background: rgba(255, 147, 41, 0.1);
    border: 1px solid rgba(255, 147, 41, 0.2);
    color: #ff9329;
    font-size: 10px;
    padding: 6px 10px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.code-btn:hover {
    background: rgba(255, 147, 41, 0.2);
}

.code-editor {
    flex: 1;
    background: #0d1117;
    color: #c9d1d9;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 12px;
    line-height: 1.5;
    padding: 12px;
    border: none;
    resize: none;
    outline: none;
    overflow: auto;
}

.code-editor::placeholder {
    color: #484f58;
}

/* =========================================
   EXPANDED PANEL STATE
   ========================================= */
.output-panel.expanded {
    position: fixed;
    top: 52px;
    left: 50%;
    right: 12px;
    bottom: 12px;
    z-index: 100;
    width: auto;
}

/* =========================================
   RETRY BUTTON
   ========================================= */
.retry-btn {
    background: linear-gradient(135deg, rgba(255, 147, 41, 0.2), rgba(255, 147, 41, 0.1));
    border: 1px solid rgba(255, 147, 41, 0.4);
    border-radius: 6px;
    color: #ff9329;
    font-size: 10px;
    font-weight: 600;
    padding: 5px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.retry-btn:hover {
    background: linear-gradient(135deg, rgba(255, 147, 41, 0.3), rgba(255, 147, 41, 0.2));
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 147, 41, 0.2);
}

/* =========================================
   DOCS TAB (Real-time generation view)
   ========================================= */
.docs-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
}

.docs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.docs-title {
    font-size: 12px;
    font-weight: 600;
    color: #ff9329;
}

.docs-status {
    font-size: 10px;
    color: #666;
    font-style: italic;
}

.docs-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 13px;
    line-height: 1.6;
    color: #ddd;
}

.docs-placeholder {
    text-align: center;
    padding: 40px 20px;
    color: #555;
}

.docs-placeholder p {
    margin: 8px 0;
}

.docs-placeholder .hint {
    font-size: 11px;
    color: #444;
}

/* =========================================
   RETRY MODEL GROUP
   ========================================= */
.retry-model-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.retry-model-dropdown {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #888;
    font-size: 10px;
    padding: 5px 8px;
    cursor: pointer;
    outline: none;
    max-width: 140px;
}

.retry-model-dropdown:focus {
    border-color: rgba(255, 147, 41, 0.4);
}

.retry-model-dropdown option {
    background: #1a1a1a;
    color: #ddd;
}

.retry-model-dropdown option:disabled {
    color: #555;
}

.same-model-option {
    color: #666 !important;
    font-style: italic;
}