:root {
    /* === DARK THEME (Default) === */
    --bg-main: #000000;
    --bg-glass: rgba(17, 25, 40, 0.75);
    --bg-glass-solid: rgba(15, 15, 20, 0.35);
    --bg-glass-strong: rgba(15, 15, 20, 0.45);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-primary: #BBBBBB;
    --text-secondary: #AAAAAA;
    --text-heading: #fff;
    --text-muted: rgba(255, 255, 255, 0.4);
    --accent: #feffff;
    --accent-hover: #E60012;
    --accent-focus: rgba(230, 0, 18, 0.2);
    --accent-color: #E60012;
    --accent-color-light: #FF3333;
    --accent-rgb: 230, 0, 18;
    --accent-glow: rgba(230, 0, 18, 0.4);

    /* 3D Viewer */
    --viewer-bg: radial-gradient(circle at 50% 50%, #260505 0%, #080000 100%);
    --viewer-bg-solid: #080000;

    /* Glass & panels */
    --glass-bg: rgba(15, 15, 20, 0.35);
    --glass-hover: rgba(255, 255, 255, 0.05);
    --panel-shadow: rgba(0, 0, 0, 0.5);
    --input-bg: rgba(120, 120, 128, 0.16);
    --input-bg-focus: rgba(120, 120, 128, 0.25);

    /* Search */
    --search-focus-ring: rgba(230, 0, 18, 0.25);

    /* ERP */
    --erp-bg: #080c14;
    --erp-main-bg: linear-gradient(135deg, #0a0e16 0%, #0f1524 50%, #0a1020 100%);
    --erp-sidebar-bg: rgba(10, 14, 22, 0.95);
    --erp-header-bg: rgba(0, 0, 0, 0.2);
    --erp-table-header-bg: rgba(10, 12, 18, 0.95);
    --erp-table-header-bg-alt: rgba(5, 8, 14, 0.95);
    --erp-table-hover: rgba(230, 0, 18, 0.06);
    --erp-card-bg: rgba(255, 255, 255, 0.03);
    --erp-card-border: rgba(255, 255, 255, 0.06);
    --erp-card-hover-bg: rgba(255, 255, 255, 0.05);
    --erp-card-hover-border: rgba(255, 255, 255, 0.1);
    --erp-modal-bg: linear-gradient(135deg, #0f1524, #131b2e);
    --erp-modal-border: rgba(255, 255, 255, 0.1);

    /* Toast */
    --toast-bg: rgba(15, 21, 36, 0.95);

    /* Loading */
    --loading-bg: rgba(10, 12, 18, 0.97);

    /* Tooltip */
    --tooltip-bg: rgba(15, 15, 20, 0.7);

    /* Scrollbar */
    --scrollbar-thumb: rgba(255, 255, 255, 0.1);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);

    /* Variable widths for BOM Columns */
    --w-desc: 300px;
    --w-cat: 180px;
    --w-mat: 180px;
}

/* === LIGHT THEME — HIGH CONTRAST (tablet / bright light) === */
[data-theme="light"] {
    --bg-main: #ebedf1;
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-glass-solid: rgba(255, 255, 255, 0.78);
    --bg-glass-strong: rgba(255, 255, 255, 0.9);
    --border-glass: rgba(0, 0, 0, 0.14);
    --text-primary: #0d0d1a;
    --text-secondary: #333344;
    --text-heading: #000;
    --text-muted: rgba(0, 0, 0, 0.58);
    --accent: #0d0d1a;
    --accent-hover: #E60012;
    --accent-focus: rgba(230, 0, 18, 0.2);
    --accent-color: #E60012;
    --accent-color-light: #FF3333;
    --accent-rgb: 230, 0, 18;
    --accent-glow: rgba(230, 0, 18, 0.35);

    /* 3D Viewer */
    --viewer-bg: radial-gradient(circle at 50% 50%, #e8ecf2 0%, #d0d6df 100%);
    --viewer-bg-solid: #e0e4ea;

    /* Glass & panels */
    --glass-bg: rgba(255, 255, 255, 0.78);
    --glass-hover: rgba(0, 0, 0, 0.06);
    --panel-shadow: rgba(0, 0, 0, 0.16);
    --input-bg: rgba(0, 0, 0, 0.07);
    --input-bg-focus: rgba(0, 0, 0, 0.12);

    /* Search */
    --search-focus-ring: rgba(230, 0, 18, 0.25);

    /* ERP */
    --erp-bg: #ebedf1;
    --erp-main-bg: linear-gradient(135deg, #ebedf1 0%, #e4e8ee 50%, #ebedf1 100%);
    --erp-sidebar-bg: rgba(255, 255, 255, 0.97);
    --erp-header-bg: rgba(255, 255, 255, 0.7);
    --erp-table-header-bg: rgba(240, 242, 247, 0.98);
    --erp-table-header-bg-alt: rgba(236, 238, 243, 0.98);
    --erp-table-hover: rgba(230, 0, 18, 0.06);
    --erp-card-bg: rgba(0, 0, 0, 0.025);
    --erp-card-border: rgba(0, 0, 0, 0.1);
    --erp-card-hover-bg: rgba(0, 0, 0, 0.05);
    --erp-card-hover-border: rgba(0, 0, 0, 0.16);
    --erp-modal-bg: linear-gradient(135deg, #fff, #f6f7f9);
    --erp-modal-border: rgba(0, 0, 0, 0.14);

    /* Toast */
    --toast-bg: rgba(255, 255, 255, 0.97);

    /* Loading */
    --loading-bg: rgba(240, 242, 245, 0.98);

    /* Tooltip */
    --tooltip-bg: rgba(255, 255, 255, 0.95);

    /* Scrollbar */
    --scrollbar-thumb: rgba(0, 0, 0, 0.18);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body,
html {
    width: 100%;
    height: 100%;
    font-family: 'Titillium Web', sans-serif;
    font-weight: 200;
    letter-spacing: 0.03em;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    margin: 0;
    padding: 0;
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(8px) saturate(150%);
    -webkit-backdrop-filter: blur(8px) saturate(150%);
    border: none;
    border-radius: 28px;
    overflow: hidden;
}

#left-column {
    position: absolute;
    left: 0;
    top: 0;
    width: 320px;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 32px;
    z-index: 60;
    resize: horizontal;
    overflow-x: visible;
    min-width: 220px;
    max-width: 800px;
}

#left-column > .glass-panel {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

#left-column > .glass-panel.standalone-header {
    border-top-right-radius: 0 !important;
}

#sidebar {
    position: relative;
    width: 100%;
    height: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    z-index: 5;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    /* No horizontal resize on individual internal panels to keep the column aligned */
    overflow: hidden;
}

#metadata-panel {
    position: absolute;
    right: 20px;
    top: 120px;
    width: 380px;
    height: calc(100% - 140px);
    display: flex;
    flex-direction: column;
    z-index: 60;
    background: var(--bg-glass-strong);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border: none;
    box-shadow: 0 16px 40px var(--panel-shadow);
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    resize: horizontal;
    direction: rtl;
    /* per fare il resize a sinistra */
    overflow-x: hidden;
}

#metadata-panel>* {
    direction: ltr;
}

#metadata-panel.open {
    transform: translateX(0);
}

.metadata-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px 0;
    gap: 8px;
    border-bottom: 1px solid transparent;
}

.metadata-label {
    color: var(--text-secondary);
    font-weight: 500;
    flex: 1 1 35%;
    min-width: 100px;
    padding-top: 4px;
}

.metadata-value {
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
    flex: 1 1 50%;
    min-width: 120px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid transparent;
}

.standalone-header {
    padding: 16px 20px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.standalone-search {
    padding: 12px 20px;
    flex-shrink: 0;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.search-box-standalone {
    width: 100%;
    background: transparent;
    border: none;
    color: #f8fafc;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    outline: none;
}

.search-box-standalone::placeholder {
    color: rgba(235, 235, 245, 0.4);
}

.standalone-footer {
    display: flex;
    gap: 16px;
    flex-shrink: 0;
    justify-content: flex-start;
}

.action-btn-standalone {
    border: none !important;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    border-radius: 50% !important;
    /* Forza la circolarità ignorando glass-panel base */
    margin: 0;
    flex: none;
}

.action-btn-standalone svg {
    opacity: 0.5;
    width: 20px;
    height: 20px;
    margin: 0 !important;
}

.action-btn-standalone:hover {
    transform: scale(1.05);
}

.action-btn-standalone:active {
    transform: scale(0.95);
}

.brand-logo {
    max-width: 90px;
    height: auto;
    margin: 0 auto 8px auto;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    /* Fa risaltare il logo bianco sul vetro */
}

.subtitle {
    font-size: 0.75rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.45em;
    /* <-- INCEPTION STYLE HUGE KERNING */
    margin-left: 0.45em;
    /* Compensa la crenatura finale per la centratura perfetta */
    font-weight: 200;
    text-align: center;
}

.search-box {
    margin-top: 20px;
    width: 100%;
    padding: 10px 16px;
    background: var(--input-bg);
    border: 1px solid transparent;
    border-radius: 14px;
    color: var(--text-primary);
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    outline: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-sizing: border-box;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(2px) saturate(180%);
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.05),
        0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-box:focus {
    background: var(--input-bg-focus);
    border-color: transparent;
    box-shadow:
        inset 0 1px 1px rgba(255, 255, 255, 0.1),
        0 0 0 3px var(--search-focus-ring),
        0 8px 16px rgba(0, 0, 0, 0.2);
}

.action-btn-small {
    margin-top: 10px;
    width: 100%;
    padding: 6px 16px;
    background: rgba(239, 68, 68, 0.15);
    /* Rosso debole per attenzione */
    border: 1px solid transparent;
    border-radius: 8px;
    color: #fca5a5;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn-small:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #fff;
}

.search-box::placeholder {
    color: rgba(235, 235, 245, 0.4);
    font-weight: 400;
}

.controls-panel {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 14px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    border: 1px solid transparent;
}

.xray-control,
.clay-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.controls-panel label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

#xrayValue {
    font-size: 0.7rem;
    color: var(--accent);
    font-family: monospace;
    font-weight: 500;
    letter-spacing: 0.05em;
}

#xraySlider {
    -webkit-appearance: none;
    appearance: none;
    /* Lint fix */
    width: 100%;
    height: 4px;
    /* Ultra-thin Apple style */
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
    transition: background 0.2s;
}

#xraySlider:hover {
    background: rgba(255, 255, 255, 0.2);
}

#xraySlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    /* Apple light shadow */
    transition: transform 0.1s ease;
}

#xraySlider::-webkit-slider-thumb:active {
    transform: scale(1.3);
}

.render-mode-control {
    display: flex;
    flex-direction: column;
    margin-top: 8px;
}

.segmented-control {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    /* very light base */
    border-radius: 10px;
    padding: 3px;
    overflow: hidden;
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    flex: 1;
    text-align: center;
    padding: 6px 4px;
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.45);
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    letter-spacing: 0.05em;
}

.segmented-control label:hover {
    color: rgba(255, 255, 255, 0.8);
}

.segmented-control input[type="radio"]:checked+label {
    background: rgba(255, 255, 255, 0.15);
    /* iOS Aqua translucent fill */
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    /* depth feel */
    border: none;
}

.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
}

.tree-container::-webkit-scrollbar {
    width: 6px;
}

.tree-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.tree-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Tree Component Styles */
.tree-item-container {
    margin-left: 16px;
    margin-top: 4px;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border: 1px solid transparent;
    overflow: hidden;
    /* For table cell clipping */
}

.tree-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.tree-item.active {
    background: var(--accent-focus);
    color: var(--accent-color);
    border-color: rgba(var(--accent-rgb), 0.3);
}

.toggle-icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.toggle-icon svg {
    display: block;
    flex-shrink: 0;
}

.toggle-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.eye-icon,
.isolate-icon,
.ghost-icon,
.edit-icon,
.trash-icon,
.transform-icon {
    width: 20px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.eye-icon:hover,
.isolate-icon:hover,
.ghost-icon:hover,
.edit-icon:hover,
.transform-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--accent);
}

.trash-icon:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    /* Rosso minaccia */
}

.eye-icon.hidden,
.isolate-icon.hidden {
    color: rgba(255, 255, 255, 0.2);
}

.ghost-icon.active,
.isolate-icon.active {
    color: var(--accent);
}

.item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    flex: 1;
}

#toggleBOMBtn {
    position: absolute;
    top: 30%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50% !important;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: all 0.2s ease;
}

#toggleBOMBtn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-50%) scale(1.1);
}

#toggleBOMBtn.active {
    background: rgba(var(--accent-rgb), 0.2);
    border-color: rgba(var(--accent-rgb), 0.4);
}

#toggleBOMBtn.active svg {
    color: #fff;
    opacity: 1;
}

#left-column.bom-mode {
    max-width: 90vw;
}

/* === BOM TABLE (real HTML table) === */

#bom-table-wrapper {
    display: none;
    flex: 1;
    overflow: auto;
}

#left-column.bom-mode #bom-table-wrapper {
    display: block;
}

#left-column.bom-mode #component-tree {
    display: none;
}

#bom-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.8rem;
}

#bom-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
}

#bom-table th {
    background: rgba(10, 12, 18, 0.95);
    backdrop-filter: blur(8px);
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
    user-select: none;
}

#bom-table th::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.15s;
}

#bom-table th:hover::after {
    background: rgba(var(--accent-rgb), 0.5);
}

#bom-table td {
    padding: 7px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#bom-table td:nth-child(1) {
    background: rgba(0, 0, 0, 0.05);
}

#bom-table td:nth-child(2) {
    background: rgba(0, 0, 0, 0.12);
}

#bom-table td:nth-child(3) {
    background: rgba(255, 255, 255, 0.02);
}

#bom-table td:nth-child(4) {
    background: rgba(0, 0, 0, 0.12);
}

#bom-table th:nth-child(2),
#bom-table th:nth-child(4) {
    background: rgba(5, 8, 14, 0.95);
}

#bom-table tr:hover td {
    background: rgba(var(--accent-rgb), 0.06) !important;
}

#bom-table td:first-child {
    color: var(--text-primary);
    font-weight: 300;
}

/* Legacy .bom-col spans hidden */
.bom-col {
    display: none;
}

/* PDF full-page overlay (body-level, escapes transform parents) */
#pdf-fullpage-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 9999;
    background: rgba(10, 12, 18, 0.97);
    flex-direction: column;
}

#pdf-fullpage-overlay.open {
    display: flex;
}

#pdf-overlay-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 600;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#pdf-overlay-frame {
    flex: 1;
    width: 100%;
    border: none;
    background: rgba(0, 0, 0, 0.3);
}

.badge {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 12px;
    margin-left: 8px;
}

#viewer-container {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--viewer-bg);
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.5s ease;
    border: none;
}

.loader {
    text-align: center;
    max-width: 400px;
}

.spinner {
    width: 56px;
    height: 56px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 24px;
}

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

#loading-text {
    font-size: 1.4rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: #e2e8f0;
}

.status-msg {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Tooltip 3D Picking */
.tooltip-3d {
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(15, 15, 20, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #f8fafc;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -100%);
    transition: opacity 0.2s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

/* ======================================================= */
/* TRANSFORM TOOLBAR (CAD-style Move/Rotate/Undo/Redo)     */
/* ======================================================= */
#transform-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    padding: 8px 14px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(var(--accent-rgb), 0.15);
    animation: tf-slide-up 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    pointer-events: auto;
}

@keyframes tf-slide-up {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.transform-toolbar-label {
    font-size: 0.55rem;
    letter-spacing: 0.15em;
    color: rgba(var(--accent-rgb), 0.7);
    font-weight: 600;
    text-transform: uppercase;
}

.transform-toolbar-btns {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tf-separator {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 4px;
}

.tf-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.55);
    padding: 6px 10px;
    font-size: 0.65rem;
    font-weight: 600;
    font-family: 'Titillium Web', sans-serif;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    justify-content: center;
}

.tf-btn:hover:not(:disabled) {
    background: rgba(var(--accent-rgb), 0.12);
    border-color: rgba(var(--accent-rgb), 0.25);
    color: var(--accent-color);
}

.tf-btn.active {
    background: rgba(var(--accent-rgb), 0.18);
    border-color: rgba(var(--accent-rgb), 0.4);
    color: var(--accent-color);
    box-shadow: 0 0 12px rgba(var(--accent-rgb), 0.15);
}

.tf-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.tf-btn.tf-done {
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.2);
}

.tf-btn.tf-done:hover {
    background: rgba(52, 211, 153, 0.15);
    border-color: rgba(52, 211, 153, 0.4);
    color: #34d399;
    box-shadow: 0 0 12px rgba(52, 211, 153, 0.15);
}

.transform-info {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.35);
    text-align: center;
    letter-spacing: 0.06em;
    min-height: 14px;
}

/* ======================================================= */
/* VIEWCUBE (Fusion 360-style orientation cube)             */
/* ======================================================= */
#viewcube-canvas {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 90px;
    height: 90px;
    z-index: 100;
    cursor: pointer;
    pointer-events: auto;
    border-radius: 6px;
}

#viewcube-label {
    position: absolute;
    top: 108px;
    right: 16px;
    width: 90px;
    text-align: center;
    font-size: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: rgba(148, 163, 184, 0.6);
    z-index: 100;
    pointer-events: auto;
    cursor: pointer;
    transition: color 0.2s ease;
}

#viewcube-label:hover {
    color: var(--accent-color);
}

#viewcube-label.ortho {
    color: var(--accent-color);
}

/* ======================================================= */
/* ERP MODULE — Full-Page Automotive ERP Overlay            */
/* ======================================================= */

#erp-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 15000;
    background: var(--erp-bg);
    flex-direction: row;
    animation: erp-fade-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

#erp-overlay.open {
    display: flex;
}

@keyframes erp-fade-in {
    from { opacity: 0; transform: scale(0.98); }
    to   { opacity: 1; transform: scale(1); }
}

/* --- ERP Sidebar --- */
#erp-sidebar {
    width: 72px;
    min-width: 72px;
    height: 100%;
    background: var(--erp-sidebar-bg);
    border-right: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 4px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Remove expensive blur on touch devices for smooth scrolling */
@media (pointer: coarse) {
    #erp-sidebar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--erp-sidebar-bg);
    }
}

.erp-sidebar-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding-bottom: 16px;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    width: 100%;
}

.erp-sidebar-brand span {
    font-size: 0.55rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    color: #f59e0b;
    text-transform: uppercase;
}

.erp-nav-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    width: 100%;
    padding: 0 8px;
}

.erp-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.25s ease;
    position: relative;
    font-family: 'Titillium Web', sans-serif;
    width: 100%;
}

.erp-nav-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.erp-nav-btn span {
    font-size: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.erp-nav-btn:hover {
    color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.04);
}

.erp-nav-btn.active {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.erp-nav-btn.active::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: #f59e0b;
    border-radius: 0 3px 3px 0;
}

.erp-nav-btn.erp-close {
    margin-top: auto;
    color: rgba(255,255,255,0.3);
    border-top: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding-top: 14px;
}

.erp-nav-btn.erp-close:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

/* --- ERP Main Content Area --- */
#erp-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Added transition for AI panel shift */
    background: var(--erp-main-bg);
    transition: padding-right 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#erp-main.ai-open {
    padding-right: 400px; /* Width of the AI chat panel */
}

/* --- ERP Header --- */
#erp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border-glass);
    background: var(--erp-header-bg);
    flex-shrink: 0;
}

.erp-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.erp-header-left h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: #fff;
    margin: 0;
}

.erp-vehicle-badge {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
}

.erp-header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.erp-variant-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.erp-variant-selector label {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
}

.erp-variant-selector select {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.4)' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.erp-variant-selector select:hover {
    border-color: rgba(245, 158, 11, 0.3);
}

.erp-variant-selector select:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.erp-variant-selector select option {
    background: #0f1524;
    color: #fff;
}

/* --- ERP Content --- */
#erp-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 28px 32px;
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
    transform: translateZ(0);
}

#erp-content::-webkit-scrollbar {
    width: 6px;
}

#erp-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

#erp-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

.erp-section {
    display: none;
    animation: erp-section-in 0.35s ease forwards;
}

.erp-section.active {
    display: block;
}

@keyframes erp-section-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Stat Cards Grid --- */
.erp-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.erp-stat-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.erp-stat-card:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.erp-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 16px 16px 0 0;
}

.erp-stat-card.accent-cyan::before { background: linear-gradient(90deg, var(--accent-color), var(--accent-color-light)); }
.erp-stat-card.accent-green::before { background: linear-gradient(90deg, #34d399, #10b981); }
.erp-stat-card.accent-amber::before { background: linear-gradient(90deg, #f59e0b, #d97706); }
.erp-stat-card.accent-red::before { background: linear-gradient(90deg, #ef4444, #dc2626); }
.erp-stat-card.accent-purple::before { background: linear-gradient(90deg, #a78bfa, #7c3aed); }
.erp-stat-card.accent-pink::before { background: linear-gradient(90deg, #f472b6, #ec4899); }

.erp-stat-label {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    margin-bottom: 8px;
}

.erp-stat-value {
    font-size: 1.8rem;
    font-weight: 300;
    color: #fff;
    letter-spacing: -0.02em;
    line-height: 1;
}

.erp-stat-sub {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.35);
    margin-top: 6px;
}

/* --- Section Headings --- */
.erp-section-heading {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.35);
    text-transform: uppercase;
    margin: 28px 0 14px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.erp-section-heading::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255,255,255,0.06);
}

/* --- ERP Data Tables --- */
.erp-table-wrapper {
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 24px;
    /* GPU acceleration for smooth scroll */
    -webkit-overflow-scrolling: touch;
    will-change: transform;
    transform: translateZ(0);
    contain: layout style;
}

.erp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    table-layout: auto;
    contain: content;
}

.erp-table thead {
    position: sticky;
    top: 0;
    z-index: 5;
    transform: translateZ(0); /* GPU layer for sticky header */
}

.erp-table th {
    padding: 14px 16px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    background: rgba(14, 20, 31, 0.95);
    z-index: 10;
    font-family: 'Titillium Web', sans-serif;
    white-space: nowrap;
}

/* Sortable Headers & Resizer Handles */
.erp-table th.sortable { cursor: pointer; user-select: none; transition: background 0.2s; }
.erp-table th.sortable:hover { background: rgba(255, 255, 255, 0.05); }
.resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 5px; cursor: col-resize; z-index: 15; }
.resizer:hover, .resizing { background: rgba(var(--accent-rgb), 0.4); }

.erp-table td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.erp-table tr:hover td {
    background: var(--erp-table-hover);
}

.erp-table td:first-child {
    color: #fff;
    font-weight: 400;
}

/* --- Status Badges --- */
.erp-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.erp-badge.green { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.erp-badge.amber { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.erp-badge.red { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.erp-badge.cyan { background: rgba(var(--accent-rgb), 0.15); color: var(--accent-color); }
.erp-badge.purple { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
.erp-badge.gray { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.4); }

/* --- Progress Bars --- */
.erp-progress {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    overflow: hidden;
}

.erp-progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.erp-progress-fill.cyan { background: linear-gradient(90deg, var(--accent-color), var(--accent-color-light)); }
.erp-progress-fill.green { background: linear-gradient(90deg, #34d399, #10b981); }
.erp-progress-fill.amber { background: linear-gradient(90deg, #f59e0b, #d97706); }
.erp-progress-fill.red { background: linear-gradient(90deg, #ef4444, #dc2626); }
.erp-progress-fill.purple { background: linear-gradient(90deg, #a78bfa, #7c3aed); }

/* --- Variant Cards Grid --- */
.erp-variants-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.erp-variant-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
}

.erp-variant-card:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.erp-variant-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.erp-variant-card-header h3 {
    font-size: 0.95rem;
    font-weight: 400;
    color: #fff;
    margin: 0;
}

.erp-variant-card-meta {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
}

.erp-variant-card-meta .meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.erp-variant-card-meta .meta-label {
    color: rgba(255,255,255,0.35);
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- Progress Ring (CSS-only) --- */
.erp-ring {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    position: relative;
}

.erp-ring::before {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: rgba(10, 14, 22, 0.9);
    z-index: 1;
}

.erp-ring span {
    position: relative;
    z-index: 2;
}

/* --- Timeline / Gantt-like --- */
.erp-timeline-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.erp-timeline-label {
    width: 160px;
    min-width: 160px;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.7);
}

.erp-timeline-bar-container {
    flex: 1;
    height: 24px;
    background: rgba(255,255,255,0.03);
    border-radius: 6px;
    position: relative;
    overflow: hidden;
}

.erp-timeline-bar {
    position: absolute;
    height: 100%;
    border-radius: 6px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 0.6rem;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Supplier Cards --- */
.erp-supplier-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    transition: all 0.25s ease;
}

.erp-supplier-card:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
}

.erp-supplier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.erp-supplier-header h3 {
    font-size: 1rem;
    font-weight: 400;
    color: #fff;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.erp-supplier-header .supplier-total {
    color: #34d399;
    font-weight: 600;
    font-size: 1rem;
}

/* --- Empty State --- */
.erp-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: rgba(255,255,255,0.3);
}

.erp-empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.erp-empty-state h3 {
    font-size: 1rem;
    font-weight: 400;
    color: rgba(255,255,255,0.4);
    margin: 0 0 8px 0;
}

.erp-empty-state p {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.25);
}

/* --- Checklist Items --- */
.erp-checklist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 0.8rem;
    color: rgba(255,255,255,0.7);
}

.erp-checklist-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.6rem;
}

.erp-checklist-icon.pass { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.erp-checklist-icon.fail { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.erp-checklist-icon.pending { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.3); }

/* --- Cost Breakdown Bar --- */
.erp-cost-bar {
    display: flex;
    height: 32px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}

.erp-cost-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: 600;
    color: rgba(255,255,255,0.85);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    padding: 0 6px;
    transition: flex 0.4s ease;
}

/* --- Sub-tabs within sections --- */
.erp-sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: rgba(255,255,255,0.03);
    border-radius: 12px;
    padding: 4px;
    border: 1px solid rgba(255,255,255,0.04);
}

.erp-sub-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.4);
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
}

.erp-sub-tab:hover {
    color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.04);
}

.erp-sub-tab.active {
    color: #fff;
    background: rgba(245, 158, 11, 0.15);
}

/* ======================================================= */
/* ERP INTERACTIVE — Editable Cells, Modals, Toasts         */
/* ======================================================= */

/* --- Inline Editable Cells --- */
.erp-table td.erp-editable {
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
}

.erp-table td.erp-editable:hover {
    background: rgba(245, 158, 11, 0.08) !important;
}

.erp-table td.erp-editable::after {
    content: '✎';
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.55rem;
    color: rgba(255,255,255,0.12);
    opacity: 0;
    transition: opacity 0.2s;
}

.erp-table td.erp-editable:hover::after {
    opacity: 1;
}

.erp-inline-input {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.8rem;
    width: 100%;
    max-width: 160px;
    outline: none;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
    transition: all 0.2s;
}

.erp-inline-input:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

/* --- Clickable Badges (status cycling) --- */
.erp-badge.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.erp-badge.clickable:hover {
    filter: brightness(1.3);
    transform: scale(1.05);
}

.erp-badge.clickable:active {
    transform: scale(0.95);
}

/* --- Clickable checklist icons --- */
.erp-checklist-icon.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.erp-checklist-icon.clickable:hover {
    transform: scale(1.2);
    filter: brightness(1.3);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

/* --- Toggle dot (variant applicability) --- */
.erp-variant-toggle {
    cursor: pointer;
    transition: all 0.15s;
    font-size: 1rem;
    user-select: none;
}

.erp-variant-toggle:hover {
    transform: scale(1.3);
}

/* --- Action Buttons --- */
.erp-actions-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

.erp-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: #f59e0b;
    border-radius: 10px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.25s ease;
}

.erp-action-btn:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.15);
}

.erp-action-btn:active {
    transform: scale(0.97);
}

.erp-action-btn.danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.25);
    color: #ef4444;
}

.erp-action-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.15);
}

.erp-action-btn.success {
    background: rgba(52, 211, 153, 0.1);
    border-color: rgba(52, 211, 153, 0.25);
    color: #34d399;
}

.erp-action-btn.success:hover {
    background: rgba(52, 211, 153, 0.2);
    border-color: #34d399;
    box-shadow: 0 4px 16px rgba(52, 211, 153, 0.15);
}

.erp-row-action {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.25);
    font-size: 0.85rem;
    padding: 4px 6px;
    border-radius: 6px;
    transition: all 0.2s;
}

.erp-row-action:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* --- Toast Notifications --- */
.erp-toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 20000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.erp-toast {
    background: rgba(15, 21, 36, 0.95);
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.8);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: toast-in 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    pointer-events: auto;
    max-width: 360px;
}

.erp-toast.toast-out {
    animation: toast-out 0.3s ease forwards;
}

.erp-toast.success { border-color: rgba(52, 211, 153, 0.3); }
.erp-toast.success .toast-icon { color: #34d399; }
.erp-toast.error { border-color: rgba(239, 68, 68, 0.3); }
.erp-toast.error .toast-icon { color: #ef4444; }
.erp-toast.info { border-color: rgba(var(--accent-rgb), 0.3); }
.erp-toast.info .toast-icon { color: var(--accent-color); }

.toast-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* --- Modal Dialog --- */
.erp-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 18000;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: erp-fade-in 0.25s ease forwards;
}

.erp-modal {
    background: linear-gradient(135deg, #0f1524, #131b2e);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 28px 32px;
    min-width: 420px;
    max-width: 560px;
    width: 90%;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
    animation: erp-section-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.erp-modal h2 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #fff;
    margin: 0 0 20px 0;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    text-transform: uppercase;
}

.erp-form-group {
    margin-bottom: 16px;
}

.erp-form-group label {
    display: block;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.erp-form-input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font-family: 'Titillium Web', sans-serif;
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.erp-form-input:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.erp-form-input::placeholder {
    color: rgba(255,255,255,0.2);
}

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

select.erp-form-input {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.4)' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

select.erp-form-input option {
    background: #0f1524;
    color: #fff;
}

.erp-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.erp-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* --- Editable load slider within table --- */
.erp-load-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.erp-load-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #f59e0b;
    border: 2px solid #0f1524;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
    cursor: pointer;
    transition: all 0.2s;
}

.erp-load-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
}

/* --- Star rating --- */
.erp-star-rating {
    display: inline-flex;
    gap: 2px;
    cursor: pointer;
}

.erp-star {
    color: rgba(255,255,255,0.15);
    font-size: 1rem;
    transition: all 0.15s;
    cursor: pointer;
}

.erp-star.filled {
    color: #f59e0b;
}

.erp-star:hover {
    transform: scale(1.2);
}

/* --- Notes badge --- */
.erp-notes-icon {
    cursor: pointer;
    color: rgba(255,255,255,0.2);
    font-size: 0.75rem;
    transition: all 0.2s;
}

.erp-notes-icon:hover {
    color: var(--accent-color);
}

.erp-notes-icon.has-note {
    color: var(--accent-color);
}
/* ERP Search Box */
.erp-search-box {
    position: relative;
    margin-bottom: 20px;
}
.erp-search-box input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    color: #fff;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    outline: none;
    transition: all 0.25s ease;
    font-family: inherit;
}
.erp-search-box input:focus {
    border-color: rgba(245,158,11,0.5);
    background: rgba(255,255,255,0.06);
    box-shadow: 0 0 0 3px rgba(245,158,11,0.1);
}
.erp-search-box input::placeholder {
    color: rgba(255,255,255,0.25);
}
.erp-search-box::before {
    content: '🔍';
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    opacity: 0.4;
    pointer-events: none;
}
.erp-search-count {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: rgba(255,255,255,0.3);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    pointer-events: none;
}
.erp-search-count.has-filter {
    color: #f59e0b;
}

/* --- AI Chat Panel --- */
.erp-ai-panel { position: absolute; top: 0; right: -450px; width: 400px; height: 100%; background: rgba(12, 17, 28, 0.95); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-left: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; z-index: 1000; box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5); transition: right 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); }
.erp-ai-panel.open { right: 0; }

/* --- Floating AI Button --- */
.floating-ai-btn {
    position: absolute;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #E60012, #cc0010);
    color: white;
    font-weight: 800;
    font-size: 1.2rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(230, 0, 18, 0.4);
    z-index: 20000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.floating-ai-btn:hover {
    transform: scale(1.1) translateY(-5px);
    box-shadow: 0 12px 28px rgba(230, 0, 18, 0.6);
}

.floating-ai-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.5);
}

/* --- ERP Pill Button --- */
#erpBtn.erp-button-pill {
    background: rgba(245, 158, 11, 0.15) !important;
    border: 1px solid rgba(245, 158, 11, 0.4) !important;
    border-left: none !important;
    padding: 8px 16px 8px 12px !important;
    border-radius: 0 16px 16px 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 80px;
    transition: all 0.2s;
    margin-left: 0;
}

#erpBtn.erp-button-pill span {
    font-size: 1.1rem !important;
    font-weight: 800 !important;
    letter-spacing: 0.1em !important;
}

#erpBtn.erp-button-pill:hover {
    background: rgba(245, 158, 11, 0.3) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}
.ai-header { padding: 20px; border-bottom: 1px solid var(--border-glass); display: flex; justify-content: space-between; align-items: center; background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.1) 0%, transparent 100%); }
.ai-header h3 { margin: 0; font-size: 1.1rem; font-weight: 600; color: var(--accent-color); letter-spacing: 0.05em; }
.ai-close-btn { background: none; border: none; color: rgba(255, 255, 255, 0.5); font-size: 1.2rem; cursor: pointer; transition: color 0.2s; }
.ai-close-btn:hover { color: #fff; }
.ai-messages { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.message { max-width: 85%; padding: 12px 16px; border-radius: 12px; font-size: 0.85rem; line-height: 1.5; word-wrap: break-word; }
.ai-message { background: rgba(var(--accent-rgb), 0.12); border: 1px solid rgba(var(--accent-rgb), 0.25); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 4px; }
.user-message { background: rgba(255, 255, 255, 0.1); color: #f8fafc; align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-action-btn { margin-top: 10px; background: var(--accent-color); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: background 0.2s; letter-spacing: 0.05em; text-transform: uppercase; }
.ai-action-btn:hover { background: #cc0010; }
.ai-action-btn.cancel { background: rgba(255, 255, 255, 0.1); margin-left: 8px; }
.ai-action-btn.cancel:hover { background: rgba(255, 255, 255, 0.2); }
.ai-dropzone { margin: 0 20px 10px 20px; border: 2px dashed rgba(var(--accent-rgb), 0.4); border-radius: 12px; padding: 20px; text-align: center; color: rgba(var(--accent-rgb), 0.6); background: rgba(var(--accent-rgb), 0.05); transition: all 0.3s ease; display: flex; justify-content: center; align-items: center; min-height: 80px; cursor: pointer; }
.ai-dropzone.dragover { background: rgba(var(--accent-rgb), 0.2); border-color: var(--accent-color); color: var(--text-primary); transform: scale(1.02); }
.ai-dropzone p { margin: 0; font-size: 0.85rem; font-weight: 500; pointer-events: none; }
.ai-input-wrapper { padding: 16px 20px; background: rgba(0, 0, 0, 0.2); border-top: 1px solid rgba(255, 255, 255, 0.05); display: flex; gap: 12px; align-items: flex-end; }
#ai-input { flex: 1; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; padding: 12px 14px; color: #fff; font-family: inherit; font-size: 0.85rem; resize: none; height: 50px; min-height: 50px; max-height: 200px; outline: none; transition: border-color 0.2s; }
#ai-input:focus { border-color: rgba(var(--accent-rgb), 0.5); }
#ai-send-btn { background: var(--accent-color); border: none; width: 44px; height: 44px; border-radius: 12px; display: flex; justify-content: center; align-items: center; cursor: pointer; color: #fff; flex-shrink: 0; transition: transform 0.15s, background 0.2s; }
#ai-send-btn:hover { background: #cc0010; transform: scale(1.05); }
#ai-send-btn:active { transform: scale(0.95); }
#ai-send-btn svg { width: 20px; height: 20px; }
.typing-indicator { display: flex; gap: 4px; padding: 4px 8px; align-items: center; }
.typing-dot { width: 6px; height: 6px; background: rgba(var(--accent-rgb), 0.8); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* ======================================================= */
/* THEME TOGGLE BUTTON                                      */
/* ======================================================= */
#theme-toggle-btn {
    position: absolute;
    top: 16px;
    right: 120px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    padding: 0;
}

#section-btn {
    position: absolute;
    top: 16px;
    right: 232px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    padding: 0;
    color: rgba(255, 255, 255, 0.6);
}

#settings-btn {
    position: absolute;
    top: 16px;
    right: 176px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    padding: 0;
    color: rgba(255, 255, 255, 0.6);
}

#theme-toggle-btn:hover, #settings-btn:hover, #section-btn:hover {
    transform: scale(1.08);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#theme-toggle-btn svg {
    width: 20px;
    height: 20px;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

#theme-toggle-btn .icon-sun { display: none; color: #f59e0b; }
#theme-toggle-btn .icon-moon { display: block; color: rgba(255, 255, 255, 0.6); }

/* ======================================================= */
/* LIGHT THEME — Element-specific overrides                 */
/* ======================================================= */
[data-theme="light"] #theme-toggle-btn, [data-theme="light"] #settings-btn, [data-theme="light"] #section-btn {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
[data-theme="light"] #theme-toggle-btn:hover, [data-theme="light"] #settings-btn:hover, [data-theme="light"] #section-btn:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
[data-theme="light"] #settings-btn, [data-theme="light"] #section-btn {
    color: #64748b;
}
[data-theme="light"] #theme-toggle-btn .icon-sun { display: block; }
[data-theme="light"] #theme-toggle-btn .icon-moon { display: none; }

/* ==================================================================
   LIGHT / HIGH CONTRAST — Global font-weight & text boost
   Designed for tablet usage under bright ambient light.
   ================================================================== */
[data-theme="light"] body,
[data-theme="light"] html {
    font-weight: 400;
}
[data-theme="light"] h1, [data-theme="light"] h2, [data-theme="light"] h3,
[data-theme="light"] strong, [data-theme="light"] b {
    font-weight: 700;
}

/* Light glass panels */
[data-theme="light"] .glass-panel {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] #sidebar {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .standalone-header,
[data-theme="light"] .standalone-search {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Search box light */
[data-theme="light"] .search-box-standalone {
    color: var(--text-primary);
    font-weight: 400;
}
[data-theme="light"] .search-box-standalone::placeholder {
    color: rgba(0, 0, 0, 0.45);
}
[data-theme="light"] .search-box::placeholder {
    color: rgba(0, 0, 0, 0.45);
}

/* Tree view light */
[data-theme="light"] .tree-item {
    font-weight: 400;
}
[data-theme="light"] .tree-item:hover {
    background: rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .toggle-icon {
    color: rgba(0, 0, 0, 0.45);
}
[data-theme="light"] .toggle-icon:hover {
    background: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .eye-icon,
[data-theme="light"] .isolate-icon,
[data-theme="light"] .ghost-icon,
[data-theme="light"] .edit-icon,
[data-theme="light"] .trash-icon,
[data-theme="light"] .transform-icon {
    color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] .eye-icon:hover,
[data-theme="light"] .isolate-icon:hover,
[data-theme="light"] .ghost-icon:hover,
[data-theme="light"] .edit-icon:hover,
[data-theme="light"] .transform-icon:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--accent-color);
}
[data-theme="light"] .trash-icon:hover {
    background: rgba(239, 68, 68, 0.12);
}

/* Segmented control light */
[data-theme="light"] .segmented-control {
    background: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .segmented-control label {
    color: rgba(0, 0, 0, 0.55);
    font-weight: 500;
}
[data-theme="light"] .segmented-control label:hover {
    color: rgba(0, 0, 0, 0.8);
}
[data-theme="light"] .segmented-control input[type="radio"]:checked+label {
    background: rgba(255, 255, 255, 0.92);
    color: #000;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Controls panel light */
[data-theme="light"] .controls-panel {
    background: rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .controls-panel label {
    font-weight: 500;
    color: rgba(0, 0, 0, 0.65);
}
[data-theme="light"] #xraySlider {
    background: rgba(0, 0, 0, 0.14);
}
[data-theme="light"] #xraySlider:hover {
    background: rgba(0, 0, 0, 0.2);
}
[data-theme="light"] #xraySlider::-webkit-slider-thumb {
    background: var(--text-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* BOM Table light */
[data-theme="light"] #bom-table th {
    background: rgba(240, 242, 247, 0.98);
    color: rgba(0, 0, 0, 0.65);
    font-weight: 700;
    border-bottom-color: rgba(0, 0, 0, 0.12);
}
[data-theme="light"] #bom-table th:nth-child(2),
[data-theme="light"] #bom-table th:nth-child(4) {
    background: rgba(236, 238, 243, 0.98);
}
[data-theme="light"] #bom-table td {
    border-bottom-color: rgba(0, 0, 0, 0.06);
    font-weight: 400;
}
[data-theme="light"] #bom-table td:nth-child(1) { background: rgba(0, 0, 0, 0.01); }
[data-theme="light"] #bom-table td:nth-child(2) { background: rgba(0, 0, 0, 0.035); }
[data-theme="light"] #bom-table td:nth-child(3) { background: rgba(0, 0, 0, 0.01); }
[data-theme="light"] #bom-table td:nth-child(4) { background: rgba(0, 0, 0, 0.035); }

/* Scrollbars light */
[data-theme="light"] .tree-container::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
}
[data-theme="light"] .tree-container::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}
[data-theme="light"] #erp-content::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
}

/* BOM toggle button light */
[data-theme="light"] #toggleBOMBtn {
    border-color: rgba(0, 0, 0, 0.14);
    background: rgba(255, 255, 255, 0.8);
}
[data-theme="light"] #toggleBOMBtn:hover {
    background: rgba(255, 255, 255, 0.95);
}
[data-theme="light"] #toggleBOMBtn svg {
    stroke: var(--text-primary);
}

/* Tooltip light */
[data-theme="light"] .tooltip-3d {
    background: var(--tooltip-bg);
    border-color: rgba(0, 0, 0, 0.14);
    color: #000;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}

/* Loading overlay light */
[data-theme="light"] #loading-text {
    color: var(--text-primary);
    font-weight: 500;
}
[data-theme="light"] .spinner {
    border-color: rgba(0, 0, 0, 0.14);
    border-top-color: var(--accent-color);
}

/* Badge light */
[data-theme="light"] .badge {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.6);
    font-weight: 600;
}

/* ============================================================= */
/* LIGHT MODE — Comprehensive text color fixes                   */
/* Covers ALL elements with hardcoded white/light text            */
/* ============================================================= */

/* X-Ray value label */
[data-theme="light"] #xrayValue {
    color: var(--text-primary);
}

/* Subtitle (brand) */
[data-theme="light"] .subtitle {
    color: var(--text-primary);
}

/* Tree item names */
[data-theme="light"] .item-name {
    color: var(--text-primary);
    font-weight: 400;
}
[data-theme="light"] .tree-item td:first-child {
    color: var(--text-primary);
    font-weight: 400;
}

/* Eye icon states */
[data-theme="light"] .eye-icon.hidden,
[data-theme="light"] .isolate-icon.hidden {
    color: rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .ghost-icon.active,
[data-theme="light"] .isolate-icon.active {
    color: var(--accent-color);
}

/* Metadata panel close button */
[data-theme="light"] #closeMetadataBtn {
    color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] #closeMetadataBtn:hover {
    color: #000;
}

/* Metadata panel header text */
[data-theme="light"] #metadata-panel .sidebar-header h2 {
    color: var(--accent-color);
}

/* PDF preview */
[data-theme="light"] #pdf-preview-section [style*="rgba(255,255,255,0.5)"] {
    color: rgba(0, 0, 0, 0.5) !important;
}
[data-theme="light"] #pdf-overlay-bar {
    color: rgba(0, 0, 0, 0.5);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] #pdfOverlayCloseBtn {
    color: rgba(0, 0, 0, 0.5) !important;
}

/* BOM Table td first col */
[data-theme="light"] #bom-table td:first-child {
    color: var(--text-primary);
    font-weight: 400;
}

/* BOM Table header resize handle */
[data-theme="light"] #bom-table th::after {
    background: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] #bom-table th:hover::after {
    background: rgba(var(--accent-rgb), 0.5);
}

/* Action button small (reset) */
[data-theme="light"] .action-btn-small {
    background: rgba(239, 68, 68, 0.08);
    color: #b91c1c;
    font-weight: 600;
}
[data-theme="light"] .action-btn-small:hover {
    background: rgba(239, 68, 68, 0.18);
    color: #991b1b;
}

/* ERP button pill */
[data-theme="light"] .erp-button-pill {
    color: #92400e !important;
}

/* Add STEP button (+) */
[data-theme="light"] #addStepBtn {
    color: var(--accent-color) !important;
}

/* Transform toolbar */
[data-theme="light"] .transform-toolbar-label {
    color: rgba(var(--accent-rgb), 0.8);
}
[data-theme="light"] .transform-info {
    color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .tf-btn.tf-done {
    color: #059669;
    border-color: rgba(5, 150, 105, 0.2);
}
[data-theme="light"] .tf-btn.tf-done:hover {
    background: rgba(5, 150, 105, 0.1);
    color: #047857;
}
[data-theme="light"] .tf-btn.active {
    background: rgba(var(--accent-rgb), 0.1);
    border-color: rgba(var(--accent-rgb), 0.3);
    color: var(--accent-color);
}

/* ViewCube label */
[data-theme="light"] #viewcube-label {
    color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] #viewcube-label:hover {
    color: var(--accent-color);
}
[data-theme="light"] #viewcube-label.ortho {
    color: var(--accent-color);
}

/* Sidebar collapse button */
[data-theme="light"] #sidebar-collapse-btn {
    background: rgba(0, 0, 0, 0.04);
    border-top-color: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.5);
}
[data-theme="light"] #sidebar-collapse-btn:active {
    background: rgba(0, 0, 0, 0.08);
}

/* ERP Header */
[data-theme="light"] .erp-header-left h1 {
    color: #000;
}
[data-theme="light"] .erp-variant-selector label {
    color: rgba(0, 0, 0, 0.6);
    font-weight: 700;
}
[data-theme="light"] .erp-variant-selector select {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.12);
    color: #000;
    font-weight: 400;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(0,0,0,0.4)' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
[data-theme="light"] .erp-variant-selector select option {
    background: #fff;
    color: #000;
}
[data-theme="light"] .erp-variant-selector select:hover {
    border-color: rgba(var(--accent-rgb), 0.3);
}

/* ERP Nav button */
[data-theme="light"] .erp-nav-btn {
    color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .erp-nav-btn:hover {
    color: rgba(0, 0, 0, 0.7);
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .erp-nav-btn.active {
    color: var(--accent-color);
    background: rgba(var(--accent-rgb), 0.08);
}
[data-theme="light"] .erp-nav-btn.erp-close {
    color: rgba(0, 0, 0, 0.35);
    border-top-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .erp-nav-btn.erp-close:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.06);
}
[data-theme="light"] .erp-sidebar-brand {
    border-bottom-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .erp-sidebar-brand span {
    color: #92400e;
}

/* Floating AI button */
[data-theme="light"] .floating-ai-btn {
    color: rgba(0, 0, 0, 0.6);
}

/* AI Panel header */
[data-theme="light"] .ai-header h3 {
    color: #000;
}
[data-theme="light"] .ai-message {
    color: var(--text-primary);
}

/* ERP light overrides */
[data-theme="light"] .erp-sidebar-brand {
    border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .erp-nav-btn {
    color: rgba(0, 0, 0, 0.55);
    font-weight: 600;
}
[data-theme="light"] .erp-nav-btn:hover {
    color: rgba(0, 0, 0, 0.85);
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .erp-nav-btn.erp-close {
    color: rgba(0, 0, 0, 0.45);
    border-top-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .erp-header-left h1 {
    color: #000;
    font-weight: 700;
}

/* ---- Stat Cards ---- */
[data-theme="light"] .erp-stat-card {
    background: rgba(0, 0, 0, 0.025);
    border: 1px solid rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .erp-stat-card:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.18);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .erp-stat-label {
    color: rgba(0, 0, 0, 0.7);
    font-weight: 700;
}
[data-theme="light"] .erp-stat-value {
    color: #000;
    font-weight: 500;
}
[data-theme="light"] .erp-stat-sub {
    color: rgba(0, 0, 0, 0.58);
    font-weight: 500;
}

/* ---- Section Headings ---- */
[data-theme="light"] .erp-section-heading {
    color: rgba(0, 0, 0, 0.65);
    font-weight: 700;
}
[data-theme="light"] .erp-section-heading::after {
    background: rgba(0, 0, 0, 0.14);
}

/* ---- Tables ---- */
[data-theme="light"] .erp-table-wrapper {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .erp-table th {
    color: rgba(0, 0, 0, 0.7);
    font-weight: 700;
    border-bottom: 1px solid rgba(0, 0, 0, 0.14);
    background: rgba(240, 242, 247, 0.98);
}
[data-theme="light"] .erp-table th.sortable:hover {
    background: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .erp-table td {
    color: rgba(0, 0, 0, 0.8);
    font-weight: 400;
    border-bottom-color: rgba(0, 0, 0, 0.07);
}
[data-theme="light"] .erp-table td:first-child {
    color: #000;
    font-weight: 600;
}
[data-theme="light"] .erp-table tr:hover td {
    background: rgba(0, 0, 0, 0.04);
}

/* ---- Variant Cards ---- */
[data-theme="light"] .erp-variant-card {
    background: rgba(0, 0, 0, 0.025);
    border: 1px solid rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .erp-variant-card:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.18);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .erp-variant-card-header h3 {
    color: #000;
    font-weight: 600;
}
[data-theme="light"] .erp-variant-card-meta {
    color: rgba(0, 0, 0, 0.75);
    font-weight: 500;
}
[data-theme="light"] .erp-variant-card-meta .meta-label {
    color: rgba(0, 0, 0, 0.6);
    font-weight: 700;
}
[data-theme="light"] .erp-variant-card-meta .meta-row {
    color: rgba(0, 0, 0, 0.8);
}

/* ---- Badges ---- */
[data-theme="light"] .erp-badge {
    font-weight: 700;
}
[data-theme="light"] .erp-badge.green {
    background: rgba(5, 150, 105, 0.12);
    color: #047857;
}
[data-theme="light"] .erp-badge.amber {
    background: rgba(180, 83, 9, 0.1);
    color: #92400e;
}
[data-theme="light"] .erp-badge.red {
    background: rgba(220, 38, 38, 0.1);
    color: #b91c1c;
}
[data-theme="light"] .erp-badge.cyan {
    background: rgba(var(--accent-rgb), 0.1);
    color: #b30010;
}
[data-theme="light"] .erp-badge.purple {
    background: rgba(124, 58, 237, 0.1);
    color: #6d28d9;
}
[data-theme="light"] .erp-badge.gray {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.6);
}

/* ---- Progress Bars ---- */
[data-theme="light"] .erp-progress {
    background: rgba(0, 0, 0, 0.08);
}

/* ---- Cost Bar ---- */
[data-theme="light"] .erp-cost-bar {
    background: rgba(0, 0, 0, 0.04);
}

/* ---- Ring (progress circle) ---- */
[data-theme="light"] .erp-ring {
    border-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .erp-ring-label {
    color: #fff;
}

/* ---- Variant selector ---- */
[data-theme="light"] .erp-variant-selector select {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.12);
    color: #111;
}
[data-theme="light"] .erp-variant-selector select option {
    background: #fff;
    color: #111;
}
[data-theme="light"] .erp-variant-selector label {
    color: rgba(0, 0, 0, 0.5);
}

/* ---- Form Inputs ---- */
[data-theme="light"] .erp-form-input {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.12);
    color: #111;
}
[data-theme="light"] .erp-form-input::placeholder {
    color: rgba(0, 0, 0, 0.35);
}
[data-theme="light"] .erp-form-input:focus {
    border-color: var(--accent-color);
}

/* ---- Modals ---- */
[data-theme="light"] .erp-modal {
    background: linear-gradient(135deg, #fff, #f8f9fa);
    border-color: rgba(0, 0, 0, 0.12);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .erp-modal h2 {
    color: #111;
    border-bottom-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .erp-modal label {
    color: rgba(0, 0, 0, 0.6);
}

/* ---- Toast ---- */
[data-theme="light"] .erp-toast {
    background: rgba(255, 255, 255, 0.97);
    border-color: rgba(0, 0, 0, 0.1);
    color: #111;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .erp-toast .toast-icon {
    opacity: 0.85;
}
[data-theme="light"] .toast-message {
    color: rgba(0, 0, 0, 0.7);
}

/* ---- Variant toggle button ---- */
[data-theme="light"] .erp-variant-toggle {
    color: rgba(0, 0, 0, 0.5);
    border-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .erp-variant-toggle:hover {
    color: rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.04);
}

/* ---- Row actions ---- */
[data-theme="light"] .erp-row-action {
    color: rgba(0, 0, 0, 0.35);
}
[data-theme="light"] .erp-row-action:hover {
    color: rgba(0, 0, 0, 0.7);
}

/* ---- Editable cells ---- */
[data-theme="light"] .erp-editable:hover {
    background: rgba(0, 0, 0, 0.04);
}

/* ---- Notes icon ---- */
[data-theme="light"] .erp-notes-icon {
    color: rgba(0, 0, 0, 0.3);
}
[data-theme="light"] .erp-notes-icon:hover {
    color: var(--accent-color);
}
[data-theme="light"] .erp-notes-icon.has-note {
    color: var(--accent-color);
}

/* ---- ERP Header elements ---- */
[data-theme="light"] .erp-header-actions button {
    color: rgba(0, 0, 0, 0.5);
    border-color: rgba(0, 0, 0, 0.1);
}
[data-theme="light"] .erp-header-actions button:hover {
    color: rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.04);
}

/* ---- Gantt Chart (Production) ---- */
[data-theme="light"] .gantt-phase-label {
    color: rgba(0, 0, 0, 0.65);
}

/* ---- ERP Sidebar nav active state ---- */
[data-theme="light"] .erp-nav-btn.active {
    color: var(--accent-color);
    background: rgba(var(--accent-rgb), 0.08);
}

/* ============================================================= */
/* LIGHT MODE — Nuclear overrides for JS-generated inline styles */
/* These use !important to override hardcoded rgba(255,255,255,  */
/* ...) inline colors from dynamically-generated ERP HTML.       */
/* ============================================================= */

/* Force all text inside ERP to be dark when inline styles use white */
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.3)"],
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.35)"],
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.4)"],
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.5)"],
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.6)"],
[data-theme="light"] #erp-content [style*="rgba(255,255,255,0.7)"] {
    color: rgba(0, 0, 0, 0.7) !important;
    font-weight: 500 !important;
}

/* White text (#fff) inside ERP → black */
[data-theme="light"] #erp-content [style*="color:#fff"],
[data-theme="light"] #erp-content [style*="color: #fff"],
[data-theme="light"] #erp-content [style*="color:white"] {
    color: #000 !important;
}

/* Supplier card meta (rating, parts count, tooling, email, phone) */
[data-theme="light"] .erp-supplier-card [style*="rgba(255,255,255"] {
    color: rgba(0, 0, 0, 0.7) !important;
    font-weight: 500 !important;
}
[data-theme="light"] .erp-supplier-card [style*="color:#fff"] {
    color: #000 !important;
}

/* Supplier card */
[data-theme="light"] .erp-supplier-card {
    background: rgba(0, 0, 0, 0.025) !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
}
[data-theme="light"] .erp-supplier-card:hover {
    background: rgba(0, 0, 0, 0.05) !important;
}
[data-theme="light"] .erp-supplier-header h3 {
    color: #000 !important;
    font-weight: 600 !important;
}
[data-theme="light"] .supplier-total {
    color: #000 !important;
    font-weight: 600 !important;
}

/* Supplier notes */
[data-theme="light"] .erp-supplier-card [style*="background:rgba(255,255,255,0.03)"] {
    background: rgba(0, 0, 0, 0.04) !important;
    color: rgba(0, 0, 0, 0.6) !important;
}

/* ERP "No matches" empty state */
[data-theme="light"] #erp-content td[style*="rgba(255,255,255,0.3)"] {
    color: rgba(0, 0, 0, 0.4) !important;
}

/* Variant toggle off state */
[data-theme="light"] .erp-variant-toggle [style*="rgba(255,255,255,0.15)"] {
    color: rgba(0, 0, 0, 0.2) !important;
}

/* Gantt chart / Production timeline week labels */
[data-theme="light"] #erp-content div[style*="rgba(255,255,255,0.3)"][style*="uppercase"] {
    color: rgba(0, 0, 0, 0.55) !important;
    font-weight: 600 !important;
}

/* Workstation load percentage */
[data-theme="light"] #erp-content span[id^="ws-load-"] {
    color: rgba(0, 0, 0, 0.7) !important;
    font-weight: 500 !important;
}

/* Search count */
[data-theme="light"] .erp-search-count {
    color: rgba(0, 0, 0, 0.55) !important;
    font-weight: 600 !important;
}

/* BOM group header row fix */
[data-theme="light"] .bom-group-header td {
    color: #b30010 !important;
    font-weight: 700 !important;
}

/* Action buttons bar */
[data-theme="light"] .erp-action-btn {
    color: rgba(0, 0, 0, 0.75) !important;
    border-color: rgba(0, 0, 0, 0.14) !important;
    font-weight: 600 !important;
}
[data-theme="light"] .erp-action-btn:hover {
    background: rgba(0, 0, 0, 0.06) !important;
    color: #000 !important;
}

/* ERP search input and count */
[data-theme="light"] .erp-search-box input {
    background: rgba(0, 0, 0, 0.06) !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #000 !important;
    font-weight: 400 !important;
}
[data-theme="light"] .erp-search-box input::placeholder {
    color: rgba(0, 0, 0, 0.45) !important;
}

/* Cost segment text within the stacked bar */
[data-theme="light"] .erp-cost-segment {
    color: #fff !important;
    font-weight: 600 !important;
}

/* Checklist icons */
[data-theme="light"] .erp-checklist-icon {
    opacity: 0.9;
}

/* ERP Sub-tabs light */
[data-theme="light"] .erp-sub-tabs {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .erp-sub-tab {
    color: rgba(0, 0, 0, 0.55);
    font-weight: 600;
}
[data-theme="light"] .erp-sub-tab:hover {
    color: rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .erp-sub-tab.active {
    color: #000;
    font-weight: 700;
    background: rgba(var(--accent-rgb), 0.1);
}

/* ERP Search box light */
[data-theme="light"] .erp-search-box input {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
    color: var(--text-heading);
}
[data-theme="light"] .erp-search-box input::placeholder {
    color: rgba(0, 0, 0, 0.3);
}

/* AI Panel light */
[data-theme="light"] .erp-ai-panel {
    background: rgba(255, 255, 255, 0.95);
    border-left-color: rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .ai-close-btn {
    color: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .ai-close-btn:hover {
    color: rgba(0, 0, 0, 0.8);
}
[data-theme="light"] .user-message {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
}
[data-theme="light"] .ai-input-wrapper {
    background: rgba(0, 0, 0, 0.04);
    border-top-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] #ai-input {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--text-heading);
}

/* PDF overlay light */
[data-theme="light"] #pdf-fullpage-overlay {
    background: rgba(240, 242, 245, 0.97);
}
[data-theme="light"] #pdf-overlay-bar {
    color: rgba(0, 0, 0, 0.5);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

/* Transform toolbar light */
[data-theme="light"] .tf-btn {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.06);
    color: rgba(0, 0, 0, 0.5);
}

/* Metadata panel light */
[data-theme="light"] #metadata-panel {
    background: var(--bg-glass-strong);
}

/* Brand logo: light mode - no invert needed, we swap the file directly via JS */
[data-theme="light"] .brand-logo {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

/* Sidebar header border light */
[data-theme="light"] .action-btn-standalone {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ==================================================================== */
/* PWA STANDALONE MODE — iOS Safe Areas & Fullscreen adjustments        */
/* Edge-to-edge: the dark background fills everything.                  */
/* Only interactive elements are pushed away from status bar / home bar */
/* ==================================================================== */
@supports (padding: env(safe-area-inset-top)) {
    body.pwa-standalone {
        padding: 0 !important;
        margin: 0 !important;
    }
    body.pwa-standalone #app {
        height: calc(100vh + env(safe-area-inset-bottom, 34px));
    }
    body.pwa-standalone #erp-overlay {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ==================================================================== */
/* TOUCH DEVICE — Larger tap targets, no hover-dependent elements       */
/* ==================================================================== */
@media (pointer: coarse) {
    /* Increase touch targets to minimum 44px (Apple HIG) */
    .tree-item {
        padding: 10px 10px;
        min-height: 40px;
    }
    /* HIDE all 6 action icons by default on touch — only show on active row */
    .tree-item .eye-icon,
    .tree-item .isolate-icon,
    .tree-item .ghost-icon,
    .tree-item .edit-icon,
    .tree-item .trash-icon,
    .tree-item .transform-icon {
        display: none;
    }
    /* Show icons ONLY on the active (selected) row */
    .tree-item.active .eye-icon,
    .tree-item.active .isolate-icon,
    .tree-item.active .ghost-icon,
    .tree-item.active .edit-icon,
    .tree-item.active .trash-icon,
    .tree-item.active .transform-icon {
        display: flex;
        width: 28px;
        height: 28px;
        min-width: 28px;
    }
    .toggle-icon {
        width: 22px;
        height: 22px;
        min-width: 22px;
        font-size: 0.7rem;
        margin-right: 4px;
    }
    /* Component name: more prominent on touch */
    .item-name {
        font-size: 0.82rem;
        font-weight: 300;
    }
    .badge {
        font-size: 0.55rem;
        padding: 1px 5px;
        margin-left: 4px;
    }
    .action-btn-standalone {
        width: 48px;
        height: 48px;
    }
    .erp-nav-btn {
        padding: 14px 4px;
    }
    .segmented-control label {
        padding: 10px 6px;
        font-size: 0.6rem;
    }
    .erp-action-btn {
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
    }
    #xraySlider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }
    #xraySlider {
        height: 8px;
    }
    /* Disable hover effects on touch (they cause "sticky hover" on iOS) */
    .tree-item:hover {
        background: transparent;
        color: inherit;
    }
    .tree-item.active {
        background: var(--accent-focus);
        color: var(--accent-color);
    }
    /* ViewCube: slightly larger for fingers */
    #viewcube-canvas {
        width: 100px;
        height: 100px;
    }
    #viewcube-label {
        top: 118px;
        width: 100px;
        font-size: 0.55rem;
    }
    /* Theme toggle */
    #theme-toggle-btn {
        width: 44px;
        height: 44px;
    }
    /* BOM toggle */
    #toggleBOMBtn {
        width: 40px;
        height: 40px;
    }
    /* Controls panel compact */
    .controls-panel {
        padding: 8px 10px;
        margin-top: 10px;
        gap: 10px;
    }
    .tree-item-container {
        margin-left: 10px;
        margin-top: 2px;
    }
}

/* ==================================================================== */
/* COLLAPSIBLE LEFT SIDEBAR (tablet/touch)                              */
/* ==================================================================== */
#sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: -16px;
    width: 32px;
    height: 32px;
    background: var(--bg-glass-solid);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glass);
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s ease;
    z-index: 20;
    padding: 0;
    flex-shrink: 0;
}
#sidebar-collapse-btn:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
}
#sidebar-collapse-btn svg {
    width: 14px;
    height: 14px;
    transition: transform 0.3s ease;
}
/* Collapse: hide everything below search bar */
#left-column.collapsed .standalone-header {
    display: none;
}
#left-column.collapsed #sidebar {
    display: none;
}
#left-column.collapsed .standalone-footer {
    display: none;
}
#left-column.collapsed #sidebar-collapse-btn svg {
    transform: rotate(180deg); /* arrow points down = expand */
}
/* Hide the BOM expand button when sidebar is collapsed */
#left-column.collapsed ~ #toggleBOMBtn {
    display: none !important;
}

/* ==================================================================== */
/* TABLET LANDSCAPE (768px – 1194px wide, e.g. iPad landscape)          */
/* ==================================================================== */
@media screen and (max-width: 1194px) and (min-width: 768px) {
    #left-column {
        width: 360px;
        min-width: 200px;
        max-width: 500px;
        left: 12px;
        gap: 20px;
    }
    .standalone-header {
        padding: 10px 16px 16px 16px;
    }
    .brand-logo {
        max-width: 70px;
    }
    .subtitle {
        font-size: 0.65rem;
        letter-spacing: 0.3em;
        margin-left: 0.3em;
    }
    #metadata-panel {
        width: 320px;
        right: 12px;
        top: 110px;
        height: calc(100% - 122px);
    }
    /* ERP: narrower sidebar */
    #erp-sidebar {
        width: 60px;
        min-width: 60px;
    }
    .erp-nav-btn span {
        font-size: 0.4rem;
    }
    #erp-header {
        padding: 12px 20px;
        flex-wrap: wrap;
        gap: 10px;
    }
    .erp-header-left h1 {
        font-size: 0.95rem;
    }
    #erp-content {
        padding: 20px;
    }
    .erp-stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 12px;
    }
    /* AI Chat panel narrower */
    #erp-main.ai-open {
        padding-right: 320px;
    }
    .erp-ai-panel {
        width: 320px !important;
    }
}

/* ==================================================================== */
/* TABLET PORTRAIT (max 767px, e.g. iPad portrait or large phones)      */
/* ==================================================================== */
@media screen and (max-width: 767px) {
    /* --- 3D Viewer mode: sidebar becomes bottom sheet --- */
    #left-column {
        position: fixed;
        left: 0;
        bottom: 0;
        top: auto;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        height: 42vh;
        border-radius: 20px 20px 0 0;
        gap: 0;
        z-index: 200;
        padding: 8px;
        transition: height 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
        resize: none;
        overflow: hidden;
    }
    /* Collapsed state: minimal height, just search bar visible */
    #left-column.collapsed {
        height: auto !important;
        min-height: 0;
        padding: 4px 8px;
    }
    /* Full-height when BOM is expanded */
    #left-column.bom-mode {
        height: 85vh;
        max-width: 100% !important;
    }
    /* Collapse handle */
    #left-column::before {
        content: '';
        display: block;
        width: 36px;
        height: 5px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 3px;
        margin: 4px auto 8px;
        flex-shrink: 0;
    }
    #left-column.collapsed::before {
        margin: 2px auto 4px;
    }
    /* Compact header */
    .standalone-header {
        padding: 6px 12px 10px;
        border-radius: 16px;
    }
    .brand-logo {
        max-width: 50px;
        margin-bottom: 4px;
    }
    .subtitle {
        font-size: 0.55rem;
        letter-spacing: 0.2em;
        margin-left: 0.2em;
    }
    .standalone-search {
        padding: 8px 12px;
        border-radius: 16px;
    }
    /* Footer buttons: row at bottom */
    .standalone-footer {
        padding: 6px 8px;
        gap: 10px;
        justify-content: center;
    }
    /* Metadata panel: full-width overlay */
    #metadata-panel {
        position: fixed;
        right: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        z-index: 300;
    }
    /* ViewCube: smaller on phones */
    #viewcube-canvas {
        width: 60px;
        height: 60px;
        top: 10px;
        right: 10px;
    }
    #viewcube-label {
        top: 72px;
        right: 10px;
        width: 60px;
        font-size: 0.4rem;
    }
    /* Theme toggle */
    #theme-toggle-btn {
        top: 10px;
        left: 10px;
    }
    /* BOM Toggle button */
    #toggleBOMBtn {
        top: auto;
        bottom: 43vh;
        right: 12px;
        z-index: 210;
    }
    /* Loading overlay */
    .loader h3 {
        font-size: 1.1rem;
    }
    .loader .status-msg {
        font-size: 0.75rem;
    }

    /* --- ERP overlay in portrait --- */
    #erp-overlay.open {
        flex-direction: column;
    }
    #erp-sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        flex-direction: row;
        padding: 8px 4px;
        gap: 2px;
        border-right: none;
        border-bottom: 1px solid var(--border-glass);
        overflow-x: auto;
        overflow-y: hidden;
    }
    .erp-sidebar-brand {
        flex-direction: row;
        padding-bottom: 0;
        margin-bottom: 0;
        padding-right: 12px;
        margin-right: 4px;
        border-bottom: none;
        border-right: 1px solid rgba(255,255,255,0.06);
        min-width: fit-content;
    }
    .erp-nav-items {
        flex-direction: row;
        gap: 2px;
        overflow-x: auto;
        padding: 0 4px;
    }
    .erp-nav-btn {
        flex-direction: column;
        min-width: 56px;
        padding: 6px 4px;
    }
    .erp-nav-btn svg {
        width: 18px;
        height: 18px;
    }
    .erp-nav-btn span {
        font-size: 0.4rem;
    }
    .erp-nav-btn.active::before {
        top: auto;
        bottom: -8px;
        left: 50%;
        transform: translateX(-50%);
        width: 24px;
        height: 3px;
        border-radius: 3px 3px 0 0;
    }
    .erp-nav-btn.erp-close {
        margin-top: 0;
        margin-left: auto;
        border-top: none;
        border-left: 1px solid rgba(255,255,255,0.06);
        padding-top: 6px;
        padding-left: 8px;
    }
    /* ERP Header (portrait) */
    #erp-header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .erp-header-left h1 {
        font-size: 0.85rem;
    }
    .erp-header-right {
        flex-wrap: wrap;
        gap: 8px;
    }
    #erp-content {
        padding: 14px;
    }
    .erp-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .erp-stat-card {
        padding: 14px;
    }
    .erp-stat-value {
        font-size: 1.4rem;
    }
    /* AI Chat panel: full width on portrait */
    .erp-ai-panel {
        position: fixed !important;
        width: 100% !important;
        left: 0;
        right: 0;
        height: 60vh;
        bottom: 0;
        top: auto !important;
        border-left: none !important;
        border-top: 1px solid var(--border-glass);
        border-radius: 20px 20px 0 0;
        z-index: 16000;
    }
    #erp-main.ai-open {
        padding-right: 0;
        padding-bottom: 0;
    }
    /* Floating AI button */
    .floating-ai-btn {
        bottom: 20px !important;
        right: 14px !important;
    }
}

/* ==================================================================== */
/* SMALL PHONES (max 480px)                                             */
/* ==================================================================== */
@media screen and (max-width: 480px) {
    #left-column {
        height: 35vh;
    }
    .standalone-header {
        padding: 4px 8px 6px;
    }
    .brand-logo {
        max-width: 40px;
    }
    .subtitle {
        font-size: 0.5rem;
    }
    .erp-stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ==================================================================== */
/* PRINT — hide UI, fullscreen content                                  */
/* ==================================================================== */
@media print {
    #left-column, #viewcube-canvas, #viewcube-label, #theme-toggle-btn,
    #toggleBOMBtn, .standalone-footer, #transform-toolbar {
        display: none !important;
    }
    #viewer-container {
        position: static;
        width: 100%;
        height: 100vh;
    }
}

/* Kiosk mode: allow text selection in editable elements */
input, textarea, select, [contenteditable="true"], .erp-table td {
    -webkit-user-select: text !important;
    user-select: text !important;
}
