/* ═══════════════════════════════════════════════════════════════════════════
   HeLL IDE Web — main stylesheet
   Dark VS Code–inspired theme, responsive for desktop and mobile.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset / base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-app:       #1e1e1e;
    --bg-panel:     #252526;
    --bg-sidebar:   #2d2d2d;
    --bg-toolbar:   #3c3c3c;
    --bg-console:   #1a1a1a;
    --bg-input:     #2a2a2a;
    --bg-hover:     #383838;
    --bg-active:    #094771;
    --bg-selection: #264f78;

    --border:       #444;
    --border-light: #555;

    --text:         #d4d4d4;
    --text-muted:   #858585;
    --text-heading: #cccccc;

    --accent:       #007acc;
    --accent-hover: #1a8fe8;
    --danger:       #f44747;
    --warning:      #cca700;
    --success:      #4ec9b0;
    --info:         #75beff;

    --font-mono: 'Consolas', 'Fira Code', 'Cascadia Code', 'Courier New', monospace;
    --font-ui:   system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    --toolbar-h: 42px;
    --console-h: 220px;
    --debug-w:   300px;
    --tab-bar-h: 36px;
}

html, body {
    height: 100%;
    background: var(--bg-app);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 13px;
    overflow: hidden;
}

/* ── IDE shell (grid) ─────────────────────────────────────────────────────── */
#ide {
    display: grid;
    height: 100vh;
    grid-template-rows: var(--toolbar-h) 1fr var(--console-h);
    grid-template-columns: 1fr var(--debug-w);
    grid-template-areas:
        "toolbar  toolbar"
        "editor   debug"
        "console  console";
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
#toolbar {
    grid-area: toolbar;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-sep {
    width: 1px;
    height: 22px;
    background: var(--border-light);
    margin: 0 4px;
}

.toolbar-filename {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 8px;
}

.toolbar-filename.modified::before {
    content: '● ';
    color: var(--warning);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font-ui);
    white-space: nowrap;
    transition: background 0.1s, border-color 0.1s;
    user-select: none;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-light); }
.btn:active:not(:disabled) { background: var(--bg-active); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger  { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(244,71,71,.15); border-color: var(--danger); }
.btn-success { color: var(--success); }
.btn-icon    { padding: 4px 6px; }

.btn svg { width: 14px; height: 14px; fill: currentColor; flex-shrink: 0; }

/* ── Editor pane ──────────────────────────────────────────────────────────── */
#editor-pane {
    grid-area: editor;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border);
}

#editor-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Find bar */
#find-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}
#find-bar.hidden { display: none; }
#find-input {
    flex: 1;
    max-width: 240px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 3px 7px;
    outline: none;
}
#find-input:focus { border-color: var(--accent); }
#find-bar label {
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
}

.CodeMirror {
    flex: 1;
    height: 100%;
    font-family: var(--font-mono) !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    background: var(--bg-panel) !important;
    color: var(--text) !important;
}
.CodeMirror-scroll { height: 100%; }
.CodeMirror-gutters {
    background: var(--bg-panel) !important;
    border-right: 1px solid var(--border) !important;
}
.CodeMirror-linenumber { color: var(--text-muted) !important; }
.CodeMirror-cursor { border-left-color: var(--text) !important; }
.CodeMirror-selected { background: var(--bg-selection) !important; }

/* Breakpoint gutter */
.gutter-bp { width: 16px; }
.bp-marker {
    width: 10px; height: 10px;
    background: var(--danger);
    border-radius: 50%;
    margin: 3px auto;
    cursor: pointer;
}

/* Debug position highlight – line background (subtle, column mark is the precise indicator) */
.cm-debug-line   { background: rgba(255, 200,   0, 0.07) !important; }
.cm-debug-line-c { background: rgba(100, 200, 255, 0.07) !important; }

/* XLAT2 active-cycle mark: bold the character whose value currently sits in
   that memory cell, showing the encryption phase of every CODE instruction. */
.cm-xlat2-active { font-weight: bold; }

/* Per-cell column marks – D register (data, yellow) and C register (code, blue) */
.cm-debug-col-d {
    background:  rgba(255, 200,   0, 0.38);
    border-radius: 2px;
    outline: 1px solid rgba(255, 200,   0, 0.70);
}
.cm-debug-col-c {
    background:  rgba(100, 200, 255, 0.38);
    border-radius: 2px;
    outline: 1px solid rgba(100, 200, 255, 0.70);
}
/* When C and D land on the same cell, C (code) mark wins on top */
.cm-debug-col-d.cm-debug-col-c { background: rgba(180, 200, 255, 0.50); }

/* HeLL syntax colours (matching Qt IDE) */
.cm-s-hell-ide .cm-comment   { color: #6a9955; }
.cm-s-hell-ide .cm-keyword   { color: #569cd6; }
.cm-s-hell-ide .cm-builtin   { color: #c8a055; }   /* instructions */
.cm-s-hell-ide .cm-def       { color: #9e3d3d; }   /* labels */
.cm-s-hell-ide .cm-def.cm-special { color: #ce9178; font-weight: bold; } /* ENTRY: */
.cm-s-hell-ide .cm-number    { color: #569cd6; }
.cm-s-hell-ide .cm-string    { color: #6a9955; }
.cm-s-hell-ide .cm-meta      { color: #569cd6; }   /* ?- */
.cm-s-hell-ide .cm-variable  { color: var(--text); }
.cm-s-hell-ide .cm-error     { background: var(--danger); color: #fff; border-radius: 2px; }
.cm-s-hell-ide .cm-operator  { color: var(--text-muted); }

/* Search highlight indicator */
.cm-search-highlight { background: rgba(255, 255, 0, 0.25); border-radius: 2px; }

/* ── Console pane ─────────────────────────────────────────────────────────── */
#console-pane {
    grid-area: console;
    display: flex;
    flex-direction: column;
    background: var(--bg-console);
    border-top: 2px solid var(--border);
}

#console-header {
    display: flex;
    align-items: center;
    padding: 3px 8px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    gap: 8px;
    flex-shrink: 0;
}
#console-header span { flex: 1; }

#console-output {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
}

.console-stdout  { color: var(--text); }
.console-stderr  { color: var(--danger); }
.console-info    { color: var(--info); }
.console-input   { color: var(--success); }
.console-waiting { color: var(--warning); font-style: italic; }

#console-input-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
#console-input-row label {
    color: var(--success);
    font-family: var(--font-mono);
    font-size: 13px;
    flex-shrink: 0;
}
#console-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--success);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 3px 6px;
    outline: none;
}
#console-input:focus { border-color: var(--accent); }
#console-input:disabled { opacity: 0.4; }

/* ── Debug panel ──────────────────────────────────────────────────────────── */
#debug-pane {
    grid-area: debug;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    overflow-y: auto;
    font-size: 12px;
}

/* Navigation bar at top of debug pane */
#debug-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
#debug-nav .btn { font-size: 11px; padding: 3px 7px; font-family: var(--font-mono); }

/* Active/toggled button state */
.btn-active {
    background: var(--bg-active) !important;
    border-color: var(--accent) !important;
    color: var(--info) !important;
}

.debug-section {
    border-bottom: 1px solid var(--border);
}

.debug-section-title {
    padding: 6px 10px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-panel);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
}
.debug-section-title:hover { color: var(--text); }
.debug-section-title .arrow { transition: transform 0.15s; }
.debug-section-title.collapsed .arrow { transform: rotate(-90deg); }

.debug-section-body { padding: 6px 0; }
.debug-section-body.hidden { display: none; }

/* Registers */
.reg-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
}
.reg-table td { padding: 3px 10px; }
.reg-table td:first-child { color: var(--text-muted); width: 40px; }
.reg-table td:last-child  { color: var(--success); word-break: break-all; }

/* Memory watches */
#watch-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 11px;
}
#watch-table th {
    background: var(--bg-panel);
    padding: 3px 6px;
    text-align: left;
    color: var(--text-muted);
    font-weight: normal;
    border-bottom: 1px solid var(--border);
}
#watch-table td {
    padding: 3px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
#watch-table td:first-child { color: var(--info); }
#watch-table td:last-child  { color: var(--text); word-break: break-all; }
#watch-table tr:last-child td { border-bottom: none; }
#watch-table input.watch-expr,
#watch-add-input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--info);
    font-family: var(--font-mono);
    font-size: 11px;
    width: 100%;
}
#watch-add-input { color: var(--text-muted); }
#watch-add-input:focus { color: var(--info); }

/* Status bar */
#status-bar {
    grid-area: toolbar;   /* overlaid at bottom of toolbar, actually appended to body */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 22px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 16px;
    font-size: 11px;
    z-index: 100;
}
#status-bar.status-running { background: #388a34; }
#status-bar.status-paused  { background: #8a6a00; }
#status-bar.status-error   { background: #8a3434; }
#status-bar.status-halted  { background: #555; }

#status-message { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status-cursor  { flex-shrink: 0; }

/* Adjust body padding to avoid content behind status bar */
body { padding-bottom: 22px; }
#ide { height: calc(100vh - 22px); }

/* ── Dialogs / modals ─────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal-overlay.hidden { display: none; }

.modal {
    background: var(--bg-sidebar);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 20px 24px;
    min-width: 320px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal h3 { font-size: 14px; color: var(--text-heading); }
.modal input[type=text] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 5px 8px;
    width: 100%;
    outline: none;
}
.modal input[type=text]:focus { border-color: var(--accent); }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; }

/* File list in open dialog */
#file-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-input);
}
#file-list li {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    cursor: pointer;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}
#file-list li:last-child { border-bottom: none; }
#file-list li:hover { background: var(--bg-hover); }
#file-list li.selected { background: var(--bg-active); }
#file-list .file-name { flex: 1; font-family: var(--font-mono); font-size: 12px; }
#file-list .file-size { color: var(--text-muted); font-size: 11px; }
#file-list .file-del  {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1;
}
#file-list .file-del:hover { color: var(--danger); }
#file-list .file-list-separator {
    cursor: default; color: var(--text-muted); font-size: 11px;
    justify-content: center; padding: 4px 10px;
    background: var(--bg-editor); pointer-events: none;
}
#file-list .file-list-separator:hover { background: var(--bg-editor); }
#file-list li.file-example .file-name { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE – mobile (≤ 768 px)
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    #ide {
        grid-template-rows: var(--toolbar-h) var(--tab-bar-h) 1fr;
        grid-template-columns: 1fr;
        grid-template-areas:
            "toolbar"
            "tab-bar"
            "panel";
    }

    #editor-pane,
    #debug-pane,
    #console-pane {
        grid-area: panel;
        display: none;
    }
    #editor-pane.active-panel,
    #debug-pane.active-panel,
    #console-pane.active-panel {
        display: flex;
        grid-area: panel;
    }

    #editor-pane { border-right: none; }
    #console-pane { border-top: none; }

    #tab-bar {
        grid-area: tab-bar;
        display: flex;
        background: var(--bg-sidebar);
        border-bottom: 1px solid var(--border);
    }

    .tab-btn {
        flex: 1;
        background: none;
        border: none;
        border-bottom: 2px solid transparent;
        color: var(--text-muted);
        font-size: 12px;
        font-family: var(--font-ui);
        padding: 0;
        cursor: pointer;
    }
    .tab-btn.active {
        color: var(--accent);
        border-bottom-color: var(--accent);
    }

    /* Shrink toolbar on mobile */
    .toolbar-filename { display: none; }
    .btn span { display: none; }   /* icon-only buttons on mobile */
    .btn { padding: 4px 7px; }

    /* Debug panel takes full height */
    #debug-pane { overflow-y: auto; }

    /* Console full height */
    #console-pane { flex-direction: column; }
}

/* ── Scrollbars ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #666; }

/* ── Tab bar (desktop – hidden) ───────────────────────────────────────────── */
#tab-bar { display: none; }
