/* ==================== ПАНЕЛЬ СТЕКА ==================== */
/*
   Панель стека используется в двух местах:
   1) Внутри видео-панели Intel 8086 (.video-stack-wrap) —
      между видеоэкраном и просмотром памяти.
   2) (Опционально) как боковая панель редактора — на случай
      будущего использования вне видео-панели.

   🎯 Базовые стили .editor-stack-panel рассчитаны на вертикальную
      боковую панель. Внутри .video-stack-wrap они переопределяются,
      чтобы панель корректно встраивалась в трёхколоночную раскладку.

   🎯 Стек ВСЕГДА развёрнут. Сворачивание убрано.
*/

/* ============================================================ */
/* 🎯 БАЗОВЫЕ СТИЛИ .editor-stack-panel                        */
/*    (используются, если панель вставлена вне .video-stack-wrap) */
/* ============================================================ */

.editor-stack-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 10px;
    background-color: #0d0d0d;
    border-right: 1px solid #2a2a2a;
    font-family: 'Source Code Pro', 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
    flex-shrink: 0;
    align-items: stretch;
    width: max-content;
    min-width: 130px;
    max-width: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: background-color 0.5s ease, border-color 0.5s ease;
    scrollbar-width: thin;
    scrollbar-color: #333 #0d0d0d;
}

body.light-theme .editor-stack-panel {
    background-color: #f5f5f5;
    border-right: 1px solid #e0e0e0;
}

.editor-stack-panel::-webkit-scrollbar {
    width: 6px;
}

.editor-stack-panel::-webkit-scrollbar-track {
    background: #0d0d0d;
}

.editor-stack-panel::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

body.light-theme .editor-stack-panel::-webkit-scrollbar-track {
    background: #f5f5f5;
}

body.light-theme .editor-stack-panel::-webkit-scrollbar-thumb {
    background: #ccc;
}

/* Заголовок панели стека */
.editor-stack-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding-bottom: 6px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #7BD7DD;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    user-select: none;
}

body.light-theme .editor-stack-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
    color: #2F6F7A;
}

.editor-stack-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}

/* Строка стека: маркер + адрес + значение */
.editor-stack-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 8px;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

body.light-theme .editor-stack-row {
    background-color: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

/* Строка, где находится SP (вершина стека) */
.editor-stack-row.is-sp {
    background-color: rgba(183, 255, 105, 0.12);
    border-color: rgba(183, 255, 105, 0.4);
    box-shadow: inset 3px 0 0 #B7FF69;
}

body.light-theme .editor-stack-row.is-sp {
    background-color: rgba(72, 0, 150, 0.1);
    border-color: rgba(72, 0, 150, 0.4);
    box-shadow: inset 3px 0 0 #480096;
}

/* Строка, где находится BP */
.editor-stack-row.is-bp {
    background-color: rgba(255, 165, 0, 0.12);
    border-color: rgba(255, 165, 0, 0.45);
    box-shadow: inset 3px 0 0 #FFA500;
}

body.light-theme .editor-stack-row.is-bp {
    background-color: rgba(180, 95, 6, 0.1);
    border-color: rgba(180, 95, 6, 0.4);
    box-shadow: inset 3px 0 0 #B45F06;
}

/* Строка, где SP и BP совпадают */
.editor-stack-row.is-sp-bp {
    background-color: rgba(255, 212, 103, 0.15);
    border-color: rgba(255, 212, 103, 0.55);
    box-shadow: inset 3px 0 0 #FFD467;
}

body.light-theme .editor-stack-row.is-sp-bp {
    background-color: rgba(180, 130, 6, 0.12);
    border-color: rgba(180, 130, 6, 0.45);
    box-shadow: inset 3px 0 0 #B48206;
}

/* Маркер (SP→, BP→, SP,BP→) */
.editor-stack-marker {
    font-family: 'Source Code Pro', monospace;
    font-weight: 700;
    font-size: 0.65rem;
    flex-shrink: 0;
    min-width: 38px;
    text-align: left;
    letter-spacing: -0.3px;
}

.editor-stack-marker.is-sp {
    color: #B7FF69;
}

body.light-theme .editor-stack-marker.is-sp {
    color: #480096;
}

.editor-stack-marker.is-bp {
    color: #FFA500;
}

body.light-theme .editor-stack-marker.is-bp {
    color: #B45F06;
}

.editor-stack-marker.is-sp-bp {
    color: #FFD467;
}

body.light-theme .editor-stack-marker.is-sp-bp {
    color: #B48206;
}

/* 🎯 Пометки адреса возврата: IP→ (все процедуры), CS→ (только FAR) */
.editor-stack-marker.is-ret-ip {
    color: #9AA7B4;
}

.editor-stack-marker.is-ret-cs {
    color: #C39BE0;
}

body.light-theme .editor-stack-marker.is-ret-ip {
    color: #5A6874;
}

body.light-theme .editor-stack-marker.is-ret-cs {
    color: #7B4FA0;
}

.editor-stack-row.is-ret-ip,
.editor-stack-row.is-ret-cs {
    background-color: rgba(255, 255, 255, 0.02);
}

body.light-theme .editor-stack-row.is-ret-ip,
body.light-theme .editor-stack-row.is-ret-cs {
    background-color: rgba(0, 0, 0, 0.02);
}

.editor-stack-addr {
    color: #7BD7DD;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    /* 🎯 Адрес в формате SEG:OFFSET (1000:00FA) — не переносим */
    white-space: nowrap;
    min-width: 9ch;
}

body.light-theme .editor-stack-addr {
    color: #2F6F7A;
}

.editor-stack-value {
    color: #FFFFFF;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 34px;
}

body.light-theme .editor-stack-value {
    color: #000000;
}

/* Пустое состояние */
.editor-stack-empty {
    text-align: center;
    padding: 12px 8px;
    color: #666;
    font-size: 0.75rem;
    font-style: italic;
}

body.light-theme .editor-stack-empty {
    color: #999;
}

/* Значение слова (2 байта) — переход по клику */
.editor-stack-word {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    cursor: pointer;
    border-radius: 3px;
    padding: 1px 3px;
    transition: background-color 0.15s ease;
}

.editor-stack-word:hover {
    background-color: rgba(183, 255, 105, 0.15);
}

body.light-theme .editor-stack-word:hover {
    background-color: rgba(72, 0, 150, 0.1);
}

/* ========================================================= */
/*  ПАНЕЛЬ СТЕКА ВНУТРИ ВИДЕО-ПАНЕЛИ (.video-stack-wrap)     */
/*  Переопределяем базовые стили, чтобы панель корректно     */
/*  встроилась в трёхколоночную раскладку.                   */
/* ========================================================= */

/* Обёртка средней колонки в видео-панели — УЗКАЯ */
.video-stack-wrap {
    flex: 0 0 128px;      /* ← было 180px */
    min-width: 118px;     /* ← было 160px */
    max-width: 170px;     /* ← было 240px */
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0 6px;       /* ← было 0 8px */
    overflow: hidden;
    max-height: 480px;
    align-items: stretch;
    justify-content: flex-start;
    box-sizing: border-box;
}

body.light-theme .video-stack-wrap {
    border-left-color: rgba(0, 0, 0, 0.08);
    border-right-color: rgba(0, 0, 0, 0.08);
}

/* Панель стека внутри video-stack-wrap — сброс боковых стилей */
.video-stack-wrap .editor-stack-panel {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    max-height: 100% !important;
    height: 100% !important;
    border-right: none !important;
    border-left: none !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 2px;
    padding: 4px 0 !important;
    background-color: transparent !important;
    overflow-y: auto;
    overflow-x: hidden;
    font-size: 0.72rem;
    box-sizing: border-box;
}

body.light-theme .video-stack-wrap .editor-stack-panel {
    background-color: transparent !important;
    border-right: none !important;
}

/* Заголовок внутри видео-панели — компактный */
.video-stack-wrap .editor-stack-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4px;
    padding: 2px 0 4px 0 !important;
    margin: 0 0 2px 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.68rem !important;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #7BD7DD;
    flex-shrink: 0;
    flex-wrap: nowrap;
}

body.light-theme .video-stack-wrap .editor-stack-header {
    border-bottom-color: rgba(0, 0, 0, 0.08);
    color: #2F6F7A;
}

/* Контент внутри видео-панели */
.video-stack-wrap .editor-stack-content {
    display: flex !important;
    flex-direction: column !important;
    gap: 2px;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

/* 🎯 Строки стека внутри видео-панели — КОМПАКТНЫЕ.
      justify-content: flex-start убирает «разлёт» маркера
      и адреса по краям. Адрес идёт сразу после маркера. */
.video-stack-wrap .editor-stack-row {
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;   /* ← НОВОЕ */
    flex-wrap: nowrap !important;             /* ← НОВОЕ */
    gap: 4px;
    padding: 3px 6px !important;
    font-size: 0.7rem !important;
    white-space: nowrap;
    width: 100%;
    box-sizing: border-box;
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    flex-shrink: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

body.light-theme .video-stack-wrap .editor-stack-row {
    background-color: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
}

.video-stack-wrap .editor-stack-row.is-sp {
    background-color: rgba(183, 255, 105, 0.12);
    border-color: rgba(183, 255, 105, 0.4);
    box-shadow: inset 3px 0 0 #B7FF69;
}

body.light-theme .video-stack-wrap .editor-stack-row.is-sp {
    background-color: rgba(72, 0, 150, 0.1);
    border-color: rgba(72, 0, 150, 0.4);
    box-shadow: inset 3px 0 0 #480096;
}

.video-stack-wrap .editor-stack-row.is-bp {
    background-color: rgba(255, 165, 0, 0.12);
    border-color: rgba(255, 165, 0, 0.45);
    box-shadow: inset 3px 0 0 #FFA500;
}

body.light-theme .video-stack-wrap .editor-stack-row.is-bp {
    background-color: rgba(180, 95, 6, 0.1);
    border-color: rgba(180, 95, 6, 0.4);
    box-shadow: inset 3px 0 0 #B45F06;
}

.video-stack-wrap .editor-stack-row.is-sp-bp {
    background-color: rgba(255, 212, 103, 0.15);
    border-color: rgba(255, 212, 103, 0.55);
    box-shadow: inset 3px 0 0 #FFD467;
}

body.light-theme .video-stack-wrap .editor-stack-row.is-sp-bp {
    background-color: rgba(180, 130, 6, 0.12);
    border-color: rgba(180, 130, 6, 0.45);
    box-shadow: inset 3px 0 0 #B48206;
}

/* 🎯 Маркер внутри видео-панели — УЖАТ.
      Самый длинный маркер "SP,BP→" — 6 символов.
      При 0.58rem и letter-spacing -0.5px он влезает в ~30px. */
.video-stack-wrap .editor-stack-marker {
    font-family: 'Source Code Pro', monospace;
    font-weight: 700;
    font-size: 0.58rem !important;
    flex-shrink: 0;
    min-width: 30px;
    text-align: left;
    letter-spacing: -0.5px;
}

.video-stack-wrap .editor-stack-marker.is-sp {
    color: #B7FF69;
}

body.light-theme .video-stack-wrap .editor-stack-marker.is-sp {
    color: #480096;
}

.video-stack-wrap .editor-stack-marker.is-bp {
    color: #FFA500;
}

body.light-theme .video-stack-wrap .editor-stack-marker.is-bp {
    color: #B45F06;
}

.video-stack-wrap .editor-stack-marker.is-sp-bp {
    color: #FFD467;
}

body.light-theme .video-stack-wrap .editor-stack-marker.is-sp-bp {
    color: #B48206;
}

/* 🎯 Адрес внутри видео-панели — БЕЗ margin-left: auto.
      Идёт сразу после маркера, зазор обеспечивает gap у .editor-stack-row. */
.video-stack-wrap .editor-stack-addr {
    color: #7BD7DD;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.68rem !important;
    font-weight: 600;
    flex-shrink: 0;
    /* 🎯 Адрес в формате SEG:OFFSET — не переносим */
    white-space: nowrap;
    min-width: 9ch;
    /* margin-left: auto убран — адрес идёт сразу после маркера */
}

body.light-theme .video-stack-wrap .editor-stack-addr {
    color: #2F6F7A;
}

/* 🎯 Значение внутри видео-панели — прижато к правому краю строки.
      margin-left: auto оставляем только ЗДЕСЬ, чтобы
      адрес был слева (после маркера), а значение — справа. */
.video-stack-wrap .editor-stack-value {
    color: #FFFFFF;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.68rem !important;
    font-weight: 500;
    text-align: right;
    min-width: 32px;
    flex-shrink: 0;
    margin-left: auto;   /* ← значение уходит к правому краю */
}

body.light-theme .video-stack-wrap .editor-stack-value {
    color: #000000;
}

/* Пустое состояние внутри видео-панели */
.video-stack-wrap .editor-stack-empty {
    text-align: center;
    padding: 8px 4px;
    color: #666;
    font-size: 0.7rem;
    font-style: italic;
}

body.light-theme .video-stack-wrap .editor-stack-empty {
    color: #999;
}

/* Тонкий скроллбар панели стека внутри видео-панели */
.video-stack-wrap .editor-stack-panel::-webkit-scrollbar {
    width: 4px;
}

.video-stack-wrap .editor-stack-panel::-webkit-scrollbar-track {
    background: transparent;
}

.video-stack-wrap .editor-stack-panel::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}

body.light-theme .video-stack-wrap .editor-stack-panel::-webkit-scrollbar-thumb {
    background: #ccc;
}

/* ============================================================ */
/* 🎯 КНОПКИ НАВИГАЦИИ СТЕКА (символьные ▲ ⇤ ▼)                */
/* ============================================================ */

.editor-stack-nav {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
}

.editor-stack-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 3px;
    color: #7BD7DD;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease;
    -webkit-appearance: none;
    appearance: none;

    /* 🎯 Символьные иконки */
    font-family: 'Segoe UI Symbol', 'Arial Unicode MS', 'DejaVu Sans',
    'Noto Sans Symbols', 'Source Code Pro', monospace;
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    text-align: center;
    text-shadow: none;
    user-select: none;
}

.editor-stack-nav-btn:hover {
    background-color: rgba(123, 215, 221, 0.25);
    border-color: rgba(123, 215, 221, 0.6);
    color: #B7F5FA;
}

.editor-stack-nav-btn:active {
    background-color: rgba(123, 215, 221, 0.4);
    transform: scale(0.94);
}

/* 🎯 Кнопка «К SP» — неактивна (серая), когда мы уже на SP. */
.editor-stack-panel.at-sp .editor-stack-nav-btn[data-nav="sp"] {
    color: #555;
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    pointer-events: none;
    cursor: default;
}

/* Светлая тема */
body.light-theme .editor-stack-nav-btn {
    color: #2F6F7A;
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.15);
}

body.light-theme .editor-stack-nav-btn:hover {
    background-color: rgba(47, 111, 122, 0.18);
    border-color: rgba(47, 111, 122, 0.5);
    color: #143A40;
}

body.light-theme .editor-stack-panel.at-sp .editor-stack-nav-btn[data-nav="sp"] {
    color: #bbb;
    border-color: rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.02);
}

/* Компактные размеры внутри видео-панели */
.video-stack-wrap .editor-stack-header .editor-stack-nav {
    margin-left: auto;
}

.video-stack-wrap .editor-stack-nav-btn {
    width: 18px;
    height: 18px;
    font-size: 10px;
}

/* ============================================================ */
/* 🎯 ПОДСВЕТКА ОПЕРАЦИЙ СО СТЕКОМ                              */
/* ============================================================ */

.editor-stack-row.op-read {
    background-color: rgba(91, 192, 222, 0.18);
    border-color: rgba(91, 192, 222, 0.55);
    box-shadow: inset 3px 0 0 #5BC0DE;
}

body.light-theme .editor-stack-row.op-read {
    background-color: rgba(31, 120, 150, 0.12);
    border-color: rgba(31, 120, 150, 0.5);
    box-shadow: inset 3px 0 0 #1F7896;
}

.editor-stack-row.op-write {
    background-color: rgba(92, 184, 92, 0.18);
    border-color: rgba(92, 184, 92, 0.55);
    box-shadow: inset 3px 0 0 #5CB85C;
}

body.light-theme .editor-stack-row.op-write {
    background-color: rgba(40, 130, 40, 0.12);
    border-color: rgba(40, 130, 40, 0.5);
    box-shadow: inset 3px 0 0 #288228;
}

.editor-stack-row.op-readwrite {
    background-color: rgba(240, 173, 78, 0.18);
    border-color: rgba(240, 173, 78, 0.6);
    box-shadow: inset 3px 0 0 #F0AD4E;
}

body.light-theme .editor-stack-row.op-readwrite {
    background-color: rgba(180, 110, 6, 0.12);
    border-color: rgba(180, 110, 6, 0.5);
    box-shadow: inset 3px 0 0 #B46E06;
}

.editor-stack-row.op-future {
    background-color: rgba(255, 212, 103, 0.16);
    border-color: rgba(255, 212, 103, 0.5);
    box-shadow: inset 3px 0 0 #FFD467;
    outline: 1px dashed rgba(255, 212, 103, 0.6);
    outline-offset: -2px;
}

body.light-theme .editor-stack-row.op-future {
    background-color: rgba(180, 130, 6, 0.1);
    border-color: rgba(180, 130, 6, 0.45);
    box-shadow: inset 3px 0 0 #B48206;
    outline: 1px dashed rgba(180, 130, 6, 0.5);
    outline-offset: -2px;
}

/* Маркер подсвеченной операции — тоже подкрашиваем */
.editor-stack-row.op-read .editor-stack-addr,
.editor-stack-row.op-write .editor-stack-addr,
.editor-stack-row.op-readwrite .editor-stack-addr,
.editor-stack-row.op-future .editor-stack-addr {
    font-weight: 700;
}

