/**
 * BOM Manager - Centralized Design System
 * Modern, dark theme with glass-morphism effects
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0f1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1e293b;
    --bg-card: rgba(30, 41, 59, 0.8);
    --bg-hover: rgba(59, 130, 246, 0.1);

    /* Accent Colors */
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-muted: rgba(59, 130, 246, 0.2);

    /* Semantic Colors */
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #06b6d4;

    /* Text Colors */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    /* Border & Shadows */
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

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

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Z-index layers */
    --z-base: 1;
    --z-dropdown: 100;
    --z-modal: 1000;
    --z-toast: 2000;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;

    /* Subtle gradient background */
    background-image:
        radial-gradient(ellipse at top left, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(139, 92, 246, 0.05) 0%, transparent 50%);
}

/* ============================================
   Typography
   ============================================ */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

h4 {
    font-size: 1.125rem;
}

p {
    color: var(--text-secondary);
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

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

.invisible {
    visibility: hidden;
}

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

.text-right {
    text-align: right;
}

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

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.gap-sm {
    gap: var(--space-sm);
}

.gap-md {
    gap: var(--space-md);
}

.gap-lg {
    gap: var(--space-lg);
}

/* ============================================
   Layout Components
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: var(--z-dropdown);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.logo i {
    color: var(--accent);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

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

.search-container i {
    position: absolute;
    left: var(--space-sm);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

.search-input {
    width: 100%;
    padding: var(--space-sm) var(--space-sm) var(--space-sm) 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

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

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

/* User Menu */
.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.user-menu:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

/* ============================================
   Toolbar
   ============================================ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn i {
    width: 16px;
    height: 16px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

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

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-excel {
    background: #217346;
    color: white;
    border: none;
}

.btn-excel:hover {
    background: #1a5c38;
    box-shadow: 0 0 12px rgba(33, 115, 70, 0.4);
}

.btn-pdf {
    background: #dc2626;
    color: white;
    border: none;
}

.btn-pdf:hover {
    background: #b91c1c;
    box-shadow: 0 0 12px rgba(220, 38, 38, 0.4);
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8125rem;
}

.btn-icon {
    padding: var(--space-sm);
}

/* Action buttons in rows */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

.action-btn i {
    width: 16px;
    height: 16px;
}

/* ============================================
   BOM Tree
   ============================================ */
.main-content {
    flex: 1;
    padding: var(--space-xl);
    overflow-y: auto;
}

.bom-container {
    max-width: 1400px;
    margin: 0 auto;
}

.bom-header {
    display: grid;
    grid-template-columns: 1fr 130px 80px 90px 90px 100px 100px;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    align-items: center;
}

.bom-header span:nth-child(2),
.bom-header span:nth-child(3) {
    text-align: center;
}

.bom-header span:nth-child(4),
.bom-header span:nth-child(5),
.bom-header span:nth-child(6) {
    text-align: right;
}

.bom-header span:nth-child(7) {
    text-align: center;
}

#bomTree {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    backdrop-filter: blur(12px);
}

/* BOM Row */
.bom-row {
    border-bottom: 1px solid var(--border);
}

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

.bom-row-content {
    display: grid;
    grid-template-columns: 1fr 130px 80px 90px 90px 100px 100px;
    gap: var(--space-md);
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    transition: background var(--transition-fast);
}

.bom-row-content:hover {
    background: var(--bg-hover);
}

.bom-row-content.editable {
    cursor: pointer;
}

.bom-row-content.editable:hover {
    background: rgba(59, 130, 246, 0.08);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
}

.bom-row-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    min-width: 0;
}

/* Row Thumbnails */
.bom-thumbnail {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    overflow: visible;
    flex-shrink: 0;
    border: 2px solid var(--border);
    transition: all var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    z-index: 1;
}

.bom-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: calc(var(--radius-md) - 2px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bom-thumbnail:hover {
    z-index: 100;
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.bom-thumbnail:hover img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    object-fit: contain;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

a.bom-thumbnail {
    cursor: pointer;
}

.thumbnail-link-icon {
    position: absolute;
    bottom: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: var(--radius-full);
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 101;
}

.thumbnail-link-icon i {
    color: white;
    font-size: 0.625rem;
}

a.bom-thumbnail:hover .thumbnail-link-icon {
    opacity: 1;
}

/* Category and Version badges - centered */
.bom-category-cell,
.bom-version-cell {
    display: flex;
    justify-content: center;
}

/* Depth indentation */
.depth-0 .bom-row-left {
    padding-left: 0;
}

.depth-1 .bom-row-left {
    padding-left: 24px;
}

.depth-2 .bom-row-left {
    padding-left: 48px;
}

.depth-3 .bom-row-left {
    padding-left: 72px;
}

.depth-4 .bom-row-left {
    padding-left: 96px;
}

.depth-5 .bom-row-left {
    padding-left: 120px;
}

/* Expand button */
.expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.expand-btn:hover {
    background: var(--accent-muted);
    color: var(--accent);
}

.expand-btn i {
    width: 16px;
    height: 16px;
}

/* BOM Info */
.bom-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.bom-name {
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.bom-name:hover {
    color: var(--accent);
}

.bom-description {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

/* Category Badge */
.category-badge {
    display: inline-flex;
    padding: 2px 8px;
    font-size: 0.6875rem;
    font-weight: 500;
    background: var(--accent-muted);
    color: var(--accent);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

/* Version Badge */
.version-badge {
    display: inline-flex;
    padding: 2px 8px;
    font-size: 0.6875rem;
    font-weight: 500;
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.version-badge.base {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
}

/* Quantity & Price */
.bom-qty,
.bom-price,
.bom-total {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    text-align: right;
    white-space: nowrap;
}

.bom-qty {
    display: flex;
    gap: 4px;
    color: var(--text-secondary);
    min-width: 80px;
    justify-content: flex-end;
}

.qty-value {
    color: var(--text-primary);
}

.qty-unit {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.bom-price {
    color: var(--text-secondary);
    min-width: 90px;
}

.bom-total {
    color: var(--text-primary);
    font-weight: 600;
    min-width: 100px;
}

.bom-total.has-children {
    color: var(--accent);
}

/* Actions */
.bom-actions {
    display: flex;
    justify-content: center;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.bom-row-content:hover .bom-actions {
    opacity: 1;
}

/* Children container */
.bom-children {
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

/* ============================================
   Inline Edit
   ============================================ */
.edit-inline {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.edit-input {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.edit-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-muted);
}

.edit-input.small {
    width: 80px;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
    color: var(--text-muted);
}

.empty-state i {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: var(--space-sm);
    color: var(--text-secondary);
}

/* ============================================
   Footer
   ============================================ */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.footer-stats {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.stat-value {
    font-weight: 600;
    color: var(--text-primary);
}

.grand-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--success);
    font-family: var(--font-mono);
}

/* ============================================
   Modals
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform var(--transition-normal);
}

.modal.active .modal-content {
    transform: translateY(0) scale(1);
}

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

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    max-height: 60vh;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border);
}

/* ============================================
   Form Elements
   ============================================ */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

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

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.form-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* ============================================
   Image Paste Zone
   ============================================ */
.image-paste-zone {
    position: relative;
    width: 100%;
    min-height: 120px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-paste-zone:hover,
.image-paste-zone:focus {
    border-color: var(--accent);
    background: var(--accent-muted);
    outline: none;
}

.image-paste-zone:focus {
    box-shadow: 0 0 0 3px var(--accent-muted);
}

.image-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-muted);
    pointer-events: none;
}

.image-placeholder i {
    font-size: 2rem;
    opacity: 0.6;
}

.image-placeholder span {
    font-size: 0.8125rem;
}

.image-preview {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.image-remove-btn {
    position: absolute;
    top: var(--space-xs);
    right: var(--space-xs);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-full);
    background: var(--danger);
    color: white;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.image-paste-zone:hover .image-remove-btn:not(.hidden) {
    opacity: 1;
}

.image-remove-btn:hover {
    background: #dc2626;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    z-index: var(--z-toast);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: slideIn var(--transition-normal) ease;
}

.toast i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast-success {
    border-left: 3px solid var(--success);
}

.toast-success i {
    color: var(--success);
}

.toast-error {
    border-left: 3px solid var(--danger);
}

.toast-error i {
    color: var(--danger);
}

.toast-warning {
    border-left: 3px solid var(--warning);
}

.toast-warning i {
    color: var(--warning);
}

.toast-info {
    border-left: 3px solid var(--info);
}

.toast-info i {
    color: var(--info);
}

.toast-exit {
    animation: slideOut var(--transition-normal) ease forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* ============================================
   Login View
   ============================================ */
.login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-xl);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: var(--space-2xl);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(12px);
    box-shadow: var(--shadow-lg);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xl);
    font-size: 1.5rem;
    font-weight: 700;
}

.login-logo i {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.login-title {
    text-align: center;
    margin-bottom: var(--space-lg);
    color: var(--text-secondary);
    font-weight: 400;
}

.login-form .btn {
    width: 100%;
    margin-top: var(--space-md);
}

.login-hint {
    margin-top: var(--space-lg);
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.login-hint code {
    display: block;
    margin-top: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    color: var(--accent);
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 15, 26, 0.9);
    z-index: var(--z-modal);
    transition: opacity var(--transition-normal);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1024px) {
    .bom-header {
        display: none;
    }

    .bom-row-right {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .bom-description {
        max-width: 200px;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 13px;
    }

    .app-header {
        flex-wrap: wrap;
        gap: var(--space-md);
        padding: var(--space-md);
    }

    .search-container {
        width: 100%;
        order: 3;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: var(--space-sm);
        padding: var(--space-md);
    }

    .main-content {
        padding: var(--space-md);
    }

    .bom-row-content {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .bom-row-right {
        width: 100%;
        justify-content: space-between;
    }

    .bom-actions {
        opacity: 1;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   Role-Based Visibility
   ============================================ */
.admin-only,
.editor-only {
    display: none !important;
}

body.role-admin .admin-only {
    display: flex !important;
}

body.role-admin .editor-only,
body.role-editor .editor-only {
    display: flex !important;
}

/* ============================================
   Dashboard Layout
   ============================================ */
.dashboard-view {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.dashboard-main {
    flex: 1;
    padding: var(--space-xl);
    overflow-y: auto;
}

#dashboardContent {
    max-width: 1200px;
    margin: 0 auto;
}

.dashboard-loading {
    display: flex;
    justify-content: center;
    padding: var(--space-2xl);
}

/* Section Headers */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.section-header h2 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1.25rem;
    color: var(--text-primary);
}

.section-header h2 i {
    color: var(--accent);
}

/* ============================================
   Quick Access Card
   ============================================ */
.quick-access-section {
    margin-bottom: var(--space-xl);
}

.quick-access-card {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: linear-gradient(135deg, var(--accent-muted) 0%, var(--bg-card) 100%);
    border: 1px solid var(--accent);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quick-access-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.quick-access-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: var(--radius-md);
    color: white;
    font-size: 1.5rem;
}

.quick-access-content {
    flex: 1;
}

.quick-access-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-access-title {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.quick-access-card>i {
    color: var(--accent);
    font-size: 1.25rem;
}

/* ============================================
   BOM List Section
   ============================================ */
.bom-list-section {
    margin-bottom: var(--space-xl);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
}

/* BOM Cards */
.bom-card {
    display: flex;
    flex-direction: column;
    padding: var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
    backdrop-filter: blur(12px);
}

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

.bom-card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.bom-card-header i {
    color: var(--accent);
    font-size: 1.25rem;
}

.bom-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bom-card-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: var(--space-sm);
}

.bom-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
}

.bom-card-date {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.access-badge {
    display: inline-flex;
    padding: 2px 8px;
    font-size: 0.6875rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    text-transform: capitalize;
}

.access-badge.editor {
    background: var(--accent-muted);
    color: var(--accent);
}

.access-badge.viewer {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

/* ============================================
   Admin Panel
   ============================================ */
.admin-panel {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
}

/* Admin Grid Layout */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-lg);
    margin-top: var(--space-lg);
}

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

.admin-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(12px);
    overflow: hidden;
}

.admin-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.admin-card-header:hover {
    background: var(--bg-hover);
}

.admin-card-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.admin-card-toggle .toggle-icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.admin-card:not(.collapsed) .admin-card-toggle .toggle-icon {
    transform: rotate(90deg);
}

.admin-card-header h3 {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.admin-card-header h3 i {
    color: var(--accent);
}

.admin-card-body {
    padding: var(--space-md);
    max-height: 400px;
    overflow-y: auto;
}

.admin-card.collapsed .admin-card-body {
    display: none;
}

.admin-card.collapsed .admin-card-header {
    border-bottom: none;
}

/* Admin List */
.admin-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.admin-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

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

.admin-list-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.admin-list-title {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.admin-list-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-md);
}

.users-table th,
.users-table td {
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border);
}

.users-table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-tertiary);
}

.users-table th:first-child {
    border-radius: var(--radius-md) 0 0 0;
}

.users-table th:last-child {
    border-radius: 0 var(--radius-md) 0 0;
}

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

.role-badge {
    display: inline-flex;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    text-transform: capitalize;
}

.role-badge.admin {
    background: var(--danger-bg);
    color: var(--danger);
}

.role-badge.editor {
    background: var(--accent-muted);
    color: var(--accent);
}

.role-badge.viewer {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

/* Role Select Dropdown */
.role-select {
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.role-select:hover:not(:disabled) {
    border-color: var(--accent);
}

.role-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.role-select.admin {
    border-color: var(--danger);
    background: var(--danger-bg);
}

.role-select.editor {
    border-color: var(--accent);
    background: var(--accent-muted);
}

.role-select.viewer {
    border-color: var(--border);
}

/* Admin Info Box */
.admin-info-box {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--accent-muted);
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
}

.admin-info-box i {
    color: var(--accent);
    font-size: 1.25rem;
    flex-shrink: 0;
}

.admin-info-box p {
    color: var(--text-primary);
    margin-bottom: 4px;
}

/* ============================================
   BOM Access Modal
   ============================================ */
.bom-access-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: var(--space-md);
}

.add-user-form {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.add-user-form .form-input {
    flex: 1;
}

.bom-access-list {
    max-height: 300px;
    overflow-y: auto;
}

.access-users-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.access-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.access-user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.access-user-name {
    font-weight: 500;
}

/* BOM Card Header Flex */
.bom-card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.bom-card-header h3 {
    flex: 1;
}

.bom-access-btn {
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.bom-card:hover .bom-access-btn {
    opacity: 1;
}

/* Button Utilities */
.btn-sm {
    padding: 4px 8px;
    font-size: 0.8125rem;
}

.btn-danger-text {
    color: var(--danger);
}

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

/* ============================================
   Version Panel (per-BOM groups)
   ============================================ */
.version-bom-group {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border);
}

.version-bom-group:last-child {
    border-bottom: none;
}

.version-bom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: var(--space-xs);
    margin: calc(-1 * var(--space-xs));
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.version-bom-header:hover {
    background: var(--bg-hover);
}

.version-bom-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toggle-icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.version-bom-group:not(.collapsed) .toggle-icon {
    transform: rotate(90deg);
}

.version-bom-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.version-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-full);
}

.version-bom-content {
    margin-top: var(--space-sm);
    padding-left: var(--space-lg);
}

.version-bom-group.collapsed .version-bom-content {
    display: none;
}

.version-empty {
    font-size: 0.8125rem;
    margin: 0;
}

/* ============================================
   Header Layout Updates
   ============================================ */
.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* ============================================
   Version Filter
   ============================================ */
.version-filter-container {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.filter-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.version-select {
    min-width: 150px;
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.version-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-muted);
}

/* ============================================
   Print Styles
   ============================================ */
@media print {

    .app-header,
    .toolbar,
    .app-footer,
    .bom-actions,
    .modal,
    .toast-container {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .bom-row {
        break-inside: avoid;
    }
}