/* ============================================================
   CIRCUIT DIAGRAM MAKER — Design System & Styles
   Premium dark theme with glassmorphism effects
   ============================================================ */

/* === CSS Custom Properties === */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0e14;
    --bg-secondary: #0f1419;
    --bg-tertiary: #151c25;
    --bg-surface: #1a2332;
    --bg-surface-hover: #1f2b3d;
    --bg-surface-active: #253349;

    /* Canvas */
    --canvas-bg: #0d1117;
    --canvas-grid: #1b2535;
    --canvas-grid-major: #243044;
    --canvas-dot: #2a3a50;

    /* Accent Colors */
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-primary-glow: rgba(59, 130, 246, 0.15);
    --accent-secondary: #06b6d4;
    --accent-secondary-glow: rgba(6, 182, 212, 0.15);
    --accent-success: #22c55e;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;

    /* Text */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-disabled: #475569;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.15);
    --border-accent: rgba(59, 130, 246, 0.4);

    /* Glassmorphism */
    --glass-bg: rgba(15, 20, 25, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(20px);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.15);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Sizing */
    --toolbar-height: 48px;
    --sidebar-width: 240px;
    --right-panel-width: 260px;

    /* Transitions */
    --transition-fast: 0.12s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-xl: 14px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    font-size: inherit;
    border: none;
    background: none;
    cursor: pointer;
    color: inherit;
    outline: none;
}

input {
    font-family: inherit;
    font-size: inherit;
    border: none;
    background: none;
    color: inherit;
    outline: none;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* === TOOLBAR === */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-height);
    padding: 0 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 100;
    user-select: none;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.toolbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
}

.brand-icon {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.4));
}

.brand-name {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-default);
    margin: 0 6px;
}

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

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    white-space: nowrap;
    font-size: 12px;
    font-weight: 500;
}

.toolbar-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.toolbar-btn:active {
    background: var(--bg-surface-active);
    transform: scale(0.97);
}

.toolbar-btn:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.toolbar-btn svg {
    flex-shrink: 0;
}

.toolbar-btn-icon {
    padding: 6px;
}

.circuit-name-input {
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 4px 12px;
    width: 240px;
    transition: all var(--transition-base);
}

.circuit-name-input:hover {
    border-color: var(--border-default);
}

.circuit-name-input:focus {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    background: var(--bg-surface);
    box-shadow: var(--shadow-glow);
}

.zoom-display {
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-width: 48px;
    text-align: center;
    padding: 4px 0;
}

/* Dropdown */
.toolbar-dropdown {
    position: relative;
}

.dropdown-arrow {
    margin-left: 2px;
    transition: transform var(--transition-fast);
}

.toolbar-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 4px;
    min-width: 180px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all var(--transition-base);
    z-index: 200;
}

.toolbar-dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* === APP CONTAINER === */
.app-container {
    display: flex;
    height: calc(100svh - var(--toolbar-height));
    overflow: hidden;
}

/* === SIDEBAR === */
.sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    overflow: hidden;
    user-select: none;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    padding: 8px;
}

.sidebar-section-grow {
    flex: 1;
    overflow: hidden;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* Tool Buttons */
.tool-buttons {
    display: flex;
    gap: 4px;
}

.tool-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    position: relative;
}

.tool-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.tool-btn.active {
    background: var(--accent-primary-glow);
    color: var(--accent-primary);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.3);
}

.tool-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 25%;
    right: 25%;
    height: 2px;
    background: var(--accent-primary);
    border-radius: 1px;
}

/* View Toggle */
.view-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px 5px;
    border-radius: 3px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.view-btn:hover {
    color: var(--text-secondary);
}

.view-btn.active {
    background: var(--bg-surface-active);
    color: var(--text-primary);
}

/* Search */
.search-container {
    position: relative;
    padding: 0 8px;
    margin-bottom: 8px;
}

.search-icon {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 7px 10px 7px 30px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 12px;
    transition: all var(--transition-base);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

/* Component Library */
.component-library {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.component-category {
    margin-bottom: 8px;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.category-header:hover {
    background: var(--bg-surface);
    color: var(--text-secondary);
}

.category-header .chevron {
    transition: transform var(--transition-fast);
}

.category-header.collapsed .chevron {
    transform: rotate(-90deg);
}

.category-items {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 4px 0;
}

.category-items.list-view {
    grid-template-columns: 1fr;
}

.category-items.collapsed {
    display: none;
}

.component-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: grab;
    transition: all var(--transition-fast);
    position: relative;
}

.component-item:hover {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
}

.component-item:active {
    cursor: grabbing;
    background: var(--accent-primary-glow);
    border-color: var(--border-accent);
    transform: scale(0.96);
}

.component-item.list-view {
    flex-direction: row;
    padding: 6px 8px;
    gap: 8px;
}

.component-item svg,
.component-item canvas {
    width: 40px;
    height: 28px;
    color: var(--text-secondary);
}

.component-item.list-view svg,
.component-item.list-view canvas {
    width: 32px;
    height: 22px;
}

.component-item .component-name {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
}

.component-item.list-view .component-name {
    font-size: 11px;
    text-align: left;
}

/* === CANVAS CONTAINER === */
.canvas-container {
    flex: 1;
    position: relative;
    background: var(--canvas-bg);
    overflow: hidden;
}

.canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.canvas-container.tool-select canvas {
    cursor: default;
}

.canvas-container.tool-wire canvas {
    cursor: crosshair;
}

.canvas-container.tool-delete canvas {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='M4 4l12 12M16 4L4 16' stroke='%23ef4444' stroke-width='2'/%3E%3C/svg%3E") 10 10, crosshair;
}

.canvas-container.panning canvas {
    cursor: grab;
}

.canvas-container.panning:active canvas {
    cursor: grabbing;
}

.coord-display {
    position: absolute;
    bottom: 32px;
    right: 12px;
    display: flex;
    gap: 12px;
    padding: 4px 10px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    pointer-events: none;
}

.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    font-size: 11px;
    color: var(--text-muted);
}

.status-bar #status-text {
    flex: 1;
}

/* === RIGHT PANEL === */
.right-panel {
    display: flex;
    flex-direction: column;
    width: var(--right-panel-width);
    min-width: var(--right-panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-subtle);
    overflow-y: auto;
    user-select: none;
}

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

.panel-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.properties-content {
    padding: 8px 14px 14px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    text-align: center;
}

.empty-state p {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Property Fields */
.property-group {
    margin-bottom: 12px;
}

.property-group-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.property-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.property-label {
    flex-shrink: 0;
    width: 70px;
    font-size: 11px;
    color: var(--text-secondary);
}

.property-input {
    flex: 1;
    padding: 5px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    transition: all var(--transition-fast);
}

.property-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

.property-select {
    flex: 1;
    padding: 5px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    appearance: none;
}

/* Info Panel */
.info-content {
    padding: 8px 14px 14px;
}

.info-shortcuts {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

.shortcut-row kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 2px 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-weight: 500;
    box-shadow: 0 1px 0 var(--border-subtle);
}

/* === CONTEXT MENU === */
.context-menu {
    position: fixed;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 4px;
    min-width: 200px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: contextMenuIn 0.12s ease;
}

@keyframes contextMenuIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 7px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    transition: all var(--transition-fast);
}

.context-item:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.context-item-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-danger);
}

.context-item kbd {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.context-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 4px 8px;
}

/* === MODAL === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    font-size: 18px;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.shortcuts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.shortcuts-grid .shortcut-row {
    padding: 6px 8px;
    border-radius: var(--radius-sm);
}

.shortcuts-grid .shortcut-row:hover {
    background: var(--bg-surface);
}

/* === TOAST === */
.toast-container {
    position: fixed;
    bottom: 48px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 3000;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    animation: toastIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.toast.toast-success {
    border-color: rgba(34, 197, 94, 0.3);
}

.toast.toast-error {
    border-color: rgba(239, 68, 68, 0.3);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(12px);
    }
}

/* === UTILITY === */
.hidden {
    display: none !important;
}

/* Selection highlight pulse */
@keyframes selectionPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Terminal connection indicator */
@keyframes terminalGlow {
    0%, 100% { box-shadow: 0 0 4px var(--accent-secondary); }
    50% { box-shadow: 0 0 12px var(--accent-secondary); }
}

/* Wire drawing preview */
.wire-preview {
    stroke: var(--accent-primary);
    stroke-width: 2;
    stroke-dasharray: 6 3;
    animation: wireDash 0.4s linear infinite;
}

@keyframes wireDash {
    to { stroke-dashoffset: -9; }
}

/* Component drag ghost */
.drag-ghost {
    position: fixed;
    pointer-events: none;
    opacity: 0.7;
    z-index: 500;
    filter: drop-shadow(0 4px 8px rgba(59, 130, 246, 0.3));
}

/* === MOBILE RESPONSIVE (HORIZONTAL / LANDSCAPE ORIENTED UI) === */
@media (max-width: 768px) {
    body {
        overflow: hidden; /* Prevent body scroll on mobile to avoid bouncing */
    }

    /* Hide desktop shortcuts, show mobile touch gestures */
    .desktop-shortcuts { display: none !important; }
    .mobile-shortcuts { display: flex !important; }

    /* Optionally hide less important toolbar items */
    .toolbar-center { display: none; }
    .toolbar-brand span { display: none; }
    
    .toolbar {
        padding: 0 4px;
        overflow-x: auto;
    }
    
    .toolbar-btn {
        padding: 6px 8px;
    }
    
    .toolbar-btn span {
        display: none; /* Icon only mode overhead */
    }

    /* Transform panels into horizontal bars stacked vertically */
    .app-container {
        flex-direction: column;
        height: calc(100svh - var(--toolbar-height));
    }

    /* Tools & Component Library become a horizontal strip at the bottom */
    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        min-height: auto;
        max-height: 40dvh; /* Enforce max height so it never pushes offscreen */
        overflow-y: auto; /* Scroll internally if tabs are too tall */
        flex: 0 0 auto;
        flex-direction: column;
        border-right: none;
        border-top: 1px solid var(--border-subtle);
        order: 3; /* Move to bottom */
        padding-bottom: env(safe-area-inset-bottom, 24px); /* Extra safety for bottom bezel/home bar */
    }

    .sidebar-section-grow {
        flex: none;
    }
    
    .search-container {
        margin-bottom: 4px;
        padding: 0 4px;
    }

    .component-library {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 4px;
        gap: 8px;
    }

    .component-category {
        margin-bottom: 0;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .category-items {
        display: flex;
        flex-direction: row;
        gap: 4px;
    }

    .category-header { display: none; }

    .component-item {
        padding: 6px;
        min-width: 50px;
    }

    /* The canvas remains in the middle */
    .canvas-container {
        order: 1;
        flex: 1 1 0;
        min-height: 25dvh; /* Ensure canvas is never crushed out of existence */
    }

    /* Properties & Info become a horizontal strip above the tools */
    .right-panel {
        width: 100%;
        min-width: 100%;
        height: 120px; /* tightly packed layout for scrolling */
        max-height: 30dvh;
        flex: 0 0 auto;
        flex-direction: row;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
        overflow-x: auto;
        overflow-y: hidden;
        order: 2;
    }

    .panel-section {
        flex: 1 0 auto; /* Ensure it doesn't shrink aggressively */
        width: 50vw; /* Take half screen width */
        min-width: 200px;
        border-bottom: none;
        border-right: 1px solid var(--border-subtle);
        display: flex;
        flex-direction: column;
    }
    
    .properties-content, .info-content {
        padding: 4px 8px;
        overflow-y: auto; /* Allow internal vertical scrolling */
        flex: 1; /* Take remaining height */
    }
    
    .shortcut-row {
        gap: 4px;
    }

    /* Expand / Collapse Section functionality */
    .toggleable-header {
        cursor: pointer;
        user-select: none;
    }
    
    .toggleable-header .section-chevron {
        transition: transform 0.2s ease;
    }
    
    .toggleable-header.collapsed .section-chevron {
        transform: rotate(-90deg);
    }
    
    /* Classes applied to content containers that hide when collapsed */
    .tool-buttons.collapsed,
    .component-library-wrap.collapsed,
    .properties-content.collapsed,
    .info-content.collapsed,
    .category-items.collapsed {
        display: none !important;
    }
    
    /* When a section collapses, let the parent flex container shrink */
    .sidebar-section:has(> .toggleable-header.collapsed),
    .panel-section:has(> .toggleable-header.collapsed) {
        flex: 0 0 auto !important; 
    }
}


