/**
 * Node Property Sidebar Styles (Rewritten)
 * ----------------------------------------
 * Dedicated panel for displaying details of the selected node.
 * Reimplemented to ensure robust scrolling behaviour and clean layout.
 */

#node-property-sidebar {
    position: fixed;
    top: 96px;
    right: var(--view-panel-tab-gutter, 0);
    bottom: auto;
    width: 360px;
    height: var(--view-panel-height, min(72vh, calc(100vh - 120px)));
    max-height: var(--view-panel-height, min(72vh, calc(100vh - 120px)));
    display: flex;
    flex-direction: column;
    background: var(--view-panel-bg, var(--bg-primary, #1f1f1f));
    border-left: 1px solid var(--color-border-light, rgba(255, 255, 255, 0.12));
    color: var(--color-text-primary, #f5f5f5);
    transform: translateX(110%);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.2s ease;
    z-index: 13000;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

#node-property-sidebar.visible {
    transform: translateX(0);
    opacity: 1;
    border-left-color: var(--color-border-light, rgba(255, 255, 255, 0.12));
    visibility: visible;
    pointer-events: auto;
}

#node-property-sidebar.collapsed {
    pointer-events: none;
}

#node-property-sidebar:not(.visible) {
    border-left-color: transparent;
    box-shadow: none;
    transform: translateX(110%);
}

[data-theme="light"] #node-property-sidebar {
    background: #ffffff;
    border-left-color: rgba(15, 23, 42, 0.12);
    color: #1f2937;
}

/* Header */
#node-property-sidebar .sidebar-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: var(--view-panel-header-pad, 16px 20px);
    height: var(--view-panel-header-height, 48px);
    border-bottom: 1px solid var(--view-panel-header-border, var(--color-border-light, rgba(255, 255, 255, 0.12)));
}

#node-property-sidebar .sidebar-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1;
}

#node-property-sidebar .sidebar-header svg {
    width: 18px;
    height: 18px;
}

#node-property-sidebar .sidebar-close-btn {
    background: transparent;
    border: none;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--color-text-secondary, #99a7b5);
    transition: background 0.2s ease, color 0.2s ease;
}

#node-property-sidebar .sidebar-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

#node-property-sidebar .sidebar-pin-btn {
    background: transparent;
    border: none;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--color-text-secondary, #99a7b5);
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    margin-left: 6px;
}

#node-property-sidebar .sidebar-close-btn:hover,
#node-property-sidebar .sidebar-close-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary, #ffffff);
}

[data-theme="light"] #node-property-sidebar .sidebar-close-btn:hover,
[data-theme="light"] #node-property-sidebar .sidebar-close-btn:focus-visible {
    background: rgba(15, 23, 42, 0.08);
    color: #1f2937;
}

#node-property-sidebar .sidebar-pin-btn:hover,
#node-property-sidebar .sidebar-pin-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary, #ffffff);
    border-color: var(--color-text-secondary, #99a7b5);
}

#node-property-sidebar .sidebar-pin-btn.pinned {
    background: var(--color-secondary, #00ff41);
    color: #0b1e0f;
}

/* Scrollable body */
#node-property-sidebar .sidebar-content {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 20px 24px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.6) transparent;
    -webkit-overflow-scrolling: touch;
}

#node-property-sidebar .sidebar-content::-webkit-scrollbar {
    width: 8px;
}

#node-property-sidebar .sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

#node-property-sidebar .sidebar-content::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.6);
    border-radius: 4px;
}

#node-property-sidebar .sidebar-content::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.8);
}

[data-theme="light"] #node-property-sidebar .sidebar-content {
    scrollbar-color: rgba(100, 116, 139, 0.55) transparent;
}

[data-theme="light"] #node-property-sidebar .sidebar-content::-webkit-scrollbar-thumb {
    background-color: rgba(100, 116, 139, 0.55);
}

/* Flattened section layout */
#node-property-sidebar .section {
    padding: 0 0 18px;
    margin: 0 0 18px;
    border-bottom: 1px solid var(--color-border-light, rgba(255, 255, 255, 0.08));
}

#node-property-sidebar .section:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

[data-theme="light"] #node-property-sidebar .section {
    border-bottom-color: rgba(15, 23, 42, 0.08);
}

#node-property-sidebar .section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

#node-property-sidebar .section-title {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-transform: none;
    color: var(--color-text-primary, #f5f5f5);
}

#node-property-sidebar .section-title::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--color-accent, #00ff9b);
    opacity: 0.75;
}

#node-property-sidebar .section-badge {
    margin-left: auto;
    font-size: 11px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(0, 255, 155, 0.12);
    color: var(--color-accent, #00ff9b);
}

[data-theme="light"] #node-property-sidebar .section-badge {
    background: rgba(5, 150, 105, 0.14);
    color: #047857;
}

#node-property-sidebar .section-subtitle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-transform: none;
    color: var(--color-text-secondary, #9ca3af);
    margin-bottom: 8px;
}

#node-property-sidebar .section-subtitle::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: currentColor;
    opacity: 0.6;
}

#node-property-sidebar .section-body {
    display: block;
    font-size: 13px;
    color: inherit;
}

#node-property-sidebar .section.section-collapsed .section-body {
    display: none;
}

#node-property-sidebar .section-toggle {
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary, #9ca3af);
    transition: background 0.2s ease, color 0.2s ease;
}

#node-property-sidebar .section-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

#node-property-sidebar .section.section-collapsed .section-toggle svg {
    transform: rotate(180deg);
}

#node-property-sidebar .section-toggle:hover,
#node-property-sidebar .section-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary, #ffffff);
}

[data-theme="light"] #node-property-sidebar .section-toggle:hover,
[data-theme="light"] #node-property-sidebar .section-toggle:focus-visible {
    background: rgba(15, 23, 42, 0.08);
    color: #1f2937;
}

/* Allow the whole sidebar to scroll; no inner scroll area */
#node-property-sidebar .section.section-scrollable .section-body {
    max-height: none;
    overflow: visible;
    padding-right: 0;
}

/* Key-value layout */
#node-property-sidebar .property-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#node-property-sidebar .property-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

#node-property-sidebar .property-label {
    flex: 0 0 88px;
    color: var(--color-text-secondary, #9ca3af);
}

#node-property-sidebar .property-value {
    flex: 1 1 auto;
    text-align: right;
    color: var(--color-text-primary, #f5f5f5);
    word-break: break-word;
}

[data-theme="light"] #node-property-sidebar .property-label {
    color: #6b7280;
}

[data-theme="light"] #node-property-sidebar .property-value {
    color: #1f2937;
}

/* Pills */
#node-property-sidebar .pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#node-property-sidebar .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    font-size: 12px;
    color: var(--color-text-primary, #f5f5f5);
}

#node-property-sidebar .pill .pill-meta {
    color: var(--color-text-secondary, #a0aec0);
}

[data-theme="light"] #node-property-sidebar .pill {
    background: rgba(15, 23, 42, 0.06);
    border-color: rgba(15, 23, 42, 0.12);
    color: #1f2937;
}

/* Misc elements */
#node-property-sidebar .section-description {
    font-size: 12px;
    line-height: 1.5;
    color: var(--color-text-secondary, #9ca3af);
    margin-bottom: 12px;
}

#node-property-sidebar .json-preview {
    font-family: 'JetBrains Mono', 'Consolas', 'SFMono-Regular', monospace;
    font-size: 12px;
    line-height: 1.5;
    background: rgba(15, 23, 42, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 10px 12px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text-primary, #f5f5f5);
}

[data-theme="light"] #node-property-sidebar .json-preview {
    background: rgba(15, 23, 42, 0.08);
    border-color: rgba(15, 23, 42, 0.12);
    color: #1f2937;
}

#node-property-sidebar .section-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

#node-property-sidebar .action-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--color-accent, #00ff9b);
    text-decoration: none;
    font-size: 12px;
    transition: opacity 0.2s ease;
}

#node-property-sidebar .action-link:hover {
    opacity: 0.85;
}

#node-property-sidebar .section-empty {
    font-size: 12px;
    color: var(--color-text-secondary, #9ca3af);
    padding: 8px 0;
    text-align: left;
}

.script-language-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.script-language-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

[data-theme="light"] .script-language-option {
    border-color: rgba(15, 23, 42, 0.12);
}

.script-language-option input[type="radio"] {
    margin-top: 4px;
}

.script-language-option .option-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.script-language-option .option-title {
    font-weight: 600;
    color: var(--color-text-primary, #f5f5f5);
}

[data-theme="light"] .script-language-option .option-title {
    color: #1f2937;
}

.script-language-option .option-desc {
    font-size: 12px;
    color: var(--color-text-secondary, #9ca3af);
    line-height: 1.4;
}

[data-theme="light"] .script-language-option .option-desc {
    color: #6b7280;
}

.script-language-option:hover,
.script-language-option.selected {
    border-color: var(--color-primary-light, rgba(0, 255, 155, 0.4));
    background: rgba(0, 255, 155, 0.08);
}

[data-theme="light"] .script-language-option:hover,
[data-theme="light"] .script-language-option.selected {
    border-color: rgba(5, 150, 105, 0.35);
    background: rgba(5, 150, 105, 0.08);
}

.language-tip {
    font-size: 12px;
    color: var(--color-text-secondary, #9ca3af);
    text-align: right;
}

[data-theme="light"] .language-tip {
    color: #6b7280;
}

#node-property-sidebar .section-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 12px 0;
}

[data-theme="light"] #node-property-sidebar .section-divider {
    background: rgba(15, 23, 42, 0.08);
}

#node-property-sidebar .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-secondary, #9ca3af);
    font-size: 13px;
}

#node-property-sidebar .empty-state svg {
    width: 28px;
    height: 28px;
    opacity: 0.8;
}

#node-property-sidebar .empty-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary, #f5f5f5);
}

#node-property-sidebar .empty-subtitle {
    font-size: 12px;
    line-height: 1.6;
    color: var(--color-text-secondary, #9ca3af);
    max-width: 240px;
}

/* Toolbar button highlight */
.product-page .toolbar-btn.node-property-toggle svg {
    transition: stroke 0.2s ease;
}

.product-page .toolbar-btn.node-property-toggle.active svg {
    stroke: var(--color-accent, #00ff9b);
}
