/* Terminal Container */
.terminal-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background-color: #000;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    padding: 0;
    padding-top: env(safe-area-inset-top);
}

/* Session Loading */
.session-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #fff;
}

.loading-spinner {
    border: 4px solid #333;
    border-top: 4px solid #fff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

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

/* Session Error */
.session-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #f00;
    text-align: center;
}

    .session-error h3 {
        margin-bottom: 10px;
    }

    .session-error button {
        margin-top: 20px;
        padding: 10px 20px;
        background-color: #fff;
        color: #000;
        border: 1px solid #fff;
        cursor: pointer;
        font-family: 'Courier New', Courier, monospace;
        font-size: 14px;
    }

        .session-error button:hover {
            background-color: #ccc;
        }

/* Window Tabs */
.window-tabs {
    display: flex;
    background-color: #111;
    border-bottom: 2px solid #fff;
    padding: 5px 10px;
    gap: 5px;
}

.tab-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.tab-button {
    padding: 8px 16px;
    background-color: #222;
    color: #fff;
    border: 1px solid #fff;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    transition: all 0.2s;
}

    .tab-button:hover {
        background-color: #444;
    }

    .tab-button.active {
        background-color: #fff;
        color: #000;
        font-weight: bold;
    }

    .tab-button.add-button {
        background-color: #444;
        color: #fff;
        font-weight: bold;
        min-width: 40px;
    }

        .tab-button.add-button:hover {
            background-color: #666;
        }

.close-button {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 20px;
    height: 20px;
    background-color: #f00;
    color: #fff;
    border: 1px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    padding: 0;
    font-weight: bold;
    z-index: 10;
}

    .close-button:hover {
        background-color: #c00;
    }

/* Terminal Header */
.terminal-header {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    background-color: #111;
    border-bottom: 1px solid #fff;
}

.terminal-title {
    color: #fff;
    font-weight: bold;
}

.terminal-status {
    color: #fff;
}

/* Terminal Grid */
.terminal-grid-container {
    flex: 1;
    background-color: #008080;
    border: 2px solid #fff;
    margin: 10px;
    padding: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    outline: none;
    font-size: 16px;
    line-height: 1.2;
    letter-spacing: 0.05em;
    cursor: text;
    position: relative;
    white-space: nowrap;
}

    .terminal-grid-container:focus {
        border-color: #fff;
        box-shadow: 0 0 10px #fff;
    }

.terminal-row {
    display: flex;
    white-space: pre;
    height: 1.2em;
    width: fit-content;
    min-width: 100%;
}

.terminal-cell {
    display: inline-block;
    width: 0.6em;
    flex-shrink: 0;
    color: #fff;
    background-color: transparent;
}

    .terminal-cell.cursor {
        background-color: #fff;
        color: #000;
        animation: blink 1s step-end infinite;
    }

@keyframes blink {
    0%, 50% {
        background-color: #fff;
        color: #000;
    }

    51%, 100% {
        background-color: transparent;
        color: #fff;
    }
}

/* Mobile Keyboard Input */
.mobile-keyboard-input {
    position: absolute;
    border: none;
    background: transparent;
    color: transparent;
    caret-color: transparent;
    outline: none;
    font-size: 16px;
    font-family: 'Courier New', Courier, monospace;
    padding: 0;
    margin: 0;
    resize: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    pointer-events: auto;
}

    .mobile-keyboard-input:focus {
        outline: none;
        border: none;
    }

/* Error Message */
.error-message {
    margin: 10px;
    padding: 10px;
    background-color: #300;
    border: 1px solid #f00;
    color: #f00;
}

/* Scrollbar Styling */
.terminal-grid-container::-webkit-scrollbar {
    width: 8px;
}

.terminal-grid-container::-webkit-scrollbar-track {
    background: #111;
}

.terminal-grid-container::-webkit-scrollbar-thumb {
    background: #fff;
    border-radius: 4px;
}

    .terminal-grid-container::-webkit-scrollbar-thumb:hover {
        background: #ccc;
    }

/* Responsive Design */
@media (max-width: 768px) {
    .terminal-container {
        padding: 0;
    }

    .terminal-grid-container {
        font-size: 12px;
        margin: 5px;
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    .window-tabs {
        padding: 3px 5px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-button {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .close-button {
        width: 18px;
        height: 18px;
        font-size: 12px;
        line-height: 16px;
    }

    .terminal-header {
        padding: 8px;
        font-size: 12px;
        flex-wrap: wrap;
    }

    .terminal-title,
    .terminal-status {
        font-size: 11px;
    }

    .mobile-keyboard-input {
        font-size: 16px !important;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .terminal-grid-container {
        font-size: 11px;
        margin: 3px;
    }

    .window-tabs {
        padding: 2px 3px;
    }

    .tab-button {
        padding: 4px 8px;
        font-size: 11px;
        min-height: 36px;
    }

    .terminal-header {
        padding: 5px;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .terminal-container {
        height: -webkit-fill-available;
    }

    .mobile-keyboard-input {
        font-size: 16px !important;
    }
}

/* Prevent text selection on mobile (except input) */
@media (hover: none) and (pointer: coarse) {
    .terminal-grid-container {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    .mobile-keyboard-input {
        -webkit-user-select: text;
        user-select: text;
    }
}
/* Scrollable LOG window */
.log-window-content {
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px; /* Space for scrollbar */
    -webkit-overflow-scrolling: touch;
}

.log-row {
    display: flex;
    white-space: pre;
    height: 1.2em;
    width: fit-content;
    min-width: 100%;
}

    /* Optional: slightly dim older log lines for better readability */
    .log-row:nth-child(n+50) {
        opacity: 0.8;
    }

/* Custom scrollbar for LOG (matches your theme) */
.log-window-content::-webkit-scrollbar {
    width: 8px;
}

.log-window-content::-webkit-scrollbar-track {
    background: #111;
}

.log-window-content::-webkit-scrollbar-thumb {
    background: #fff;
    border-radius: 4px;
}

.log-window-content::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}