/* Terminal Section - Simple Fixed Layout */
#terminal {
    /* Normal section, no special positioning */
}

/* Only show terminal when it's the active section */
#terminal.hidden {
    display: none !important;
}

/* Fixed-size container that defines the terminal display region */
.terminal-fixed-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 136px);
    overflow: hidden; /* CRITICAL: Hide any overflow */
}

/* Terminal Frame - fits exactly to container */
.terminal-frame {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
    background-color: #2a2a3c;
    border: 1px solid #3a3a4c;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3), 0 6px 6px rgba(0, 0, 0, 0.2);
}

/* Terminal title bar - fixed height */
.terminal-titlebar {
    background: linear-gradient(to bottom, #3a3a4c, #333342);
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 1px solid #444;
    user-select: none;
}

.terminal-title {
    color: #ccc;
    font-size: 12px;
    font-weight: 600;
}

.terminal-controls {
    display: flex;
    gap: 6px;
}

.terminal-control {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

/* Terminal body - fills remaining space */
.terminal-body {
    flex: 1;
    background-color: #1e1e2e;
    padding: 8px;
    overflow: hidden; /* CRITICAL: Hide overflow */
    position: relative;
}

.remote-desktop-shell {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.15), transparent 28%),
        radial-gradient(circle at bottom right, rgba(16, 185, 129, 0.12), transparent 26%),
        linear-gradient(160deg, #0f172a, #111827 45%, #1f2937);
    border-radius: 14px;
    padding: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.remote-desktop-section {
    height: 100vh;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
    box-sizing: border-box;
}

.remote-desktop-section > .flex.items-center.justify-between.mb-4.bg-gray-100.rounded-md.p-3.gap-4.flex-wrap {
    flex: 0 0 auto;
    margin-bottom: 0;
}

.remote-desktop-canvas-wrap {
    min-height: 0;
    height: 100%;
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    position: relative;
    padding: 12px;
    box-sizing: border-box;
    border-radius: 10px;
    background:
        linear-gradient(180deg, rgba(15, 23, 42, 0.6), rgba(15, 23, 42, 0.92)),
        repeating-linear-gradient(45deg, rgba(148, 163, 184, 0.04) 0, rgba(148, 163, 184, 0.04) 10px, transparent 10px, transparent 20px);
    outline: none;
}

.remote-desktop-canvas-wrap:fullscreen {
    height: 100vh;
    padding: 18px;
    border-radius: 0;
}

.remote-desktop-canvas-wrap:focus {
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.55);
}

.remote-desktop-canvas-wrap.capturing {
    box-shadow: inset 0 0 0 2px rgba(14, 165, 233, 0.9), 0 0 0 1px rgba(14, 165, 233, 0.35);
}

.remote-desktop-stage {
    position: relative;
    width: 960px;
    height: 540px;
    flex: none;
    overflow: hidden;
}

.remote-desktop-canvas {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
    background: #020617;
}

.remote-desktop-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #cbd5e1;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.78rem;
}

.desktop-stream-stats {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    background: rgba(15, 23, 42, 0.08);
    color: #334155;
    font-size: 0.75rem;
    font-weight: 600;
}

.desktop-clipboard-status {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    background: rgba(14, 116, 144, 0.08);
    color: #155e75;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: Consolas, "Courier New", monospace;
}

.desktop-clipboard-status[data-state="warning"] {
    background: rgba(217, 119, 6, 0.12);
    color: #92400e;
}

.desktop-clipboard-status[data-state="error"] {
    background: rgba(220, 38, 38, 0.12);
    color: #991b1b;
}

.desktop-clipboard-status[data-state="ok"] {
    background: rgba(22, 163, 74, 0.12);
    color: #166534;
}

.desktop-clipboard-fetch {
    border: 1px solid rgba(14, 116, 144, 0.28);
    border-radius: 9999px;
    padding: 0.22rem 0.7rem;
    background: rgba(255, 255, 255, 0.92);
    color: #0f766e;
    font-size: 0.72rem;
    font-weight: 700;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.desktop-clipboard-fetch:hover {
    background: rgba(14, 116, 144, 0.08);
    border-color: rgba(14, 116, 144, 0.48);
}

.desktop-clipboard-download {
    border: 1px solid rgba(37, 99, 235, 0.28);
    border-radius: 9999px;
    padding: 0.22rem 0.7rem;
    background: rgba(255, 255, 255, 0.92);
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 700;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.desktop-clipboard-download:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.48);
}

.desktop-stats-sep {
    color: #94a3b8;
}

.desktop-remote-cursor {
    position: absolute;
    left: 0;
    top: 0;
    width: 18px;
    height: 24px;
    pointer-events: none;
    z-index: 20;
    transform-origin: top left;
}

.desktop-remote-cursor.hidden {
    display: none;
}

.desktop-remote-cursor-arrow {
    position: relative;
    width: 0;
    height: 0;
    border-top: 18px solid #ffffff;
    border-right: 12px solid transparent;
    filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.8));
}

.desktop-remote-cursor-arrow::after {
    content: '';
    position: absolute;
    left: -10px;
    top: -18px;
    width: 0;
    height: 0;
    border-top: 18px solid rgba(15, 23, 42, 0.95);
    border-right: 12px solid transparent;
    transform: translate(1px, 1px);
    z-index: -1;
}

.desktop-remote-cursor.pressing {
    transform: scale(0.92);
}

.desktop-recorder-panel {
    flex: 0 0 auto;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.94));
    box-shadow: 0 18px 38px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}

.desktop-recorder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
}

.desktop-recorder-toggle {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    min-width: 0;
    background: transparent;
    color: #0f172a;
    text-align: left;
}

.desktop-recorder-toggle-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.08);
    color: #1d4ed8;
    flex: none;
}

.desktop-recorder-toggle-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.desktop-recorder-toggle-title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.01em;
}

.desktop-recorder-toggle-summary {
    font-size: 0.78rem;
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desktop-recorder-toggle[aria-expanded="true"] .desktop-recorder-toggle-icon i {
    transform: rotate(90deg);
}

.desktop-recorder-toggle-icon i {
    transition: transform 140ms ease;
}

.desktop-recording-state-chip,
.desktop-recording-live-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    padding: 0.33rem 0.8rem;
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.desktop-recording-state-chip[data-state="idle"],
.desktop-recording-live-pill[data-state="idle"] {
    background: rgba(148, 163, 184, 0.16);
    color: #475569;
}

.desktop-recording-state-chip[data-state="selecting"],
.desktop-recording-live-pill[data-state="selecting"] {
    background: rgba(14, 165, 233, 0.14);
    color: #0369a1;
}

.desktop-recording-state-chip[data-state="recording"],
.desktop-recording-live-pill[data-state="recording"] {
    background: rgba(220, 38, 38, 0.14);
    color: #b91c1c;
}

.desktop-recording-state-chip[data-state="saving"],
.desktop-recording-live-pill[data-state="saving"] {
    background: rgba(217, 119, 6, 0.14);
    color: #b45309;
}

.desktop-recording-state-chip[data-state="error"],
.desktop-recording-live-pill[data-state="error"] {
    background: rgba(127, 29, 29, 0.14);
    color: #991b1b;
}

.desktop-recorder-body {
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    padding: 0 1rem 1rem;
}

.desktop-recorder-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.9rem;
}

.desktop-recorder-card {
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(255, 255, 255, 0.88);
    padding: 0.95rem 1rem;
}

.desktop-recorder-card-wide {
    grid-column: auto;
}

.desktop-recorder-card-title {
    font-size: 0.78rem;
    font-weight: 800;
    color: #334155;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.7rem;
}

.desktop-recorder-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.desktop-recorder-selection-row,
.desktop-recorder-action-row,
.desktop-recorder-link-row,
.desktop-recorder-live-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.desktop-recorder-secondary-btn,
.desktop-recorder-primary-btn,
.desktop-recorder-stop-btn,
.desktop-recorder-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border-radius: 9999px;
    padding: 0.52rem 0.95rem;
    font-size: 0.8rem;
    font-weight: 700;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
}

.desktop-recorder-secondary-btn {
    border: 1px solid rgba(59, 130, 246, 0.2);
    background: rgba(255, 255, 255, 0.94);
    color: #1d4ed8;
}

.desktop-recorder-secondary-btn:hover {
    background: rgba(219, 234, 254, 0.62);
}

.desktop-recorder-primary-btn {
    border: 1px solid rgba(21, 128, 61, 0.16);
    background: linear-gradient(180deg, #16a34a, #15803d);
    color: #f8fafc;
}

.desktop-recorder-primary-btn:hover {
    background: linear-gradient(180deg, #22c55e, #15803d);
}

.desktop-recorder-stop-btn {
    border: 1px solid rgba(220, 38, 38, 0.16);
    background: linear-gradient(180deg, #ef4444, #dc2626);
    color: #f8fafc;
}

.desktop-recorder-stop-btn:hover {
    background: linear-gradient(180deg, #f87171, #dc2626);
}

.desktop-recorder-link {
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(255, 255, 255, 0.95);
    color: #0f172a;
    text-decoration: none;
}

.desktop-recorder-link:hover {
    background: rgba(241, 245, 249, 0.95);
}

.desktop-recorder-secondary-btn:disabled,
.desktop-recorder-primary-btn:disabled,
.desktop-recorder-stop-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.desktop-recorder-checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: #0f172a;
}

.desktop-recorder-checkbox-row input {
    width: 0.95rem;
    height: 0.95rem;
}

.desktop-recording-note {
    font-size: 0.78rem;
    line-height: 1.45;
    color: #475569;
}

.desktop-recording-folder-note code,
.desktop-recording-output-path {
    font-family: Consolas, "Courier New", monospace;
}

.desktop-recording-output {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.desktop-recording-output-path {
    font-size: 0.82rem;
    color: #0f172a;
    word-break: break-all;
}

.desktop-recording-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 16;
}

.desktop-recording-overlay.armed {
    pointer-events: auto;
    cursor: crosshair;
    background: rgba(15, 23, 42, 0.12);
}

.desktop-recording-selection-box {
    position: absolute;
    border: 2px solid rgba(14, 165, 233, 0.95);
    background: rgba(14, 165, 233, 0.12);
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

.desktop-recording-selection-box.preview {
    box-shadow: none;
    background: rgba(14, 165, 233, 0.08);
}

.desktop-recording-selection-label {
    position: absolute;
    left: 0.55rem;
    top: 0.55rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 9999px;
    padding: 0.2rem 0.55rem;
    background: rgba(15, 23, 42, 0.84);
    color: #f8fafc;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

/* xterm.js container - fits exactly to terminal-body */
#xterm-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Let xterm.js calculate its own size within the container */
.xterm {
    width: 100%;
    height: 100%;
}

.xterm-viewport {
    overflow-y: auto;
    overflow-x: hidden;
}

.xterm-screen {
    /* Let xterm.js manage this */
}

/* Handle scrollbars consistently */
.xterm .xterm-viewport::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.xterm .xterm-viewport::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Status indicator animations */
@keyframes blink {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

.status-connecting {
  animation: blink 1.5s infinite;
}

/* File Explorer */
.file-explorer-container {
  background-color: var(--card-background);
  border-radius: 10px;
  box-shadow: var(--shadow);
  height: calc(100vh - 6rem);
  display: flex;
  flex-direction: column;
}

/* File Explorer Button Styling */
.file-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    cursor: pointer;
    margin-right: 6px;
    transition: background-color 0.2s;
}

.file-action-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.file-action-btn:last-child {
    margin-right: 0;
}

/* File Explorer Table */
#file-explorer table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    table-layout: fixed;
}

#file-explorer table th,
#file-explorer table td {
    padding: 0.2rem 0.8rem;
}

/* File Explorer column widths */
#file-explorer table th:nth-child(1),
#file-explorer table td:nth-child(1) {
    width: 40%;
}

#file-explorer table th:nth-child(2),
#file-explorer table td:nth-child(2) {
    width: 10%;
}

#file-explorer table th:nth-child(3),
#file-explorer table td:nth-child(3) {
    width: 12%;
}

#file-explorer table th:nth-child(4),
#file-explorer table td:nth-child(4) {
    width: 20%;
}

#file-explorer table th:nth-child(5),
#file-explorer table td:nth-child(5) {
    width: 18%;
}

#file-explorer .file-name {
    display: flex;
    align-items: center;
    overflow: hidden;
}

#file-explorer .file-name span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Multi-select styling */
.multi-select-toolbar {
    background-color: #f0f9ff;
    padding: 8px 16px;
    border-radius: 4px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.multi-select-toolbar.hidden {
    display: none;
}

.file-checkbox {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.bulk-action-btn {
    padding: 6px 12px;
    border-radius: 4px;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    margin-left: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.bulk-action-btn i {
    margin-right: 6px;
}

.bulk-action-btn.btn-danger {
    background-color: #fee2e2;
    border-color: #fecaca;
    color: #b91c1c;
}

.bulk-action-btn.btn-danger:hover {
    background-color: #fecaca;
}

/* Responsive Design */
@media (max-width: 992px) {
  .dashboard-row {
    flex-direction: column;
  }
  
  .process-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 220px;
  }
  
  .main-content:not(.expanded) {
    margin-left: 0;
  }
  
  .sidebar:not(.collapsed) {
    transform: translateX(0);
  }
  
  .sidebar {
    transform: translateX(-100%);
  }

  .remote-desktop-section {
    height: auto;
    min-height: 100vh;
  }

  .desktop-recorder-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .desktop-recorder-card-wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 700px) {
  .desktop-recorder-grid {
    grid-template-columns: 1fr;
  }

  .desktop-recorder-card-wide {
    grid-column: auto;
  }
}

/* Notification styles */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    background-color: white;
    color: #333;
    border-left: 4px solid #4CAF50;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    border-radius: 4px;
    z-index: 9999;
    display: flex;
    align-items: center;
    transform: translateY(100px);
    opacity: 0;
    transition: transform 0.3s, opacity 0.3s;
}

.notification.show {
    transform: translateY(0);
    opacity: 1;
}

.notification.error {
    border-left-color: #F44336;
}

.notification i {
    margin-right: 10px;
    font-size: 18px;
    color: #4CAF50;
}

.notification.error i {
    color: #F44336;
}

/* Modal form styling */
.modal-content input[type="text"],
.modal-content input[type="password"],
.modal-content input[type="email"],
.modal-content input[type="number"],
#modal-content input[type="text"],
#modal-content input[type="password"],
#modal-content input[type="email"],
#modal-content input[type="number"],
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    margin-top: 6px;
}

/* Form group proper spacing */
.form-group {
    margin-bottom: 16px;
    width: 100%;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

/* Sidebar collapse/expand */
.sidebar {
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 64px !important;
}

.sidebar.collapsed .sidebar-brand-text {
    display: none;
}

.sidebar.collapsed .min-h-16 {
    justify-content: center;
    padding: 1rem;
}

.sidebar.collapsed .min-h-16 .flex.items-start {
    justify-content: center;
}

.sidebar.collapsed .min-h-16 i {
    margin-right: 0;
}

.sidebar.collapsed nav ul li {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0.25rem;
    margin-right: 0.25rem;
}

.sidebar.collapsed nav ul li span {
    display: none;
}

.sidebar.collapsed nav ul li i {
    margin-right: 0;
}

.sidebar.collapsed #editor-tabs-container {
    display: none;
}

.sidebar.collapsed .sidebar-toggle span {
    display: none;
}

.main-content {
    transition: margin-left 0.3s ease;
}

.main-content.sidebar-collapsed {
    margin-left: 64px !important;
}

/* AI Operations full-height adaptive layout */
#ai-operations:not(.hidden) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    box-sizing: border-box;
}

.ai-ops-content {
    flex: 1;
    min-height: 0;
}
