/**
 * Design System Styles
 *
 * Core styling for all design system components.
 * Uses CSS custom properties from tokens.js
 */

/* ========== CSS CUSTOM PROPERTIES ========== */
:root {
    /* Spacing */
    --ds-space-xs: 4px;
    --ds-space-sm: 8px;
    --ds-space-md: 12px;
    --ds-space-lg: 16px;
    --ds-space-xl: 24px;
    --ds-space-xxl: 32px;

    /* Colors - Node */
    --ds-color-node-bg: #2a2a2a;
    --ds-color-node-bg-hover: #323232;
    --ds-color-node-bg-active: #353535;
    --ds-color-node-border: #3a3a3a;
    --ds-color-node-border-active: #4a4a4a;

    /* Colors - Semantic */
    --ds-color-primary: #2196f3;
    --ds-color-secondary: #757575;
    --ds-color-success: #4caf50;
    --ds-color-warning: #ff9800;
    --ds-color-danger: #f44336;
    --ds-color-info: #00bcd4;

    /* Colors - Text */
    --ds-color-text-primary: #ffffff;
    --ds-color-text-secondary: rgba(255, 255, 255, 0.7);
    --ds-color-text-disabled: rgba(255, 255, 255, 0.3);
    --ds-color-text-hint: rgba(255, 255, 255, 0.5);

    /* Colors - Background */
    --ds-color-bg-canvas: #1a1a1a;
    --ds-color-bg-panel: #242424;
    --ds-color-bg-input: rgba(0, 0, 0, 0.3);

    /* Colors - State */
    --ds-color-state-active: rgba(33, 150, 243, 0.2);
    --ds-color-state-hover: rgba(255, 255, 255, 0.05);
    --ds-color-state-focus: rgba(33, 150, 243, 0.3);

    /* Typography */
    --ds-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --ds-font-family-mono: 'Courier New', Courier, monospace;
    --ds-font-size-xs: 10px;
    --ds-font-size-sm: 11px;
    --ds-font-size-base: 12px;
    --ds-font-size-md: 13px;
    --ds-font-size-lg: 14px;
    --ds-font-size-xl: 16px;

    /* Node Sizes - Includes space for port labels */
    --ds-node-width-small: 320px;   /* TEST: 180px content + 140px label space */
    --ds-node-width-medium: 580px;  /* 380px content + 200px label space */
    --ds-node-width-large: 720px;   /* 520px content + 200px label space */
    --ds-node-width-xlarge: 880px;  /* 680px content + 200px label space */
    --ds-node-height-compact: 160px;  /* Increased from 120px for better content space */
    --ds-node-height-small: 180px;
    --ds-node-height-medium: 280px;
    --ds-node-height-large: 380px;

    /* Shadows */
    --ds-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --ds-shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3);
    --ds-shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.3);

    /* Transitions */
    --ds-transition-fast: 0.1s ease;
    --ds-transition-base: 0.15s ease;
    --ds-transition-slow: 0.3s ease;
}

/* ========== NODE SHELL ========== */
.node-shell {
    background: var(--ds-color-node-bg);
    border: 1px solid var(--ds-color-node-border);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--ds-shadow-sm);
    font-family: var(--ds-font-family);
    font-size: var(--ds-font-size-base);
    color: var(--ds-color-text-primary);
    position: relative;  /* Establish positioning context */
}

/* Node sizes - WIDTH (controlled by 'size' parameter) */
.node-shell-width--small { width: var(--ds-node-width-small); }
.node-shell-width--medium { width: var(--ds-node-width-medium); }
.node-shell-width--large { width: var(--ds-node-width-large); }
.node-shell-width--xlarge { width: var(--ds-node-width-xlarge); }

/* Node sizes - HEIGHT (controlled by 'height' parameter) */
.node-shell-height--compact { min-height: var(--ds-node-height-compact); }
.node-shell-height--small { min-height: var(--ds-node-height-small); }
.node-shell-height--medium { min-height: var(--ds-node-height-medium); }
.node-shell-height--large { min-height: var(--ds-node-height-large); }
.node-shell-height--auto { height: auto; min-height: var(--ds-node-height-compact); }

/* Node header */
.node-shell__header {
    padding: var(--ds-space-sm) var(--ds-space-md);
    border-bottom: 1px solid var(--ds-color-node-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.node-shell__title {
    display: flex;
    align-items: center;
    gap: var(--ds-space-sm);
    font-weight: 500;
}

.node-shell__icon {
    font-size: var(--ds-font-size-lg);
    line-height: 1;
}

.node-shell__title-text {
    font-size: var(--ds-font-size-md);
}

.node-shell__status {
    font-size: var(--ds-font-size-xs);
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
}

.node-shell__status--success { background: rgba(76, 175, 80, 0.2); color: #4caf50; }
.node-shell__status--warning { background: rgba(255, 152, 0, 0.2); color: #ff9800; }
.node-shell__status--error { background: rgba(244, 67, 54, 0.2); color: #f44336; }

/* Node content */
.node-shell__content {
    flex: 1;
    padding: var(--ds-space-md);
    overflow: visible;
}

/* Size-specific padding for port labels */
.node-shell-width--small .node-shell__content {
    padding-left: 70px;   /* Smaller label space for compact nodes */
    padding-right: 70px;
}

.node-shell-width--medium .node-shell__content,
.node-shell-width--large .node-shell__content,
.node-shell-width--xlarge .node-shell__content {
    padding-left: 100px;   /* Standard label space */
    padding-right: 100px;
}

.node-shell__content::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.node-shell__content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.node-shell__content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Node actions */
.node-shell__actions {
    padding: var(--ds-space-sm) var(--ds-space-md);
    border-top: 1px solid var(--ds-color-node-border);
    display: flex;
    justify-content: center;  /* Center action buttons */
    gap: var(--ds-space-sm);
    flex-wrap: wrap;
    background: rgba(0, 0, 0, 0.1);
}

/* Node sections */
.node-shell__section {
    margin-bottom: var(--ds-space-md);
}

.node-shell__section:last-child {
    margin-bottom: 0;
}

.node-shell__section-title {
    font-size: var(--ds-font-size-xs);
    color: var(--ds-color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--ds-space-xs);
}

/* Node columns */
.node-shell__columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--ds-space-md);
}

/* ========== BUTTON ========== */
.ds-button {
    font-family: var(--ds-font-family);
    font-size: var(--ds-font-size-sm);
    padding: var(--ds-space-xs) var(--ds-space-md);
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--ds-transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-xs);
    font-weight: 500;
    white-space: nowrap;
}

.ds-button:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.ds-button:active:not(:disabled) {
    transform: translateY(0);
}

.ds-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Button variants */
.ds-button--default {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--ds-color-text-primary);
}

.ds-button--default:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.ds-button--primary {
    background: var(--ds-color-primary);
    color: white;
}

.ds-button--success {
    background: var(--ds-color-success);
    color: white;
}

.ds-button--warning {
    background: var(--ds-color-warning);
    color: white;
}

.ds-button--danger {
    background: var(--ds-color-danger);
    color: white;
}

/* Button sizes */
.ds-button--sm {
    padding: 3px var(--ds-space-sm);
    font-size: var(--ds-font-size-xs);
}

.ds-button--md {
    padding: var(--ds-space-xs) var(--ds-space-md);
    font-size: var(--ds-font-size-sm);
}

.ds-button--lg {
    padding: var(--ds-space-sm) var(--ds-space-lg);
    font-size: var(--ds-font-size-md);
}

.ds-button--full {
    width: 100%;
}

.ds-button--icon-only {
    padding: var(--ds-space-xs);
    aspect-ratio: 1;
}

/* Button group */
.ds-button-group {
    display: flex;
    gap: var(--ds-space-xs);
}

.ds-button-group--vertical {
    flex-direction: column;
}

/* ========== DISPLAY ========== */
.ds-display {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ds-display__label {
    font-size: var(--ds-font-size-xs);
    color: var(--ds-color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ds-display__value {
    font-size: var(--ds-font-size-base);
    color: var(--ds-color-text-primary);
    font-weight: 500;
}

.ds-display--sm .ds-display__value { font-size: var(--ds-font-size-sm); }
.ds-display--lg .ds-display__value { font-size: var(--ds-font-size-lg); }

.ds-display__unit {
    color: var(--ds-color-text-secondary);
    font-size: 0.9em;
    margin-left: 2px;
}

.ds-display__status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ds-color-success);
    margin-right: var(--ds-space-xs);
}

/* Display meter */
.ds-display__meter {
    position: relative;
    height: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.ds-display__meter-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    background: linear-gradient(90deg, var(--ds-color-success), var(--ds-color-primary));
    transition: width var(--ds-transition-base);
}

.ds-display__meter-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--ds-font-size-xs);
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* Key-value display */
.ds-display-kv__row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--ds-space-xs) 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ds-display-kv__row:last-child {
    border-bottom: none;
}

.ds-display-kv__key {
    font-size: var(--ds-font-size-sm);
    color: var(--ds-color-text-secondary);
}

.ds-display-kv__value {
    font-size: var(--ds-font-size-sm);
    color: var(--ds-color-text-primary);
    font-weight: 500;
}

/* Stat display */
.ds-display-stat {
    text-align: center;
    padding: var(--ds-space-md);
}

.ds-display-stat__value {
    font-size: var(--ds-font-size-xxxl);
    font-weight: 700;
    color: var(--ds-color-text-primary);
    line-height: 1;
}

.ds-display-stat__label {
    font-size: var(--ds-font-size-sm);
    color: var(--ds-color-text-secondary);
    margin-top: var(--ds-space-xs);
}

.ds-display-stat__trend {
    font-size: var(--ds-font-size-sm);
    margin-top: var(--ds-space-xs);
}

.ds-display-stat__trend--up { color: var(--ds-color-success); }
.ds-display-stat__trend--down { color: var(--ds-color-danger); }

/* ========== PREVIEW ========== */
.ds-preview {
    position: relative;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: hidden;
}

/* Preview sizes */
.ds-preview--small { max-width: 200px; }
.ds-preview--medium { max-width: 320px; }
.ds-preview--large { max-width: 480px; }
.ds-preview--fill { width: 100%; }

/* Aspect ratios */
.ds-preview--16-9 { aspect-ratio: 16 / 9; }
.ds-preview--4-3 { aspect-ratio: 4 / 3; }
.ds-preview--1-1 { aspect-ratio: 1 / 1; }

.ds-preview__canvas,
.ds-preview__video,
.ds-preview__image,
.ds-preview__custom {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ds-preview__controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--ds-space-sm);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    display: flex;
    gap: var(--ds-space-xs);
    opacity: 0;
    transition: opacity var(--ds-transition-base);
}

.ds-preview:hover .ds-preview__controls {
    opacity: 1;
}

/* ========== INPUT ========== */
.ds-input {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: var(--ds-space-sm);
}

.ds-input__label {
    font-size: var(--ds-font-size-xs);
    color: var(--ds-color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ds-input__field,
.ds-input__select,
.ds-input__textarea {
    font-family: var(--ds-font-family);
    font-size: var(--ds-font-size-sm);
    padding: var(--ds-space-xs) var(--ds-space-sm);
    background: var(--ds-color-bg-input);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: var(--ds-color-text-primary);
    transition: all var(--ds-transition-base);
}

.ds-input__field:focus,
.ds-input__select:focus,
.ds-input__textarea:focus {
    outline: none;
    border-color: var(--ds-color-primary);
    background: rgba(0, 0, 0, 0.4);
}

.ds-input__textarea {
    min-height: 60px;
    resize: vertical;
}

.ds-input__color {
    height: 32px;
    padding: 2px;
    cursor: pointer;
}

/* Checkbox */
.ds-input__checkbox-wrapper {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.ds-input__checkbox {
    position: absolute;
    opacity: 0;
}

.ds-input__checkbox-indicator {
    display: block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    background: var(--ds-color-bg-input);
    transition: all var(--ds-transition-base);
}

.ds-input__checkbox:checked + .ds-input__checkbox-indicator {
    background: var(--ds-color-primary);
    border-color: var(--ds-color-primary);
}

.ds-input__checkbox:checked + .ds-input__checkbox-indicator::after {
    content: '✓';
    display: block;
    text-align: center;
    color: white;
    font-size: 12px;
    line-height: 14px;
}

/* Slider */
.ds-input__slider-wrapper {
    display: flex;
    align-items: center;
    gap: var(--ds-space-sm);
}

.ds-input__slider {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    -webkit-appearance: none;
}

.ds-input__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--ds-color-primary);
    cursor: pointer;
    transition: transform var(--ds-transition-base);
}

.ds-input__slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.ds-input__slider-value {
    min-width: 40px;
    font-size: var(--ds-font-size-sm);
    color: var(--ds-color-text-secondary);
    text-align: right;
}

/* Input group */
.ds-input-group {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-sm);
}

.ds-input-group__title {
    font-size: var(--ds-font-size-sm);
    font-weight: 600;
    color: var(--ds-color-text-primary);
    margin-bottom: var(--ds-space-xs);
}
