/**
 * Terminal Styles
 * Styles für das xterm.js Terminal und Offcanvas
 */

/* ==========================================================================
   Terminal Theme Variables
   ========================================================================== */

:root {
    /* Terminal Colors */
    --terminal-bg: #1e1e1e;
    --terminal-fg: #d4d4d4;
    --terminal-cursor: #d4d4d4;
    --terminal-selection: #264f78;

    /* ANSI Colors */
    --terminal-black: #1e1e1e;
    --terminal-red: #f44747;
    --terminal-green: #6a9955;
    --terminal-yellow: #dcdcaa;
    --terminal-blue: #569cd6;
    --terminal-magenta: #c586c0;
    --terminal-cyan: #4ec9b0;
    --terminal-white: #d4d4d4;

    /* Bright ANSI Colors */
    --terminal-bright-black: #808080;
    --terminal-bright-red: #f44747;
    --terminal-bright-green: #6a9955;
    --terminal-bright-yellow: #dcdcaa;
    --terminal-bright-blue: #569cd6;
    --terminal-bright-magenta: #c586c0;
    --terminal-bright-cyan: #4ec9b0;
    --terminal-bright-white: #ffffff;

    /* Terminal Settings */
    --terminal-font-size: 14px;
    --terminal-font-family: Consolas, "Courier New", monospace;
    --terminal-scrollback: 1000;
}

/* ==========================================================================
   Terminal Offcanvas (Bottom)
   ========================================================================== */

.terminal-offcanvas {
    --bs-offcanvas-height: auto;
    min-height: 150px;
    max-height: 80vh;
    transition: transform 0.3s ease-in-out;
    z-index: 9999 !important;
}


.offcanvas-backdrop.show {
    z-index: 9998 !important;
}

.terminal-offcanvas .offcanvas-header {
    background-color: var(--color-background-dark);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.terminal-offcanvas .offcanvas-title {
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.terminal-offcanvas .offcanvas-body {
    background-color: var(--terminal-bg);
    padding: 0;
    overflow: hidden;
}

.terminal-offcanvas .btn-close {
    filter: invert(1);
}

/* ==========================================================================
   Resize Handle
   ========================================================================== */

.terminal-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0.5rem;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-background-dark);
    z-index: 10;
}

.terminal-resize-handle:hover {
    background-color: var(--bs-primary);
}

.terminal-resize-grip {
    width: 3rem;
    height: 0.25rem;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 0.125rem;
}

.terminal-resize-handle:hover .terminal-resize-grip {
    background-color: rgba(255, 255, 255, 0.6);
}

.terminal-resize-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    cursor: ns-resize;
}

/* ==========================================================================
   Terminal Container
   ========================================================================== */

.terminal-container {
    height: 100%;
    width: 100%;
    padding: 0.5rem;
}

.terminal-container .xterm {
    height: 100%;
}

.terminal-container .xterm-viewport {
    overflow-y: auto !important;
}

/* ==========================================================================
   Terminal Header Controls
   ========================================================================== */

.terminal-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.terminal-controls .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.terminal-server-select {
    min-width: 12rem;
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.terminal-server-select:focus {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: var(--bs-primary);
    color: #fff;
}

.terminal-server-select:disabled {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.5);
    opacity: 1;
}

.terminal-server-select option {
    background-color: var(--color-background-dark);
    color: #fff;
}

/* ==========================================================================
   Connection Status Badge
   ========================================================================== */

.terminal-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
}

.terminal-status-connected {
    background-color: rgba(106, 153, 85, 0.2);
    color: #6a9955;
}

.terminal-status-disconnected {
    background-color: rgba(244, 71, 71, 0.2);
    color: #f44747;
}

.terminal-status-connecting {
    background-color: rgba(220, 220, 170, 0.2);
    color: #dcdcaa;
}

.terminal-status-indicator {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: currentColor;
}

.terminal-status-connecting .terminal-status-indicator {
    animation: pulse 1s infinite;
}

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

/* ==========================================================================
   Session Tabs
   ========================================================================== */

.terminal-tabs {
    display: flex;
    background-color: var(--color-background-dark);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0 0.5rem;
    gap: 0.25rem;
    overflow-x: auto;
}

.terminal-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 0.375rem 0.375rem 0 0;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
    white-space: nowrap;
    transition: all 0.15s ease-in-out;
}

.terminal-tab:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.terminal-tab.active {
    background-color: var(--terminal-bg);
    color: #fff;
}

.terminal-tab-indicator {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.terminal-tab-indicator.connected {
    background-color: var(--terminal-green);
}

.terminal-tab-indicator.disconnected {
    background-color: var(--terminal-red);
}

.terminal-tab-name {
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.terminal-tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border-radius: 0.25rem;
    transition: all 0.15s ease-in-out;
}

.terminal-tab-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.terminal-tab-close .material-symbols-outlined {
    font-size: 1rem;
}

/* ==========================================================================
   Welcome Screen
   ========================================================================== */

.terminal-welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--terminal-fg);
    text-align: center;
    padding: 2rem;
}

.terminal-welcome-content {
    opacity: 0.7;
}

.terminal-welcome .material-symbols-outlined {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--bs-primary);
}

.terminal-welcome h5 {
    margin-bottom: 0.5rem;
    color: #fff;
}

.terminal-welcome p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* ==========================================================================
   Toggle Button in Titlebar
   ========================================================================== */

.terminal-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.375rem;
    background-color: transparent;
    border: none;
    color: var(--bs-primary);
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

.terminal-toggle-btn:hover {
    background-color: rgba(111, 27, 194, 0.1);
    color: var(--bs-primary);
}

.terminal-toggle-btn.active {
    background-color: var(--bs-primary);
    color: #fff;
}

/* ==========================================================================
   Body Adjustment when Terminal is Open
   ========================================================================== */

body.terminal-open .page-body {
    /* Reduce the height and make it scrollable so content doesn't extend behind the terminal */
    max-height: calc(100vh - 3.5rem - var(--terminal-canvas-height, 300px));
    min-height: auto;
    overflow-y: auto;
}

/* ==========================================================================
   New Session Button
   ========================================================================== */

.terminal-new-session-btn {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.terminal-new-session-btn .spinner-border {
    flex-shrink: 0;
}

/* ==========================================================================
   Font Size Controls
   ========================================================================== */

.terminal-font-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

.terminal-font-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    line-height: 1;
}

.terminal-font-btn .material-symbols-outlined {
    font-size: 1.25rem;
}

/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 767.98px) {
    .terminal-offcanvas .offcanvas-header {
        padding: 0.5rem;
    }

    .terminal-controls {
        flex: 1;
        display: flex;
        gap: 0.5rem;
    }

    .terminal-server-select {
        flex: 1;
        min-width: 0;
    }

    .terminal-new-session-btn {
        flex-shrink: 0;
    }
}
