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

:root {
    --primary: #3B82F6;
    --primary-hover: #2563EB;
    --primary-light: #DBEAFE;
    --text: #1E293B;
    --text-secondary: #64748B;
    --bg: #F8FAFC;
    --white: #FFFFFF;
    --border: #E2E8F0;
    --border-hover: #CBD5E1;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --toolbar-h: 56px;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --success: #10B981;
    --warning: #F59E0B;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

/* ===== Toolbar ===== */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.toolbar-left { display: flex; align-items: center; gap: 12px; min-width: 180px; }
.toolbar-center { display: flex; align-items: center; gap: 4px; }
.toolbar-right { display: flex; align-items: center; gap: 12px; min-width: 180px; justify-content: flex-end; }

.toolbar-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    touch-action: manipulation;
}

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

.tool-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

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

/* Search */
.search-container {
    position: relative;
}

#search-input {
    width: 180px;
    padding: 6px 12px 6px 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all 0.15s ease;
}

#search-input:focus {
    border-color: var(--primary);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
    width: 240px;
}

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

/* Zoom controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    touch-action: manipulation;
}

.zoom-btn:hover { background: var(--white); color: var(--text); }

#zoom-fit { font-size: 11px; width: auto; padding: 0 8px; }

#zoom-level {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 44px;
    text-align: center;
}

/* ===== Toolbar Divider ===== */
.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 6px;
}

/* ===== History Buttons ===== */
.history-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.history-btn:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
}

.history-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.history-btn.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

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

/* ===== History Panel ===== */
#history-panel {
    position: fixed;
    bottom: 16px;
    left: 16px;
    width: 220px;
    max-height: 320px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 50;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.history-panel-header {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#history-list {
    list-style: none;
    padding: 4px;
    margin: 0;
    overflow-y: auto;
    flex: 1;
    max-height: 270px;
}

.history-item {
    padding: 5px 10px;
    font-size: 12px;
    color: var(--text-secondary);
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
}

.history-item.history-current {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.history-item.history-redo-item {
    opacity: 0.35;
    font-style: italic;
}

.history-empty {
    padding: 12px 10px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    font-style: italic;
}

/* ===== Canvas ===== */
#canvas-container {
    position: fixed;
    top: var(--toolbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    cursor: grab;
    background-color: var(--bg);
    background-image: radial-gradient(circle, #CBD5E1 1px, transparent 1px);
    background-size: 24px 24px;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#canvas-container.grabbing { cursor: grabbing; }
#canvas-container.mode-add { cursor: crosshair; }
#canvas-container.mode-connect { cursor: crosshair; }
#canvas-container.mode-group { cursor: crosshair; }

#canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
}

#connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: visible;
    pointer-events: none;
    z-index: 2;
}

#connections-layer path {
    pointer-events: stroke;
    cursor: pointer;
}

#connections-layer path:hover {
    stroke-width: 4;
    filter: drop-shadow(0 0 3px rgba(59,130,246,0.3));
}

#nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
}

#groups-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* ===== Prototype Node Card ===== */
.proto-node {
    position: absolute;
    width: 220px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    overflow: hidden;
}

.proto-node:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-hover);
}

.proto-node.dragging {
    cursor: grabbing;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    opacity: 0.9;
}

.proto-node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15), var(--shadow-md);
}

.proto-node.connecting-source {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.3);
}

.proto-node.search-dim {
    opacity: 0.2;
    pointer-events: none;
}

.proto-node .color-strip {
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    border-radius: var(--radius) 0 0 var(--radius);
}

.proto-node .node-preview {
    width: 100%;
    height: 130px;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
}

.proto-node model-viewer {
    width: 100%;
    height: 130px;
    --poster-color: transparent;
}

.proto-node .node-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.proto-node .node-preview .placeholder-icon {
    color: var(--text-secondary);
    opacity: 0.3;
}

.proto-node .node-info {
    padding: 10px 12px 10px 16px;
}

.proto-node .node-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.proto-node .node-specs {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.proto-node .node-specs span {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Groups ===== */
.group-region {
    position: absolute;
    border-radius: var(--radius-lg);
    border: 2px dashed;
    transition: all 0.2s ease;
    cursor: grab;
}

.group-region:active { cursor: grabbing; }

.group-region .group-label {
    position: absolute;
    top: -24px;
    left: 8px;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}

/* Collapse toggle chevron */
.group-collapse-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    cursor: pointer;
    border-radius: 3px;
    font-size: 10px;
    line-height: 1;
    transition: transform 0.2s ease, background 0.15s ease;
    flex-shrink: 0;
}

.group-collapse-toggle:hover {
    background: rgba(0,0,0,0.1);
}

.group-collapse-toggle svg {
    width: 10px;
    height: 10px;
    transition: transform 0.2s ease;
}

.group-region.collapsed .group-collapse-toggle svg {
    transform: rotate(-90deg);
}

/* Collapsed group: hide contents, show compact */
.group-region.collapsed {
    min-height: 0 !important;
    overflow: hidden;
}

.group-label-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.group-collapsed-summary {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.7;
    margin-left: 2px;
}

/* Nesting depth indicator in label */
.group-nesting-breadcrumb {
    font-size: 10px;
    font-weight: 400;
    opacity: 0.6;
    margin-right: 2px;
}

/* ===== Connection Labels ===== */
.connection-label {
    position: absolute;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--white);
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid var(--border);
    pointer-events: none;
    white-space: nowrap;
    z-index: 2;
    transform: translate(-50%, -50%);
}

/* ===== Lightbox ===== */
#lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
}

.lightbox-panel {
    position: absolute;
    top: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.lightbox-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.lightbox-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lightbox-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.lightbox-close:hover { background: var(--bg); color: var(--text); }

.lightbox-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.lightbox-body model-viewer {
    width: 100%;
    height: 350px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.lightbox-section {
    margin-bottom: 24px;
}

.lightbox-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lightbox-section p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.specs-table {
    width: 100%;
    border-collapse: collapse;
}

.specs-table td {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.specs-table td:first-child {
    font-weight: 600;
    color: var(--text);
    width: 140px;
    white-space: nowrap;
}

.specs-table td:last-child {
    color: var(--text-secondary);
}

.lightbox-connections {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.lightbox-conn-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.1s;
}

.lightbox-conn-chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.lightbox-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}

.lightbox-images img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
}

/* ===== Modal ===== */
#modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 600;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
}

.modal-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 480px;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover { background: var(--bg); }

.modal-body { padding: 20px; touch-action: pan-y; overscroll-behavior: contain; }

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
    background: var(--white);
    outline: none;
    transition: all 0.15s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-group input[type="color"] {
    width: 40px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group { flex: 1; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--white);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: var(--border-hover); }

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-danger {
    background: var(--white);
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger); color: white; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ===== Context Menu ===== */
#context-menu {
    position: fixed;
    z-index: 700;
    min-width: 160px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px;
}

.context-menu-list {
    list-style: none;
}

.context-menu-list li {
    padding: 7px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-list li:hover { background: var(--bg); }
.context-menu-list li.danger { color: var(--danger); }
.context-menu-list li.danger:hover { background: #FEF2F2; }
.context-menu-list li.separator {
    height: 1px;
    padding: 0;
    margin: 4px 8px;
    background: var(--border);
    cursor: default;
}

/* ===== Minimap ===== */
#minimap {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 180px;
    height: 120px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 50;
    overflow: hidden;
}

#minimap-canvas {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

#minimap-viewport {
    position: absolute;
    border: 2px solid var(--primary);
    background: rgba(59, 130, 246, 0.08);
    border-radius: 2px;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
}

#minimap-viewport.minimap-dragging {
    cursor: grabbing;
    border-color: #2563EB;
    background: rgba(59, 130, 246, 0.15);
}

/* ===== Welcome ===== */
#welcome-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 250, 252, 0.85);
    backdrop-filter: blur(2px);
}

.welcome-content {
    text-align: center;
    max-width: 400px;
    padding: 40px;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.welcome-content h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.welcome-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.6;
}

.welcome-hint {
    font-size: 13px;
    padding: 10px;
    background: var(--primary-light);
    border-radius: 6px;
    margin-bottom: 20px;
}

/* ===== File Upload Area ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.03);
}

.upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-area p {
    font-size: 13px;
    color: var(--text-secondary);
}

.upload-area input[type="file"] { display: none; }

/* ===== Spec Editor ===== */
.spec-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
    align-items: center;
}

.spec-row input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
}

.spec-row input:first-child { max-width: 120px; font-weight: 500; }

.spec-row .remove-spec {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    border-radius: 4px;
}

.spec-row .remove-spec:hover { background: #FEF2F2; color: var(--danger); }

.add-spec-btn {
    font-size: 12px;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
}

.add-spec-btn:hover { text-decoration: underline; }

/* ===== Confirmation Overlay ===== */
.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.confirm-overlay .modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,0.4); }

.confirm-box {
    position: relative;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    max-width: 360px;
    text-align: center;
}

.confirm-box p {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-box .confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

/* ===== Mobile Bottom Toolbar ===== */
:root {
    --mob-toolbar-h: 64px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-toolbar {
    display: none; /* Hidden on desktop, shown via media query */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mob-toolbar-h) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: var(--white);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    align-items: stretch;
    justify-content: space-around;
    z-index: 100;
}

.mob-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    min-width: 48px;
    min-height: 48px;
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease, background 0.15s ease;
    position: relative;
}

.mob-btn:active {
    background: var(--bg);
}

.mob-btn.active {
    color: var(--primary);
}

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

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

.mob-btn span {
    line-height: 1;
}

/* ===== Mobile Bottom Sheet ===== */
.mobile-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.mobile-sheet-backdrop.open {
    display: block;
    opacity: 1;
}

.mobile-sheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    background: var(--white);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: var(--safe-area-bottom);
    overflow: hidden;
}

.mobile-sheet.visible {
    display: block;
}

.mobile-sheet.open {
    transform: translateY(0);
}

.mobile-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: grab;
    touch-action: none;
}

.mobile-sheet-handle span {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-hover);
}

.mobile-sheet-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(60vh - 30px - var(--safe-area-bottom));
    padding: 0 16px 16px;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.sheet-group {
    margin-bottom: 16px;
}

.sheet-group:last-child {
    margin-bottom: 0;
}

.sheet-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    padding: 4px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.sheet-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    border-radius: 8px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s ease;
    min-height: 48px;
}

.sheet-btn:active {
    background: var(--bg);
}

.sheet-btn svg {
    flex-shrink: 0;
    color: var(--text-secondary);
}

.sheet-zoom-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.sheet-zoom-btn {
    width: 48px;
    min-width: 48px;
    flex: 0 0 auto;
    justify-content: center;
    padding: 8px;
}

.sheet-zoom-level {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    min-width: 52px;
    text-align: center;
}

/* ===== Dark mode overrides for mobile toolbar ===== */
[data-theme="dark"] .mobile-toolbar {
    background: var(--white);
    border-top-color: var(--border);
}

[data-theme="dark"] .mobile-sheet {
    background: var(--white);
}

[data-theme="dark"] .mobile-sheet-backdrop {
    background: rgba(0,0,0,0.6);
}

/* ===== Responsive: Desktop vs Mobile ===== */
@media (max-width: 768px) {
    /* Hide desktop toolbar, show mobile bottom bar */
    #toolbar { display: none !important; }
    .mobile-toolbar { display: flex; }

    /* Canvas: no top offset, add bottom padding for mobile bar */
    #canvas-container {
        top: 0;
        bottom: calc(var(--mob-toolbar-h) + var(--safe-area-bottom));
    }

    /* Mode tooltip: position near top on mobile */
    #mode-tooltip {
        top: 8px !important;
    }

    /* lightbox-panel bottom sheet styles are in the mobile bottom sheets section below */
    #minimap { width: 120px; height: 80px; bottom: calc(var(--mob-toolbar-h) + var(--safe-area-bottom) + 8px); }

    /* Bulk actions bar above mobile toolbar */
    .bulk-actions-bar {
        bottom: calc(var(--mob-toolbar-h) + var(--safe-area-bottom) + 12px) !important;
    }
}

@media (min-width: 769px) {
    /* Ensure mobile elements are hidden on desktop */
    .mobile-toolbar { display: none !important; }
    .mobile-sheet { display: none !important; }
    .mobile-sheet-backdrop { display: none !important; }
}

@media (max-width: 480px) {
    #history-panel { display: none !important; }
}

/* ===== Selection Box (for group mode) ===== */
.selection-box {
    position: absolute;
    border: 2px solid var(--primary);
    background: rgba(59, 130, 246, 0.08);
    border-radius: 4px;
    pointer-events: none;
    z-index: 50;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

#lightbox-overlay { animation: fadeIn 0.2s ease; }
.lightbox-panel { animation: slideUp 0.2s ease; }
#modal-overlay { animation: fadeIn 0.15s ease; }
@keyframes modalSlideUp { from { opacity: 0; transform: translate(-50%, -48%); } to { opacity: 1; transform: translate(-50%, -50%); } }
.modal-panel { animation: modalSlideUp 0.15s ease; }

/* ===== Dark Mode ===== */
[data-theme="dark"] {
    --primary: #60A5FA;
    --primary-hover: #3B82F6;
    --primary-light: rgba(59, 130, 246, 0.15);
    --text: #E2E8F0;
    --text-secondary: #94A3B8;
    --bg: #0F172A;
    --white: #1E293B;
    --border: #334155;
    --border-hover: #475569;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5), 0 4px 6px rgba(0,0,0,0.3);
    --danger: #F87171;
    --danger-hover: #EF4444;
    --success: #34D399;
    --warning: #FBBF24;
}

/* Canvas dot grid for dark mode */
[data-theme="dark"] #canvas-container {
    background-image: radial-gradient(circle, #475569 1px, transparent 1px);
}

/* Toolbar dark adjustments */
[data-theme="dark"] #toolbar {
    background: #1E293B;
    border-bottom-color: #334155;
}

/* Tool button active in dark mode */
[data-theme="dark"] .tool-btn.active {
    background: rgba(59, 130, 246, 0.15);
    color: #60A5FA;
    border-color: #3B82F6;
}

/* Search input dark */
[data-theme="dark"] #search-input {
    background: #0F172A;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] #search-input:focus {
    background: #1E293B;
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

[data-theme="dark"] #search-input::placeholder {
    color: #64748B;
}

/* Form inputs in dark mode */
[data-theme="dark"] .form-group input[type="text"],
[data-theme="dark"] .form-group input[type="number"],
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select {
    background: #0F172A;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-group select:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

[data-theme="dark"] .form-group input::placeholder,
[data-theme="dark"] .form-group textarea::placeholder {
    color: #64748B;
}

/* Node cards dark */
[data-theme="dark"] .proto-node {
    background: #1E293B;
    border-color: #334155;
}

[data-theme="dark"] .proto-node:hover {
    border-color: #475569;
}

[data-theme="dark"] .proto-node .node-preview {
    background: #0F172A;
    border-bottom-color: #334155;
}

[data-theme="dark"] .proto-node.selected {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.25), var(--shadow-md);
}

/* Lightbox dark */
[data-theme="dark"] .lightbox-panel {
    background: #1E293B;
}

[data-theme="dark"] .lightbox-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .lightbox-backdrop {
    background: rgba(0, 0, 0, 0.65);
}

[data-theme="dark"] .lightbox-body model-viewer {
    border-color: #334155;
}

[data-theme="dark"] .specs-table td {
    border-bottom-color: #334155;
}

/* Modal dark */
[data-theme="dark"] .modal-panel {
    background: #1E293B;
}

[data-theme="dark"] .modal-backdrop {
    background: rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] .modal-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .modal-footer {
    border-top-color: #334155;
}

/* Context menu dark */
[data-theme="dark"] #context-menu {
    background: #1E293B;
    border-color: #334155;
}

[data-theme="dark"] .context-menu-list li:hover {
    background: #0F172A;
}

[data-theme="dark"] .context-menu-list li.danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

[data-theme="dark"] .context-menu-list li.separator {
    background: #334155;
}

/* Minimap dark */
[data-theme="dark"] #minimap {
    background: #1E293B;
    border-color: #334155;
}

/* Welcome overlay dark */
[data-theme="dark"] #welcome-overlay {
    background: rgba(15, 23, 42, 0.85);
}

[data-theme="dark"] .welcome-content {
    background: #1E293B;
}

[data-theme="dark"] .welcome-hint {
    background: rgba(59, 130, 246, 0.15);
}

/* Confirm overlay dark */
[data-theme="dark"] .confirm-box {
    background: #1E293B;
}

/* Upload area dark */
[data-theme="dark"] .upload-area {
    border-color: #334155;
}

[data-theme="dark"] .upload-area:hover {
    border-color: #3B82F6;
    background: rgba(59, 130, 246, 0.05);
}

/* Connection label dark */
[data-theme="dark"] .connection-label {
    background: #1E293B;
    border-color: #334155;
}

/* Lightbox connection chip dark */
[data-theme="dark"] .lightbox-conn-chip {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .lightbox-conn-chip:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: #3B82F6;
}

/* Button adjustments for dark mode */
[data-theme="dark"] .btn {
    background: #1E293B;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .btn:hover {
    background: #0F172A;
    border-color: #475569;
}

[data-theme="dark"] .btn-primary {
    background: #3B82F6;
    color: #FFFFFF;
    border-color: #3B82F6;
}

[data-theme="dark"] .btn-primary:hover {
    background: #2563EB;
    border-color: #2563EB;
}

[data-theme="dark"] .btn-danger {
    background: #1E293B;
    color: #F87171;
    border-color: #F87171;
}

[data-theme="dark"] .btn-danger:hover {
    background: #F87171;
    color: #FFFFFF;
}

/* Zoom controls dark */
[data-theme="dark"] .zoom-controls {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .zoom-btn:hover {
    background: #1E293B;
    color: #E2E8F0;
}

/* Spec editor inputs dark */
[data-theme="dark"] .spec-row input {
    background: #0F172A;
    color: #E2E8F0;
    border-color: #334155;
}

/* Scrollbar dark */
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #475569; }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: #64748B; }

/* Lightbox images border dark */
[data-theme="dark"] .lightbox-images img {
    border-color: #334155;
}

/* ===== Keyboard Shortcuts Overlay ===== */
#shortcuts-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.shortcuts-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
}

.shortcuts-panel {
    position: relative;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: fadeSlideUp 0.15s ease;
}

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

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

.shortcuts-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.shortcuts-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.shortcuts-close:hover {
    background: var(--bg);
    color: var(--text);
}

.shortcuts-body {
    padding: 20px 24px 24px;
    overflow-y: auto;
    flex: 1;
}

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

@media (max-width: 480px) {
    .shortcuts-grid { grid-template-columns: 1fr; }
}

.shortcuts-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.shortcut-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 0;
}

.shortcut-keys {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.shortcut-keys kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 7px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    box-shadow: 0 1px 0 var(--border);
    line-height: 1;
}

.shortcut-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-left: 12px;
    text-align: right;
    flex: 1;
}

/* ===== Dark Mode Toggle Button ===== */
#darkmode-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#darkmode-toggle:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

/* ===== Snap Toggle Button ===== */
#snap-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

#snap-toggle:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

#snap-toggle.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

#snap-toggle svg { flex-shrink: 0; }

/* Snap guide layer (inherits properly since it is SVG in world) */
#snap-guide-layer line {
    stroke: #3B82F6;
    stroke-width: 1;
    stroke-dasharray: 4 3;
}

/* ===== Presentation Dots ===== */
.pres-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #475569;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
}
.pres-dot.active { background: #3b82f6; transform: scale(1.3); }
.pres-dot:hover { background: #64748b; }

/* ===== Mode Tooltip ===== */
@keyframes tooltipFadeIn { from { opacity: 0; transform: translateX(-50%) translateY(-4px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ===== Node Cost Display ===== */
.proto-node .node-cost {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 2px 6px;
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.2);
    border-radius: 4px;
    width: fit-content;
}

.proto-node .node-cost svg {
    color: var(--success);
    flex-shrink: 0;
}

.proto-node .node-cost span {
    font-size: 11px;
    font-weight: 600;
    color: var(--success);
    white-space: nowrap;
}

[data-theme="dark"] .proto-node .node-cost {
    background: rgba(52, 211, 153, 0.08);
    border-color: rgba(52, 211, 153, 0.2);
}

/* Lightbox cost display */
.lightbox-cost {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-radius: var(--radius);
}

[data-theme="dark"] .lightbox-cost {
    background: rgba(52, 211, 153, 0.06);
    border-color: rgba(52, 211, 153, 0.15);
}

/* ===== Activity Panel ===== */
#activity-panel {
    position: fixed;
    top: 0;
    right: -360px;
    width: 360px;
    height: 100%;
    background: var(--white);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0,0,0,0.08);
    z-index: 450;
    display: flex;
    flex-direction: column;
    transition: right 0.25s ease;
}

#activity-panel.open {
    right: 0;
}

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

.activity-panel-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.activity-panel-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.activity-panel-close:hover {
    background: var(--bg);
    color: var(--text);
}

.activity-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.activity-item:hover {
    background: var(--bg);
}

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.activity-icon.create { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.activity-icon.delete { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.activity-icon.edit { background: rgba(59, 130, 246, 0.1); color: var(--primary); }
.activity-icon.move { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.activity-icon.connect { background: rgba(139, 92, 246, 0.1); color: #8B5CF6; }
.activity-icon.group { background: rgba(59, 130, 246, 0.1); color: var(--primary); }

[data-theme="dark"] .activity-icon.connect { color: #A78BFA; }

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-desc {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    word-break: break-word;
}

.activity-desc strong {
    font-weight: 600;
}

.activity-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.activity-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-style: italic;
}

/* Activity panel backdrop for mobile */
.activity-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.3);
    z-index: 440;
    display: none;
}

.activity-backdrop.open {
    display: block;
}

/* Activity button in toolbar */
#activity-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#activity-toggle:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

#activity-toggle.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* Dark mode for activity panel */
[data-theme="dark"] #activity-panel {
    background: #1E293B;
    border-left-color: #334155;
    box-shadow: -4px 0 16px rgba(0,0,0,0.3);
}

[data-theme="dark"] .activity-panel-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .activity-item {
    border-bottom-color: #334155;
}

[data-theme="dark"] .activity-item:hover {
    background: #0F172A;
}

[data-theme="dark"] .activity-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

/* Activity panel 480px breakpoint superseded by 768px bottom sheet styles below */

/* ===== Tour Styles ===== */
.tour-overlay { animation: fadeIn 0.2s ease; }

/* ===== Multi-Select: Rubber-band ===== */
/* ===== Sticky Notes ===== */
.sticky-note {
    position: absolute;
    min-height: 120px;
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.08);
    z-index: 10;
    cursor: default;
    display: flex;
    flex-direction: column;
    user-select: none;
}

.sticky-note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    border-radius: 6px 6px 0 0;
    background: rgba(0,0,0,0.06);
    cursor: grab;
}

.sticky-note-header:active {
    cursor: grabbing;
}

.sticky-note-drag-handle {
    font-size: 13px;
    color: rgba(0,0,0,0.35);
    line-height: 1;
}

.sticky-note-delete {
    width: 18px;
    height: 18px;
    border: none;
    background: none;
    cursor: pointer;
    color: rgba(0,0,0,0.35);
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    padding: 0;
    transition: background 0.1s, color 0.1s;
}

.sticky-note-delete:hover {
    background: rgba(0,0,0,0.12);
    color: rgba(0,0,0,0.7);
}

.sticky-note-body {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.5;
    color: #1E293B;
    outline: none;
    word-break: break-word;
    min-height: 80px;
}

[data-theme="dark"] .sticky-note-body {
    color: #1E293B;
}

/* ===== Multiselect Rubber Band ===== */
.multiselect-rubber-band {
    position: absolute;
    border: 2px solid var(--primary);
    background: rgba(59, 130, 246, 0.08);
    border-radius: 4px;
    pointer-events: none;
    z-index: 50;
}

/* ===== Multi-Select: Bulk Actions Bar ===== */
.bulk-actions-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 80;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
    animation: bulkBarSlideUp 0.2s ease;
    white-space: nowrap;
}

@keyframes bulkBarSlideUp {
    from { opacity: 0; transform: translateX(-50%) translateY(12px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.bulk-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    padding: 0 8px;
    min-width: 70px;
}

.bulk-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
    flex-shrink: 0;
}

.bulk-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.bulk-btn:hover {
    background: var(--bg);
    color: var(--text);
}

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

.bulk-btn-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
}

/* Dark mode: Bulk actions bar */
[data-theme="dark"] .bulk-actions-bar {
    background: #1E293B;
    border-color: #334155;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .bulk-btn:hover {
    background: #0F172A;
    color: #E2E8F0;
}

[data-theme="dark"] .bulk-btn-danger:hover {
    background: rgba(248, 113, 113, 0.1);
    color: #F87171;
}

/* Responsive: stack bar items tighter on small screens */
@media (max-width: 640px) {
    .bulk-actions-bar {
        padding: 6px 10px;
        gap: 2px;
        bottom: 12px;
    }
    .bulk-btn span {
        display: none;
    }
    .bulk-btn {
        padding: 6px 8px;
    }
    .bulk-count {
        font-size: 12px;
        min-width: auto;
        padding: 0 4px;
    }
}

/* ===== Collaboration Status & Cursors ===== */

.collab-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: default;
    user-select: none;
    margin-right: 4px;
}

.collab-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #EF4444;
    display: inline-block;
    transition: background 0.3s ease;
}

.collab-user-count {
    font-variant-numeric: tabular-nums;
    min-width: 12px;
    text-align: center;
}

/* Remote user cursors */
.collab-cursor {
    position: absolute;
    pointer-events: none;
    z-index: 50;
    transition: transform 0.1s linear, opacity 0.3s ease;
    will-change: transform, opacity;
}

.collab-cursor-arrow {
    display: block;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

.collab-cursor svg {
    display: block;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.25));
}

.collab-cursor-name {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    margin-left: 14px;
    margin-top: -4px;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    letter-spacing: 0.01em;
}

/* Legacy label class (backwards compat) */
.collab-cursor-label {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    margin-left: 14px;
    margin-top: -4px;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Cursors layer inside canvas-world */
#cursors-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 50;
}

/* Dark mode overrides for collab */
[data-theme="dark"] .collab-status {
    background: #334155;
    border-color: #475569;
    color: #94A3B8;
}

[data-theme="dark"] .collab-cursor-name,
[data-theme="dark"] .collab-cursor-label {
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

@media (max-width: 768px) {
    .collab-status {
        padding: 3px 6px;
        font-size: 11px;
    }
    .collab-cursor-name,
    .collab-cursor-label {
        display: none;
    }
}

/* ===== Templates & Presets Panel ===== */

/* Toolbar button */
#templates-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#templates-toggle:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

#templates-toggle.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* Panel */
#templates-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 380px;
    height: 100%;
    background: var(--white);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0,0,0,0.08);
    z-index: 450;
    display: flex;
    flex-direction: column;
    transition: right 0.25s ease;
}

#templates-panel.open {
    right: 0;
}

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

.templates-panel-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.templates-panel-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.templates-panel-close:hover {
    background: var(--bg);
    color: var(--text);
}

/* Tabs */
.templates-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.templates-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border-bottom: 2px solid transparent;
}

.templates-tab:hover {
    color: var(--text);
    background: var(--bg);
}

.templates-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* Content area */
.templates-content {
    flex: 1;
    overflow-y: auto;
}

.templates-tab-content {
    padding: 16px;
}

.templates-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Template cards grid */
.templates-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.template-card {
    display: flex;
    align-items: stretch;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all 0.15s;
}

.template-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.template-card-color {
    width: 6px;
    flex-shrink: 0;
}

.template-card-body {
    flex: 1;
    padding: 10px 12px;
    cursor: pointer;
    min-width: 0;
}

.template-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.template-card-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.template-card-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-card-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    flex-shrink: 0;
}

.template-use-btn {
    padding: 5px 12px;
    border: 1px solid var(--primary);
    border-radius: 5px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.template-use-btn:hover {
    background: var(--primary);
    color: #fff;
}

.template-delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.template-delete-btn:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
}

/* Presets section */
.presets-save-section {
    margin-bottom: 16px;
}

.presets-save-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.presets-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.15s;
}

.preset-item:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

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

.preset-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preset-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.preset-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.preset-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.preset-load-btn {
    padding: 5px 12px;
    border: 1px solid var(--primary);
    border-radius: 5px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.preset-load-btn:hover {
    background: var(--primary);
    color: #fff;
}

.preset-delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.preset-delete-btn:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
}

/* Toast notification */
.template-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.template-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Templates backdrop */
.templates-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.3);
    z-index: 440;
    display: none;
}

.templates-backdrop.open {
    display: block;
}

/* Dark mode for templates panel */
[data-theme="dark"] #templates-panel {
    background: #1E293B;
    border-left-color: #334155;
    box-shadow: -4px 0 16px rgba(0,0,0,0.3);
}

[data-theme="dark"] .templates-panel-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .templates-tabs {
    border-bottom-color: #334155;
}

[data-theme="dark"] .templates-tab:hover {
    background: #0F172A;
}

[data-theme="dark"] .template-card {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .template-card:hover {
    border-color: #475569;
}

[data-theme="dark"] .template-use-btn {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary);
}

[data-theme="dark"] .template-use-btn:hover {
    background: var(--primary);
    color: #fff;
}

[data-theme="dark"] .template-delete-btn:hover {
    background: rgba(248, 113, 113, 0.1);
    color: #F87171;
}

[data-theme="dark"] .preset-item {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .preset-item:hover {
    border-color: #475569;
}

[data-theme="dark"] .preset-load-btn {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary);
}

[data-theme="dark"] .preset-load-btn:hover {
    background: var(--primary);
    color: #fff;
}

[data-theme="dark"] .preset-delete-btn:hover {
    background: rgba(248, 113, 113, 0.1);
    color: #F87171;
}

[data-theme="dark"] .templates-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .template-toast {
    background: #E2E8F0;
    color: #0F172A;
}

/* Templates panel 480px breakpoint superseded by 768px bottom sheet styles below */

/* ===== Sketchfab Browser ===== */
.sf-overlay {
    position: fixed;
    inset: 0;
    z-index: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.sf-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
}

.sf-panel {
    position: relative;
    width: 96%;
    max-width: 1200px;
    height: 92vh;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideUp 0.2s ease;
}

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

.sf-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sf-logo {
    color: var(--primary);
}

.sf-header-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.sf-close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.sf-close-btn:hover {
    background: var(--bg);
    color: var(--text);
}

.sf-search-bar {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sf-search-input-wrap {
    position: relative;
    margin-bottom: 10px;
}

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

.sf-search-input {
    width: 100%;
    padding: 10px 40px 10px 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: all 0.15s ease;
}

.sf-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: var(--white);
}

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

.sf-search-spinner {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: sfSpin 0.6s linear infinite;
}

@keyframes sfSpin {
    to { transform: translateY(-50%) rotate(360deg); }
}

.sf-filters {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.sf-filter-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.sf-filter-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
    cursor: pointer;
}

.sf-filter-toggle span {
    white-space: nowrap;
}

.sf-filter-license {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text);
    background: var(--white);
    cursor: pointer;
    outline: none;
}

.sf-filter-license:focus {
    border-color: var(--primary);
}

.sf-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.sf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.sf-empty,
.sf-no-results {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.sf-empty p,
.sf-no-results p {
    font-size: 14px;
    margin-bottom: 8px;
}

.sf-empty-hint {
    font-size: 12px;
    opacity: 0.7;
}

.sf-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--white);
}

.sf-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.sf-card-thumb {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    background: var(--bg);
    overflow: hidden;
}

.sf-card-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sf-card-badge {
    position: absolute;
    top: 8px;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sf-badge-download {
    right: 8px;
    background: var(--success);
}

.sf-badge-animated {
    right: 42px;
    background: var(--warning);
}

.sf-card-info {
    padding: 10px 12px;
}

.sf-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.sf-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.sf-card-author {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.sf-card-faces {
    white-space: nowrap;
    opacity: 0.7;
}

.sf-card-license {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.8;
}

.sf-load-more-wrap {
    text-align: center;
    padding: 20px 0;
}

.sf-load-more-btn {
    padding: 8px 24px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
}

.sf-load-more-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

/* Sketchfab Detail View */
.sf-detail-header {
    margin-bottom: 16px;
}

.sf-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.sf-back-btn:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

.sf-detail-body {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
}

.sf-detail-preview {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #1a1a2e;
}

.sf-embed-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.sf-detail-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sf-detail-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    line-height: 1.3;
}

.sf-detail-author {
    font-size: 13px;
    color: var(--text-secondary);
}

.sf-detail-author a {
    color: var(--primary);
    text-decoration: none;
}

.sf-detail-author a:hover {
    text-decoration: underline;
}

.sf-detail-license {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
}

.sf-detail-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.sf-stat {
    text-align: center;
}

.sf-stat-val {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.sf-stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.sf-detail-desc {
    flex: 1;
    overflow-y: auto;
    max-height: 200px;
}

.sf-detail-desc h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.sf-detail-desc p {
    font-size: 13px;
    color: var(--text);
    line-height: 1.6;
    word-break: break-word;
}

.sf-detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 8px;
}

.sf-view-on-sketchfab {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    background: var(--white);
    transition: all 0.15s ease;
}

.sf-view-on-sketchfab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.sf-use-model-wrap {
    position: relative;
}

.sf-use-model-btn:disabled {
    background: var(--primary);
    color: #fff;
    border: none;
    opacity: 0.5;
    cursor: not-allowed;
}

.sf-use-model-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--white);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 10;
}

.sf-use-model-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text);
}

.sf-tooltip-visible {
    opacity: 1;
}

/* Sketchfab Dark Mode */
[data-theme="dark"] .sf-search-input {
    background: #0F172A;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .sf-search-input:focus {
    background: #1E293B;
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .sf-filter-license {
    background: #1E293B;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .sf-card {
    border-color: #334155;
}

[data-theme="dark"] .sf-card:hover {
    border-color: #60A5FA;
}

[data-theme="dark"] .sf-back-btn {
    background: #1E293B;
    color: #94A3B8;
    border-color: #334155;
}

[data-theme="dark"] .sf-back-btn:hover {
    background: #0F172A;
    color: #E2E8F0;
}

[data-theme="dark"] .sf-view-on-sketchfab {
    background: #1E293B;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .sf-view-on-sketchfab:hover {
    border-color: #60A5FA;
    color: #60A5FA;
}

[data-theme="dark"] .sf-load-more-btn {
    background: #1E293B;
    color: #E2E8F0;
    border-color: #334155;
}

[data-theme="dark"] .sf-load-more-btn:hover {
    border-color: #60A5FA;
    color: #60A5FA;
}

[data-theme="dark"] .sf-use-model-tooltip {
    background: #E2E8F0;
    color: #1E293B;
}

[data-theme="dark"] .sf-use-model-tooltip::after {
    border-top-color: #E2E8F0;
}

/* Sketchfab Responsive */
@media (max-width: 900px) {
    .sf-detail-body {
        grid-template-columns: 1fr;
    }
    .sf-detail-info {
        order: -1;
    }
    .sf-detail-desc {
        max-height: 120px;
    }
}

@media (max-width: 600px) {
    .sf-panel {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    .sf-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 10px;
    }
    .sf-filters {
        gap: 10px;
    }
    .sf-header-title {
        font-size: 14px;
    }
    .sf-detail-actions {
        flex-direction: column;
    }
}

/* ===== AI Generation Modal ===== */
.ai-gen-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.ai-gen-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.ai-gen-modal-panel {
    position: relative;
    width: 90%;
    max-width: 540px;
    max-height: 90vh;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeSlideUp 0.2s ease;
}

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

.ai-gen-modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-gen-modal-close {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

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

.ai-gen-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.ai-gen-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.ai-gen-optional {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 12px;
}

/* Drop zone */
.ai-gen-drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 0;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ai-gen-drop-zone:hover,
.ai-gen-drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.03);
}

.ai-gen-drop-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 16px;
    color: var(--text-secondary);
    text-align: center;
}

.ai-gen-drop-placeholder svg {
    opacity: 0.4;
}

.ai-gen-drop-placeholder p {
    font-size: 13px;
    line-height: 1.4;
}

.ai-gen-drop-placeholder p span {
    color: var(--primary);
    font-weight: 500;
}

.ai-gen-drop-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    padding: 8px;
}

.ai-gen-drop-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    object-fit: contain;
}

.ai-gen-remove-img {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.ai-gen-remove-img:hover {
    background: rgba(239, 68, 68, 0.9);
}

/* Options row */
.ai-gen-options-row {
    display: flex;
    gap: 12px;
}

.ai-gen-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

.ai-gen-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Spinner */
.ai-gen-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: aiGenSpin 0.6s linear infinite;
    vertical-align: middle;
}

.ai-gen-spinner-large {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: aiGenSpin 0.8s linear infinite;
}

@keyframes aiGenSpin {
    to { transform: rotate(360deg); }
}

/* Status card */
.ai-gen-status-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px 16px;
    text-align: center;
    gap: 12px;
}

.ai-gen-status-icon {
    margin-bottom: 4px;
}

.ai-gen-status-icon.ai-job-status-completed { color: var(--success); }
.ai-gen-status-icon.ai-job-status-failed { color: var(--danger); }
.ai-gen-status-icon.ai-job-status-cancelled { color: var(--text-secondary); }

.ai-gen-status-label {
    font-size: 18px;
    font-weight: 700;
}

.ai-gen-status-label.ai-job-status-queued { color: var(--text-secondary); }
.ai-gen-status-label.ai-job-status-submitted { color: var(--warning); }
.ai-gen-status-label.ai-job-status-processing { color: var(--primary); }
.ai-gen-status-label.ai-job-status-texturing { color: #8B5CF6; }
.ai-gen-status-label.ai-job-status-completed { color: var(--success); }
.ai-gen-status-label.ai-job-status-failed { color: var(--danger); }
.ai-gen-status-label.ai-job-status-cancelled { color: var(--text-secondary); }

.ai-gen-status-stage {
    font-size: 13px;
    color: var(--text-secondary);
}

.ai-gen-progress-bar {
    width: 80%;
    max-width: 280px;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.ai-gen-progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.ai-gen-status-hint {
    font-size: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

.ai-gen-status-error-detail {
    font-size: 13px;
    color: var(--danger);
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.06);
    border-radius: 6px;
    max-width: 360px;
    word-break: break-word;
}

.ai-gen-status-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

.ai-gen-status-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ai-gen-status-error {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: 6px;
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
}

/* ===== AI Queue Panel ===== */
.ai-queue-panel {
    position: fixed;
    top: 0;
    right: -380px;
    width: 380px;
    height: 100%;
    background: var(--white);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
    z-index: 460;
    display: flex;
    flex-direction: column;
    transition: right 0.25s ease;
}

.ai-queue-panel.open {
    right: 0;
}

.ai-queue-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.ai-queue-panel-header h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-queue-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.ai-queue-health-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.ai-queue-health-btn:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

.ai-queue-panel-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.ai-queue-panel-close:hover {
    background: var(--bg);
    color: var(--text);
}

.ai-queue-gpu-status {
    padding: 8px 16px;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.ai-gpu-online { color: var(--success); font-weight: 600; }
.ai-gpu-offline { color: var(--danger); font-weight: 600; }
.ai-gpu-checking { color: var(--text-secondary); font-style: italic; }
.ai-gpu-latency { color: var(--text-secondary); font-weight: 400; }
.ai-gpu-error { color: var(--text-secondary); font-weight: 400; font-size: 11px; }
.ai-gpu-stats { margin-top: 4px; color: var(--text-secondary); font-size: 11px; }

.ai-queue-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.ai-queue-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-style: italic;
}

.ai-queue-panel-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
}

.ai-queue-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.3);
    z-index: 455;
    display: none;
}

.ai-queue-backdrop.open {
    display: block;
}

/* Job cards in queue */
.ai-job-card {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.ai-job-card:hover {
    background: var(--bg);
}

.ai-job-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.ai-job-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.ai-job-status-queued { background: rgba(100, 116, 139, 0.1); color: var(--text-secondary); }
.ai-job-status-submitted { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.ai-job-status-processing { background: rgba(59, 130, 246, 0.1); color: var(--primary); }
.ai-job-status-texturing { background: rgba(139, 92, 246, 0.1); color: #8B5CF6; }
.ai-job-status-completed { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.ai-job-status-failed { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.ai-job-status-cancelled { background: rgba(100, 116, 139, 0.1); color: var(--text-secondary); }

.ai-job-model {
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-job-prompt {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 6px;
    word-break: break-word;
}

.ai-job-prompt em {
    color: var(--text-secondary);
    font-style: italic;
}

.ai-job-progress {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.ai-job-progress-bar {
    flex: 1;
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
}

.ai-job-progress-fill {
    height: 100%;
    border-radius: 2px;
    animation: aiGenPulse 1.5s ease-in-out infinite;
}

.ai-job-progress-fill.ai-job-status-submitted { background: var(--warning); width: 20%; }
.ai-job-progress-fill.ai-job-status-processing { background: var(--primary); width: 55%; }
.ai-job-progress-fill.ai-job-status-texturing { background: #8B5CF6; width: 80%; }

@keyframes aiGenPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-job-stage {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ai-job-error {
    font-size: 12px;
    color: var(--danger);
    padding: 4px 8px;
    background: rgba(239, 68, 68, 0.05);
    border-radius: 4px;
    margin-bottom: 6px;
    word-break: break-word;
}

.ai-job-stats {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.ai-job-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-job-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.ai-job-action-btns {
    display: flex;
    gap: 4px;
}

.ai-job-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.ai-job-btn:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

.ai-job-btn-download:hover { color: var(--primary); border-color: var(--primary); }
.ai-job-btn-assign:hover { color: var(--success); border-color: var(--success); }
.ai-job-btn-cancel:hover { color: var(--danger); border-color: var(--danger); }
.ai-job-btn-retry:hover { color: var(--warning); border-color: var(--warning); }

/* AI Queue toggle button in toolbar */
#ai-queue-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#ai-queue-toggle:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border-hover);
}

#ai-queue-toggle.active {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* ===== AI Generation Dark Mode ===== */
[data-theme="dark"] .ai-gen-modal-backdrop {
    background: rgba(0, 0, 0, 0.65);
}

[data-theme="dark"] .ai-gen-modal-panel {
    background: #1E293B;
}

[data-theme="dark"] .ai-gen-modal-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .ai-gen-modal-footer {
    border-top-color: #334155;
}

[data-theme="dark"] .ai-gen-drop-zone {
    border-color: #334155;
}

[data-theme="dark"] .ai-gen-drop-zone:hover,
[data-theme="dark"] .ai-gen-drop-zone.dragover {
    border-color: #3B82F6;
    background: rgba(59, 130, 246, 0.05);
}

[data-theme="dark"] .ai-gen-spinner-large {
    border-color: #334155;
    border-top-color: #60A5FA;
}

[data-theme="dark"] .ai-gen-progress-bar {
    background: #0F172A;
}

[data-theme="dark"] .ai-gen-status-error-detail {
    background: rgba(248, 113, 113, 0.08);
}

[data-theme="dark"] .ai-gen-status-error {
    background: rgba(248, 113, 113, 0.08);
    border-color: rgba(248, 113, 113, 0.2);
}

[data-theme="dark"] .ai-queue-panel {
    background: #1E293B;
    border-left-color: #334155;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .ai-queue-panel-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .ai-queue-gpu-status {
    background: #0F172A;
    border-bottom-color: #334155;
}

[data-theme="dark"] .ai-queue-panel-footer {
    border-top-color: #334155;
}

[data-theme="dark"] .ai-queue-backdrop {
    background: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .ai-job-card {
    border-bottom-color: #334155;
}

[data-theme="dark"] .ai-job-card:hover {
    background: #0F172A;
}

[data-theme="dark"] .ai-job-progress-bar {
    background: #0F172A;
}

[data-theme="dark"] .ai-job-error {
    background: rgba(248, 113, 113, 0.06);
}

[data-theme="dark"] .ai-job-status-texturing { background: rgba(167, 139, 250, 0.1); color: #A78BFA; }
[data-theme="dark"] .ai-gen-status-label.ai-job-status-texturing { color: #A78BFA; }

/* AI Queue responsive - options row stacks on small screens */
@media (max-width: 480px) {
    .ai-gen-options-row {
        flex-direction: column;
        gap: 0;
    }
}

/* ============================================================
   MOBILE BOTTOM SHEETS - Responsive Panels (<=768px)
   All slide-out panels become bottom sheets that slide up.
   Lightbox and modals become bottom-anchored sheets.
   ============================================================ */

/* --- CSS variable for virtual keyboard height --- */
:root {
    --keyboard-height: 0px;
}

/* --- Bottom sheet slide-up animation --- */
@keyframes slideUpFromBottom {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* --- Handle bar visual affordance for bottom sheets --- */
.bottom-sheet-handle {
    display: none;
}

@media (max-width: 768px) {

    /* === Handle bar (shown on mobile only) === */
    .bottom-sheet-handle {
        display: block;
        width: 36px;
        height: 4px;
        background: var(--border-hover);
        border-radius: 2px;
        margin: 8px auto 0;
        flex-shrink: 0;
    }

    /* === LIGHTBOX as bottom sheet === */
    .lightbox-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 85vh;
        transform: none !important;
        border-radius: 16px 16px 0 0;
        animation: slideUpFromBottom 0.3s ease !important;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .lightbox-header {
        padding: 12px 16px;
    }

    .lightbox-title {
        font-size: 17px;
    }

    .lightbox-actions {
        flex-wrap: wrap;
        gap: 6px;
    }

    .lightbox-body {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    /* === MODAL as bottom sheet === */
    .modal-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        transform: none !important;
        border-radius: 16px 16px 0 0;
        max-height: 80vh;
        overflow-y: auto;
        animation: slideUpFromBottom 0.25s ease !important;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal-body {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }

    /* === ACTIVITY PANEL as bottom sheet === */
    #activity-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: auto !important;
        max-height: 70vh;
        border-left: none !important;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
        transition: transform 0.3s ease !important;
        transform: translateY(100%);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #activity-panel.open {
        right: 0 !important;
        transform: translateY(0);
    }

    .activity-list {
        max-height: calc(70vh - 60px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* === TEMPLATES PANEL as bottom sheet === */
    #templates-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: auto !important;
        max-height: 70vh;
        border-left: none !important;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
        transition: transform 0.3s ease !important;
        transform: translateY(100%);
        padding-bottom: env(safe-area-inset-bottom);
    }

    #templates-panel.open {
        right: 0 !important;
        transform: translateY(0);
    }

    .templates-content {
        max-height: calc(70vh - 110px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* === AI QUEUE PANEL as bottom sheet === */
    .ai-queue-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: auto !important;
        max-height: 70vh;
        border-left: none !important;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
        transition: transform 0.3s ease !important;
        transform: translateY(100%);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .ai-queue-panel.open {
        right: 0 !important;
        transform: translateY(0);
    }

    .ai-queue-list {
        max-height: calc(70vh - 120px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* === AI Generation modal as bottom sheet === */
    .ai-gen-modal-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        animation: slideUpFromBottom 0.25s ease !important;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .ai-gen-modal-overlay {
        align-items: flex-end !important;
    }

    .ai-gen-modal-body {
        max-height: calc(85vh - 130px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* === Confirm overlay as bottom sheet === */
    .confirm-box {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        transform: none !important;
        border-radius: 16px 16px 0 0;
        animation: slideUpFromBottom 0.2s ease;
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* === Virtual keyboard compensation === */
    .lightbox-panel,
    .modal-panel,
    #activity-panel.open,
    #templates-panel.open,
    .ai-queue-panel.open,
    .ai-gen-modal-panel,
    .confirm-box {
        padding-bottom: calc(env(safe-area-inset-bottom) + var(--keyboard-height));
    }
}

/* === Dark mode overrides for bottom sheet borders === */
@media (max-width: 768px) {
    [data-theme="dark"] .lightbox-panel,
    [data-theme="dark"] .modal-panel,
    [data-theme="dark"] #activity-panel,
    [data-theme="dark"] #templates-panel,
    [data-theme="dark"] .ai-queue-panel,
    [data-theme="dark"] .ai-gen-modal-panel,
    [data-theme="dark"] .confirm-box {
        box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
    }

    [data-theme="dark"] .bottom-sheet-handle {
        background: #475569;
    }
}

/* ===== Touch Device Enhancements ===== */

/* Touch target sizes for coarse pointers (touch screens) */
@media (pointer: coarse) {
    .tool-btn, .mob-btn, .zoom-btn {
        min-width: 44px;
        min-height: 44px;
    }
    .context-menu-list li {
        min-height: 48px;
        padding: 12px 16px;
    }
    .context-menu-list li.separator {
        min-height: 0;
        padding: 0;
    }
    .lightbox-actions button {
        min-height: 44px;
        min-width: 44px;
    }
    .lightbox-close {
        min-width: 44px;
        min-height: 44px;
    }
    .history-btn {
        min-width: 44px;
        min-height: 44px;
    }
    .sheet-btn {
        min-height: 48px;
    }
    /* Prevent iOS auto-zoom on input focus (requires 16px minimum) */
    input, textarea, select {
        font-size: 16px;
    }
}

/* Long-press visual feedback for touch context menus */
.proto-node.long-press-active {
    transform-origin: center center;
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    transition: outline 0.15s ease;
}

/* ===== Mind Map Root Node Styling ===== */

.proto-node.mindmap-root {
    border: 2px solid var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.18), 0 0 20px rgba(59, 130, 246, 0.10), var(--shadow-md);
    z-index: 10;
}

.proto-node.mindmap-root .color-strip {
    width: 6px;
}

/* Crown badge on root node */
.proto-node.mindmap-root::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: 50%;
    z-index: 11;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

.proto-node.mindmap-root::after {
    content: '\2726'; /* four-pointed star */
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    color: #fff;
    z-index: 12;
    line-height: 20px;
    text-align: center;
    width: 20px;
}

/* Dark mode overrides for root */
[data-theme="dark"] .proto-node.mindmap-root {
    border-color: #60A5FA;
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.22), 0 0 24px rgba(96, 165, 250, 0.12), var(--shadow-md);
}

[data-theme="dark"] .proto-node.mindmap-root::before {
    background: #60A5FA;
}

/* Mind Map root picker modal */
.mindmap-root-picker {
    max-height: 320px;
    overflow-y: auto;
    padding: 4px 0;
}

.mindmap-root-picker .root-pick-btn {
    transition: background 0.15s ease, border-color 0.15s ease;
    border: 1px solid var(--border);
}

.mindmap-root-picker .root-pick-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
}

/* Mind Map layout button accent in menu */
.layout-menu-btn.mindmap-btn {
    border: 1px solid rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.04);
}

.layout-menu-btn.mindmap-btn:hover {
    background: rgba(59, 130, 246, 0.08);
    border-color: var(--primary);
}

/* ===== Conflict Resolution Modal ===== */

.conflict-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.conflict-backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.conflict-panel {
    position: relative;
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 840px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    animation: slideUp 0.2s ease;
}

.conflict-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.conflict-header h2 {
    flex: 1;
    font-size: 18px;
    font-weight: 700;
    color: var(--danger);
    margin: 0;
}

.conflict-header svg {
    color: var(--danger);
    flex-shrink: 0;
}

.conflict-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 20px;
    cursor: pointer;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: background 0.15s;
}

.conflict-close:hover {
    background: var(--bg);
    color: var(--text);
}

.conflict-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.conflict-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.conflict-side {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--bg);
}

.conflict-side-mine {
    border-color: var(--primary);
    border-width: 2px;
}

.conflict-side-server {
    border-color: var(--warning);
    border-width: 2px;
}

.conflict-side-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.conflict-side-mine .conflict-side-label { color: var(--primary); }
.conflict-side-server .conflict-side-label { color: var(--warning); }

.conflict-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.conflict-field {
    display: flex;
    gap: 8px;
    font-size: 13px;
    line-height: 1.4;
}

.conflict-field-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 80px;
    flex-shrink: 0;
}

.conflict-field-value {
    color: var(--text);
    word-break: break-word;
}

.conflict-field-value.conflict-field-changed {
    background: rgba(245, 158, 11, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.conflict-color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 4px;
    border: 1px solid var(--border);
}

.conflict-spec-chip {
    display: inline-block;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 11px;
    margin: 1px 3px 1px 0;
}

/* Conflict diff table */
.conflict-diff-section {
    margin-bottom: 20px;
}

.conflict-diff-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
}

.conflict-diff-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.conflict-diff-table th {
    text-align: left;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
}

.conflict-diff-table td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    vertical-align: top;
    word-break: break-word;
    max-width: 280px;
}

.conflict-diff-field {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    width: 120px;
}

.conflict-diff-mine {
    background: rgba(59, 130, 246, 0.06);
}

.conflict-diff-theirs {
    background: rgba(245, 158, 11, 0.06);
}

.conflict-diff-row {
    border-left: 3px solid var(--warning);
}

.conflict-no-diff {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 20px;
}

/* Conflict action buttons */
.conflict-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.conflict-btn-mine {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.conflict-btn-mine:hover {
    background: var(--primary-hover);
}

.conflict-btn-theirs {
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
}

.conflict-btn-merge {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 18px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.conflict-btn-merge:hover {
    background: var(--bg);
    border-color: var(--border-hover);
}

/* Remote edit warning banner */
.conflict-remote-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin-bottom: 14px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
}

.conflict-remote-banner svg {
    color: var(--warning);
    flex-shrink: 0;
}

.conflict-remote-banner span {
    flex: 1;
}

.conflict-banner-dismiss {
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.conflict-banner-dismiss:hover {
    background: rgba(245, 158, 11, 0.15);
    color: var(--text);
}

/* Conflict responsive */
@media (max-width: 640px) {
    .conflict-panel {
        width: 96%;
        padding: 16px;
        max-height: 92vh;
    }
    .conflict-comparison {
        grid-template-columns: 1fr;
    }
    .conflict-actions {
        flex-direction: column;
    }
    .conflict-actions .btn,
    .conflict-actions .conflict-btn-mine,
    .conflict-actions .conflict-btn-merge {
        width: 100%;
        text-align: center;
    }
}

/* Conflict dark mode */
[data-theme="dark"] .conflict-panel {
    background: #1E293B;
    border: 1px solid #334155;
}

[data-theme="dark"] .conflict-side {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .conflict-side-mine { border-color: var(--primary); }
[data-theme="dark"] .conflict-side-server { border-color: var(--warning); }

[data-theme="dark"] .conflict-spec-chip {
    background: #1E293B;
    border-color: #334155;
}

[data-theme="dark"] .conflict-diff-table th {
    background: #0F172A;
    border-color: #334155;
}

[data-theme="dark"] .conflict-diff-table td {
    border-color: #334155;
}

[data-theme="dark"] .conflict-diff-mine {
    background: rgba(59, 130, 246, 0.1);
}

[data-theme="dark"] .conflict-diff-theirs {
    background: rgba(245, 158, 11, 0.1);
}

[data-theme="dark"] .conflict-field-value.conflict-field-changed {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.4);
}

[data-theme="dark"] .conflict-close:hover {
    background: #334155;
}

[data-theme="dark"] .conflict-btn-merge {
    border-color: #475569;
    color: #E2E8F0;
}

[data-theme="dark"] .conflict-btn-merge:hover {
    background: #334155;
}

[data-theme="dark"] .conflict-remote-banner {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
}

[data-theme="dark"] .conflict-banner-dismiss:hover {
    background: rgba(245, 158, 11, 0.2);
}

/* ===== Node Comment Badge ===== */

.node-comment-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
    line-height: 1;
}

/* ===== Lightbox Comments Section ===== */

.lightbox-comments {
    margin-bottom: 10px;
}

.lightbox-comment {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.lightbox-comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.lightbox-comment-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

.lightbox-comment-date {
    font-size: 11px;
    color: var(--text-secondary);
    flex: 1;
}

.lightbox-comment-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.lightbox-comment-delete:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

.lightbox-comment-text {
    font-size: 13px;
    color: var(--text);
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.lightbox-no-comments {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    padding: 12px 0;
}

.lightbox-comment-count {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
}

.lightbox-comment-add {
    display: flex;
    gap: 8px;
    align-items: center;
}

.lightbox-comment-add input {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--white);
    color: var(--text);
    transition: border-color 0.15s;
}

.lightbox-comment-add input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Dark mode: comments */
[data-theme="dark"] .lightbox-comment {
    background: #1E293B;
    border-color: #334155;
}

[data-theme="dark"] .lightbox-comment-delete:hover {
    color: #F87171;
    background: rgba(248, 113, 113, 0.1);
}

[data-theme="dark"] .lightbox-comment-add input {
    background: #1E293B;
    border-color: #334155;
    color: #E2E8F0;
}

[data-theme="dark"] .lightbox-comment-add input:focus {
    border-color: #3B82F6;
}

[data-theme="dark"] .node-comment-badge {
    background: #2563EB;
}
