/* ============================================
   LINKAGE MODE - Specific Styles
   ============================================ */

/* Hide designer/simulator sidebars in linkage mode */
body:not(.solar-mode) #left-sidebar,
body:not(.solar-mode) #right-sidebar {
    display: none !important;
}

/* Simulator sidebars live inside the unified simulate view */
#view-solar #left-sidebar {
    display: flex !important;
    flex-direction: column;
}

#view-solar #right-sidebar {
    display: flex !important;
    flex-direction: column;
}

/* Keep linkage 2D overlay hidden even when solar designer CSS is loaded globally */
#view-linkage #canvas {
    display: none !important;
    pointer-events: none !important;
}

#view-linkage #viewport {
    z-index: 1;
}

#view-linkage #viewport canvas#canvas-webgl {
    pointer-events: auto;
}

/* Viewport - Main 3D canvas area */
#viewport {
    position: fixed;
    top: 52px;
    left: 280px;
    right: 280px;
    bottom: 0;
    background-color: var(--bg-canvas);
    overflow: hidden;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 40px 40px;
    transition: left var(--transition-med), right var(--transition-med);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    cursor: grab;
}

#viewport.viewport-dragging {
    cursor: grabbing;
}

#viewport canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Right Panel - Viewports and stats */
#right-panel {
    position: fixed;
    top: 52px;
    right: 0;
    width: 280px;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border-light);
    z-index: var(--z-sticky);
}

#right-panel .view-section {
    flex: 1;
    min-height: 0;
    position: relative;
    border-bottom: 1px solid var(--border-light);
}

#right-panel .view-section canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#right-panel .view-label {
    position: absolute;
    top: 8px;
    left: 10px;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    pointer-events: none;
}

/* Stats Panel - Bottom of right panel */
#stats-panel {
    flex: 0 0 auto;
    max-height: 45%;
    overflow-y: auto;
    background: rgba(25, 39, 52, 0.98);
    padding: 12px 14px;
    font-size: 0.75rem;
}

#stats-panel::-webkit-scrollbar {
    width: 6px;
}

#stats-panel::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: var(--radius-sm);
}

/* HUD Panel styles */
#hud-panel {
    background: transparent;
    font-size: 0.8rem;
}

.hud-sec {
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 12px;
}

.hud-sec:last-child {
    border: none;
    margin: 0;
    padding: 0;
}

.hud-title {
    font-size: 0.65rem;
    color: var(--clr-primary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.hud-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.65rem;
    margin-bottom: 1px;
    color: var(--text-primary);
    padding: 0;
}

.hud-val {
    font-weight: 700;
    color: var(--clr-primary);
    text-shadow: var(--glow-primary);
}

.hud-total {
    font-size: 0.8rem;
    color: var(--energy-green);
    text-align: right;
    margin-top: 4px;
    font-weight: 700;
    text-shadow: var(--glow-green);
}

/* View label overlay */
.view-label {
    position: absolute;
    pointer-events: none;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-weight: 600;
}

/* Sidebar toggle button */
#sidebar-toggle {
    position: fixed;
    top: 50%;
    left: 280px;
    transform: translateY(-50%);
    background: var(--bg-sidebar);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-left: none;
    width: 18px;
    height: 45px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
    transition: left var(--transition-med), background-color var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

#sidebar-toggle:hover {
    background: var(--bg-input);
    color: var(--clr-primary);
}

#sidebar.collapsed ~ #sidebar-toggle {
    left: 0;
}

/* Collapsed sidebar adjustments */
#sidebar.collapsed ~ #viewport {
    left: 0;
}

#sidebar.collapsed ~ #viewport ~ #right-panel {
    right: 0;
}

/* Control row styles */
.ctrl-row {
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ctrl-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.68rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.ctrl-head span:first-child {
    color: var(--text-primary);
    font-weight: 600;
}

.ctrl-head span:last-child {
    font-size: 0.6rem;
    color: var(--text-muted);
    font-weight: 500;
}

.ctrl-row:hover .ctrl-head span:last-child {
    color: var(--clr-primary);
}

.input-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Dimension link/unlink toggle (Photoshop/Godot-style) */
.dim-link-btn {
    background: none;
    border: none;
    padding: 0 2px;
    cursor: pointer;
    color: var(--clr-primary);
    opacity: 0.8;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.dim-link-btn:hover {
    opacity: 1;
}

.dim-link-btn.unlinked {
    color: var(--text-muted);
}

.dim-link-btn .dim-link-icon--unlinked {
    display: none;
}

.dim-link-btn.unlinked .dim-link-icon--linked {
    display: none;
}

.dim-link-btn.unlinked .dim-link-icon--unlinked {
    display: block;
}

/* Input feedback */
input[type="number"].modified {
    border-color: var(--energy-amber);
}

input[type="number"]:valid {
    border-color: var(--border-med);
}

/* Only show native invalid styling after editing (avoids red flash while typing) */
input[type="number"]:invalid:not(:focus) {
    border-color: var(--energy-red);
}

input.error {
    border-color: var(--energy-red) !important;
}

/* Group collapsible styles */
.group-title::before {
    content: '▾';
    font-size: 0.55rem;
    opacity: 0.7;
    transition: transform var(--transition-fast);
    display: inline-block;
    width: 8px;
}

.group.collapsed .group-title::before {
    transform: rotate(-90deg);
}

.group.collapsed .group-title {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.group-content {
    transition: max-height var(--transition-med), opacity var(--transition-fast);
    overflow: visible;
}

.group.collapsed .group-content {
    max-height: 0;
    opacity: 0;
    margin: 0;
    overflow: hidden;
}

/* Measure mode indicator */
.measure-mode {
    background: rgba(var(--clr-primary-rgb), 0.15) !important;
    border-color: var(--clr-primary) !important;
    box-shadow: var(--glow-primary) !important;
}

/* Responsive adjustments */
@media (max-width: 1200px) {
    #right-panel {
        width: 240px;
    }
    #viewport {
        right: 240px;
    }
}

@media (max-width: 900px) {
    #sidebar {
        width: 260px;
    }
    #viewport {
        left: 260px;
    }
    #sidebar-toggle {
        left: 260px;
    }
    #right-panel {
        width: 200px;
    }
    #viewport {
        right: 200px;
    }
    .topbar-center {
        display: none;
    }
}

@media (max-width: 768px) {
    #sidebar {
        width: 100%;
        max-width: 300px;
    }
    #viewport {
        left: 0;
        right: 0;
    }
    #sidebar-toggle {
        left: 0;
    }
    #sidebar:not(.collapsed) ~ #viewport #sidebar-toggle {
        left: 300px;
    }
    #right-panel {
        display: none;
    }
}

/* Touch-friendly controls for tablets and touchscreens */
@media (pointer: coarse) {
    #sidebar button,
    .btn-group button,
    .anim-controls button,
    #sidebar-toggle {
        min-height: 44px;
        min-width: 44px;
    }

    #sidebar-toggle {
        width: 28px;
        height: 56px;
        font-size: 0.75rem;
    }

    .group-title,
    .sidebar-group-title {
        min-height: 44px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .chk-label {
        min-height: 40px;
        font-size: 0.75rem;
    }

    .input-wrap {
        min-height: 44px;
        align-items: center;
    }

    input[type="number"] {
        min-height: 40px;
        font-size: 0.85rem;
        padding: 8px 10px;
    }

    select {
        min-height: 44px;
        font-size: 0.85rem;
    }

    #stats-panel {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }
}

/* Build Guide Modal - Linkage specific */
#build-guide-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: var(--z-modal-backdrop);
    overflow-y: auto;
    padding: 20px;
}

#build-guide-modal.visible {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.guide-container {
    background: #f8f6f2;
    max-width: 1100px;
    width: 100%;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin: 20px auto;
    position: relative;
}

.guide-header {
    background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
    color: white;
    padding: 24px 30px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.guide-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.guide-header-actions {
    display: flex;
    gap: 10px;
}

.guide-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
}

.guide-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.guide-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.guide-close:hover {
    opacity: 1;
}

.guide-content {
    padding: 30px;
}

.guide-stats-bar {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    background: #fff;
    padding: 15px 20px;
    border-radius: var(--radius-md);
    border: 1px solid #e0d8cc;
    margin-bottom: 25px;
}

.guide-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.guide-stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
}

.guide-stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c3e50;
}

.guide-stat-value.highlight {
    color: #006600;
    font-size: 1.25rem;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.guide-card {
    background: #fff;
    border-radius: var(--radius-md);
    border: 1px solid #e0d8cc;
    overflow: hidden;
}

.guide-card-header {
    background: #2c3e50;
    color: white;
    padding: 10px 15px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.guide-card-content {
    padding: 15px;
}

.guide-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.guide-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid #e0d8cc;
    font-weight: 600;
    color: #555;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.guide-table td {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

.guide-table tr:last-child td {
    border-bottom: none;
}

.guide-table .qty {
    font-weight: 600;
    color: #2c3e50;
    width: 50px;
}

.guide-table .price {
    text-align: right;
    color: #666;
}

.guide-table .total {
    text-align: right;
    font-weight: 600;
}

.guide-table .item {
    color: #2c3e50;
}

.guide-views-row {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
}

.guide-view-card {
    flex: 1;
    background: #fff;
    border: 1px solid #e0d8cc;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.guide-view-label {
    background: #2c3e50;
    color: white;
    padding: 8px 15px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.guide-view-card canvas {
    width: 100%;
    height: 250px;
    display: block;
    background: #f8f8f8;
}

.guide-total-row {
    background: #f0f0f0;
    margin-top: 10px;
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.guide-total-label {
    font-weight: 600;
    color: #333;
}

.guide-total-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: #006600;
}

@media (max-width: 600px) {
    .guide-views-row {
        flex-direction: column;
    }
}

/* Specification rows inside cards */
.guide-spec-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.guide-spec-row:last-child {
    border-bottom: none;
}

.guide-spec-label {
    color: #666;
    font-size: 0.85rem;
}

.guide-spec-value {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9rem;
}

/* Beam Drill Template Diagrams */
.guide-beam-diagram {
    background: #fff;
    border: 1px solid #d4c4a8;
    border-radius: var(--radius-md);
    padding: 20px 25px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.guide-beam-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0d8cc;
}

.guide-beam-visual {
    position: relative;
    height: 120px;
    margin: 25px 0 15px 0;
}

/* The beam bar itself - looks like wood */
.guide-beam-bar {
    position: absolute;
    top: 35px;
    /* left and right set via inline style for proportional sizing */
    height: 50px;
    background: linear-gradient(to bottom, 
        #dcc8a8 0%, 
        #c9b896 15%,
        #d4c4a8 25%,
        #c9b896 50%,
        #d4c4a8 75%,
        #c9b896 85%,
        #dcc8a8 100%
    );
    border: 2px solid #5a4632;
    border-radius: 4px;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        inset 0 -2px 4px rgba(0, 0, 0, 0.1),
        0 3px 6px rgba(0, 0, 0, 0.15);
}

/* Wood grain effect */
.guide-beam-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 40px,
        rgba(139, 90, 43, 0.08) 40px,
        rgba(139, 90, 43, 0.08) 42px
    );
    border-radius: 2px;
}

/* Drill hole markers */
.guide-beam-hole {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background: radial-gradient(circle at 40% 40%, 
        #ff4444 0%, 
        #cc0000 50%, 
        #990000 100%
    );
    border: 2px solid #1a1a1a;
    border-radius: 50%;
    z-index: 2;
    box-shadow: 
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Center drill hole - slightly different style */
.guide-beam-hole:nth-child(2) {
    background: radial-gradient(circle at 40% 40%, 
        #ffaa44 0%, 
        #ff8800 50%, 
        #cc6600 100%
    );
}

/* Label below each hole */
.guide-beam-label {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    font-size: 0.75rem;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.95);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #ddd;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.guide-beam-label-name {
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guide-beam-label-value {
    color: #555;
    font-weight: 600;
    font-size: 0.8rem;
}

/* Dimension line above beam */
.guide-beam-dimension {
    position: absolute;
    top: 0;
    /* left and right set via inline style for proportional sizing */
    height: 25px;
    border-left: 2px solid #666;
    border-right: 2px solid #666;
    border-top: 2px solid #666;
}

/* Dimension arrows */
.guide-beam-dimension::before,
.guide-beam-dimension::after {
    content: '';
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
    border-style: solid;
}

.guide-beam-dimension::before {
    left: -6px;
    border-width: 5px 5px 0 5px;
    border-color: #666 transparent transparent transparent;
}

.guide-beam-dimension::after {
    right: -6px;
    border-width: 5px 5px 0 5px;
    border-color: #666 transparent transparent transparent;
}

.guide-beam-dimension-label {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    background: #f8f6f2;
    padding: 2px 12px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #2c3e50;
    border: 1px solid #d4c4a8;
    border-radius: 4px;
    white-space: nowrap;
}

/* Footer styling */
.guide-footer {
    background: linear-gradient(135deg, #e8e4dc 0%, #d8d4cc 100%);
    padding: 15px 30px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #666;
    border-top: 1px solid #d4c4a8;
}

/* Sub-section headers within cards */
.guide-subsection-title {
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.85rem;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #d4c4a8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guide-subsection {
    margin-bottom: 18px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.guide-subsection:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Notes section */
.guide-notes {
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border: 1px solid #e0d8cc;
    border-left: 4px solid #3498db;
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-top: 15px;
}

.guide-notes-title {
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.guide-notes-list {
    margin: 0;
    padding-left: 22px;
    color: #555;
    font-size: 0.88rem;
    line-height: 1.8;
}

.guide-notes-list li {
    margin-bottom: 4px;
}

.guide-notes-list li::marker {
    color: #3498db;
}

/* Bracket Detail Section */
.guide-bracket-section {
    margin-bottom: 25px;
}

.guide-bracket-views {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.guide-bracket-view {
    flex: 0 0 auto;
    background: #f8f8f8;
    border: 1px solid #e0d8cc;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.guide-bracket-view canvas {
    display: block;
    background: #ffffff;
}

.guide-bracket-specs {
    flex: 1;
    min-width: 200px;
    padding: 10px 0;
}

@media (max-width: 768px) {
    .guide-bracket-views {
        flex-direction: column;
        align-items: stretch;
    }
    
    .guide-bracket-view {
        width: 100%;
    }
    
    .guide-bracket-view canvas {
        width: 100%;
        height: auto;
    }
}

/* Improved stat bar styling */
.guide-stats-bar {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    background: linear-gradient(135deg, #fff 0%, #fefefe 100%);
    padding: 18px 24px;
    border-radius: var(--radius-md);
    border: 1px solid #e0d8cc;
    margin-bottom: 25px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.guide-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 90px;
}

.guide-stat-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #888;
    font-weight: 600;
}

.guide-stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #2c3e50;
}

.guide-stat-value.highlight {
    color: #006600;
    font-size: 1.3rem;
}

/* Card refinements */
.guide-card {
    background: #fff;
    border-radius: var(--radius-md);
    border: 1px solid #e0d8cc;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s ease;
}

.guide-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.guide-card-header {
    background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
    color: white;
    padding: 12px 18px;
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.guide-card-content {
    padding: 18px;
}

/* Table refinements */
.guide-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.guide-table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #d4c4a8;
    font-weight: 700;
    color: #444;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #f8f6f2;
}

.guide-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.guide-table tr:hover td {
    background: #fafafa;
}

.guide-table tr:last-child td {
    border-bottom: none;
}

.guide-table .qty {
    font-weight: 700;
    color: #2c3e50;
    width: 50px;
}

.guide-table .price {
    text-align: right;
    color: #666;
    font-family: var(--font-mono);
}

.guide-table .total {
    text-align: right;
    font-weight: 700;
    color: #2c3e50;
    font-family: var(--font-mono);
}

.guide-table .item {
    color: #2c3e50;
}

/* Total row refinement */
.guide-total-row {
    background: linear-gradient(135deg, #f0f0f0 0%, #e8e8e8 100%);
    margin-top: 15px;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #ddd;
}

.guide-total-label {
    font-weight: 700;
    color: #333;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guide-total-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: #006600;
}

/* BOM card spans full grid width so the table columns have room */
.guide-grid > .guide-card:first-child,
.guide-card-wide {
    grid-column: 1 / -1;
}

/* Prevent spin-wrapper from touching guide price inputs */
#guide-bom-table .number-spin-wrapper {
    display: contents;
}
#guide-bom-table .number-spin-buttons {
    display: none !important;
}

/* Editable BOM price inputs — high specificity to override global dark-theme styles */
#guide-bom-table input[type="number"].guide-price-input,
#guide-bom-table .number-spin-wrapper input[type="number"].guide-price-input {
    width: 80px;
    padding: 4px 8px !important;
    border: 1px solid #d4c4a8;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: var(--font-mono);
    text-align: right;
    background: #fff !important;
    color: #2c3e50 !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -moz-appearance: textfield;
    appearance: textfield;
    box-sizing: border-box;
}

#guide-bom-table input[type="number"].guide-price-input::-webkit-inner-spin-button,
#guide-bom-table input[type="number"].guide-price-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    display: none;
}

#guide-bom-table input[type="number"].guide-price-input:focus,
#guide-bom-table .number-spin-wrapper input[type="number"].guide-price-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
    background: #fff !important;
    color: #2c3e50 !important;
}

#guide-bom-table input[type="number"].guide-price-input:hover {
    border-color: #b0a898;
}

/* BOM table column sizing */
#guide-bom-table {
    table-layout: fixed;
}

#guide-bom-table th:nth-child(1),
#guide-bom-table td.qty { width: 50px; }

#guide-bom-table th:nth-child(3),
#guide-bom-table td.price { width: 100px; }

#guide-bom-table th:nth-child(4),
#guide-bom-table td.total { width: 90px; overflow: visible; white-space: nowrap; }

/* BOM section header rows */
.guide-bom-section-row td {
    background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.72rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    padding: 7px 10px !important;
}

/* BOM subtotal rows */
.guide-bom-subtotal-row td {
    background: #f0f0f0;
    border-top: 2px solid #d4c4a8;
    padding: 8px 10px !important;
}

/* Hardware bolt table — override dark-theme text color */
.guide-hw-table th {
    font-size: 0.7rem;
    color: #444;
}

.guide-hw-table td {
    color: #2c3e50;
    font-size: 0.88rem;
}

.guide-hw-table td.qty {
    color: #2c3e50;
    font-weight: 700;
}

/* Print styles */
@media print {
    #build-guide-modal {
        position: static;
        background: white;
        padding: 0;
    }
    .guide-container {
        box-shadow: none;
        margin: 0;
    }
    .guide-header-actions, .guide-close {
        display: none;
    }
    .guide-beam-bar {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .guide-beam-hole {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .guide-card {
        box-shadow: none;
        break-inside: avoid;
    }
    .guide-notes {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ===========================================================================
   Hardware Assembly Detail Modal
   =========================================================================== */
#hardware-detail-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 14, 26, 0.88);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal-backdrop);
    padding: var(--spacing-lg);
}

#hardware-detail-modal.visible {
    display: flex;
    justify-content: center;
    align-items: stretch;
}

.hw-container {
    background: var(--bg-panel);
    color: var(--text-primary);
    width: 100%;
    max-width: 1500px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.hw-header {
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border-light);
    padding: var(--spacing-md) var(--spacing-xl);
    display: flex;
    align-items: center;
    gap: var(--spacing-xl);
}

.hw-header h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--clr-primary);
    white-space: nowrap;
}

.hw-header-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    flex: 1;
}

.hw-header-field {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.hw-header-field select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.82rem;
    min-width: 180px;
}

.hw-explode-field { flex: 1; max-width: 360px; }
.hw-explode-field input[type="range"] {
    flex: 1;
    accent-color: var(--clr-primary);
}
.hw-fold-field { flex: 1; max-width: 360px; }
.hw-fold-field input[type="range"] {
    flex: 1;
    accent-color: var(--clr-primary);
}
#hw-explode-value,
#hw-fold-value {
    min-width: 38px;
    text-align: right;
    font-family: var(--font-mono);
    color: var(--text-data);
    font-weight: 600;
}

.hw-close {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}
.hw-close:hover {
    color: var(--text-primary);
    border-color: var(--border-light);
    background: var(--space-600);
}

.hw-body {
    display: flex;
    flex: 1;
    min-height: 0;
    height: 78vh;
}

.hw-viewport {
    flex: 1;
    min-width: 0;
    position: relative;
    background:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        radial-gradient(circle at 50% 40%, var(--space-600) 0%, var(--space-900) 75%);
    background-size: 40px 40px, 40px 40px, auto;
}

.hw-viewport canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.hw-editor {
    width: 360px;
    flex-shrink: 0;
    border-left: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
}

.hw-editor-toolbar {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-light);
    background: rgba(21, 29, 53, 0.5);
}

.hw-editor-toolbar select {
    flex: 1;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    font-size: 0.78rem;
}

.hw-copy-toolbar,
.hw-mirror-toolbar {
    align-items: center;
}

.hw-mirror-opt {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-right: 10px;
    cursor: pointer;
}

.hw-copy-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.hw-add-btn {
    background: rgba(var(--clr-primary-rgb), 0.12);
    color: var(--clr-primary);
    border: 1px solid rgba(var(--clr-primary-rgb), 0.35);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all var(--transition-fast);
}
.hw-add-btn:hover {
    background: rgba(var(--clr-primary-rgb), 0.22);
    border-color: var(--clr-primary);
    box-shadow: var(--glow-primary);
}

.hw-parts-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

.hw-parts-list::-webkit-scrollbar { width: 6px; }
.hw-parts-list::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: var(--radius-sm);
}

.hw-axis-section { margin-bottom: var(--spacing-lg); }

.hw-axis-title {
    font-family: var(--font-display);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-primary);
    font-weight: 700;
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-xs);
    border-bottom: 1px solid var(--border-light);
}

.hw-part-card {
    background: var(--space-600);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.hw-part-card:hover {
    border-color: var(--space-300);
}
.hw-part-card.selected {
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 1px rgba(var(--clr-primary-rgb), 0.35), var(--glow-primary);
}

.hw-part-head {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.hw-part-type {
    font-family: var(--font-display);
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: rgba(var(--clr-primary-rgb), 0.12);
    color: var(--clr-primary-light);
    border: 1px solid rgba(var(--clr-primary-rgb), 0.25);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    white-space: nowrap;
}

.hw-part-shared-tag {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--clr-muted, #888);
    border: 1px dashed rgba(var(--clr-primary-rgb), 0.35);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.hw-part-mirror-tag {
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--clr-muted, #888);
    border: 1px dashed rgba(var(--clr-accent-rgb, 120, 180, 255), 0.45);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.hw-part-label {
    flex: 1;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 5px 8px;
    font-size: 0.78rem;
    min-width: 0;
}
.hw-part-label:focus {
    outline: none;
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 2px rgba(var(--clr-primary-rgb), 0.2);
}

.hw-mini-btn {
    background: rgba(var(--clr-danger-rgb), 0.12);
    color: #fca5a5;
    border: 1px solid rgba(var(--clr-danger-rgb), 0.35);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 3px 7px;
    font-size: 0.72rem;
    line-height: 1;
    transition: all var(--transition-fast);
}
.hw-mini-btn:hover {
    background: rgba(var(--clr-danger-rgb), 0.22);
    border-color: var(--clr-danger);
}

.hw-param-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
}

.hw-param {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.hw-param span {
    font-size: 0.62rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hw-param input[type="number"],
.hw-param input[type="text"] {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 4px 6px;
    font-size: 0.74rem;
    font-family: var(--font-mono);
    width: 100%;
    box-sizing: border-box;
    text-align: right;
}
.hw-param input[type="number"]:focus,
.hw-param input[type="text"]:focus {
    outline: none;
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 2px rgba(var(--clr-primary-rgb), 0.2);
}

.hw-check-row {
    grid-column: 1 / -1;
    flex-direction: row !important;
    align-items: center;
    gap: var(--spacing-sm);
    padding-top: 2px;
}
.hw-check-row input[type="checkbox"] {
    accent-color: var(--clr-primary);
    width: auto;
    flex-shrink: 0;
}
.hw-check-label {
    font-size: 0.68rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Drag-and-drop reordering */
.hw-part-grip {
    cursor: grab;
    user-select: none;
    padding-right: 2px;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}
.hw-part-grip:hover { color: var(--clr-primary); }
.hw-part-grip:active { cursor: grabbing; }
.hw-part-card.hw-dragging { opacity: 0.45; }
.hw-part-card .hw-part-type { user-select: none; }
.hw-part-card.hw-drop-before { box-shadow: inset 0 3px 0 0 var(--clr-primary); }
.hw-part-card.hw-drop-after { box-shadow: inset 0 -3px 0 0 var(--clr-primary); }

.hw-preset-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding: 0 2px;
}
.hw-preset-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: 0 0 52px;
}
.hw-preset-select {
    flex: 1;
    min-width: 0;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 0.72rem;
}
.hw-preset-save { flex: 0 0 auto; }
.hw-preset-link {
    font-size: 0.65rem;
    color: var(--clr-primary);
    text-decoration: none;
    flex: 0 0 auto;
}
.sp-preset-row { margin-bottom: 10px; }
.sp-form-factor-row { margin-bottom: 8px; }
.sp-folding-controls { margin-bottom: 10px; padding-bottom: 4px; border-bottom: 1px solid var(--border-color); }
