/* ═══════════════════════════════════════════════════════════
   TOPBAR TOOLBAR  (chart name · alert · settings · fullscreen · screenshot · trade)
   All dimensions match the left-side topbar buttons:
     height 34px · font-size 13px · font-weight 600-700
═══════════════════════════════════════════════════════════ */

/* ── Chart name button ── */
.chart-name-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.chart-name-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 4px 0 10px;
    color: var(--ui-fg);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    user-select: none;
}

.chart-name-caret-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 34px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--ui-fg);
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
    font-family: inherit;
}
.chart-name-caret-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    border-color: var(--ui-panel-border);
}

/* keep .chart-name-btn as base (no standalone use now) */
.chart-name-btn {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    color: var(--ui-fg);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease;
}

/* ── Layout dropdown menu (appended to body → position:fixed) ── */
.chart-name-menu {
    position: fixed;
    background: var(--ui-panel, #1e222d);
    border: 1px solid var(--ui-border, rgba(255,255,255,.1));
    border-radius: 8px;
    padding: 6px 0;
    z-index: 99999;
    box-shadow: 0 8px 32px rgba(0,0,0,.45);
    min-width: 248px;
    font-family: inherit;
}
.chart-name-menu.hidden { display: none; }

/* ── Menu item (action row) ── */
.cnm-item {
    display: flex;
    align-items: center;
    height: 34px;
    padding: 0 14px 0 10px;
    gap: 0;
    cursor: pointer;
    color: var(--ui-fg, #d1d4dc);
    font-size: 13px;
    font-weight: 400;
    user-select: none;
    border-radius: 0;
    transition: background 0.1s;
    outline: none;
}
.cnm-item:hover { background: rgba(120,120,140,.14); }
.cnm-item:focus-visible { background: rgba(120,120,140,.14); }

/* icon cell — fixed 30px so labels always line up */
.cnm-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    flex-shrink: 0;
    color: var(--ui-fg-muted, #787b86);
}

/* label — fills remaining space */
.cnm-lbl {
    flex: 1;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

/* keyboard shortcut hint */
.cnm-sc {
    font-size: 11px;
    color: var(--ui-fg-muted, #787b86);
    margin-left: 8px;
    flex-shrink: 0;
    letter-spacing: .03em;
}

/* info icon inside label */
.cnm-info-ic {
    display: inline-flex;
    align-items: center;
    color: var(--ui-fg-muted, #787b86);
    vertical-align: middle;
}

/* toggle row — push toggle to far right */
.cnm-item-toggle {
    cursor: default;
}
.cnm-item-toggle .cnm-lbl { pointer-events: none; }
.cnm-item-disabled {
    opacity: .45;
}
.cnm-item-disabled .lp-tog { cursor: not-allowed; }

/* ── Separator ── */
.cnm-sep {
    height: 1px;
    background: var(--ui-border, rgba(255,255,255,.08));
    margin: 5px 0;
}

/* ── Section header ── */
.cnm-section-hdr {
    padding: 6px 14px 4px 14px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ui-fg-muted, #787b86);
    user-select: none;
}

/* ── Recently-used layout row ── */
.cnm-layout-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 2px 6px;
    padding: 7px 8px 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.cnm-layout-row:hover { background: rgba(120,120,140,.14); }
.cnm-layout-row.cnm-layout-active {
    background: var(--ui-fg, #d1d4dc);
    color: var(--ui-panel, #1e222d);
}
.cnm-layout-row.cnm-layout-active .cnm-layout-sub {
    color: var(--ui-panel, #1e222d);
    opacity: .65;
}
.cnm-layout-row.cnm-layout-active .cnm-star-btn {
    color: var(--ui-panel, #1e222d);
}

.cnm-layout-info { flex: 1; min-width: 0; }

.cnm-layout-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cnm-layout-sub {
    font-size: 11px;
    color: var(--ui-fg-muted, #787b86);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Star / favourite button inside layout row ── */
.cnm-star-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.1s, background 0.1s;
}
.cnm-star-btn:hover {
    background: rgba(120,120,140,.18);
    color: var(--ui-fg, #d1d4dc);
}

/* ── Empty state ── */
.cnm-empty {
    padding: 8px 14px;
    font-size: 12px;
    color: var(--ui-fg-muted, #787b86);
    font-style: italic;
}

/* ── Right-toolbar icon buttons — match left-side icon-action-btn but 34×34 ── */
#quickAlertBtn,
#settingsBtn,
#fullscreenBtn,
#screenshotBtn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 50%;
    color: var(--ui-fg);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s ease, border-color 0.12s ease;
    font-family: inherit;
}
#quickAlertBtn:hover,
#settingsBtn:hover,
#fullscreenBtn:hover,
#screenshotBtn:hover {
    background: rgba(15, 23, 42, 0.06);
    border-color: var(--ui-panel-border);
}

/* ── Trade pill button ── */
.trade-pill-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 18px;
    border: none;
    border-radius: 18px;
    background: var(--accent, #2962ff);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.12s ease;
}
.trade-pill-btn:hover { background: #1e4fcf; }

/* ── Flash effect on screenshot click ── */
.tb-btn-flash { opacity: .35 !important; transition: opacity 0.5s; }

/* ── Light theme overrides ── */
html[data-theme="light"] .chart-name-menu {
    background: #ffffff;
    border-color: #e2e5e9;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
html[data-theme="light"] .cnm-item { color: #131722; }
html[data-theme="light"] .cnm-item:hover { background: rgba(0,0,0,.06); }
html[data-theme="light"] .cnm-icon,
html[data-theme="light"] .cnm-sc,
html[data-theme="light"] .cnm-info-ic { color: #6b7280; }
html[data-theme="light"] .cnm-section-hdr { color: #6b7280; }
html[data-theme="light"] .cnm-sep { background: #e5e7eb; }
html[data-theme="light"] .cnm-layout-row:hover { background: rgba(0,0,0,.06); }
html[data-theme="light"] .cnm-layout-row.cnm-layout-active {
    background: #131722;
    color: #ffffff;
}
html[data-theme="light"] .cnm-layout-row.cnm-layout-active .cnm-layout-sub { color: rgba(255,255,255,.65); }
html[data-theme="light"] .cnm-layout-name { color: #131722; }
html[data-theme="light"] .cnm-layout-sub  { color: #6b7280; }
html[data-theme="light"] .cnm-star-btn    { color: #9ca3af; }

/* ── layout picker button ── */
#layoutPickerBtn { margin-right: 2px; }

/* ── chart layout icon button (single square before Unnamed) ── */
.chart-layout-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--ui-fg);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s ease;
}
.chart-layout-icon-btn:hover { background: rgba(15,23,42,.06); }
html[data-theme="light"] .chart-layout-icon-btn:hover { background: rgba(0,0,0,.07); }

/* lp-tog / lp-tog-rail defined in style.css */

/* ═══════════════════════════════════════════════════════════
   PINE EDITOR LAUNCH BUTTON  (bottom bar)
═══════════════════════════════════════════════════════════ */
.pe-launch-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
}
.pe-launch-btn:hover,
.pe-launch-btn.pe-active {
    background: rgba(41,98,255,.14);
    color: #2962ff;
}

/* ═══════════════════════════════════════════════════════════
   PINE EDITOR PANEL  (slides up from bottom)
═══════════════════════════════════════════════════════════ */
.pe-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 56px;
    height: 320px;
    background: var(--ui-panel, #1e222d);
    border-top: 1px solid var(--ui-border, rgba(255,255,255,.08));
    z-index: 500;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -6px 24px rgba(0,0,0,.35);
    transition: height 0.18s ease;
    resize: vertical;
    overflow: hidden;
}
.pe-panel.hidden { display: none !important; }

/* ── Header ── */
.pe-header {
    display: flex;
    align-items: center;
    height: 38px;
    min-height: 38px;
    padding: 0 8px 0 12px;
    border-bottom: 1px solid var(--ui-border, rgba(255,255,255,.08));
    gap: 6px;
    flex-shrink: 0;
}
.pe-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--ui-fg, #d1d4dc);
    white-space: nowrap;
    margin-right: 8px;
}
.pe-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.pe-spacer { flex: 1; }

/* ── Script name button ── */
.pe-script-wrap { position: relative; }
.pe-script-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid var(--ui-border, rgba(255,255,255,.08));
    border-radius: 5px;
    background: transparent;
    color: var(--ui-fg, #d1d4dc);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}
.pe-script-btn:hover {
    background: rgba(120,120,140,.14);
    border-color: rgba(120,120,140,.3);
}

/* ── Tool buttons ── */
.pe-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.pe-tool-btn:hover {
    background: rgba(120,120,140,.14);
    color: var(--ui-fg, #d1d4dc);
}

/* ── Publish button ── */
.pe-publish-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 12px;
    border: 1px solid var(--ui-border, rgba(255,255,255,.08));
    border-radius: 5px;
    background: transparent;
    color: var(--ui-fg, #d1d4dc);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}
.pe-publish-btn:hover {
    background: rgba(120,120,140,.14);
    border-color: rgba(120,120,140,.3);
}

/* ── Close button ── */
.pe-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    margin-left: 4px;
    transition: background 0.12s, color 0.12s;
}
.pe-close-btn:hover {
    background: rgba(120,120,140,.14);
    color: var(--ui-fg, #d1d4dc);
}

/* ── Editor area ── */
.pe-editor-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: var(--ui-panel, #1e222d);
}
.pe-line-nums {
    width: 44px;
    padding: 10px 8px 10px 0;
    text-align: right;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--ui-fg-muted, #787b86);
    background: rgba(0,0,0,.12);
    border-right: 1px solid var(--ui-border, rgba(255,255,255,.06));
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
}
.pe-editor {
    flex: 1;
    padding: 10px 12px;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--ui-fg, #d1d4dc);
    overflow-y: auto;
    overflow-x: auto;
    tab-size: 4;
    white-space: pre;
}
.pe-editor::selection {
    background: rgba(41,98,255,.35);
}

/* ── Status bar ── */
.pe-statusbar {
    display: flex;
    align-items: center;
    height: 26px;
    min-height: 26px;
    padding: 0 8px;
    border-top: 1px solid var(--ui-border, rgba(255,255,255,.06));
    background: rgba(0,0,0,.12);
    gap: 6px;
    flex-shrink: 0;
}
.pe-terminal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.pe-terminal-btn:hover {
    background: rgba(120,120,140,.14);
    color: var(--ui-fg, #d1d4dc);
}
.pe-error-msg {
    font-size: 11px;
    color: #ef5350;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pe-status-spacer { flex: 1; }
.pe-cursor-pos {
    font-size: 11px;
    color: var(--ui-fg-muted, #787b86);
    white-space: nowrap;
}
.pe-lang-tag {
    font-size: 11px;
    color: var(--ui-fg-muted, #787b86);
    white-space: nowrap;
    padding-left: 8px;
    border-left: 1px solid var(--ui-border, rgba(255,255,255,.08));
}

/* ── Script name dropdown ── */
.pe-dropdown {
    position: fixed;
    background: var(--ui-panel, #1e222d);
    border: 1px solid var(--ui-border, rgba(255,255,255,.1));
    border-radius: 8px;
    padding: 6px 0;
    z-index: 99999;
    box-shadow: 0 8px 32px rgba(0,0,0,.45);
    min-width: 200px;
}
.pe-dropdown.hidden { display: none; }
.pe-dd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 34px;
    padding: 0 14px;
    cursor: pointer;
    color: var(--ui-fg, #d1d4dc);
    font-size: 13px;
    transition: background 0.1s;
}
.pe-dd-item:hover { background: rgba(120,120,140,.14); }
.pe-dd-sep {
    height: 1px;
    background: var(--ui-border, rgba(255,255,255,.08));
    margin: 4px 0;
}

/* ── Title bar (Row 1) ── */
.pe-titlebar {
    display: flex;
    align-items: center;
    height: 36px;
    min-height: 36px;
    padding: 0 8px 0 12px;
    border-bottom: 1px solid var(--ui-border, rgba(255,255,255,.08));
    flex-shrink: 0;
}
.pe-titlebar .pe-title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--ui-fg, #d1d4dc);
    margin-right: 0;
}
.pe-titlebar-right {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* ── Icon button (popout + close in titlebar) ── */
.pe-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}
.pe-icon-btn:hover {
    background: rgba(120,120,140,.14);
    color: var(--ui-fg, #d1d4dc);
}

/* ── Action bar (Row 2) ── */
.pe-actionbar {
    display: flex;
    align-items: center;
    height: 38px;
    min-height: 38px;
    padding: 0 8px 0 10px;
    border-bottom: 1px solid var(--ui-border, rgba(255,255,255,.08));
    gap: 4px;
    flex-shrink: 0;
}
.pe-actionbar-divider {
    width: 1px;
    height: 20px;
    background: var(--ui-border, rgba(255,255,255,.1));
    margin: 0 4px;
    flex-shrink: 0;
}

/* ── Action buttons: Add to chart / Save ── */
.pe-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border: none;
    border-radius: 5px;
    background: rgba(120,120,140,.1);
    color: var(--ui-fg, #d1d4dc);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.12s;
}
.pe-action-btn:hover { background: rgba(120,120,140,.22); }
.pe-action-btn.pe-save-btn {
    background: var(--accent, #2962ff);
    color: #fff;
}
.pe-action-btn.pe-save-btn:hover { background: #1e4fcf; }

/* ── More options button ── */
.pe-more-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--ui-fg-muted, #787b86);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
    margin-left: auto;
}
.pe-more-btn:hover {
    background: rgba(120,120,140,.14);
    color: var(--ui-fg, #d1d4dc);
}
.pe-more-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ef5350;
    pointer-events: none;
}

/* ── Light theme ── */
html[data-theme="light"] .pe-panel {
    background: #ffffff;
    border-top-color: #e2e5e9;
    box-shadow: 0 -4px 16px rgba(0,0,0,.12);
}
html[data-theme="light"] .pe-header { border-bottom-color: #e2e5e9; }
html[data-theme="light"] .pe-title  { color: #131722; }
html[data-theme="light"] .pe-script-btn { color: #131722; border-color: #d1d5db; }
html[data-theme="light"] .pe-script-btn:hover { background: rgba(0,0,0,.06); }
html[data-theme="light"] .pe-tool-btn { color: #6b7280; }
html[data-theme="light"] .pe-tool-btn:hover { background: rgba(0,0,0,.06); color: #131722; }
html[data-theme="light"] .pe-publish-btn { color: #131722; border-color: #d1d5db; }
html[data-theme="light"] .pe-editor { color: #131722; }
html[data-theme="light"] .pe-editor-wrap { background: #ffffff; }
html[data-theme="light"] .pe-line-nums { color: #9ca3af; background: #f9fafb; border-right-color: #e5e7eb; }
html[data-theme="light"] .pe-statusbar { background: #f9fafb; border-top-color: #e5e7eb; }
html[data-theme="light"] .pe-cursor-pos,
html[data-theme="light"] .pe-lang-tag { color: #6b7280; }
html[data-theme="light"] .pe-dropdown { background: #ffffff; border-color: #e2e5e9; box-shadow: 0 8px 32px rgba(0,0,0,.15); }
html[data-theme="light"] .pe-dd-item { color: #131722; }
html[data-theme="light"] .pe-dd-item:hover { background: rgba(0,0,0,.06); }
html[data-theme="light"] .pe-titlebar { border-bottom-color: #e2e5e9; }
html[data-theme="light"] .pe-titlebar .pe-title { color: #131722; }
html[data-theme="light"] .pe-icon-btn { color: #6b7280; }
html[data-theme="light"] .pe-icon-btn:hover { background: rgba(0,0,0,.06); color: #131722; }
html[data-theme="light"] .pe-actionbar { border-bottom-color: #e2e5e9; }
html[data-theme="light"] .pe-actionbar-divider { background: #d1d5db; }
html[data-theme="light"] .pe-action-btn { background: rgba(0,0,0,.06); color: #131722; }
html[data-theme="light"] .pe-action-btn:hover { background: rgba(0,0,0,.12); }
html[data-theme="light"] .pe-action-btn.pe-save-btn { background: var(--accent, #2962ff); color: #fff; }
html[data-theme="light"] .pe-more-btn { color: #6b7280; }
html[data-theme="light"] .pe-more-btn:hover { background: rgba(0,0,0,.06); color: #131722; }
