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

:root {
    --bg-dark: #1a1a2e;
    --bg-darker: #16162a;
    --bg-panel: #0f0f1a;
    --bg-sidebar: #12121f;
    --bg-tab: #1e1e3a;
    --bg-tab-active: #2d2d5a;
    --bg-input: #1e1e38;
    --border-color: #2a2a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #8888aa;
    --text-muted: #555577;
    --accent-blue: #4a9eff;
    --accent-green: #4ade80;
    --accent-yellow: #fbbf24;
    --accent-orange: #fb923c;
    --accent-red: #f87171;
    --accent-purple: #a78bfa;
    --accent-cyan: #22d3ee;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    /* Use dynamic viewport height for mobile (includes keyboard) */
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior-y: none;
}

/* Fallback for browsers that don't support dvh */
@supports not (height: 100dvh) {
    body {
        height: 100vh;
    }
}

/* ========== Top Menu Bar ========== */
.menu-bar {
    background: linear-gradient(180deg, #2a2a4a 0%, #1e1e3a 100%);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    height: 32px;
}

.menu-item {
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.15s;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.menu-item:hover {
    background: rgba(74, 158, 255, 0.2);
    color: var(--text-primary);
}

.menu-spacer {
    flex: 1;
}

/* ── Combined top-right status bar (SLS + Remote Share) ── */
.top-status-bar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px 6px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    margin-right: 4px;
}

.top-status-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 7px;
    border-radius: 8px;
    transition: background 0.15s;
    user-select: none;
    -webkit-user-select: none;
}

.top-status-indicator:hover {
    background: rgba(255, 255, 255, 0.07);
}

.top-status-divider {
    width: 1px;
    height: 14px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 2px;
}

.top-status-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.top-status-icon {
    font-size: 11px;
    line-height: 1;
    opacity: 0.7;
}

/* ── Dot shared by both indicators ── */
.top-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);   /* grey = unknown / disconnected */
    flex-shrink: 0;
    transition: background 0.3s;
}

.top-status-dot.online {
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    animation: top-dot-pulse 2s ease-in-out infinite;
}

.top-status-dot.offline {
    background: var(--accent-yellow);
    box-shadow: 0 0 4px var(--accent-yellow);
    animation: none;
}

.top-status-dot.checking {
    background: var(--accent-orange);
    animation: top-dot-blink 0.8s ease-in-out infinite;
}

@keyframes top-dot-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.7); }
    50%  { box-shadow: 0 0 0 5px rgba(34, 197, 94, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0);   }
}

@keyframes top-dot-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

/* Legacy .status-dot kept for modal internals (cloud-modal status row) */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.status-dot.online {
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
}
.status-dot.offline {
    background: var(--accent-yellow);
    box-shadow: 0 0 6px var(--accent-yellow);
}
.status-dot.checking {
    background: var(--accent-orange);
    animation: top-dot-blink 0.8s ease-in-out infinite;
}


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

/* ========== Toolbar ========== */
.toolbar {
    background: var(--bg-darker);
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid var(--border-color);
}

.toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 60px;
}

.toolbar-btn:hover {
    background: rgba(74, 158, 255, 0.15);
    border-color: var(--accent-blue);
}

.toolbar-btn.active {
    background: rgba(34, 197, 94, 0.2);
    border-color: var(--accent-green);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.4), inset 0 0 20px rgba(34, 197, 94, 0.1);
}

.toolbar-btn.active:hover {
    background: rgba(34, 197, 94, 0.3);
}

.toolbar-btn.active .label {
    color: var(--accent-green);
    font-weight: 600;
}

.toolbar-btn.active .icon {
    animation: iconPulse 2s ease-in-out infinite;
}

/* Remote Share button: suppress active glow — dot in top-right bar is sufficient */
#messagingToolbarBtn.active {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}
#messagingToolbarBtn.active:hover {
    background: rgba(74, 158, 255, 0.15);
    border-color: var(--accent-blue);
}
#messagingToolbarBtn.active .label {
    color: inherit;
    font-weight: inherit;
}
#messagingToolbarBtn.active .icon {
    animation: none;
}

@keyframes iconPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn .icon {
    font-size: 20px;
    margin-bottom: 2px;
}

.toolbar-btn .label {
    font-size: 10px;
    color: var(--text-secondary);
}

/* Messaging/Share button specific styling */
#messagingToolbarBtn.active {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.25) 0%, rgba(16, 185, 129, 0.25) 100%);
    border-color: var(--accent-green);
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.5), inset 0 0 25px rgba(34, 197, 94, 0.15);
}

#messagingToolbarBtn.active .label {
    color: #22c55e;
    font-weight: 700;
    text-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

#messagingToolbarBtn.active .icon {
    filter: drop-shadow(0 0 4px rgba(34, 197, 94, 0.8));
}

.toolbar-separator {
    width: 1px;
    height: 36px;
    background: var(--border-color);
    margin: 0 6px;
}

/* ========== Main Layout ========== */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ========== Left Sidebar (Sessions) ========== */
/* ========== Sidebar with Tabs ========== */
.sidebar {
    width: 300px;
    min-width: 150px;
    max-width: 50%;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    user-select: none;
}

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-blue) var(--bg-darker);
}

/* Webkit scrollbar for sidebar tabs */
.sidebar-tabs::-webkit-scrollbar {
    height: 4px;
}

.sidebar-tabs::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

.sidebar-tabs::-webkit-scrollbar-thumb {
    background: var(--accent-blue);
    border-radius: 2px;
}

.sidebar-tabs::-webkit-scrollbar-thumb:hover {
    background: var(--accent-cyan);
}

.sidebar-tab {
    flex: 1;
    min-width: fit-content;
    padding: 10px 8px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    position: relative;
}

.sidebar-tab:hover {
    background: rgba(74, 158, 255, 0.1);
    color: var(--text-primary);
}

.sidebar-tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
    background: rgba(74, 158, 255, 0.05);
}

.sidebar-tab-icon {
    font-size: 16px;
}

.sidebar-tab-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #fbbf24; /* Bright yellow/gold */
    color: #0f0f1a; /* Very dark text for maximum contrast */
    font-size: 9px;
    font-weight: 700; /* Bolder for better visibility */
    padding: 2px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); /* Subtle shadow for depth */
    border: 1px solid rgba(0, 0, 0, 0.2); /* Slight border for definition */
}

/* Sidebar Content Panels */
.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.sidebar-panel.active {
    display: flex;
}

/* Resize Handle */
.resize-handle {
    width: 8px;
    background: rgba(74, 158, 255, 0.1);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    cursor: ew-resize;
    flex-shrink: 0;
    transition: background 0.2s;
}

.resize-handle:hover,
.resize-handle.resizing {
    background: var(--accent-blue);
}

.sidebar-header {
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 3px;
}

.sidebar-header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.session-list::-webkit-scrollbar {
    width: 6px;
}

.session-list::-webkit-scrollbar-track {
    background: transparent;
}

.session-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.session-group {
    margin-bottom: 16px;
}

.session-group-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 4px 8px;
    margin-bottom: 4px;
}

.session-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.session-item:hover {
    background: rgba(74, 158, 255, 0.1);
}

.session-item.active {
    background: var(--accent-blue);
    color: white;
}

.session-item.active .session-info {
    color: rgba(255, 255, 255, 0.8);
}

.session-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.session-icon.local {
    background: linear-gradient(135deg, #4a9eff, #2563eb);
}

.session-icon.ssh {
    background: linear-gradient(135deg, #22d3ee, #0891b2);
}

.session-icon.disconnected {
    background: linear-gradient(135deg, #6b7280, #374151);
    opacity: 0.6;
}

.session-details {
    flex: 1;
    min-width: 0;
}

.session-name {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-info {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========== Notes List ========== */
.notes-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    user-select: none;
}

.notes-list::-webkit-scrollbar {
    width: 6px;
}

.notes-list::-webkit-scrollbar-track {
    background: transparent;
}

.notes-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.note-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
}

.note-item:hover {
    background: rgba(74, 158, 255, 0.1);
    border-color: var(--accent-blue);
}

.note-item.active {
    background: rgba(74, 158, 255, 0.2);
    border-color: var(--accent-blue);
}

.note-item.shared {
    border-left: 3px solid var(--accent-green);
}

.note-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.note-details {
    flex: 1;
    min-width: 0;
}

.note-title {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.note-preview {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.note-meta {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========== Terminal Area ========== */
.terminal-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
}

/* ========== Tab Bar ========== */
.tab-bar-container {
    display: flex;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.tab-scroll-btn {
    width: 32px;
    min-width: 32px;
    height: 36px;
    background: var(--bg-darker);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.15s;
    border-right: 1px solid var(--border-color);
}

.tab-scroll-btn:last-child {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.tab-scroll-btn:hover {
    background: rgba(74, 158, 255, 0.2);
    color: var(--accent-blue);
}

.tab-scroll-btn.visible {
    display: flex;
}

.tab-bar {
    display: flex;
    flex: 1;
    min-height: 28px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
}

.tab-bar::-webkit-scrollbar {
    height: 0;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: 28px;
    background: var(--bg-tab);
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.15s;
    min-width: 120px;
    max-width: 180px;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.tab:hover {
    background: var(--bg-tab-active);
}

.tab.active {
    background: var(--bg-panel);
    border-bottom: 2px solid var(--accent-blue);
    box-shadow: 0 2px 8px rgba(74, 158, 255, 0.3);
    position: relative;
    z-index: 1;
}

.tab.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-blue);
    border-radius: 0 2px 2px 0;
}

.tab.active .tab-title {
    font-weight: 600;
    color: var(--accent-blue);
}

.tab.disconnected {
    opacity: 0.6;
}

.tab.disconnected::after {
    content: '●';
    color: var(--accent-red);
    font-size: 8px;
    position: absolute;
    top: 8px;
    right: 30px;
}

.tab-icon {
    font-size: 14px;
}

.tab-title {
    flex: 1;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-close {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-muted);
    transition: all 0.15s;
}

.tab-close:hover {
    background: var(--accent-red);
    color: white;
}

.tab-shared-badge {
    font-size: 12px;
    margin-left: 4px;
    opacity: 0.8;
    animation: pulse 2s ease-in-out infinite;
}

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

.tab-add {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
}

.tab-add:hover {
    background: rgba(74, 158, 255, 0.2);
    color: var(--accent-blue);
}

/* ========== Terminal Container ========== */
.terminal-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.terminal-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    flex-direction: column;
}

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

.terminal-content {
    flex: 1;
    padding: 0;
    background: #000;
    min-height: 0; /* Important: allows flex child to shrink below content size */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ========== Status Bar (Bottom) ========== */
.status-bar {
    height: 24px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11px;
    color: var(--text-secondary);
    gap: 8px;
    flex-shrink: 0;
}

/* Typing indicator in status bar */
.status-bar-typing {
    margin-left: auto;
    color: var(--accent-cyan, #22d3ee);
    font-size: 11px;
    font-weight: 500;
    animation: typingPulse 1.5s ease-in-out infinite;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

@keyframes typingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========== Disabled Toolbar Buttons (SLS Offline) ========== */
.toolbar-btn:disabled,
.toolbar-btn.sls-disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
    filter: grayscale(60%);
}

/* ========== Disabled Shell Buttons with Hover Tooltip ========== */
.toolbar-btn[disabled]:not(.sls-disabled) {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: all; /* Allow hover for tooltip */
    filter: grayscale(40%);
    position: relative;
}

/* Show enhanced visual feedback on hover for disabled shell buttons */
.toolbar-btn[disabled]:not(.sls-disabled):hover {
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.3);
    transform: none; /* Don't scale */
}

/* Tooltip on hover for disabled buttons */
.toolbar-btn[disabled]:not(.sls-disabled):hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #2d2d5a;
    border: 1px solid rgba(248, 113, 113, 0.6);
    border-radius: 6px;
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), 0 0 20px rgba(248, 113, 113, 0.4);
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease-out;
}

/* Tooltip arrow */
.toolbar-btn[disabled]:not(.sls-disabled):hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 20px;
    margin-bottom: 2px;
    border: 6px solid transparent;
    border-top-color: rgba(248, 113, 113, 0.6);
    z-index: 999;
    pointer-events: none;
    animation: tooltipFadeIn 0.2s ease-out;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== Viewer List (My Shares Sidebar) ========== */
.viewer-list {
    margin-top: 4px;
    padding-left: 8px;
    border-left: 2px solid var(--border-color);
    margin-left: 12px;
}

.viewer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    font-size: 10px;
    color: var(--text-muted);
    border-radius: 3px;
    transition: background 0.15s;
    cursor: context-menu;
}

.viewer-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.viewer-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    flex-shrink: 0;
}

.viewer-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-perm-indicator {
    font-size: 11px;
    opacity: 0.8;
    flex-shrink: 0;
}

.viewer-perm-toggle[title*="Read-Write"] {
    color: var(--accent-green);
}

.viewer-perm-toggle[title*="Read-Only"] {
    color: var(--accent-blue);
}

.status-bar-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-bar-label {
    color: var(--text-muted);
    font-weight: 500;
}

.status-bar-value {
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
}

.status-bar-separator {
    color: var(--border-color);
    user-select: none;
}

/* Ensure xterm.js container fills the parent */
.terminal-content > div {
    flex: 1;
    width: 100%;
    height: 100%;
}



/* ========== Connecting Loader Overlay ========== */
.connecting-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.connecting-overlay.visible {
    display: flex;
}

.connecting-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

.connecting-text {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 600;
}

.connecting-subtext {
    font-size: 12px;
    color: var(--text-muted);
}


/* ========== Status Bar ========== */
.status-bar {
    background: var(--bg-darker);
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-item .label {
    color: var(--text-muted);
}

.status-item .value {
    color: var(--text-secondary);
}

/* ========== Modal ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

/* Cloud modal specific - higher z-index and backdrop blur */
#cloudModalOverlay {
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 450px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--accent-red);
    color: white;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.form-group textarea {
    min-height: 80px;
    font-family: 'Consolas', monospace;
    font-size: 12px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #3b8bff;
}

.btn-secondary {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-secondary:active {
    transform: scale(0.98);
}

.btn-info {
    background: var(--accent-cyan);
    color: white;
}

.btn-info:hover {
    background: #1db9d4;
}

.btn-info.loading {
    background: #fbbf24;
    cursor: wait;
    opacity: 0.8;
}

.btn-info.success {
    background: var(--accent-green);
    cursor: default;
}

.btn-info.error {
    background: var(--accent-red);
    cursor: default;
}

.btn-info:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* ========== Typing Indicator ========== */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.typing-indicator {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ========== Permission Request Notification ========== */
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.permission-request-notification {
    animation: slideIn 0.3s ease-out;
}

/* ========== Session Badge ========== */
.session-badge {
    pointer-events: none;
    user-select: none;
}

/* ========== Received Shared Tab Styles ========== */
.tab.received-share {
    position: relative;
    border: 1px solid var(--accent-cyan);
    background: linear-gradient(90deg, rgba(34, 211, 238, 0.15), transparent);
}

.tab.received-share::before {
    content: '📡';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
}

.tab.received-share .tab-icon {
    margin-left: 16px;
}

/* Tab with write access */
.tab.write-access {
    border-color: var(--accent-green);
}

/*.tab.write-access::after {
    content: '✏️';
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
}*/

/* Tab read-only indicator */
.tab.read-only::after {
    content: '👁️';
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
}

/* ========== Context Menu ========== */
.context-menu {
    position: fixed;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    min-width: 200px;
    padding: 6px 0;
    display: none;
    animation: contextMenuFadeIn 0.15s ease-out;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu.visible {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
}

.context-menu-item:hover {
    background: rgba(74, 158, 255, 0.15);
}

.context-menu-item.danger {
    color: var(--accent-red);
}

.context-menu-item.danger:hover {
    background: rgba(248, 113, 113, 0.15);
}

.context-menu-item .icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
}

.context-menu-separator {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* ========== Context Menu Disabled State ========== */
.context-menu-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ========== Cloud Actions Row Buttons ========== */
.cloud-actions-row .cloud-btn {
    font-size: 11px;
    padding: 8px 10px;
}

.cloud-btn.cloud-btn-secondary {
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
}

.cloud-btn.disconnect {
    background: linear-gradient(90deg, var(--accent-red), #dc2626);
}

/* ========== Empty State ========== */
.empty-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state-message {
    font-size: 13px;
    text-align: center;
    max-width: 400px;
    line-height: 1.6;
}

/* ========== Input Group ========== */
.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
}

.regen-btn, .cloud-regen-btn {
    min-width: 36px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
}

.regen-btn:hover, .cloud-regen-btn:hover {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.regen-btn:active, .cloud-regen-btn:active {
    transform: scale(0.95);
}

.regen-btn:disabled, .cloud-regen-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ========== Cloud Panel ========== */
.cloud-panel {
    position: fixed;
    top: 68px;
    right: 16px;
    width: 320px;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 999;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.cloud-panel:not(.expanded) .cloud-panel-body {
    display: none;
}

.cloud-panel.expanded .cloud-panel-body {
    display: block;
}

.cloud-panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}

.cloud-panel-header:hover {
    background: rgba(255, 255, 255, 0.02);
}

.cloud-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
}

.cloud-panel-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.cloud-panel-body {
    padding: 16px;
    overflow-y: auto;
}

.cloud-form-row {
    margin-bottom: 12px;
}

.cloud-form-row label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.cloud-form-row input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
}

.cloud-form-row input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.cloud-input-group {
    display: flex;
    gap: 6px;
}

.cloud-input-group input {
    flex: 1;
}

.cloud-actions {
    margin-top: 16px;
}

.cloud-btn {
    width: 100%;
    padding: 10px;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.cloud-btn:hover {
    filter: brightness(1.1);
}

.cloud-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cloud-btn.disconnect {
    background: linear-gradient(90deg, var(--accent-red), var(--accent-orange));
}

.cloud-btn.cloud-btn-secondary {
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
}

.cloud-btn-small {
    padding: 8px 12px;
    font-size: 11px;
}

.cloud-actions-row {
    display: flex;
    gap: 8px;
}

.cloud-btn.active {
    background: linear-gradient(90deg, var(--accent-green), var(--accent-cyan));
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

.cloud-agents {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.cloud-agents-title {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.cloud-agent-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 11px;
}

.cloud-agent-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
}

/* ========== Shared Panel (Right Side) ========== */
.shared-panel {
    width: 240px;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.shared-panel-header {
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.shared-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.shared-session-list::-webkit-scrollbar {
    width: 6px;
}

.shared-session-list::-webkit-scrollbar-track {
    background: transparent;
}

.shared-session-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.shared-session-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.shared-session-item:hover {
    background: rgba(167, 139, 250, 0.2);
}

.shared-session-icon {
    font-size: 16px;
}

.shared-session-info {
    flex: 1;
    min-width: 0;
}

.shared-session-name {
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shared-session-agent {
    font-size: 10px;
    color: var(--text-muted);
}

/* ========== Shared Shell Styles ========== */
.tab.shared {
    padding-left: 24px;
    border: 1px solid var(--accent-purple);
    background: linear-gradient(90deg, rgba(167, 139, 250, 0.1), transparent);
}

/* Hide the shell icon when shared (only show the 🌐 icon) */
.tab.shared .tab-icon {
    display: none;
}

.shared-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--accent-purple);
    padding: 2px 6px;
    background: rgba(167, 139, 250, 0.2);
    border-radius: 10px;
}

/* ========== API Reference Styles ========== */
.api-section {
    margin-bottom: 32px;
}

.api-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-cyan);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
}

.api-endpoint {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px;
    background: var(--bg-panel);
    border-left: 3px solid var(--border-color);
    border-radius: 6px;
}

.api-method {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 4px;
    text-align: center;
    min-width: 50px;
    flex-shrink: 0;
}

.api-method.get {
    background: rgba(74, 222, 128, 0.2);
    color: var(--accent-green);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.api-method.post {
    background: rgba(74, 158, 255, 0.2);
    color: var(--accent-blue);
    border: 1px solid rgba(74, 158, 255, 0.3);
}

.api-method.put {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.api-method.delete {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.api-method.ws {
    background: rgba(167, 139, 250, 0.2);
    color: var(--accent-purple);
    border: 1px solid rgba(167, 139, 250, 0.3);
}

.api-path {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
    flex-shrink: 0;
    min-width: 200px;
}

.api-desc {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
    flex: 1;
}

.api-example {
    margin: 8px 0 20px 0;
    padding: 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    color: var(--accent-green);
    overflow-x: auto;
    line-height: 1.6;
}

/* ========== Help Modal Tabs ========== */
.help-tab {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.help-tab:hover {
    background: rgba(74, 158, 255, 0.1);
    color: var(--text-primary);
}

.help-tab.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.05);
}

.help-content {
    display: none;
}

.help-content.active {
    display: block;
}

/* ========== Cloud Modal Tabs ========== */
.cloud-tab {
    flex: 1;
    padding: 12px 20px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.cloud-tab:hover {
    background: rgba(74, 158, 255, 0.1);
    color: var(--text-primary);
}

.cloud-tab.active {
    color: var(--accent-blue);
    border-bottom-color: var(--accent-blue);
    background: rgba(74, 158, 255, 0.05);
}

.cloud-tab-content {
    display: none;
}

.cloud-tab-content.active {
    display: block;
}

/* ========================================
   XTERM.JS MOBILE KEYBOARD FIX
   ======================================== */
/* Ensure xterm.js hidden textarea works on mobile - NO text suggestions */
.xterm-helper-textarea {
    /* Allow mobile keyboard to appear */
    position: absolute !important;
    opacity: 0 !important;
    left: -9999px !important;
    top: 0 !important;
    width: 0 !important;
    height: 0 !important;
    z-index: -10 !important;
    /* Prevent iOS zoom */
    font-size: 16px !important;
    /* Enable mobile keyboard */
    -webkit-user-select: text !important;
    user-select: text !important;
    /* Text suggestion attributes are set via JavaScript (applyNoSuggestionAttrs) */
    -webkit-text-security: none !important;
}

/* Ensure terminal container allows touch and is fully responsive */
.terminal-content {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* ✅ xterm.js full responsive - fill container completely */
.xterm {
    height: 100% !important;
    width: 100% !important;
}

.xterm-screen {
    width: 100% !important;
}

.xterm-viewport {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   Complete responsive overhaul for phones/tablets
   ======================================== */

/* ── Global: Disable text suggestions on ALL terminal inputs (via JS attrs) ── */
/* Note: autocomplete/autocorrect/autocapitalize are HTML attributes, set via JS */
.xterm-helper-textarea,
.terminal-content textarea,
.terminal-content input {
    -webkit-text-security: none;
}

/* ── Tablet: 768px–1024px ── */
@media (max-width: 1024px) {
    .sidebar {
        width: 200px;
        min-width: 120px;
    }
    .toolbar-btn {
        padding: 4px 8px;
        min-width: 50px;
    }
    .toolbar-btn .label {
        font-size: 9px;
    }
    .modal {
        width: 90vw;
        max-width: 500px;
    }
}

/* ── Mid-size mobile: 481px–767px ── */
@media (max-width: 767px) {
    .menu-bar {
        height: auto;
        min-height: 28px;
        flex-wrap: wrap;
        padding: 2px 4px;
    }
    .menu-item {
        padding: 3px 8px;
        font-size: 11px;
    }
    .toolbar {
        padding: 4px 6px;
        gap: 4px;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar-btn {
        padding: 4px 6px;
        min-width: 45px;
        flex-shrink: 0;
    }
    .toolbar-btn .icon { font-size: 16px; }
    .toolbar-btn .label { font-size: 8px; }
    .sidebar {
        width: 150px;
        min-width: 100px;
    }
    .sidebar-header {
        font-size: 10px;
        padding: 8px 10px;
    }
    .session-item { padding: 6px 8px; }
    .session-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    .session-name { font-size: 11px; }
    .session-info { font-size: 9px; }
    .tab {
        min-width: 100px;
        max-width: 150px;
        padding: 0 10px;
        font-size: 11px;
    }
    .tab-title { font-size: 11px; }
    .status-bar {
        font-size: 10px;
        padding: 0 8px;
        height: 20px;
    }
    .modal {
        width: 95vw;
        max-height: 85vh;
    }
    .modal-header { padding: 12px 16px; }
    .modal-title { font-size: 14px; }
    .modal-body { padding: 16px; }
    .context-menu {
        min-width: 160px;
        font-size: 12px;
    }
    .context-menu-item { padding: 8px 12px; }
}

/* ══════════════════════════════════════════
   MOBILE PORTRAIT ≤ 480px  (Primary phone)
   ══════════════════════════════════════════ */
@media (max-width: 480px) {

    /* ── Show mobile hamburger ── */
    .mobile-menu-toggle {
        display: flex !important;
        background: rgba(74, 158, 255, 0.2);
        border: 1px solid var(--accent-blue);
    }

    /* ── Sidebar = fixed drawer ── */
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 280px;
        max-width: 80vw;
        z-index: 2000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.mobile-visible {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.7);
    }

    /* Overlay behind sidebar */
    body::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        z-index: 1999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }
    body.sidebar-open::before {
        opacity: 1;
        pointer-events: auto;
    }

    /* Kill resize handle */
    .resize-handle { display: none !important; }

    /* ── Terminal area full-width ── */
    .terminal-area {
        width: 100% !important;
        margin-left: 0 !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* ── Terminal wrapper / content scrollable ── */
    .terminal-wrapper {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.2) transparent;
    }
    .terminal-wrapper::-webkit-scrollbar { width: 3px; }
    .terminal-wrapper::-webkit-scrollbar-track { background: transparent; }
    .terminal-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

    .terminal-panel {
        display: flex;
        flex-direction: column;
        min-height: 100%;
    }
    .terminal-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    .terminal-content::-webkit-scrollbar { width: 3px; }
    .terminal-content::-webkit-scrollbar-track { background: transparent; }
    .terminal-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

    /* ── Toolbar: horizontal scroll, no wrap ── */
    .toolbar {
        gap: 2px;
        padding: 2px 4px;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar-btn {
        padding: 3px 5px;
        min-width: 40px;
        flex-shrink: 0;
    }
    .toolbar-btn .icon { font-size: 14px; margin-bottom: 1px; }
    .toolbar-btn .label { font-size: 7px; }
    .toolbar-separator { height: 28px; margin: 0 3px; flex-shrink: 0; }

    /* ── Tabs: scroll, compact ── */
    .tab-bar-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tab-bar-container::-webkit-scrollbar { display: none; }
    .tab { min-width: 80px; max-width: 120px; padding: 0 8px; height: 24px; flex-shrink: 0; }
    .tab-icon { font-size: 12px; }
    .tab-title { font-size: 10px; }
    .tab-close { width: 16px; height: 16px; font-size: 12px; }
    .tab-add { width: 32px; height: 32px; font-size: 16px; }

    /* ── Status bar: compact ── */
    .status-bar { font-size: 9px; padding: 0 6px; height: 18px; gap: 4px; }
    .status-bar-separator { margin: 0 2px; }

    /* ══ CRITICAL: Prevent zoom on ALL inputs (16px minimum) ══ */
    /* Note: autocomplete/autocorrect/autocapitalize are HTML attrs, set via JS */
    input, textarea, select {
        font-size: 16px !important;
    }

    /* ── Touch targets ≥ 44px (Apple HIG) ── */
    button, .btn, .context-menu-item,
    .sidebar-tab, .session-item, .note-item {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── Modals: fullscreen on phones ── */
    .modal {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    .modal.cloud-modal {
        width: 100vw !important;
        max-width: 100vw !important;
    }
    .modal-body {
        padding: 12px !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-header {
        padding: 10px 12px !important;
        flex-wrap: wrap;
    }
    .modal-title { font-size: 14px !important; }
    .modal-footer { padding: 10px 12px; }

    /* ── Buttons ── */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    /* ── Form groups ── */
    .form-group { margin-bottom: 12px !important; }
    .form-group label { font-size: 12px !important; margin-bottom: 6px !important; }
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px !important;
        padding: 12px !important;
        border-radius: 8px;
    }

    /* ── Cloud / help tabs ── */
    .cloud-tab, .help-tab {
        padding: 10px 12px !important;
        font-size: 12px !important;
        flex: 1;
        text-align: center;
    }

    /* ── Toast ── */
    .toast {
        max-width: calc(100vw - 20px) !important;
        min-width: auto !important;
        font-size: 12px;
        padding: 10px 14px;
    }

    /* ── Context menu: bigger tap targets ── */
    .context-menu { min-width: 200px; max-width: calc(100vw - 20px); font-size: 14px; }
    .context-menu-item { padding: 12px 16px; min-height: 44px; }

    /* ── Sidebar tabs ── */
    .sidebar-tab { padding: 10px 6px; }
    .sidebar-tab-icon { font-size: 16px; }

    /* ── Menu bar ── */
    .menu-bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        height: auto;
        min-height: 28px;
        padding: 4px;
        gap: 2px;
    }
    .menu-item {
        padding: 4px 8px;
        font-size: 11px;
        min-height: 28px;
        display: flex;
        align-items: center;
    }
    .menu-status {
        width: 100%;
        justify-content: center;
        padding: 2px 0;
        font-size: 10px;
    }
    /* compact top-status-bar on mobile */
    .top-status-bar { gap: 1px; padding: 2px 4px; }
    .top-status-indicator { padding: 2px 4px; gap: 4px; }
    .top-status-label { display: none; }
    .top-status-icon  { display: none; } /* dots only on mobile */

    /* ── File Explorer: fullscreen overlay ── */
    .sftp-panel {
        width: 100% !important;
        max-width: 100% !important;
        position: fixed !important;
        inset: 0 !important;
        z-index: 2500 !important;
        border-left: none !important;
    }

    /* ── File Editor: fullscreen overlay ── */
    .file-editor-pinned {
        width: 100% !important;
        position: fixed !important;
        inset: 0 !important;
        z-index: 2500 !important;
        border-left: none !important;
    }
}

/* ── Extra-small phones ≤ 360px ── */
@media (max-width: 360px) {
    .toolbar-btn .label { display: none; }
    .toolbar-btn { min-width: 36px; padding: 3px 4px; }
    .toolbar-btn .icon { font-size: 16px; }
    .tab { min-width: 70px; max-width: 100px; }
    .status-bar-item .status-bar-label { display: none; }
    .modal-title { font-size: 12px !important; }
    .menu-item { padding: 3px 5px; font-size: 10px; }
    .sidebar-tab-icon { font-size: 14px; }
}

/* ══════════════════════════════════════════
   LANDSCAPE ≤ 500px height
   ══════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
    html, body {
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        overflow: hidden;
    }
    body {
        display: flex;
        flex-direction: column;
    }
    .main-container {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
    .terminal-area {
        height: 100%;
        max-height: 100%;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    .terminal-wrapper {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.2) transparent;
    }
    .terminal-wrapper::-webkit-scrollbar { width: 4px; }
    .terminal-wrapper::-webkit-scrollbar-track { background: transparent; }
    .terminal-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
    .terminal-panel {
        height: 100%;
        max-height: 100%;
        display: flex;
        flex-direction: column;
    }
    .terminal-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: thin;
    }
    .terminal-content::-webkit-scrollbar { width: 4px; }
    .terminal-content::-webkit-scrollbar-track { background: transparent; }
    .terminal-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

    /* Compact chrome */
    .menu-bar { height: 22px; padding: 2px 4px; font-size: 10px; }
    .toolbar { padding: 2px 4px; min-height: 30px; }
    .tab-bar-container { min-height: 22px; }
    .tab { height: 22px; padding: 0 8px; font-size: 10px; }
    .status-bar { height: 14px; font-size: 9px; padding: 0 6px; }
    .modal { max-height: 90vh; overflow-y: auto; }

    /* Sidebar hidden by default */
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: 200px;
        z-index: 2000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.mobile-visible {
        transform: translateX(0);
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    }
}

/* ══════════════════════════════════════════
   TOUCH DEVICES (no hover, coarse pointer)
   ══════════════════════════════════════════ */
@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets */
    .toolbar-btn, .tab, .session-item, .menu-item {
        min-height: 44px;
    }
    .btn {
        min-height: 44px;
        padding: 10px 20px;
    }
    .tab-close {
        min-width: 28px;
        min-height: 28px;
    }

    /* Remove hover effects (they stick on touch) */
    .toolbar-btn:hover,
    .tab:hover,
    .session-item:hover,
    .menu-item:hover {
        background: transparent;
    }

    /* Better active states for touch feedback */
    .toolbar-btn:active,
    .tab:active,
    .session-item:active,
    .menu-item:active,
    .btn:active {
        opacity: 0.7;
        transform: scale(0.97);
        transition: transform 0.1s ease, opacity 0.1s ease;
    }

    /* Prevent text selection on UI elements */
    .toolbar, .tab-bar-container, .sidebar, .menu-bar, .status-bar {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }

    /* Scrollbar thin on touch */
    * {
        scrollbar-width: thin;
    }
}

/* ══════════════════════════════════════════
   PORTRAIT MODE ≤ 768px
   ══════════════════════════════════════════ */
@media (max-width: 768px) and (orientation: portrait) {
    .toolbar {
        padding: 4px 6px;
        gap: 4px;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .toolbar::-webkit-scrollbar { display: none; }
    .toolbar-btn {
        min-width: 50px;
        padding: 4px 8px;
        flex-shrink: 0;
    }
    .toolbar-btn .icon { font-size: 18px; margin-bottom: 1px; }
    .toolbar-btn .label { font-size: 9px; }
    .toolbar-separator { height: 28px; flex-shrink: 0; margin: 0 2px; }

    /* Sidebar: visible but compact */
    .sidebar {
        width: 180px;
        min-width: 120px;
        max-width: 35%;
        position: relative;
        transform: none;
    }
    .menu-bar { padding: 2px 6px; height: 28px; gap: 2px; }
    .menu-item { padding: 4px 8px; font-size: 11px; }
    .tab-bar-container { min-height: 28px; }
    .tab { height: 28px; padding: 0 10px; font-size: 11px; }
    .tab-close { width: 20px; height: 20px; }
    .status-bar { height: 16px; font-size: 10px; padding: 0 8px; }
    .modal { max-width: 95%; max-height: 85vh; margin: 20px; }
    .modal-overlay { padding: 10px; }
}

/* ── Duplicate ≤480 portrait override: sidebar becomes drawer ── */
@media (max-width: 480px) and (orientation: portrait) {
    .sidebar {
        position: fixed;
        max-width: 80vw;
        width: 280px;
        transform: translateX(-100%);
    }
    .sidebar.mobile-visible {
        transform: translateX(0);
    }
}

/* ══════════════════════════════════════════
   iOS SAFE AREA INSETS (notch devices)
   ══════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-top)) {
    .menu-bar {
        padding-top: max(2px, env(safe-area-inset-top));
        padding-left: max(4px, env(safe-area-inset-left));
        padding-right: max(4px, env(safe-area-inset-right));
    }
    .status-bar {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    .toolbar {
        padding-left: max(4px, env(safe-area-inset-left));
        padding-right: max(4px, env(safe-area-inset-right));
    }
}

