/* ===== TERMINAL STYLING ===== */
:root {
    /* Terminal Colors - Dark Theme */
    --terminal-bg: #1e1e1e;
    --terminal-fg: #d4d4d4;
    --terminal-cursor: #ffffff;
    --terminal-selection: #264f78;
    
    /* ANSI Colors */
    --terminal-black: #000000;
    --terminal-red: #cd3131;
    --terminal-green: #0dbc79;
    --terminal-yellow: #e5e510;
    --terminal-blue: #2472c8;
    --terminal-magenta: #bc3fbc;
    --terminal-cyan: #11a8cd;
    --terminal-white: #e5e5e5;
    
    /* Bright ANSI Colors */
    --terminal-bright-black: #666666;
    --terminal-bright-red: #f14c4c;
    --terminal-bright-green: #23d18b;
    --terminal-bright-yellow: #f5f543;
    --terminal-bright-blue: #3b8eea;
    --terminal-bright-magenta: #d670d6;
    --terminal-bright-cyan: #29b8db;
    --terminal-bright-white: #e5e5e5;
    
    /* Terminal Font */
    --terminal-font-family: 'Consolas', 'Liberation Mono', 'Menlo', 'Courier', monospace;
    --terminal-font-size: 14px;
    --terminal-line-height: 1.2;
}

/* Mobile Terminal Font Size */
@media (max-width: 768px) {
    :root {
        --terminal-font-size: 12px;
    }
}

/* Light Theme Terminal Colors */
.theme-light {
    --terminal-bg: #ffffff;
    --terminal-fg: #333333;
    --terminal-cursor: #000000;
    --terminal-selection: #add6ff;
    
    --terminal-black: #333333;
    --terminal-red: #cd3131;
    --terminal-green: #00bc00;
    --terminal-yellow: #949800;
    --terminal-blue: #0451a5;
    --terminal-magenta: #bc05bc;
    --terminal-cyan: #0598bc;
    --terminal-white: #000000;
}

/* ===== TERMINAL CONTAINER ===== */
.terminal-instance {
    width: 100%;
    height: 100%;
    background-color: var(--terminal-bg);
    position: relative;
    display: none;
    flex-direction: column;
}

.terminal-instance.active {
    display: flex;
}

.terminal-wrapper {
    flex: 1;
    padding: var(--spacing-sm);
    padding-bottom: calc(var(--spacing-sm) + 24px); /* Extra space for tmux status bar */
    overflow: hidden;
    position: relative;
    min-height: 0; /* Allow flex item to shrink below content size */
}

/* ===== XTERM.JS OVERRIDES ===== */
.xterm {
    height: 100%;
    width: 100%;
}

.terminal {
    height: 100%;
    width: 100%;
    display: block;
}

.xterm .xterm-viewport {
    background-color: var(--terminal-bg) !important;
    overflow-y: auto;
    width: 100% !important;
    height: 100% !important;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.xterm .xterm-screen {
    background-color: var(--terminal-bg) !important;
    width: 100% !important;
    height: 100% !important;
    display: block !important;
}

/* ===== TERMINAL LINE NUMBERS ===== */
.xterm .xterm-rows {
    /* Add padding-left to make room for line numbers */
    padding-left: 50px !important;
    position: relative !important;
    /* Initialize counter for fixed line numbers 1-45 */
    counter-reset: terminal-line 0 !important;
}

.xterm .xterm-rows > div {
    position: relative !important;
    /* Increment counter for each row */
    counter-increment: terminal-line !important;
    /* Allow line numbers to be visible outside the row bounds */
    overflow: visible !important;
}

.xterm .xterm-rows > div::before {
    /* Display fixed line number using CSS counter */
    content: counter(terminal-line) !important;
    position: absolute !important;
    left: -50px !important;
    top: 0 !important;
    width: 45px !important;
    text-align: right !important;
    padding-right: 5px !important;
    color: #d4d4d4 !important;
    opacity: 0.5 !important;
    font-family: 'Consolas', 'Liberation Mono', 'Menlo', 'Courier', monospace !important;
    font-size: inherit !important;
    line-height: inherit !important;
    background-color: #1e1e1e !important;
    border-right: 1px solid rgba(212, 212, 212, 0.2) !important;
    user-select: none !important;
    pointer-events: none !important;
    z-index: 1000 !important;
    display: block !important;
}

.xterm .xterm-helper-textarea {
    position: absolute;
    opacity: 0;
    left: -9999em;
    top: 0;
    width: 0;
    height: 0;
    z-index: -10;
    white-space: nowrap;
    overflow: hidden;
    resize: none;
}

.xterm .composition-view {
    background: var(--terminal-bg);
    color: var(--terminal-fg);
    display: none;
    position: absolute;
    white-space: nowrap;
    z-index: 1;
}

.xterm .composition-view.active {
    display: block;
}

.xterm .xterm-cursor {
    background-color: var(--terminal-cursor);
    color: var(--terminal-bg);
}

.xterm .xterm-cursor.xterm-cursor-blink {
    animation: xterm-cursor-blink 1.2s infinite step-end;
}

.xterm .xterm-cursor.xterm-cursor-wide {
    left: 0;
    line-height: 1;
    right: 0;
    top: 0;
}

@keyframes xterm-cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.xterm .xterm-selection {
    background-color: var(--terminal-selection) !important;
    opacity: 0.6;
}

.xterm.focus .xterm-selection {
    opacity: 0.8;
}

.xterm .xterm-bold {
    font-weight: bold;
}

.xterm .xterm-italic {
    font-style: italic;
}

.xterm .xterm-underline {
    text-decoration: underline;
}

.xterm .xterm-strikethrough {
    text-decoration: line-through;
}

.xterm .xterm-dim {
    opacity: 0.5;
}

/* ===== ANSI COLOR CLASSES ===== */
.xterm .xterm-color-0 { color: var(--terminal-black); }
.xterm .xterm-color-1 { color: var(--terminal-red); }
.xterm .xterm-color-2 { color: var(--terminal-green); }
.xterm .xterm-color-3 { color: var(--terminal-yellow); }
.xterm .xterm-color-4 { color: var(--terminal-blue); }
.xterm .xterm-color-5 { color: var(--terminal-magenta); }
.xterm .xterm-color-6 { color: var(--terminal-cyan); }
.xterm .xterm-color-7 { color: var(--terminal-white); }
.xterm .xterm-color-8 { color: var(--terminal-bright-black); }
.xterm .xterm-color-9 { color: var(--terminal-bright-red); }
.xterm .xterm-color-10 { color: var(--terminal-bright-green); }
.xterm .xterm-color-11 { color: var(--terminal-bright-yellow); }
.xterm .xterm-color-12 { color: var(--terminal-bright-blue); }
.xterm .xterm-color-13 { color: var(--terminal-bright-magenta); }
.xterm .xterm-color-14 { color: var(--terminal-bright-cyan); }
.xterm .xterm-color-15 { color: var(--terminal-bright-white); }

/* Background colors */
.xterm .xterm-bg-color-0 { background-color: var(--terminal-black); }
.xterm .xterm-bg-color-1 { background-color: var(--terminal-red); }
.xterm .xterm-bg-color-2 { background-color: var(--terminal-green); }
.xterm .xterm-bg-color-3 { background-color: var(--terminal-yellow); }
.xterm .xterm-bg-color-4 { background-color: var(--terminal-blue); }
.xterm .xterm-bg-color-5 { background-color: var(--terminal-magenta); }
.xterm .xterm-bg-color-6 { background-color: var(--terminal-cyan); }
.xterm .xterm-bg-color-7 { background-color: var(--terminal-white); }
.xterm .xterm-bg-color-8 { background-color: var(--terminal-bright-black); }
.xterm .xterm-bg-color-9 { background-color: var(--terminal-bright-red); }
.xterm .xterm-bg-color-10 { background-color: var(--terminal-bright-green); }
.xterm .xterm-bg-color-11 { background-color: var(--terminal-bright-yellow); }
.xterm .xterm-bg-color-12 { background-color: var(--terminal-bright-blue); }
.xterm .xterm-bg-color-13 { background-color: var(--terminal-bright-magenta); }
.xterm .xterm-bg-color-14 { background-color: var(--terminal-bright-cyan); }
.xterm .xterm-bg-color-15 { background-color: var(--terminal-bright-white); }

/* ===== TERMINAL STATUS BAR ===== */
.terminal-status {
    background-color: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-xs) var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    flex-shrink: 0;
    min-height: 32px; /* Ensure minimum height for status bar */
    width: 100%; /* Ensure full width */
}

.terminal-status-left,
.terminal-status-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.terminal-status-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.terminal-status-item .icon {
    font-size: var(--font-size-sm);
}

.terminal-status-item.success {
    color: var(--accent-success);
}

.terminal-status-item.warning {
    color: var(--accent-warning);
}

.terminal-status-item.error {
    color: var(--accent-danger);
}

/* ===== TERMINAL COMMAND PALETTE ===== */
.terminal-command-palette {
    position: absolute;
    top: var(--spacing-md);
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-dropdown);
    min-width: 400px;
    max-width: 600px;
    max-height: 300px;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(-10px);
    transition: all var(--transition-normal);
}

.terminal-command-palette.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.command-palette-input {
    width: 100%;
    padding: var(--spacing-md);
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: var(--font-size-md);
    outline: none;
    border-bottom: 1px solid var(--border-color);
}

.command-palette-input::placeholder {
    color: var(--text-muted);
}

.command-palette-results {
    max-height: 200px;
    overflow-y: auto;
}

.command-palette-item {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.command-palette-item:hover,
.command-palette-item.selected {
    background-color: var(--bg-hover);
}

.command-palette-item .icon {
    font-size: var(--font-size-md);
    opacity: 0.7;
}

.command-palette-item .title {
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.command-palette-item .description {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-left: auto;
}

/* ===== TERMINAL INPUT SUGGESTIONS ===== */
.terminal-suggestions {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
    max-height: 200px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
    display: none;
}

.terminal-suggestions.active {
    display: block;
}

.suggestion-item {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.suggestion-item:hover,
.suggestion-item.selected {
    background-color: var(--bg-hover);
}

.suggestion-icon {
    font-size: var(--font-size-sm);
    opacity: 0.7;
}

.suggestion-text {
    font-family: var(--terminal-font-family);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
}

.suggestion-description {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin-left: auto;
}

/* ===== TERMINAL SEARCH ===== */
.terminal-search {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--transition-normal);
}

.terminal-search.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.terminal-search input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    outline: none;
    width: 200px;
}

.terminal-search input::placeholder {
    color: var(--text-muted);
}

.terminal-search .btn {
    padding: var(--spacing-xs);
    min-height: auto;
    min-width: auto;
}

/* ===== TERMINAL SCROLLBAR STYLING ===== */
.xterm .xterm-viewport::-webkit-scrollbar {
    width: 8px;
}

.xterm .xterm-viewport::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 4px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
    transition: background-color var(--transition-fast);
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb:hover {
    background-color: var(--border-hover);
}

/* Light Theme Scrollbar Override */
.theme-light .xterm .xterm-viewport {
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.theme-light .xterm .xterm-viewport::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
}

.theme-light .xterm .xterm-viewport::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.3);
}

/* ===== TERMINAL LINKS ===== */
.terminal-link {
    color: var(--accent-primary) !important;
    text-decoration: underline;
    cursor: pointer;
}

.terminal-link:hover {
    color: var(--accent-secondary) !important;
}

/* ===== TERMINAL OUTPUT FORMATTING ===== */
.terminal-wrapper .output-group {
    margin-bottom: var(--spacing-sm);
}

.terminal-wrapper .command-output {
    white-space: pre-wrap;
    font-family: var(--terminal-font-family);
    font-size: var(--terminal-font-size);
    line-height: var(--terminal-line-height);
}

.terminal-wrapper .error-output {
    color: var(--terminal-red);
}

.terminal-wrapper .success-output {
    color: var(--terminal-green);
}

.terminal-wrapper .warning-output {
    color: var(--terminal-yellow);
}

/* ===== TERMINAL THEMES ===== */
.terminal-theme-high-contrast {
    --terminal-bg: #000000;
    --terminal-fg: #ffffff;
    --terminal-cursor: #ffffff;
    --terminal-selection: #ffffff;
}

.terminal-theme-solarized-dark {
    --terminal-bg: #002b36;
    --terminal-fg: #839496;
    --terminal-cursor: #93a1a1;
    --terminal-selection: #073642;
    
    --terminal-black: #073642;
    --terminal-red: #dc322f;
    --terminal-green: #859900;
    --terminal-yellow: #b58900;
    --terminal-blue: #268bd2;
    --terminal-magenta: #d33682;
    --terminal-cyan: #2aa198;
    --terminal-white: #eee8d5;
}

.terminal-theme-solarized-light {
    --terminal-bg: #fdf6e3;
    --terminal-fg: #657b83;
    --terminal-cursor: #586e75;
    --terminal-selection: #eee8d5;
    
    --terminal-black: #073642;
    --terminal-red: #dc322f;
    --terminal-green: #859900;
    --terminal-yellow: #b58900;
    --terminal-blue: #268bd2;
    --terminal-magenta: #d33682;
    --terminal-cyan: #2aa198;
    --terminal-white: #eee8d5;
}

.terminal-theme-monokai {
    --terminal-bg: #272822;
    --terminal-fg: #f8f8f2;
    --terminal-cursor: #f8f8f2;
    --terminal-selection: #49483e;
    
    --terminal-black: #272822;
    --terminal-red: #f92672;
    --terminal-green: #a6e22e;
    --terminal-yellow: #f4bf75;
    --terminal-blue: #66d9ef;
    --terminal-magenta: #ae81ff;
    --terminal-cyan: #a1efe4;
    --terminal-white: #f8f8f2;
}

/* ===== TERMINAL RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    :root {
        --terminal-font-size: 12px;
    }
    
    .terminal-command-palette {
        min-width: 300px;
        max-width: calc(100vw - var(--spacing-lg));
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        transform: none;
    }
    
    .terminal-command-palette.active {
        transform: none;
    }
    
    .terminal-search {
        position: relative;
        top: auto;
        right: auto;
        margin-bottom: var(--spacing-sm);
        opacity: 1;
        visibility: visible;
        transform: none;
    }
    
    .terminal-search input {
        width: 150px;
    }
    
    .terminal-status {
        flex-direction: column;
        gap: var(--spacing-xs);
        align-items: flex-start;
    }
    
    .terminal-status-left,
    .terminal-status-right {
        width: 100%;
        justify-content: space-between;
    }
}

@media (max-width: 480px) {
    :root {
        --terminal-font-size: 11px;
    }
    
    .terminal-wrapper {
        padding: var(--spacing-xs);
        padding-bottom: calc(var(--spacing-xs) + 20px); /* Extra space for tmux status bar on mobile */
    }
    
    .terminal-suggestions {
        max-height: 150px;
    }
    
    .command-palette-input {
        padding: var(--spacing-sm);
        font-size: var(--font-size-sm);
    }
    
    /* Hide line numbers on very small screens to save space */
    .xterm .xterm-rows {
        padding-left: 0;
    }
    
    .xterm .xterm-rows > div::before {
        display: none;
    }
}

/* ===== TERMINAL ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
    .xterm .xterm-cursor.xterm-cursor-blink {
        animation: none;
        opacity: 1;
    }
    
    .terminal-command-palette,
    .terminal-search {
        transition: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .xterm {
        filter: contrast(150%);
    }
    
    .terminal-status {
        border-top-width: 2px;
    }
    
    .terminal-command-palette {
        border-width: 2px;
    }
}

/* ===== TERMINAL PERFORMANCE OPTIMIZATIONS ===== */
.xterm .xterm-rows {
    will-change: transform;
}

.xterm .xterm-viewport {
    contain: strict;
}

.terminal-wrapper {
    contain: layout style paint;
}

/* ===== MOBILE TERMINAL OPTIMIZATIONS ===== */
@media (max-width: 768px) {
    /* Improve terminal readability on mobile */
    .xterm {
        font-size: var(--terminal-font-size) !important;
        line-height: 1.4;
    }
    
    /* Terminal instance spacing */
    .terminal-instance {
        padding: 0;
    }
    
    /* Terminal status bar mobile adjustments */
    .terminal-status {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: var(--font-size-xs);
    }
    
    .terminal-status-actions {
        gap: var(--spacing-xs);
    }
    
    .terminal-status-actions .btn {
        padding: var(--spacing-xs);
        min-width: 32px;
        min-height: 32px;
    }
    
    /* Hide less important status items on mobile */
    .terminal-status-item:not(:first-child) {
        display: none;
    }
    
    /* Command palette mobile */
    .terminal-command-palette {
        max-height: 50vh;
    }
    
    .terminal-command-item {
        padding: var(--spacing-md);
        min-height: 44px;
    }
    
    /* Reduce line number width on mobile */
    .xterm .xterm-rows {
        padding-left: 35px;
    }
    
    .xterm .xterm-rows > div::before {
        left: -35px;
        width: 30px;
        font-size: 10px;
    }
}

/* Touch-friendly terminal interactions */
@media (pointer: coarse) {
    /* Larger touch targets for terminal controls */
    .terminal-controls button {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Prevent accidental text selection */
    .terminal-wrapper {
        -webkit-user-select: none;
        user-select: none;
    }
    
    .xterm .xterm-screen {
        -webkit-user-select: text;
        user-select: text;
    }
}

/* ===== TERMINAL SCROLL CONTROLS ===== */
.terminal-scroll-controls {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

.scroll-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    user-select: none;
    -webkit-user-select: none;
    /* Enhanced mobile keyboard prevention */
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-modify: read-only;
    pointer-events: auto;
    /* Force non-focusable behavior */
    outline: none !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.scroll-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.scroll-btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.scroll-btn:focus {
    /* Disable focus outline to prevent mobile keyboard popup */
    outline: none;
    /* Add subtle visual feedback instead */
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

/* Specific button styling */
.scroll-up {
    background-color: rgba(28, 128, 56, 0.8);
}

.scroll-down {
    background-color: rgba(28, 128, 56, 0.8);
}

.scroll-up:hover {
    background-color: rgba(28, 128, 56, 1);
}

.scroll-down:hover {
    background-color: rgba(28, 128, 56, 1);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .terminal-scroll-controls {
        right: 10px;
        gap: 8px;
    }
    
    .scroll-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
}

/* Hide old scroll buttons completely since we now have mobile terminal controls */
.terminal-scroll-controls {
    display: none !important;
}

/* Touch device optimizations for mobile devices */
@media (max-width: 1023px) and (pointer: coarse) {
    .scroll-btn {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
    
    /* Prevent focus and keyboard popup on mobile */
    .scroll-btn:focus {
        outline: none !important;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Prevent touch scroll on buttons */
    .terminal-scroll-controls {
        touch-action: manipulation;
    }
}

/* Fallback for devices that don't support pointer queries */
@media (max-width: 1023px) {
    .scroll-btn {
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
    
    /* Prevent focus and keyboard popup on mobile devices */
    .scroll-btn:focus {
        outline: none !important;
        -webkit-user-select: none;
        user-select: none;
    }
    
    .terminal-scroll-controls {
        touch-action: manipulation;
    }
}

/* Dark theme adjustments */
.theme-dark .scroll-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.theme-dark .scroll-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Light theme adjustments */
.theme-light .scroll-btn {
    background: rgba(0, 0, 0, 0.8);
    color: white;
}

.theme-light .scroll-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

/* ===== COPY MODE EXIT BUTTON ===== */
.copy-mode-exit-button {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 9999;
    pointer-events: auto;
}

.exit-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(30, 144, 255, 0.9);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(30, 144, 255, 0.3);
    user-select: none;
    -webkit-user-select: none;
    min-height: 48px;
    white-space: nowrap;
}

.exit-btn:hover {
    background: rgba(30, 144, 255, 1);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(30, 144, 255, 0.4);
}

.exit-btn:active {
    transform: translateY(0);
    transition: transform 0.1s ease;
}

.exit-btn:focus {
    outline: 2px solid var(--accent-color, #007acc);
    outline-offset: 2px;
}

.exit-btn-icon {
    font-size: 18px;
    line-height: 1;
}

.exit-btn-text {
    font-size: 14px;
    line-height: 1;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .copy-mode-exit-button {
        right: 10px;
        bottom: 70px;
    }
    
    .exit-btn {
        padding: 14px 18px;
        font-size: 15px;
        min-height: 52px;
    }
    
    .exit-btn-icon {
        font-size: 20px;
    }
    
    .exit-btn-text {
        font-size: 15px;
    }
}

/* Touch device optimizations */
@media (pointer: coarse) {
    .exit-btn {
        padding: 16px 20px;
        min-height: 56px;
    }
    
    .copy-mode-exit-button {
        touch-action: manipulation;
    }
}

/* Dark theme adjustments */
.theme-dark .exit-btn {
    background: rgba(30, 144, 255, 0.8);
    border: 1px solid rgba(30, 144, 255, 0.3);
}

.theme-dark .exit-btn:hover {
    background: rgba(30, 144, 255, 1);
}

/* Light theme adjustments */
.theme-light .exit-btn {
    background: rgba(30, 144, 255, 0.9);
}

.theme-light .exit-btn:hover {
    background: rgba(30, 144, 255, 1);
}

/* ===== MOBILE TERMINAL CONTROLS ===== */
.mobile-terminal-controls {
    position: fixed;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: none; /* Hidden by default, shown on mobile */
    flex-direction: column;
    gap: 6px;
    z-index: 1000;
    background: rgba(18, 18, 18, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 8px 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    /* Enhanced mobile keyboard prevention for container */
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
    /* Smooth transition for collapse/expand - include all changing properties */
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                padding 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                background-color 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                backdrop-filter 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                border 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                box-shadow 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Collapsed state - show only toggle button */
.mobile-terminal-controls.collapsed {
    /* Position only the toggle button area */
    width: 28px;
    padding: 0;
    background: transparent;
    border: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    transform: translateY(-50%) translateX(calc(100% - 28px));
}

.mobile-terminal-controls.collapsed .mobile-controls-content {
    display: none;
}

.mobile-terminal-controls.collapsed .mobile-controls-toggle {
    position: static;
    left: auto;
    top: auto;
    transform: none;
    width: 28px;
    height: 50px;
    background: rgba(18, 18, 18, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Expanded state - show full controls */
.mobile-terminal-controls.expanded {
    width: auto;
    padding: 8px 4px;
    background: rgba(18, 18, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transform: translateY(-50%) translateX(0);
}

.mobile-terminal-controls.expanded .mobile-controls-content {
    display: flex;
}

.mobile-terminal-controls.expanded .mobile-controls-toggle {
    position: absolute;
    left: -28px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 50px;
    background: rgba(18, 18, 18, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-right: none;
    border-radius: 8px 0 0 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Toggle button - common styles */
.mobile-controls-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                height 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                border 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                backdrop-filter 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                border-radius 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    /* Prevent keyboard activation */
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* Hover states for toggle button */
.mobile-terminal-controls.collapsed .mobile-controls-toggle:hover,
.mobile-terminal-controls.expanded .mobile-controls-toggle:hover {
    background: rgba(32, 32, 32, 0.9) !important;
}

.mobile-terminal-controls.collapsed .mobile-controls-toggle:active,
.mobile-terminal-controls.expanded .mobile-controls-toggle:active {
    background: rgba(48, 48, 48, 0.9) !important;
}

.mobile-controls-toggle-icon {
    color: #ffffff;
    font-size: 18px;
    font-weight: bold;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                color 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    user-select: none !important;
    -webkit-user-select: none !important;
}

/* Controls content wrapper */
.mobile-controls-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-user-modify: read-only !important;
    -khtml-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    /* Prevent any focus on container */
    outline: none !important;
    -webkit-tap-highlight-color: transparent !important;
    /* Ensure container doesn't interfere with touch events */
    touch-action: manipulation !important;
}

.mobile-key-btn {
    width: 45px;
    height: 40px;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    text-align: center;
    line-height: 1;
    background: rgba(64, 64, 64, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* Enhanced mobile keyboard prevention */
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-modify: read-only !important;
    -khtml-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    pointer-events: auto !important;
    /* Force non-focusable behavior */
    outline: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    /* Prevent any form-like behavior */
    -webkit-writing-mode: horizontal-tb !important;
    writing-mode: horizontal-tb !important;
    /* Prevent text input capabilities */
    -webkit-text-size-adjust: none !important;
    text-size-adjust: none !important;
}

/* Different color themes for different button types */
.mobile-key-btn.page-up-btn, 
.mobile-key-btn.page-down-btn {
    background: rgba(59, 130, 246, 0.8); /* Blue - Page functions */
    border-color: rgba(59, 130, 246, 0.4);
}

.mobile-key-btn.arrow-up-btn, 
.mobile-key-btn.arrow-down-btn {
    background: rgba(34, 197, 94, 0.8); /* Green - Arrow keys */
    border-color: rgba(34, 197, 94, 0.4);
}

.mobile-key-btn.enter-btn {
    background: rgba(168, 85, 247, 0.8); /* Purple - Confirm action */
    border-color: rgba(168, 85, 247, 0.4);
}

.mobile-key-btn.escape-btn {
    background: rgba(239, 68, 68, 0.8); /* Red - Exit action */
    border-color: rgba(239, 68, 68, 0.4);
    font-size: 12px;
    font-weight: 600;
}

.mobile-key-btn.ctrl-c-btn {
    background: rgba(245, 101, 101, 0.8); /* Light red - Control action */
    border-color: rgba(245, 101, 101, 0.4);
    font-size: 10px;
    font-weight: 600;
}

/* Button interactions */
.mobile-key-btn:hover {
    transform: scale(1.05);
    opacity: 0.9;
}

.mobile-key-btn:active {
    transform: scale(0.95);
    opacity: 0.8;
    transition: all 0.1s ease;
}

.mobile-key-btn:focus,
.mobile-key-btn:focus-within,
.mobile-key-btn:focus-visible {
    outline: none !important;
    /* Enhanced mobile keyboard prevention on focus */
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    /* Force blur any focused state */
    filter: none !important;
    box-shadow: none !important;
}

/* Show mobile controls only on mobile devices */
@media (max-width: 768px) {
    .mobile-terminal-controls {
        display: flex !important;
    }
}

/* Adjustments for smaller screens */
@media (max-width: 480px) {
    .mobile-terminal-controls.expanded {
        right: 4px;
        gap: 4px;
        padding: 6px 3px;
    }
    
    .mobile-terminal-controls.collapsed {
        width: 24px;
        transform: translateY(-50%) translateX(calc(100% - 24px));
    }
    
    .mobile-terminal-controls.collapsed .mobile-controls-toggle {
        width: 24px;
        height: 45px;
        border-radius: 6px;
    }
    
    .mobile-terminal-controls.expanded .mobile-controls-toggle {
        left: -24px;
        width: 24px;
        height: 45px;
        border-radius: 6px 0 0 6px;
    }
    
    .mobile-controls-toggle-icon {
        font-size: 12px;
    }
    
    .mobile-key-btn {
        width: 42px;
        height: 36px;
        font-size: 14px;
    }
    
    .mobile-key-btn.escape-btn {
        font-size: 11px;
    }
}

/* Touch device optimizations */
@media (pointer: coarse) {
    .mobile-key-btn {
        width: 48px;
        height: 42px;
        font-size: 17px;
    }
    
    .mobile-terminal-controls.expanded {
        gap: 8px;
        padding: 10px 5px;
    }
    
    .mobile-terminal-controls.collapsed {
        width: 30px;
        transform: translateY(-50%) translateX(calc(100% - 30px));
    }
    
    .mobile-terminal-controls.collapsed .mobile-controls-toggle {
        width: 30px;
        height: 55px;
    }
    
    .mobile-terminal-controls.expanded .mobile-controls-toggle {
        width: 30px;
        height: 55px;
        left: -30px;
    }
}

/* Dark theme adjustments (default) */
.theme-dark .mobile-terminal-controls.expanded {
    background: rgba(18, 18, 18, 0.9);
    border-color: rgba(255, 255, 255, 0.15);
}

.theme-dark .mobile-terminal-controls.collapsed .mobile-controls-toggle,
.theme-dark .mobile-terminal-controls.expanded .mobile-controls-toggle {
    background: rgba(18, 18, 18, 0.9);
    border-color: rgba(255, 255, 255, 0.15);
}

.theme-dark .mobile-terminal-controls.collapsed .mobile-controls-toggle:hover,
.theme-dark .mobile-terminal-controls.expanded .mobile-controls-toggle:hover {
    background: rgba(32, 32, 32, 0.9) !important;
}

.theme-dark .mobile-terminal-controls.collapsed .mobile-controls-toggle:active,
.theme-dark .mobile-terminal-controls.expanded .mobile-controls-toggle:active {
    background: rgba(48, 48, 48, 0.9) !important;
}

.theme-dark .mobile-key-btn {
    color: white;
    background: rgba(64, 64, 64, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Light theme adjustments */
.theme-light .mobile-terminal-controls.expanded {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.15);
}

.theme-light .mobile-terminal-controls.collapsed .mobile-controls-toggle,
.theme-light .mobile-terminal-controls.expanded .mobile-controls-toggle {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.15);
}

.theme-light .mobile-terminal-controls.collapsed .mobile-controls-toggle:hover,
.theme-light .mobile-terminal-controls.expanded .mobile-controls-toggle:hover {
    background: rgba(240, 240, 240, 0.9) !important;
}

.theme-light .mobile-terminal-controls.collapsed .mobile-controls-toggle:active,
.theme-light .mobile-terminal-controls.expanded .mobile-controls-toggle:active {
    background: rgba(220, 220, 220, 0.9) !important;
}

.theme-light .mobile-controls-toggle-icon {
    color: #333333;
}

.theme-light .mobile-key-btn {
    color: white;
    /* Keep colored backgrounds for better visibility in light theme */
}

.theme-light .mobile-key-btn:not(.page-up-btn):not(.page-down-btn):not(.arrow-up-btn):not(.arrow-down-btn):not(.enter-btn):not(.escape-btn) {
    background: rgba(64, 64, 64, 0.9);
    border-color: rgba(64, 64, 64, 0.4);
}

/* Animation for button press feedback */
@keyframes mobile-key-press {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.mobile-key-btn.pressed {
    animation: mobile-key-press 0.15s ease;
}