/*
// -----------------------------------------------------------------------------
// This file is part of the Nyl Language project.
//
// Copyright (c) 2026 Nyl Developers
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------------
*/

:root {
    --bg-primary: #181818;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #252526;
    --text-primary: #d4d4d4;
    --text-secondary: #858585;
    --accent-color: #007acc;
    --accent-hover: #0062a3;
    --border-color: #333333;
    --success-color: #4caf50;
    --error-color: #f48771;
    --debug-color: #d65600;
    --toolbar-height: 48px;
    --tabs-height: 36px;
    --status-height: 22px;
}

body.light-theme {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f3f3;
    --bg-tertiary: #eeeeee;
    --text-primary: #1e1e1e;
    --text-secondary: #616161;
    --border-color: #d1d1d1;
    --accent-color: #005fb8;
    --accent-hover: #004a8f;
    --success-color: #28a745;
    --error-color: #d73a49;
    --debug-color: #af4c00;
}

body.sepia-theme {
    --bg-primary: #f4ecd8;
    --bg-secondary: #e9e2d0;
    --bg-tertiary: #dfd7bf;
    --text-primary: #5b4636;
    --text-secondary: #7e6b5a;
    --border-color: #d6cca9;
    --accent-color: #8b4513;
    --accent-hover: #703810;
    --success-color: #3d7e3f;
    --error-color: #a52a2a;
    --debug-color: #8b4513;
}

body.solarized-theme {
    --bg-primary: #fdf6e3;
    --bg-secondary: #eee8d5;
    --bg-tertiary: #e1d9c1;
    --text-primary: #657b83;
    --text-secondary: #93a1a1;
    --border-color: #dcd0b3;
    --accent-color: #268bd2;
    --accent-hover: #1b669a;
    --success-color: #859900;
    --error-color: #dc322f;
    --debug-color: #b58900;
}

body.vs-light-theme {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f3f3;
    --bg-tertiary: #eeeeee;
    --text-primary: #1e1e1e;
    --text-secondary: #6e6e6e;
    --border-color: #cccccc;
    --accent-color: #68217a;
    /* VS Purple */
    --accent-hover: #50195e;
    --success-color: #107c10;
    --error-color: #a80000;
    --debug-color: #af4c00;
}

/* Theme-specific overrides for Variable Explorer and Console */
body.light-theme .var-name,
body.vs-light-theme .var-name {
    color: #0056b3;
}

body.light-theme .var-value,
body.vs-light-theme .var-value {
    color: #a31515;
}

body.sepia-theme .var-name {
    color: #8b4513;
}

body.sepia-theme .var-value {
    color: #6b4226;
}

body.high-contrast-theme .var-name {
    color: #ffffff;
    text-decoration: underline;
}

body.high-contrast-theme .var-value {
    color: #ffffff;
    font-weight: bold;
}

body.light-theme #console-output,
body.vs-light-theme #console-output {
    background-color: #f8f9fa;
}

body.sepia-theme #console-output {
    background-color: #f0e6cc;
}

body.solarized-theme #console-output {
    background-color: #eee8d5;
}

/* VS Light Status Bar Special Style */
body.vs-light-theme #status-bar {
    background-color: var(--accent-color);
    color: #ffffff;
    border-top: none;
}

body.vs-light-theme #status-bar span {
    color: #ffffff;
}

body.vs-light-theme #status-bar .status-dot {
    border: 1px solid #ffffff;
}

body.tokyo-night-theme {
    --bg-primary: #1a1b26;
    --bg-secondary: #16161e;
    --bg-tertiary: #1f2335;
    --text-primary: #a9b1d6;
    --text-secondary: #565f89;
    --border-color: #3b4261;
    --accent-color: #7aa2f7;
    --accent-hover: #89ddff;
    --success-color: #9ece6a;
    --error-color: #f7768e;
    --debug-color: #ff9e64;
}

body.high-contrast-theme {
    --bg-primary: #000000;
    --bg-secondary: #000000;
    --bg-tertiary: #121212;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --border-color: #ffffff;
    --accent-color: #ffffff;
    --accent-hover: #ffffff;
    --success-color: #ffffff;
    --error-color: #ffffff;
    --debug-color: #ffffff;
}

body.high-contrast-theme ::-webkit-scrollbar-thumb {
    border-radius: 0;
}

body.high-contrast-theme .btn-primary {
    background-color: transparent;
    color: #ffffff;
    border: 2px solid #ffffff;
    box-shadow: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 0;
    /* Flat look */
}

body.high-contrast-theme .btn-primary:hover {
    background-color: #ffffff;
    color: #000000;
}

body.high-contrast-theme .tab {
    border-radius: 0;
}

body.high-contrast-theme .tab.active {
    border-top: 4px solid #ffffff;
    background-color: #1a1a1a;
}

body.high-contrast-theme .icon-btn {
    border: 1px solid transparent;
    border-radius: 0;
    /* Flat look */
}

body.high-contrast-theme .icon-btn:hover {
    border-color: #ffffff;
    background-color: transparent;
}

/* Active Debug Buttons High Contrast Overrides */
body.high-contrast-theme #debug-continue-btn:not(:disabled),
body.high-contrast-theme #debug-step-over-btn:not(:disabled),
body.high-contrast-theme #debug-step-into-btn:not(:disabled),
body.high-contrast-theme #debug-step-out-btn:not(:disabled) {
    background-color: #ffffff !important;
    color: #000000 !important;
    border: 2px solid #ffffff;
}

body.high-contrast-theme #console-output {
    background-color: #000000;
    border: 1px solid #ffffff;
    color: #ffffff !important;
}

body.high-contrast-theme .log-entry {
    color: #ffffff !important;
    border-bottom: none;
    /* Removed as requested */
}

/* Ace Markers High Contrast Overrides */
body.high-contrast-theme .ace_active-line {
    background-color: transparent !important;
    border: 1px solid #ffffff !important;
    box-sizing: border-box;
}

body.high-contrast-theme .ace_gutter-cell.ace_breakpoint {
    box-shadow: 0px 0px 0px 2px #ffffff inset !important;
}

body.high-contrast-theme .ace_gutter-cell.ace_breakpoint::after {
    color: #ffffff !important;
}

body.high-contrast-theme .ace_gutter {
    border-right: 1px solid #ffffff;
}

body.high-contrast-theme .ace_selection {
    background: #ffffff !important;
    color: #000000 !important;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header / Toolbar */
header.main-toolbar {
    min-height: var(--toolbar-height);
    height: auto;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px;
    z-index: 10;
    flex-wrap: wrap;
    gap: 10px;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 1;
    min-width: 0;
}

.logo-section h1 {
    font-size: 1rem;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 415px) {
    .logo-section h1 {
        display: none;
    }

    .logo-section {
        gap: 0;
    }
}

.actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* removed scoped status-dot */

/* Tabs Bar */
#tabs-bar {
    height: var(--tabs-height);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Ensure left alignment */
}

#tabs-container {
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    height: 100%;
    flex: 1;
    /* Allow to fill space */
}

#tabs-container::-webkit-scrollbar {
    display: none;
}

.tab {
    height: 100%;
    padding: 0 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    margin-right: 0;
    /* Remove horizontal spacing */
}

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

.tab.active {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-top: 2px solid var(--accent-color);
}

.tab.is-debugging {
    border-top: 2px solid var(--debug-color);
    background-color: rgba(220, 104, 3, 0.1);
    /* Subtle orange tint */
    color: var(--debug-color);
}

.tab .close-btn {
    opacity: 0.3;
    padding: 10px;
    /* Increased hit box */
    margin-right: -10px;
    border-radius: 4px;
    font-size: 18px;
    /* Increased for mobile */
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab .close-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}

/* Editor Area */
main#editor-main {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
}

#editor-workspace {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
}

#editor-instance {
    flex: 1;
    height: 100%;
}

.side-panel {
    width: 280px;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s;
    overflow: hidden;
}

.side-panel.closed {
    width: 0;
    border-left: none;
}

@media (max-width: 600px) {
    .side-panel {
        position: fixed;
        right: 0;
        top: calc(var(--toolbar-height) + 1px);
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 1000;
        /* Above editor and status bar */
        box-shadow: -10px 0 20px rgba(0, 0, 0, 0.4);
        transform: translateX(0);
        border-left: 1px solid var(--border-color);
        background-color: var(--bg-secondary);
        border-radius: 12px 0 0 0;
        /* Elegant rounded corner at the top-left */
    }

    .side-panel.closed {
        transform: translateX(100%);
        width: 85% !important;
        /* Keep width for animation */
        border-left: none;
        box-shadow: none;
    }

    #editor-workspace {
        position: relative;
    }
}

.panel-header {
    height: 38px;
    /* Slightly taller for touch */
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-tertiary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
    background-color: var(--success-color);
    /* Fallback to green */
    flex-shrink: 0;
}

.status-dot.loading {
    background-color: var(--error-color);
    /* Red for loading */
}

/* Resizer */
.resizer-horizontal {
    height: 8px;
    /* Larger hit area */
    background-color: var(--bg-primary);
    /* Blend with background */
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--bg-primary);
    cursor: ns-resize;
    z-index: 50;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

@media (max-width: 600px) {
    .resizer-horizontal {
        height: 16px;
        /* Even larger hit area for fingers */
    }
}

.resizer-horizontal:hover,
.resizer-horizontal.dragging {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

/* Console Panel */
#console-panel {
    height: 210px;
    /* Default height */
    min-height: 40px;
    max-height: 80vh;
    max-height: 80dvh;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.console-header {
    height: 30px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-tertiary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

#console-output {
    flex: 1;
    overflow-y: auto;
    padding: 10px 16px;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 13px;
    white-space: pre-wrap;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
}

/* Sidebar /* Overlay for bottom sheets */
.log-debug {
    color: var(--debug-color);
}
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 900;
    pointer-events: none;
    backdrop-filter: blur(2px);
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.5);
}

.bottom-sheet.open {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    margin: 12px auto;
}

/* Buttons and Inputs */
button.btn-primary {
    background-color: var(--success-color);
    color: #181818;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

button.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

button.btn-primary:active {
    transform: translateY(0);
}

button.btn-primary:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
    animation: pulse-loading 1.8s ease-in-out infinite;
}

@keyframes pulse-loading {

    0%,
    100% {
        opacity: 0.35;
    }

    50% {
        opacity: 0.55;
    }
}

/* icon-btn adjustments */
.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

/* Active Debug Buttons Highlight */
#debug-continue-btn:not(:disabled),
#debug-step-over-btn:not(:disabled),
#debug-step-into-btn:not(:disabled),
#debug-step-out-btn:not(:disabled) {
    color: var(--debug-color);
    background-color: rgba(214, 86, 0, 0.15);
    /* var(--debug-color) with opacity */
    font-weight: 500;
}

#debug-continue-btn:not(:disabled):hover,
#debug-step-over-btn:not(:disabled):hover,
#debug-step-into-btn:not(:disabled):hover,
#debug-step-out-btn:not(:disabled):hover {
    background-color: var(--debug-color);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(214, 86, 0, 0.25);
}

.icon-btn span {
    margin-left: 6px;
    font-size: 11px;
    font-weight: 600;
}

@media (max-width: 600px) {
    .icon-btn span {
        display: none;
    }
}

/* Variables Explorer */
.variables-explorer-ui {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.var-section-header {
    background: var(--bg-hover);
    color: var(--text-secondary);
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    margin-top: 10px;
}

.var-section-header:first-child {
    margin-top: 0;
}

.var-entry {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    font-family: 'JetBrains Mono', monospace;
}

.var-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 11px;
}

.var-name {
    color: #9cdcfe;
    font-weight: 600;
}

.var-type {
    color: var(--text-secondary);
}

.var-value-container {
    display: flex;
}

.var-value {
    color: #ce9178;
    word-break: break-all;
    font-size: 13px;
}

.var-value-input {
    background: transparent;
    border: 1px solid transparent;
    color: #ce9178;
    width: 100%;
    font-family: inherit;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 3px;
}

.var-value-input:hover {
    border-color: var(--border-color);
}

.var-value-input:focus {
    background-color: var(--bg-primary);
    border-color: var(--accent-color);
    outline: none;
}

@keyframes flash-success {
    from {
        background-color: var(--success-color);
        color: #000;
    }

    to {
        background-color: transparent;
    }
}

.success-flash {
    animation: flash-success 0.5s ease-out;
}

@keyframes flash-error {
    from {
        background-color: var(--error-color);
        color: #fff;
    }

    to {
        background-color: transparent;
    }
}

.error-flash {
    animation: flash-error 0.8s ease-out;
}

/* Settings Menu Items */
.settings-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-group label {
    font-size: 14px;
    color: var(--text-secondary);
}

.settings-input {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.settings-input:focus {
    outline: 2px solid var(--accent-color);
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.menu-item {
    padding: 12px 15px;
    font-size: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-item:active {
    background-color: var(--bg-tertiary);
}

.menu-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 10px 0;
}

/* Ace Markers */
.ace_active-line {
    background-color: rgba(214, 86, 0, 0.2) !important;
    border-left: 3px solid var(--debug-color);
}

.ace_gutter-cell.ace_breakpoint {
    border-radius: 20px 0px 0px 20px;
    box-shadow: 0px 0px 1px 1px var(--error-color) inset;
}

.ace_gutter-cell.ace_breakpoint::after {
    content: "●";
    color: var(--error-color);
    position: absolute;
    left: 4px;
    font-size: 14px;
}

.debug-line-highlight {
    background-color: rgba(220, 104, 3, 0.4) !important;
    position: absolute;
    width: 100% !important;
    left: 0 !important;
    z-index: 20;
}

.console-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.tab-add-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 16px;
    /* Increased hit box */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 20px;
}

.tab-add-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn.small {
    padding: 2px 8px;
    font-size: 10px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

#status-bar {
    height: var(--status-height);
    background-color: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom);
    /* Fix for Brave/iOS bars */
    box-sizing: content-box;
    /* Ensure padding adds to height if needed */
    font-size: 11px;
    color: var(--text-secondary);
}

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

.full-width {
    width: 100%;
    justify-content: center;
}

.menu-content {
    padding: 20px;
}

/* --- Nyl Integration & PWA Styles --- */
.toolbar-nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 12px;
}

.toolbar-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.toolbar-nav-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    border-color: var(--accent-color);
}

.menu-section-label {
    padding: 6px 15px 4px 15px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.menu-link-item {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 12px;
}

@media (max-width: 768px) {
    .toolbar-nav-links {
        display: none;
    }
}
