/* App shell layout */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

/* Top bar */
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 9px;
    height: 48px;
    background: #252526;
    border-bottom: 1px solid #3c3c3c;
    flex-shrink: 0;
    gap: 8px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 9px;
}

.topbar-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.logo {
    font-size: 15px;
    font-weight: 600;
    color: #cccccc;
    letter-spacing: 0.3px;
    text-decoration: none;
}

.logo:hover {
    color: #ffffff;
}

.warp-control {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
}

.warp-label {
    font-size: 12px;
    color: #888;
    letter-spacing: 0.3px;
}

.warp-input {
    width: 42px;
    height: 30px;
    padding: 0 6px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 3px;
    color: #d4d4d4;
    font-size: 13px;
    text-align: center;
    -moz-appearance: textfield;
    box-sizing: border-box;
}

.warp-input::-webkit-outer-spin-button,
.warp-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.warp-input:focus {
    outline: none;
    border-color: #007acc;
}

.warp-input:disabled {
    opacity: 0.5;
}

.warp-sep {
    font-size: 13px;
    color: #666;
}

.btn-run {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 30px;
    width: 100px;
    padding: 0 16px;
    background: #0e639c;
    color: white;
    border: none;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-run:hover:not(:disabled) {
    background: #1177bb;
}

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

/* Spinner */
.spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Main split */
.main-split {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.editor-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.resize-h-handle {
    width: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: col-resize;
    transition: background 0.15s;
    user-select: none;
}

.resize-h-handle:hover,
.resize-h-handle:active {
    background: #007acc;
}

.output-panel {
    display: flex;
    flex-direction: column;
    width: 38vw;
    min-width: 160px;
    min-height: 0;
    flex-shrink: 0;
    background: #252526;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: 28px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #bbbbbb;
    background: #2d2d2d;
    border-bottom: 1px solid #3c3c3c;
    flex-shrink: 0;
}

.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.footer-select {
    height: 18px;
    padding: 0 4px;
    background: #3c3c3c;
    border: 1px solid #555;
    border-radius: 3px;
    color: #d4d4d4;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 11px;
    cursor: pointer;
}

.footer-select:focus {
    outline: none;
    border-color: #007acc;
}


/* Tab bar */
.editor-tabs {
    display: flex;
    flex-direction: row;
    background: #2d2d2d;
    border-bottom: 1px solid #1e1e1e;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.editor-tabs::-webkit-scrollbar { display: none; }
.editor-tab {
    padding: 0 16px;
    height: 35px;
    display: flex;
    align-items: center;
    font-size: 13px;
    color: #969696;
    cursor: pointer;
    white-space: nowrap;
    border-right: 1px solid #1e1e1e;
    user-select: none;
    flex-shrink: 0;
}
.editor-tab:hover { color: #d4d4d4; background: #2a2d2e; }
.editor-tab.active {
    color: #d4d4d4;
    background: #1e1e1e;
    border-top: 1px solid #007acc;
}
.editor-tab-close {
    margin-left: 8px;
    font-size: 11px;
    opacity: 0;
    border-radius: 3px;
    padding: 1px 3px;
    line-height: 1;
}
.editor-tab:hover .editor-tab-close,
.editor-tab.active .editor-tab-close { opacity: 0.6; }
.editor-tab-close:hover { opacity: 1 !important; background: rgba(255,255,255,0.1); }

.editor-toolbar-group {
    display: flex;
    align-items: stretch;
    height: 100%;
    margin-left: -12px; /* bleed to panel-header left padding */
}
.btn-editor-toolbar {
    padding: 0 12px;
    height: 100%;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #bbbbbb;
    background: transparent;
    border: none;
    border-right: 1px solid #3c3c3c;
    cursor: pointer;
}
.btn-editor-toolbar:hover { background: rgba(255,255,255,0.07); color: #e8e8e8; }

/* Monaco editor container */
.editor-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Output body */
.output-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.hint {
    color: #666;
    font-size: 13px;
    padding: 16px 0;
    text-align: center;
}

.hint strong {
    color: #888;
}

.running-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    color: #999;
}

.spinner-output {
    border-color: rgba(255,255,255,0.15);
    border-top-color: #999;
    width: 14px;
    height: 14px;
}

.output-text {
    font-size: 15px;
    color: #9cdcfe;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    margin: 0 0 8px 0;
}

.error-text {
    font-size: 15px;
    color: #f48771;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    margin: 0;
}

/* Image section */
.image-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: var(--section-h, 45vh);
    min-height: 60px;
    overflow: hidden;
}

.resize-v-handle {
    height: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: row-resize;
    transition: background 0.15s;
    user-select: none;
}

.resize-v-handle:hover,
.resize-v-handle:active {
    background: #007acc;
}

.image-container {
    flex: 1;
    min-height: 0;
    padding: 12px;
    background: #141414;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#color-canvas {
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Debug controls in topbar */
.debug-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-dbg {
    height: 30px;
    width: 30px;
    padding: 0;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
    line-height: 1;
}

.btn-dbg:hover:not(:disabled) {
    background: #4e4e4e;
}

.btn-dbg:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-dbg-continue {
    background: #1a7a3a;
    border-color: #1a7a3a;
    color: white;
}

.btn-dbg-continue:hover:not(:disabled) {
    background: #22964a;
}

.btn-dbg-continue-back {
    background: #0e639c;
    border-color: #0e639c;
    color: white;
}

.btn-dbg-continue-back:hover:not(:disabled) {
    background: #1177bb;
}

.dbg-controls-sep {
    width: 1px;
    height: 20px;
    background: #555;
    margin: 0 2px;
    flex-shrink: 0;
}

.btn-icon-mirror {
    display: inline-block;
    transform: scaleX(-1);
}

.icon-step-into      { display: inline-block; transform: rotate(-45deg); }
.icon-step-out       { display: inline-block; transform: rotate(45deg); }
.icon-step-into-back { display: inline-block; transform: scaleX(-1) rotate(-45deg); }
.icon-step-out-back  { display: inline-block; transform: scaleX(-1) rotate(45deg); }

.btn-stop {
    height: 30px;
    width: 100px;
    padding: 0 12px;
    background: #6b1414;
    color: #f48771;
    border: 1px solid #8b2020;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-stop:hover {
    background: #8b1a1a;
}

.debug-step-info {
    font-size: 12px;
    color: #888;
    padding: 0 6px;
    white-space: nowrap;
    min-width: 150px;
    font-variant-numeric: tabular-nums;
}

.thread-selector .warp-sep {
    min-width: 62px;
    font-variant-numeric: tabular-nums;
}

.btn-permalink {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 30px;
    padding: 0 12px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    text-decoration: none;
    box-sizing: border-box;
}

.btn-permalink:hover {
    background: #4e4e4e;
    border-color: #777;
}

.btn-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 30px;
    width: 100px;
    padding: 0 12px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-settings:hover {
    background: #4e4e4e;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-label {
    font-size: 13px;
    color: #cccccc;
    width: 90px;
    flex-shrink: 0;
}

.settings-text-input {
    height: 30px;
    padding: 0 8px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    box-sizing: border-box;
    flex: 1;
    min-width: 0;
}

.settings-row > .warp-control {
    flex: 1;
}

.settings-row > .warp-control .warp-input {
    flex: 1;
    min-width: 0;
    width: 0;
}

.settings-text-input:focus {
    outline: none;
    border-color: #007acc;
}

.settings-text-input:disabled {
    opacity: 0.5;
}

.btn-debug-start {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 30px;
    width: 100px;
    padding: 0 12px;
    background: #3c3c3c;
    color: #d4d4d4;
    border: 1px solid #555;
    border-radius: 3px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    box-sizing: border-box;
}

.btn-debug-start:hover:not(:disabled) {
    background: #4e4e4e;
    border-color: #777;
}

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

/* Thread selector in debug mode */
.thread-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    font-size: 12px;
    color: #888;
}

/* Breakpoint hint in panel header */
.breakpoint-hint {
    font-size: 10px;
    color: #666;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 400;
}

/* Variable inspector */
.debug-vars-body {
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

/* Hierarchical variable list */
.var-list {
    width: 100%;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
}

.var-subsection-header {
    display: flex;
    align-items: center;
    gap: 2px;
    background: #252526;
    position: sticky;
    top: 0;
    z-index: 1;
    border-bottom: 1px solid #3c3c3c;
    padding: 4px 10px 4px 6px;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: #999;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
}

.var-subsection-header:hover {
    background: #2d2d2d;
}

.var-row {
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid #2d2d2d;
    padding: 3px 10px 3px 0;
    min-height: 22px;
}

.var-row:hover {
    background: #2a2a2a;
}

.var-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
    color: #888;
    font-size: 9px;
    transition: transform 0.12s ease;
    user-select: none;
    margin-right: 4px;
}

.var-toggle.expanded {
    transform: rotate(90deg);
}

.var-toggle-spacer {
    display: inline-block;
    width: 14px;
    flex-shrink: 0;
    margin-right: 4px;
}

.var-row-name {
    color: #9cdcfe;
    flex: 0 0 35%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 8px;
    /* subtract toggle width from the 35% so name+toggle = 35% of container */
    max-width: calc(35% - 18px);
}

.var-row-value {
    color: #ce9178;
    flex: 1;
    word-break: break-all;
}


/* Call stack table (reuses var-table) */
.var-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    table-layout: fixed;
}

.var-table col.col-name { width: 35%; }
.var-table col.col-value { width: 65%; }

.var-table thead tr {
    background: #2a2a2a;
    position: sticky;
    top: 0;
    z-index: 1;
}

.var-table th {
    padding: 5px 10px;
    text-align: left;
    font-weight: 600;
    color: #999;
    border-bottom: 1px solid #3c3c3c;
    font-size: 11px;
    letter-spacing: 0.3px;
}

.var-table tr:hover {
    background: #2a2a2a;
}

.callstack-selected {
    background: #094771 !important;
}

.var-table td {
    padding: 4px 10px;
    border-bottom: 1px solid #2d2d2d;
    vertical-align: top;
}

.var-name {
    color: #9cdcfe;
    white-space: nowrap;
    min-width: 80px;
}

.var-value {
    color: #ce9178;
    word-break: break-all;
}

/* Collapsible debug sections */
.debug-section {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.debug-section-vars {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-vars.section-collapsed {
    height: auto;
}

.debug-section-console {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-console.section-collapsed {
    height: auto;
}

.debug-console-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px;
}

.debug-section-exec {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
}

.callstack-exec-body {
    display: flex;
    flex-direction: row;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.callstack-pane {
    flex: 0 0 var(--callstack-w, 70%);
    min-width: 40px;
    overflow-y: auto;
    overflow-x: hidden;
}

.resize-inner-h-handle {
    width: 4px;
    flex-shrink: 0;
    background: #3c3c3c;
    cursor: col-resize;
    transition: background 0.1s;
}

.resize-inner-h-handle:hover,
.resize-inner-h-handle.dragging {
    background: #007acc;
}

/* Immediate window */
.debug-section-immediate {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.debug-section-immediate.section-collapsed {
    height: auto;
}

.imm-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-height: 0;
}

.imm-history {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.imm-entry {
    padding: 4px 10px;
    border-bottom: 1px solid #2d2d2d;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
}

.imm-expr {
    color: #9cdcfe;
}

.imm-prompt {
    color: #569cd6;
    user-select: none;
}

.imm-result {
    color: #ce9178;
    padding-left: 14px;
}

.imm-error {
    color: #f44747;
}

.imm-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-top: 1px solid #3c3c3c;
    background: #1e1e1e;
    flex-shrink: 0;
}

.imm-prompt-inline {
    color: #569cd6;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    user-select: none;
}

.imm-input {
    flex: 1;
    background: #2d2d2d;
    border: 1px solid #3c3c3c;
    border-radius: 3px;
    color: #d4d4d4;
    font-family: 'JetBrains Mono', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
    font-size: 12px;
    padding: 3px 6px;
    outline: none;
}

.imm-input:focus {
    border-color: #569cd6;
}

.imm-eval-btn {
    background: #0e639c;
    border: none;
    border-radius: 3px;
    color: #fff;
    font-size: 11px;
    padding: 3px 8px;
    cursor: pointer;
    white-space: nowrap;
}

.imm-eval-btn:hover {
    background: #1177bb;
}

.imm-eval-btn:disabled {
    background: #3c3c3c;
    color: #666;
    cursor: default;
}

.debug-section-exec.section-collapsed {
    height: auto;
}

.debug-section-callstack {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.debug-section-callstack.section-collapsed {
    height: auto;
}

.debug-section-image {
    height: var(--section-h, 240px);
    min-height: 0;
    flex-shrink: 0;
}

.debug-section-image.section-collapsed {
    height: auto;
}

.debug-panel-spacer {
    flex: 1;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
}

.collapsible-header:hover {
    background: #333;
}

.panel-header-left {
    display: flex;
    align-items: center;
    gap: 2px;
}

.collapse-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 18px;
    color: #777;
    flex-shrink: 0;
    transition: transform 0.12s ease;
    transform: rotate(0deg);
    line-height: 1;
}

.collapse-icon.expanded {
    transform: rotate(90deg);
}

/* Execution state section (kept for non-debug image-section) */

.exec-state-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}

/* Execution state grid */
.thread-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: #777;
}

.tl-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
}

.thread-grid {
    display: grid;
    gap: 2px;
}

.thread-cell {
    border-radius: 2px;
    cursor: pointer;
    transition: opacity 0.1s;
}

.thread-cell:hover { opacity: 0.75; }

.tc-active    { background: #4caf50; }
.tc-diverged  { background: #e88f1a; }
.tc-suspended { background: #e88f1a; }
.tc-exited    { background: #555; }

.tc-selected {
    box-shadow: 0 0 0 2px #ffffff, 0 0 0 3px rgba(0, 0, 0, 0.6);
    filter: brightness(1.6);
    position: relative;
    z-index: 2;
}

.debug-section-sep {
    height: 1px;
    background: #3c3c3c;
    margin: 4px 0;
}

.debug-output-section {
    border-top: 1px solid #3c3c3c;
    padding: 8px 12px;
}

.debug-output-label {
    font-size: 10px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

/* Scrollbar */
.output-body::-webkit-scrollbar {
    width: 6px;
}
.output-body::-webkit-scrollbar-track {
    background: #1e1e1e;
}
.output-body::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

#blazor-error-ui {
    background: #c00;
    bottom: 0;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: white;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}
