/* Footer height variable - must be defined at root level */
:root {
    --footer-height: 24px;
}

/* Grundlegende Stile und Farbschema */
body {
    font-family: 'Roboto Mono', 'Courier New', monospace;
    background-color: #0a0a14;
    color: #e0e0e0;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Dark scrollbars for all elements */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a24;
}

::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4a4a5a;
}

::-webkit-scrollbar-corner {
    background: #1a1a24;
}

/* Firefox scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: #3a3a4a #1a1a24;
}

/* Header-Bereich für die Steuerung */
header {
    position: relative;
    background-color: #191923;
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid #333;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* ============================================
   Header Panels - Shared Styles
   ============================================ */

/* Base panel - floating below header */
.header-panel {
    position: absolute;
    top: 100%;
    background-color: #191923;
    border: 1px solid #333;
    border-top: none;
    border-radius: 0 0 6px 6px;
    z-index: 100;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.header-panel.hidden {
    display: none !important;
}

/* Collapsed state button */
.header-panel-collapsed {
    position: absolute;
    top: 100%;
    background-color: #191923;
    border: 1px solid #333;
    border-top: none;
    border-radius: 0 0 4px 4px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    color: #888;
    cursor: pointer;
}

.header-panel-collapsed:hover {
    color: #e0e0e0;
}

.header-panel-collapsed.hidden {
    display: none !important;
}

.header-panel-collapsed .panel-info {
    font-family: 'Roboto Mono', 'Courier New', monospace;
    white-space: nowrap;
}

/* Toggle button inside panels */
.panel-toggle {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 10px;
    line-height: 1;
}

.panel-toggle:hover {
    color: #e0e0e0;
    background: rgba(255,255,255,0.05);
    border-radius: 3px;
}

/* ============================================
   Tick Panel - Left side
   ============================================ */

#tick-panel {
    left: 22px;
    padding: 6px 10px 6px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

#tick-panel-collapsed {
    left: 22px;
    padding: 2px 10px;
}

/* ============================================
   Organism Panel - Right side
   ============================================ */

#organism-panel {
    right: 35px;
    width: 620px;
    padding: 0;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 54px - 40px - var(--footer-height, 24px));
    overflow: hidden;
}

/* Organism panel header with toggle and summary */
.organism-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 10px;
    border-bottom: 1px solid #333;
    cursor: pointer;
}

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

.organism-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #e0e0e0;
}

.organism-count {
    color: #888;
    font-size: 12px;
}

.organism-panel-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Organism list (collapsible) */
.organism-list-container {
    border-bottom: 1px solid #333;
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.organism-list-container.collapsed {
    max-height: 0;
    border-bottom: none;
}

.organism-list {
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
}

.organism-list-item {
    padding: 3px 12px;
    cursor: pointer;
    font-size: 12px;
    color: #aaa;
    display: flex;
    align-items: center;
    gap: 0;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    line-height: 1.3;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.organism-list-item:hover {
    background: rgba(255,255,255,0.05);
}

.organism-list-item.selected {
    background: rgba(74, 158, 255, 0.15);
}

/* Table-like column layout */
.organism-col {
    flex-shrink: 0;
    padding-right: 4px;
}

.organism-col-id {
    width: 30px;
    font-weight: bold;
}

.organism-col-er {
    width: 70px;
    color: #888;
}

.organism-col-sr {
    width: 120px;
    color: #888;
}

/* Info line in organism state view */
.organism-info-line {
    color: #888;
    font-style: italic;
}

.organism-col-ip {
    width: 120px;
    color: #aaa;
}

.organism-col-dps {
    width: 25px;
    color: #666;
}

.organism-col-dp0 {
    width: 80px;
    color: #888;
}

.organism-col-dp1 {
    width: 80px;
    color: #888;
}

.organism-col-deselect {
    width: 20px;
    flex-shrink: 0;
    margin-left: auto;
    text-align: right;
}

/* Labels in columns */
.organism-label {
    color: #555;
    margin-right: 2px;
}

/* Deselect button */
.organism-deselect {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 0 4px;
    font-size: 12px;
    line-height: 1;
}

.organism-deselect:hover {
    color: #ff6666;
}

/* Clickable links in organism list */
.organism-list-item .clickable-position,
.organism-list-item .clickable-parent,
.organism-list-item .clickable-tick {
    color: #4a9eff;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
}

.organism-list-item .clickable-position:hover,
.organism-list-item .clickable-parent:hover,
.organism-list-item .clickable-tick:hover {
    color: #7cb9ff;
}

/* Selected organism display (shown when list collapsed) */
.organism-selected-display {
    border-bottom: 1px solid #333;
}

.organism-selected-display:empty {
    display: none;
    border-bottom: none;
}

.organism-selected-display .organism-list-item {
    background: rgba(74, 158, 255, 0.1);
}

/* Organism details section */
.organism-details-container {
    flex: 1;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    font-size: 12px;
    font-family: 'Roboto Mono', 'Courier New', monospace;
}

/* Hide padding when all children are empty */
.organism-details-container:not(:has([data-section]:not(:empty))) {
    padding: 0;
}

/* Placeholder when no organism selected */
.organism-panel-empty {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 12px;
}

/* Logo Container */
.logo-container {
    display: flex;
    align-items: center;
    position: relative;
}

/* Logo Text - Doto Black 900 */
.logo-text {
    font-family: 'Doto', sans-serif;
    font-weight: 900;
    font-size: 36px;
    color: #e0e0e0;
    letter-spacing: 2px;
    line-height: 1;
    opacity: 0.9;
    white-space: nowrap;
}

/* Loading Indicator - animated line under the logo */
.loading-indicator {
    position: absolute;
    top: 100%; /* Position directly below the logo text */
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background-color: #4a9eff;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    margin-top: 2px;
    /* Ensure it doesn't affect header height by being absolutely positioned */
    pointer-events: none;
}

/* When active, animate width to match logo text width */
.loading-indicator.active {
    opacity: 1;
    animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {
    0% {
        width: 0;
    }
    50% {
        /* Width matches the logo text width - calculated dynamically via JavaScript */
        width: var(--logo-text-width, 280px);
    }
    100% {
        width: 0;
    }
}

/* Instruction View Styles - styled like State View */
.failed-instruction {
    position: relative;
    background-color: rgba(255, 0, 0, 0.15);
    cursor: help; /* Shows tooltip on hover */
}

.failed-instruction::before {
    content: '';
    position: absolute;
    left: -8px; /* Position left of .code-view padding */
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: #ff4444;
}

/* Register annotations (e.g., =D:0) in green and italic */
.register-annotation {
    color: #a0e0a0; /* Match injected-value color from call stack */
    font-style: italic;
}

/* Instruction line layout with fixed-width columns */
.instruction-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    margin: 0; /* Remove default margin to keep spacing tight */
    line-height: 1.4; /* Keep line height consistent */
}

.instruction-content {
    flex: 0 0 auto;
    min-width: 0; /* Allow shrinking if needed */
}

.instruction-position {
    display: inline-block;
    font-family: 'Roboto Mono', 'Courier New', monospace;
}

.instruction-energy {
    flex: 0 0 auto;
    margin-left: auto;
    padding-left: 1em;
}

/* Tooltip */
.cell-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    /* Position wird dynamisch gesetzt */
}

.cell-tooltip.show {
    opacity: 1;
}

.cell-tooltip .tooltip-coords {
    color: #a0e0a0;
    font-weight: bold;
}

.cell-tooltip .tooltip-type {
    color: #ffd700;
}

.cell-tooltip .tooltip-owner {
    color: #87ceeb;
}

.cell-tooltip .tooltip-opcode {
    color: #dda0dd;
}

.cell-tooltip .tooltip-separator {
    color: #666;
    margin: 0 4px;
}

button {
    background-color: #3a3a5a;
    border: 1px solid #5a5a7a;
    color: #e0e0e0;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
}
button:hover { background-color: #4a4a6a; }

#btn-zoom-toggle {
    white-space: nowrap;
}

.tick-input-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.tick-input-wrapper input[type="number"] {
    width: 120px;
    background-color: #222;
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 8px 44px 8px 8px; /* space for suffix */
    border-radius: 4px;
}
.tick-input-wrapper input[type="number"]::-webkit-outer-spin-button,
.tick-input-wrapper input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.tick-input-wrapper input[type="number"] {
    -moz-appearance: textfield; /* Firefox: remove arrows */
    appearance: textfield;
}
.tick-input-wrapper .tick-total-suffix {
    position: absolute;
    right: 8px;
    pointer-events: none;
    color: #aaa;
    font-size: 1em;
}

/* Hauptcontainer (ohne Header) */
main.container {
    display: flex;
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    margin-bottom: var(--footer-height); /* Leave space for fixed footer */
}

/* Welt-Container, der den Viewport für das Canvas bereitstellt (keine DOM-Scrollbars für die Welt) */
.world-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden; /* Welt wird über Kamera bewegt, nicht per DOM-Scrollbars */
    padding: 0;
    box-sizing: border-box;
    background-color: #1a1a28; /* Dark gray border area - distinguishable from grid #14141e */
}

#worldCanvas {
    background-color: #14141e;
    flex-shrink: 0;
}

/* Unchangeable info styles */
.unchangeable-info {
    color: #aaa;
    margin-bottom: 8px;
    line-height: 1.4;
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: center;
    padding-left: 8px;
}

.unchangeable-info-item {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.unchangeable-info-label {
    color: #888;
    font-weight: 500;
}

.unchangeable-info-value {
    color: #e0e0e0;
}

.clickable-parent {
    color: #4a9eff;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.clickable-parent:hover {
    color: #6bb3ff;
}

.parent-dead {
    color: #666;
    text-decoration: line-through;
    cursor: not-allowed;
}

.clickable-tick {
    color: #4a9eff;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.clickable-tick:hover {
    color: #6bb3ff;
}

.clickable-position {
    color: #4a9eff;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
    margin-right: 4px;
}

.clickable-position:hover {
    color: #6bb3ff;
}


.changeable-box {
    background-color: #000;
    border: 1px solid #333;
    padding: 8px;
    border-radius: 3px;
    margin-top: 5px;
    white-space: pre;
    overflow-x: auto;
    font-size: 1em;
}

.code-view {
    background-color: #000;
    padding: 8px;
    border-radius: 3px;
    margin-top: 5px;
    border: 1px solid #333;
    white-space: pre;
    overflow-x: auto;
    overflow-y: visible; /* Allow red bar to extend left */
    font-size: 1em;
    line-height: 1.4; /* Fixed line height to prevent height changes when highlighting */
}

/* Change highlighting styles */
.changed {
    color: #ffb366;
    font-weight: bold;
}

.changed-field {
    color: #ffb366;
    font-weight: bold;
    display: inline-block;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    font-family: 'Roboto Mono', 'Courier New', monospace !important;
    white-space: pre !important;
    letter-spacing: normal !important;
    word-spacing: normal !important;
    box-sizing: border-box !important;
    line-height: inherit !important;
    vertical-align: baseline !important;
    width: fit-content !important;
    min-width: fit-content !important;
    max-width: fit-content !important;
}

.changed-line {
    color: #ffb366;
    font-weight: bold;
    display: inline;
    margin: 0;
    padding: 0;
    line-height: inherit;
    vertical-align: baseline;
}

.injected-value {
    font-style: italic;
    color: #a0e0a0;
    font-size: 1em;
    margin-left: 1px;
    opacity: 0.8;
}

/* Error bar for displaying API errors */
.error-bar {
    position: fixed; /* Take the element out of the normal document flow */
    top: 54px; /* Position it directly below the header (approx. height) */
    left: 0;
    width: 100%;
    box-sizing: border-box; /* Ensure padding is included in the width */
    background-color: #8b1a1a; /* Dark red background */
    color: #ffffff;
    padding: 10px 40px 10px 15px;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #aa2a2a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    z-index: 1001; /* Ensure it's above the world-container and sidebar */
}

.error-bar.error-bar-visible {
    display: flex;
}

.error-bar-message {
    flex: 1;
    font-size: 0.9em;
    line-height: 1.4;
}

.error-bar-close {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.error-bar-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.error-bar-close:active {
    background-color: rgba(255, 255, 255, 0.3);
}

.header-bar {
    display: flex;
    justify-content: space-between;
}

/* --- Source Code View --- */
.source-view-container {
    margin-top: 15px;
    border-top: 1px solid #333;
    padding-top: 15px;
}

.assembly-code-view {
    background-color: #000;
    border: 1px solid #333;
    padding: 8px;
    border-radius: 3px;
    font-size: 10px;
    line-height: 1.4;
    max-height: 320px;
    overflow-y: auto;
}

.source-line {
    display: flex;
    white-space: pre;
    align-items: baseline;
    line-height: 1.4;
}

.source-line.collapsible-source-line {
    cursor: pointer;
}

.source-line.collapsible-source-line:hover {
    background-color: rgba(60, 80, 120, 0.3); /* Slight highlight on hover */
}

.active-source-line {
    background-color: #3c5078; /* Same blue as sidebar-toggle-btn */
    color: #ffffff;
    font-weight: bold;
    width: 100%; /* Ensure background covers full width */
}

/* Collapse indicator placeholder - always takes space to keep columns aligned */
.collapse-indicator-placeholder {
    flex-shrink: 0;
    width: 16px;
    margin-right: 2px;
}

.collapse-indicator {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    color: #888;
    font-size: 0.8em;
    user-select: none;
    cursor: pointer;
    margin-right: 2px;
}

.collapse-indicator:hover {
    color: #aaa;
}

#source-status-bar {
    /* Container for status messages */
    flex-shrink: 0;
}

.line-number {
    flex-shrink: 0;
    width: 36px;
    color: #888;
    text-align: right;
    padding-right: 6px;
    user-select: none;
}

/* Machine instructions container - visually groups instructions belonging to a source line */
.machine-instructions-container {
    margin-left: 49px; /* Align border-left with collapse-indicator position: line-number (36px + 6px padding) = 42px */
    margin-top: 2px;
    margin-bottom: 4px;
    padding: 4px 8px 0px 0; /* No left padding, so border-left aligns with collapse-indicator */
    border-left: 1px solid #444; /* Thin vertical line to show grouping, positioned directly under collapse-indicator */
    background-color: rgba(255, 255, 255, 0.02); /* Slight highlighting */
    overflow: hidden;
    transition: max-height 0.2s ease-out, opacity 0.2s ease-out;
    max-height: 500px; /* Sufficiently large for expanded state */
    opacity: 1;
}

.machine-instructions-container.collapsed {
    max-height: 0;
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

/* Individual machine instruction line */
.machine-instruction {
    display: flex;
    align-items: center;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    font-size: 12px;
    color: #aaa;
    margin-left: 10px;
    padding: 2px 0;
    line-height: 1.4;
}

/* Active machine instruction - highlighted */
.machine-instruction.active-machine-instruction {
    color: #fff;
    background-color: rgba(74, 158, 255, 0.15); /* Slight blue tint */
}

/* Machine instruction indicator (arrow for active instruction) */
.machine-instruction-indicator {
    width: 20px;
    padding-right: 4px;
    text-align: center;
    color: #888;
    font-weight: bold;
}

.machine-instruction.active-machine-instruction .machine-instruction-indicator {
    color: #4a9eff;
}

/* Machine instruction opcode */
.machine-instruction-opcode {
    color: #bbb;
    font-weight: 500;
    margin-right: 4px;
}

.machine-instruction.active-machine-instruction .machine-instruction-opcode {
    color: #fff;
}

/* Machine instruction operands */
.machine-instruction-operands {
    color: #999;
}

.machine-instruction.active-machine-instruction .machine-instruction-operands {
    color: #ccc;
}

.assembly-line {
    margin: 0;
    padding: 0;
    line-height: inherit;
}

.assembly-file-dropdown {
    width: 100%;
    background-color: #000;
    border: 1px solid #333;
    color: #e0e0e0;
    padding: 6px 8px;
    border-radius: 3px;
    margin-bottom: 10px;
    font-size: 12px;
    font-family: 'Roboto Mono', 'Courier New', monospace;
    flex-shrink: 0; /* Prevent dropdown from shrinking */
}

/* Virtual Scrollbars */
.scrollbar-track-v, .scrollbar-track-h {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.1);
    display: none; /* Initially hidden */
    z-index: 10;
    /* Adjustments for positioning within main.container */
    box-sizing: border-box; 
}
.scrollbar-track-v {
    right: 0;
    top: 0;
    width: 10px;
    height: calc(100% - 10px); /* Avoid overlapping horizontal scrollbar */
}
.scrollbar-track-h {
    bottom: 0;
    left: 0;
    height: 10px;
    width: calc(100% - 10px); /* Avoid overlapping vertical scrollbar */
}

.scrollbar-thumb-v, .scrollbar-thumb-h {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.4);
    border-radius: 5px;
}
.scrollbar-thumb-v {
    width: 100%;
}
.scrollbar-thumb-h {
    height: 100%;
}

/* --- Tooltips --- */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: 115%; /* Position below the button */
    left: 50%;
    transform: translateX(-50%);
    
    background-color: #2a2a3a;
    color: #e0e0e0;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid #4a4a6a;
    font-size: 12px;
    font-family: sans-serif;
    white-space: nowrap;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    transition-delay: 0.5s; /* Add a small delay before showing */
    z-index: 1000;
    pointer-events: none;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
}
