/* Import font for better Unicode support */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Session Selection Styles */
.session-selection {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #1a1a1a;
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

.session-selection-container {
    background: #2d2d2d;
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid #404040;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.session-selection h2 {
    color: #ffffff;
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 1.8rem;
}

.session-selection .user-info {
    text-align: center;
    color: #cccccc;
    margin-bottom: 2rem;
    font-size: 1rem;
}

.session-selection h3 {
    color: #ffffff;
    margin-bottom: 1rem;
    margin-top: 2rem;
    font-size: 1.2rem;
    border-bottom: 1px solid #404040;
    padding-bottom: 0.5rem;
}

.existing-sessions {
    margin-bottom: 2rem;
}

.session-option {
    background: #1a1a1a;
    border: 2px solid #404040;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.session-option:hover {
    border-color: #0078d4;
    background: #252526;
}

.session-option .session-name {
    font-weight: 600;
    color: #ffffff;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.session-option .session-info {
    color: #cccccc;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.session-option .session-status {
    position: absolute;
    top: 1rem;
    right: 1rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.session-option .session-status.active {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

.session-option .session-status.inactive {
    background: rgba(255, 152, 0, 0.2);
    color: #ff9800;
    border: 1px solid rgba(255, 152, 0, 0.3);
}

.new-session-section {
    background: #252526;
    border-radius: 8px;
    padding: 1.5rem;
    border: 1px solid #404040;
}

.new-session-section .form-group {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.new-session-section input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #404040;
    border-radius: 6px;
    background: #1a1a1a;
    color: #e0e0e0;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.new-session-section input:focus {
    outline: none;
    border-color: #0078d4;
}

.new-session-section button {
    background: #0078d4;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.new-session-section button:hover {
    background: #106ebe;
}

.session-actions {
    margin-top: 2rem;
    text-align: center;
}

.session-actions button {
    background: #404040;
    color: #e0e0e0;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.session-actions button:hover {
    background: #555555;
}

/* Minimal header */
.minimal-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: rgba(45, 45, 45, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 100;
    border-bottom: 1px solid #404040;
    gap: 1rem;
}

.hamburger-menu {
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    position: relative;
}

.hamburger-menu:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-menu {
    position: absolute;
    top: 40px;
    left: 0;
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 101;
    min-width: 150px;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    color: #e0e0e0;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #404040;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

#session-name-header {
    color: #cccccc;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Full-screen terminal layout */
.terminal-area-full {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding-top: 40px; /* Account for minimal header */
}

.terminal-area-full .terminal-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.terminal-area-full #terminal {
    flex: 1;
    height: 100%;
}

/* Error toast */
.error-toast {
    position: fixed;
    top: 50px;
    right: 1rem;
    background: #d32f2f;
    color: white;
    padding: 1rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 300px;
    display: none;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: #2d2d2d;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #404040;
    flex-wrap: wrap;
    gap: 0.5rem;
}

header h1 {
    color: #ffffff;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.controls button {
    background: #0078d4;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    margin-left: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 44px;
    touch-action: manipulation;
}

.controls button:hover {
    background: #106ebe;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 300px;
    background: #252526;
    border-right: 1px solid #404040;
    padding: 1rem;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 10;
}

.sidebar.mobile-hidden {
    transform: translateX(-100%);
}

.mobile-sidebar-toggle {
    display: none;
    background: #0078d4;
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 20;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 5;
}

.sidebar h3 {
    margin-bottom: 1rem;
    color: #ffffff;
    font-size: 1.1rem;
}

.session-item {
    background: #2d2d30;
    border: 1px solid #404040;
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    touch-action: manipulation;
}

.session-item:hover {
    background: #37373d;
    border-color: #0078d4;
}

.session-item.active {
    background: #0078d4;
    border-color: #0078d4;
}

.session-item.disconnected {
    opacity: 0.6;
    border-color: #ff6b6b;
}

.session-name {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 0.25rem;
}

.session-info {
    font-size: 0.8rem;
    color: #cccccc;
}

.session-status {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.session-status.connected {
    background: #4caf50;
    color: white;
}

.session-status.disconnected {
    background: #ff6b6b;
    color: white;
}

.terminal-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.no-session {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.no-session h3 {
    color: #ffffff;
    margin-bottom: 1rem;
}

.no-session p {
    color: #cccccc;
}

.terminal-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.terminal-header {
    background: #2d2d2d;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #404040;
}

.terminal-header span {
    color: #ffffff;
    font-weight: 600;
}

.terminal-controls button {
    background: #ff4444;
    color: white;
    border: none;
    padding: 0.5rem 0.75rem;
    margin-left: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    min-height: 44px;
    touch-action: manipulation;
}

.terminal-controls button:first-child {
    background: #ffa500;
}

.terminal-controls button:hover {
    opacity: 0.8;
}

#terminal {
    flex: 1;
    background: #000000;
    padding: 0.5rem;
    overflow: hidden;
    min-height: 300px;
    max-width: 100%;
}

/* Ensure proper font loading for Unicode characters */
#terminal .xterm-screen {
    font-feature-settings: "liga" 0;
}

#terminal .xterm-char-measure-element {
    font-family: "JetBrains Mono", "SF Mono", Monaco, Consolas, "Liberation Mono", "DejaVu Sans Mono", "Courier New", monospace;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
}

.modal-content {
    background-color: #2d2d2d;
    margin: 15% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    color: #ffffff;
    margin-bottom: 1rem;
}

.modal-content label {
    display: block;
    color: #e0e0e0;
    margin-bottom: 0.5rem;
}

.modal-content input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #404040;
    border-radius: 4px;
    background: #1a1a1a;
    color: #e0e0e0;
    margin-bottom: 1rem;
    font-size: 16px;
    min-height: 44px;
    box-sizing: border-box;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.modal-buttons button {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    min-height: 44px;
    touch-action: manipulation;
}

.modal-buttons button:first-child {
    background: #0078d4;
    color: white;
}

.modal-buttons button:last-child {
    background: #6c757d;
    color: white;
}

.modal-buttons button:hover {
    opacity: 0.8;
}

/* Terminal theme adjustments */
.xterm {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.2;
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    .xterm {
        font-size: 12px;
    }
    
    .terminal-area {
        touch-action: pan-x pan-y;
    }
    
    .terminal-container {
        -webkit-overflow-scrolling: touch;
    }
}

.xterm-viewport {
    background-color: #000000 !important;
}

.xterm-screen {
    background-color: #000000 !important;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    body {
        font-size: 14px;
    }
    
    header {
        padding: 0.75rem;
        flex-direction: column;
        align-items: stretch;
    }
    
    header h1 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
        text-align: center;
    }
    
    .controls {
        display: flex;
        gap: 0.5rem;
        justify-content: center;
    }
    
    .controls button {
        flex: 1;
        margin-left: 0;
        font-size: 0.85rem;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        padding-top: 4rem;
        transform: translateX(-100%);
    }
    
    .sidebar.mobile-visible {
        transform: translateX(0);
    }
    
    .mobile-sidebar-toggle {
        display: block;
    }
    
    .mobile-sidebar-overlay.active {
        display: block;
    }
    
    .terminal-area {
        width: 100%;
        height: calc(100vh - 120px);
    }
    
    .terminal-header {
        padding: 0.5rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .terminal-header span {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .terminal-controls {
        display: flex;
        gap: 0.25rem;
    }
    
    .terminal-controls button {
        margin-left: 0;
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    #terminal {
        padding: 0.25rem;
        touch-action: manipulation;
    }
    
    .session-item {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .session-info {
        font-size: 0.85rem;
        line-height: 1.4;
    }
    
    .no-session {
        padding: 2rem;
        text-align: center;
    }
    
    .no-session h3 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }
    
    .no-session p {
        font-size: 0.9rem;
        line-height: 1.5;
    }
    
    .modal-content {
        margin: 10% auto;
        padding: 1.5rem;
        max-width: 95%;
    }
    
    .modal-content h3 {
        font-size: 1.1rem;
    }
    
    .modal-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .modal-buttons button {
        width: 100%;
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* Portrait mode specific adjustments */
@media (max-width: 480px) and (orientation: portrait) {
    header h1 {
        font-size: 1.1rem;
    }
    
    .controls button {
        padding: 0.6rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .sidebar {
        width: 260px;
    }
    
    .terminal-area {
        height: calc(100vh - 110px);
    }
    
    .xterm {
        font-size: 11px;
    }
    
    .session-item {
        padding: 0.75rem;
    }
    
    .session-info {
        font-size: 0.8rem;
    }
    
    .terminal-controls button {
        padding: 0.4rem 0.6rem;
        font-size: 0.7rem;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    header {
        padding: 0.5rem;
    }
    
    header h1 {
        font-size: 1rem;
        margin-bottom: 0.25rem;
    }
    
    .controls button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .terminal-area {
        height: calc(100vh - 90px);
    }
    
    .sidebar {
        width: 240px;
    }
    
    .xterm {
        font-size: 10px;
    }
}

/* Mobile hint visibility */
@media (max-width: 768px) {
    .mobile-hint {
        display: block;
        margin-top: 1rem;
        font-style: italic;
        color: #999;
    }
}

@media (min-width: 769px) {
    .mobile-hint {
        display: none;
    }
}


/* User info and authentication styles */
.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.username {
    color: #ffffff;
    font-weight: 600;
}

.session-count {
    color: #cccccc;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
}

.logout-btn {
    background: #ff4444;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    min-height: 44px;
    touch-action: manipulation;
}

.logout-btn:hover {
    background: #ff6666;
}

/* Session item enhancements */
.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.session-type {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: capitalize;
}

.session-actions {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #404040;
}

.view-logs-btn {
    background: #4caf50;
    color: white;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    min-height: 32px;
    touch-action: manipulation;
}

.view-logs-btn:hover {
    background: #66bb6a;
}

/* Session type select */
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #404040;
    border-radius: 4px;
    background: #1a1a1a;
    color: #e0e0e0;
    font-size: 16px;
    min-height: 44px;
    box-sizing: border-box;
}

.form-group select:focus {
    outline: none;
    border-color: #0078d4;
}

/* Logs modal */
.logs-modal {
    max-width: 80vw;
    max-height: 80vh;
    width: 800px;
}

.logs-content {
    background: #000000;
    color: #ffffff;
    padding: 1rem;
    border-radius: 4px;
    max-height: 60vh;
    overflow-y: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Error toast */
.error-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #ff6b6b;
    color: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 400px;
    display: none;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Mobile adjustments for new elements */
@media (max-width: 768px) {
    .user-info {
        gap: 0.5rem;
        font-size: 0.85rem;
    }
    
    .username {
        font-size: 0.9rem;
    }
    
    .session-count {
        font-size: 0.8rem;
        padding: 0.2rem 0.4rem;
    }
    
    .logout-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }
    
    .session-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .session-type {
        align-self: flex-end;
    }
    
    .logs-modal {
        max-width: 95vw;
        max-height: 90vh;
    }
    
    .logs-content {
        font-size: 11px;
        max-height: 50vh;
    }
    
    .error-toast {
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* Terminal scrolling improvements - don't override the main #terminal rule */

/* Ensure terminal viewport handles scrolling properly */
.xterm-viewport {
    overflow-y: auto !important;
    overflow-x: hidden;
}

.xterm-screen {
    background-color: #000000 !important;
}

/* Improve scrollbar styling */
.xterm-viewport::-webkit-scrollbar {
    width: 8px;
}

.xterm-viewport::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.xterm-viewport::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

.xterm-viewport::-webkit-scrollbar-thumb:hover {
    background: #777;
}

/* Mobile terminal scrolling */
@media (max-width: 768px) {
    .xterm-viewport {
        -webkit-overflow-scrolling: touch;
    }
}
