/*!
 * invocation_tree_web
 * Description: Online debugger tool for Python code using invocation_tree  
 * for visualization of data on the call stack.
 * 
 * @copyright (c) 2025 Bas Terwijn. All rights reserved.
 * 
 * This file, its source code, and its functionality are the proprietary
 * property of Bas Terwijn and are protected by copyright law. You are
 * granted no right to reproduce, distribute, or create derivative works
 * from this code without explicit permission.
 * 
 * For inquiries, contact: bterwijn@gmail.com
 * Terms of Service: https://invocation-tree.com/terms
 */

/* Import friendly font from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Apply friendly font to all elements */
html, body, * {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
}

/* Preserve original font for SVG container and its contents */
#svg-container, #svg-container * {
    font-family: initial !important;
}

/* Preserve original font for CodeMirror editor */
.CodeMirror, .CodeMirror * {
    font-family: monospace !important;
}

html, body { 
    height: 100%; 
    margin: 0; 
    /* Enable browser UI hiding on mobile */
    -webkit-overflow-scrolling: touch;
}

/* Mobile-specific full screen behavior */
@media (max-width: 768px), (max-height: 768px) and (orientation: landscape) {
    html, body {
        height: 100%;
        min-height: 100vh;
        /* Use dynamic viewport units for mobile browser UI hiding */
        min-height: 100dvh; /* Dynamic viewport height - adjusts as browser UI hides */
        overflow-x: hidden;
    }
    
    #full-page { 
        height: 100vh; /* Use full viewport height on mobile */
        min-height: 100vh;
        min-height: 100dvh; /* Dynamic viewport height */
        display: flex; 
        flex-direction: row; 
    }
    
    /* Hide footer on mobile to maximize screen space */
    #footer {
        display: none;
    }
}

/* Desktop behavior */
@media (min-width: 769px) and (min-height: 769px) {
    #full-page { 
        height: calc(100vh - 26px); 
        display: flex; 
        flex-direction: row; 
    }
}
#left-side { flex: 0 0 50%; min-width: 8px; display: flex; flex-direction: column; }
#right-side { flex: 1 1 auto; min-width: 8px; display: flex; flex-direction: column; }

#footer {
    height: 26px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #6c757d;
}

#footer a {
    color: #6c757d;
    text-decoration: none;
}

#footer a:hover {
    text-decoration: underline;
}

#divider-horizontal { width: 8px; min-width: 8px; background: #ddd; cursor: col-resize; z-index: 1000; position: relative; }
#divider-horizontal:hover { background: #afafaf; }
#divider-vertical-left { height: 8px; min-height: 8px; background: #ddd; cursor: row-resize; z-index: 1000; position: relative; }
#divider-vertical-left:hover { background: #afafaf; }
#divider-vertical-right { height: 8px; min-height: 8px; background: #ddd; cursor: row-resize; z-index: 1000; position: relative; }
#divider-vertical-right:hover { background: #afafaf; }

@media (max-width: 768px), (max-height: 768px) and (orientation: landscape) {
    #divider-horizontal {
        width: 20px !important;
        min-width: 20px !important;
        background: #bbb !important;
        cursor: col-resize;
        touch-action: pan-y; /* Allow vertical scrolling, prevent horizontal */
    }

    #divider-vertical-left,
    #divider-vertical-right {
        height: 20px !important;
        min-height: 20px !important;
        background: #bbb !important;
        cursor: row-resize;
        touch-action: pan-x; /* Allow horizontal scrolling, prevent vertical */
    }
    
    /* Dragging state for mobile dividers */
    #divider-horizontal.dragging,
    #divider-vertical-left.dragging,
    #divider-vertical-right.dragging {
        background: #7f7f7f !important;
    }
}

#left-top { flex: 0 0 20%; min-height: 8px; display: flex; flex-direction: column; position: relative; z-index: 1; }
#left-bottom { flex: 1 1 auto; min-height: 8px; display: flex; flex-direction: column; position: relative; z-index: 10; }
#right-top { flex: 0 0 75%; min-height: 8px; display: flex; flex-direction: column; position: relative; z-index: 100; }
#right-bottom { flex: 1 1 auto; min-height: 8px; display: flex; flex-direction: column; position: relative; z-index: 100; }

#header-row {
    display: flex;
    align-items: center;
    padding: 5px;
    position: relative;
}

#title {
    text-align: center;
    flex-grow: 1;
}

#title h3 {margin:4px;}
#log {width: 100%; height: 100%; box-sizing: border-box; resize: none;}

/* Debug Buttons Layout */
#debug-buttons {
    padding: 4px;
    background: #f7f7f7;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.debug-left {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Make timestep input fit exactly 4 characters */
#timestep {
    width: 5ch !important; /* 5 character width */
    min-width: 5ch !important;
    max-width: 5ch !important;
    text-align: center;
}

.debug-right {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: auto;
}

#timestep {
    width: 40px;
    text-align: right;
}

/* SVG Viewer Styles */
#image-buttons {
    padding: 5px;
    background: #f7f7f7;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;  /* Aligns items to the right */
    position: relative;
    z-index: -1;  /* Hide below right-side content */
}

#image-buttons button {
    padding: 3px 8px;
    cursor: pointer;
}

/* Allow the inner button group to wrap as well */
#image-buttons .d-flex {
    flex-wrap: wrap;
    gap: 2px;
}

#svg-zoom-info {
    margin-left: 2px;  /* Give some space after the last button */
    color: #666;
    font-size: 12px;
    min-width: 44px;    /* Fixed minimum width */
    text-align: right;  /* Right-align the text within the fixed width */
    display: inline-block; /* Ensure width property is respected */
}

#svg-viewer {
    flex: 1;
    overflow: hidden;
    position: relative;
    background: #fff;
    min-height: 0;
    display: flex;
}

#svg-container {
    position: relative;
    overflow: hidden; /* Changed from 'auto' to 'hidden' to remove scrollbars */
    flex: 1;
    cursor: grab;
}

#svg-container:active {
    cursor: grabbing;
}

#svg-container svg {
    display: block;
    transform-origin: 0 0;
}
#code-wrap {flex: 1 1 auto; min-height: 0; display: flex; }
#code {width:100%;height:100%}
#output {width: 100%; height: 100%; box-sizing: border-box; resize: none; font-family: monospace !important;}

.CodeMirror { border: 1px solid #ddd; height: 100%; width: 100%; }
.CodeMirror-gutters { border-right: 1px solid #ddd; background: #f7f7f7; }
.breakpoints { width: 1.2em; }
.breakpoint { color: #d00; font-size: 16px; line-height: 16px; }
.current-line { background: rgba(255, 230, 180, 0.7); }

/* Simulated pressed button styling */
.sim-pressed {
    background-color: #d4d4d4 !important;
    border-color: #adadad !important;
    box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125) !important;
    transform: translateY(1px);
    transition: all 0.05s ease;
}

/* Custom button colors for animate/play/pause */
#animate.btn-warning {
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
    color: #000 !important;
}

#animate.btn-warning:hover:not(:disabled) {
    background-color: #e0a800 !important;
    border-color: #d39e00 !important;
    color: #000 !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.15s ease;
}

#animate.paused {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: #fff !important;
}

#animate.paused:hover:not(:disabled) {
    background-color: #c82333 !important;
    border-color: #bd2130 !important;
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.15s ease;
}

/* Enhanced hover effects for all buttons */
.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
    background-color: #0056b3 !important;
    border-color: #004085 !important;
}

.btn-success:hover:not(:disabled) {
    background-color: #1e7e34 !important;
    border-color: #1c7430 !important;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #545b62 !important;
    border-color: #4e555b !important;
}

.btn-danger:hover:not(:disabled) {
    background-color: #c82333 !important;
    border-color: #bd2130 !important;
}

.btn-outline-secondary:hover:not(:disabled) {
    background-color: #6c757d !important;
    border-color: #6c757d !important;
    color: #fff !important;
}
