/* =============================================
   REORGANIZED CSS - STEP 1: CONSOLIDATION
   ============================================= */

/* === 1. CSS VARIABLES === */
:root {
    /* Light mode (default) */
    --bg-color: #f5f5f5;
    --text-color: #333;
    --button-text: white;
    --card-bg: white;
    --border-color: #ddd;
    --primary-color: #aa30aa;
    --primary-hover: #882088;
    --danger-color: #dc3545;
    --danger-hover: #c82333;
    --success-color: #28a745;
    --success-hover: #218838;
    --warning-color: #ffc107;
    --warning-hover: #e0a800;
    --neutral-color: #6c757d;
    --neutral-hover: #5a6268;
    --visited-color: #8a2be2; 
    --link-decoration: none; 
    
    /* Shadows */
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-heavy: 0 5px 15px rgba(0,0,0,0.3);
    --modal-bg: rgba(0,0,0,0.7);
    
    /* Form elements */
    --input-bg: white;
    --input-border: #ddd;
    
    /* UI Elements */
    --section-bg: #f8f9fa;
    --icon-bg: #f0f0f0;
    --hover-bg: #f8f9fa;
    --border-light: #eee;
    
    /* Text variations */
    --title-color: #333;
    --label-color: #555;
    --link-color: #495057;
    
    /* Status colors */
    --warning-bg: #fff3cd;
    --warning-border: #ffeaa7;
    --warning-text: #856404;
    --ok-bg: #d4edda;
    --ok-border: #c3e6cb;
    --ok-text: #155724;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Dark mode */
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --button-text: #e0e0e0;
        --card-bg: #2d2d2d;
        --border-color: #444;
        --primary-color: #882088;
        --primary-hover: #aa30aa;
        --danger-color: #d00000;
        --danger-hover: #ff5252;
        --success-color: #00a000;
        --success-hover: #37b24d;
        --warning-color: #ffd43b;
        --warning-hover: #e0a800;
        --neutral-color: #868e96;
        --neutral-hover: #747d86;
        --visited-color: #b19cd9;
        --link-decoration: none; 
        
        /* Shadows */
        --shadow: 0 1px 3px rgba(0,0,0,0.5);
        --shadow-heavy: 0 5px 15px rgba(0,0,0,0.7);
        --modal-bg: rgba(0,0,0,0.85);
        
        /* Form elements */
        --input-bg: #3d3d3d;
        --input-border: #555;
        
        /* UI Elements */
        --section-bg: #343a40;
        --icon-bg: #e0e0e0;
        --hover-bg: #343a40;
        --border-light: #444;
        
        /* Text variations */
        --title-color: #e0e0e0;
        --label-color: #b0b0b0;
        --link-color: #adb5bd;
        
        /* Status colors */
        --warning-bg: #3a2e00;
        --warning-border: #5a4a00;
        --warning-text: #ffd43b;
        --ok-bg: #0d2a1c;
        --ok-border: #1c4a32;
        --ok-text: #8affb3;
    }
}

/* === 2. BASE STYLES & RESET === */
* { box-sizing: border-box; }

body { 
    font-family: Arial, sans-serif; 
    margin: 0;
    padding: 0px 20px 5px;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1;
}

a {
    color: var(--primary-color);
    text-decoration: var(--link-decoration);
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: none;
}

a:visited {
    color: var(--visited-color);
}

.home-link {
    text-decoration: none !important;
    color: inherit;
}

.home-link:hover {
    color: inherit;
    text-decoration: none !important;
}

#detailModal a:not(.home-link):not(.clickable-computer):not(.clickable-component) {
    text-decoration: underline;
}

#detailModal a:not(.home-link):not(.clickable-computer):not(.clickable-component):hover {
    text-decoration: none;
}

h1, h2, h3, h4 {
    color: var(--title-color);
    margin: 0 0 20px 0;
}

h1 { margin-bottom: 0; }

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

.hidden {
    display: none !important;
}

/* === 3. LAYOUT & GRID === */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

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

.top-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 20px;
}

#items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px; 
    margin-top: 5px;
}

/* Detail modal layout */
.detail-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 0;
}

.detail-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 10px;
    height: 100%;
    justify-content: flex-start;
	min-width: 0;
}

.detail-right {
    flex: 1;
}

/* === 4. BUTTONS (ALL BUTTON STYLES TOGETHER) === */
/* Base button style */
button,
.standard-btn,
.logout-btn,
.admin-toggle-btn,
.new-item-btn,
.save-btn,
.cancel-btn,
.save-links-btn,
.detail-actions button {
    padding: 10px 15px;
    background: var(--primary-color);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    text-align: center;
}

button:hover,
.standard-btn:hover,
.logout-btn:hover,
.admin-toggle-btn:hover,
.new-item-btn:hover,
.save-btn:hover,
.cancel-btn:hover,
.save-links-btn:hover,
.detail-actions button:hover {
    background: var(--primary-hover);
}

/* Button variants */
.logout-btn,
.cancel-btn {
    background: var(--danger-color);
}

.logout-btn:hover,
.cancel-btn:hover {
    background: var(--danger-hover);
}

.new-item-btn,
.save-btn,
.save-links-btn {
    background: var(--success-color);
}

.new-item-btn:hover,
.save-btn:hover,
.save-links-btn:hover {
    background: var(--success-hover);
}

.admin-toggle-btn {
    background: var(--neutral-color);
}

.admin-toggle-btn:hover {
    background: var(--neutral-hover);
}

/* Small utility buttons */
.small-btn {
    padding: 0.25rem 0.5rem;
    min-width: 28px;
    height: 28px;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.danger-btn {
    background: #dc3545;
    color: white;
}

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

.success-btn {
    background: #28a745;
    color: white;
}

.success-btn:hover {
    background: #218838;
}

/* Button groups */
.button-group,
.modal-buttons,
.detail-actions,
.item-admin .actions {
    display: flex;
    gap: 5px;
    margin-top: 25px;
}

.detail-actions {
    gap: 8px;
    flex-wrap: wrap;
    margin-top: auto;
    width: 100%;
}

.detail-actions button {
    flex: 1;
    min-width: 80px;
    text-align: center;
    padding: 10px 15px;
}

/* Admin-specific buttons */
.new-item-btn { background: var(--success-color); color: white; }
.new-category-btn { background: var(--primary-color); color: white; }
.edit-category-btn { background: var(--warning-color); color: black; }
.delete-category-btn { background: var(--danger-color); color: white; }

.new-item-btn:hover { background: var(--success-hover); }
.new-category-btn:hover { background: var(--primary-hover); }
.edit-category-btn:hover { background: var(--warning-hover); }
.delete-category-btn:hover { background: var(--danger-hover); }

/* === 5. FORMS & INPUTS === */
#search,
.modal-content input,
.modal-content select,
.modal-content textarea,
.link-select,
#editForm input,
#editForm select,
#editForm textarea {
    padding: 10px 15px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
    background: var(--input-bg);
    color: var(--text-color);
    width: 100%;
}

#search { 
    max-width: 400px; 
    margin-bottom: 0; 
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 20%, transparent);
}

label {
    display: block;
    margin: 15px 0 5px;
    font-weight: bold;
    color: var(--label-color);
}

/* Form group layout - ALWAYS column (desktop and mobile) */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.form-group label {
    width: 100%;
    text-align: left;
    font-weight: bold;
    color: var(--label-color);
    margin: 0;
}

.input-wrapper {
    width: 100%;
}

/* Button inside input wrapper */
.input-wrapper .guess-year-btn-small {
    margin-top: 8px;
    align-self: flex-start; /* Align left instead of center */
}


/* === 6. MODALS (ALL MODAL STYLES TOGETHER) === */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--modal-bg);
    z-index: 1000; /* Base z-index */
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

/* Specific modal z-index values (higher numbers = more front) */
#confirmModal {
    z-index: 3000; /* Highest - confirmation dialogs */
}

#linkModal, #editModal {
    z-index: 2000; /* Middle - action modals */
}

#detailModal, #loginModal, #categoryModal {
    z-index: 1000; /* Standard modals */
}

.modal-content {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px; /* DEFAULT max-width for all modals */
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-heavy);
    cursor: default;
}

/* Specific modal widths */
#detailModal .modal-content {
    max-width: 1024px; /* Detail modal wider for photos */
    padding-bottom: 10px;
}

#linkModal .modal-content {
    max-width: 900px; /* Link modal can be wide for component lists */
    padding: 30px;
}

/* Link modal specific icons */
#linkModal .link-modal-icon,
#linkModal .mfg-icon,
#linkModal img[src$=".svg"] {
    width: 32px !important;
    height: 32px !important;
    padding: 4px !important;
    background: var(--icon-bg) !important;
    border-radius: 4px !important;
    border: 1px solid var(--border-color) !important;
}

/* Also fix the linked item info icons */
#linkModal .linked-item-info .mfg-icon {
    width: 32px !important;
    height: 32px !important;
    padding: 4px !important;
}

#editModal .modal-content {
    max-width: 600px; /* Edit forms don't need to be too wide */
}

#loginModal .modal-content {
    max-width: 400px; /* Login is simple */
    margin: auto;
    padding: 2em 2em;
}

#categoryModal .modal-content {
    max-width: 700px; /* Category forms medium width */
}

#confirmModal .modal-content {
    max-width: 400px; /* Confirm dialogs small */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    position: relative;
    padding: 5px 0 15px 0;
    margin: 0;
    min-height: auto;
}

.modal-header h2,
.modal-header h3,
.modal-header .modal-title {
    margin: 0;
    padding: 0;
    font-size: 28px;
    line-height: 1.1;
    width: 100%;
}

.modal-header .close {
    font-size: 40px;
    font-weight: 300;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
    opacity: 0.6;
    transition: all 0.2s;
    position: absolute;
    top: 0px;
    right: 0px;
    background: var(--card-bg);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.modal-header .close:hover {
    opacity: 1;
    color: var(--danger-color);
    transform: scale(1.05);
}

/* === 7. LIST ITEMS & CARDS === */

/* Sorting Controls */
.sorting-controls {
    position: relative;
    display: inline-block;
}

.sort-toggle-btn {
    padding: 10px 15px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.sort-toggle-btn:hover {
    background: var(--hover-bg);
}

.sort-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-heavy);
    z-index: 100;
    min-width: 200px;
    margin-top: 5px;
}

.sorting-controls.open .sort-dropdown {
    display: block;
}

.sort-options {
    padding: 10px;
}

.sort-header {
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--label-color);
}

.sort-field-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 10px;
}

.sort-field-btn {
    display: block;
    width: 100%;
    padding: 8px 10px;
    text-align: left;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-color);
}

.sort-field-btn:hover {
    background: var(--hover-bg);
}

.sort-field-btn.active {
    background: var(--primary-color);
    color: var(--button-text);
}

.sort-order {
    display: flex;
    gap: 5px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

.sort-order-btn {
    flex: 1;
    padding: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.sort-order-btn:hover {
    background: var(--hover-bg);
}

.sort-order-btn.active {
    background: var(--primary-color);
    color: var(--button-text);
    border-color: var(--primary-color);
}

.sort-direction {
    font-size: 16px;
    padding: 0 5px;
    display: inline-block;
}

.sort-toggle-btn {
    padding: 10px 15px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    justify-content: space-between;
}

#currentSortLabel {
    flex: 1;
    text-align: left;
}

.sort-direction {
    font-size: 14px;
    opacity: 0.8;
}

.item, .item-admin, .list-item {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    margin-bottom: 10px;
}

.item:hover, .item-admin:hover, .list-item:hover {
    background: var(--hover-bg);
    transform: translateY(-2px);
}

.list-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 15px 10px;
	transition: transform 0.2s ease, opacity 0.2s ease;
}

.list-item-content {
    display: flex;
    flex-direction: column;
    margin-top: 2px;
    align-items: center;
}

.list-item:hover {
	transform: scale(1.05);
	}
	
.item strong, .item-admin strong { 
    font-size: 1.1em; 
    display: block; 
    margin-bottom: 8px; 
}

.item strong { color: var(--primary-color); }
.item-admin strong { color: var(--success-color); }

/* ============================================
   DRAG-AND-DROP - PROPER GRID VERSION
   ============================================ */

.list-item.draggable {
    cursor: grab;
    transition: transform 0.2s ease;
    position: relative;
}

.list-item.draggable:active {
    cursor: grabbing;
}

.list-item.dragging {
    opacity: 0.3;
}

.drag-ghost {
    position: fixed !important;
    z-index: 9999 !important;
    pointer-events: none !important;
    opacity: 0.7 !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3) !important;
    transform: none !important;
}

.drag-ghost * {
    transform: none !important;
}

.drag-ghost .mfg-icon-thumbnail,
.drag-ghost img[src$=".svg"] {
    width: 226px !important;
    height: 226px !important;
    object-fit: contain !important;
    padding: 16px !important;
    background: var(--icon-bg) !important;
    border: 1px solid var(--border-color) !important;
    box-sizing: border-box !important;
}

/* Drop indicators */
.list-item.drop-before {
    border-top: 4px solid var(--success-color) !important;
    margin-top: -4px !important;
    padding-top: 4px !important;
}

.list-item.drop-after {
    border-bottom: 4px solid var(--success-color) !important;
    margin-bottom: -4px !important;
    padding-bottom: 4px !important;
}

/* Handle indicator */
.drag-handle {
    pointer-events: auto !important; /* Ensure it's touchable */
    touch-action: manipulation;
    position: absolute;
    top: 8px;
    right: 8px;
    color: var(--neutral-color);
    opacity: 0.5;
    font-size: 16px;
    cursor: grab;
    user-select: none;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 2;
}

.list-item:hover .drag-handle {
    opacity: 0.8;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .drag-handle {
        width: 44px !important;
        height: 44px !important;
        font-size: 20px !important;
        top: 4px !important;
        right: 4px !important;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Prevent text selection during drag */
.list-item.draggable {
    user-select: none;
    -webkit-user-select: none;
}

/* === 8. ICONS & IMAGES - KOMPLETT === */

/* TITELIKON - ALLTID 48px */
.detail-title-with-icon .mfg-icon {
    width: 48px !important;
    height: 48px !important;
    padding: 8px !important;
    background: var(--icon-bg);
    border-radius: 8px;
    object-fit: contain;
    box-sizing: border-box;
}

/* ALLA BILDER I DETAIL-LEFT - 512px som bas */
#detailModal .detail-left img {
    width: 512px;
    height: 512px;
    max-width: 100%;
    border-radius: 10px;
    display: block;
}

/* MFG-ikoner som HUVUDBILD (när foto saknas) */
#detailModal .detail-left img[src*="mfg/"] {
    object-fit: contain;
    padding: 40px;
    background: var(--icon-bg);
    box-sizing: border-box;
}

/* DATORFOTON som HUVUDBILD */
#detailModal .detail-left img.computer-photo {
    object-fit: cover;
    padding: 0;
}

/* Alla ÖVRIGA bilder som huvudbild (komponentfoton) */
#detailModal .detail-left img:not([src*="mfg/"]):not(.computer-photo) {
    object-fit: contain;
    padding: 0;
}

/* GRIDVY - ALLA BILDER */
#items.card-view .list-item .icon-row {
    width: 226px;
    height: 226px;
    margin: 0 auto 10px;
}

/* SVG-loggor i gridvy - contain med padding */
#items.card-view .list-item .icon-row img[src$=".svg"] {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 16px;
    background: var(--icon-bg);
    border-radius: 8px;
    box-sizing: border-box;
}

/* Alla andra bilder i gridvy (JPG, PNG) - cover */
#items.card-view .list-item .icon-row img:not([src$=".svg"]) {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

/* LISTVY - ALLA bilder i listvyn */
.list-cell-photo img {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    display: block;
}

/* Vanliga foton i listvyn */
.list-cell-photo img:not([src*="mfg/"]) {
    object-fit: cover;
}

/* MFG-loggor i listvyn */
.list-cell-photo img[src*="mfg/"] {
    object-fit: scale-down;
    padding: 6px;
    background: var(--icon-bg);
    box-sizing: border-box;
}

/* KOMPONENTLOGGOR I DATORNS DETALJVY - 48px */
#detailModal .detail-specs .component-item img.mfg-icon,
#detailModal .detail-specs .component-item img[src*="mfg/"] {
    width: 48px !important;
    height: 48px !important;
    padding: 6px !important;
    background: var(--icon-bg);
    border-radius: 6px;
    object-fit: contain;
    box-sizing: border-box;
}

/* KOMPONENTLOGGOR I DATORNS DETALJVY - 48px */
#detailModal .detail-specs .component-item img.mfg-icon,
#detailModal .detail-specs .component-item img[src*="mfg/"] {
    width: 48px !important;
    height: 48px !important;
    padding: 6px !important;
    background: var(--icon-bg);
    border-radius: 6px;
    object-fit: contain;
    box-sizing: border-box;
}

/* === 9. SPECIFIC UI COMPONENTS === */
/* Category menu */
.category-menu {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
    width: auto;
    max-width: 300px;
}

.category-menu-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    min-width: 200px;
    max-width: 300px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.category-menu-toggle:hover {
    background: var(--primary-hover);
}

.category-menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-heavy);
    z-index: 100;
    display: none;
    flex-direction: column;
    max-height: 400px;
    overflow-y: auto;
}

.category-menu-dropdown.show {
    display: flex;
}

.category-menu-dropdown button {
    padding: 10px 15px;
    background: none;
    color: var(--text-color);
    border: none;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    cursor: pointer;
    font-size: 15px;
    margin: 0;
    border-radius: 0;
}

.category-menu-dropdown button:hover {
    background: var(--hover-bg);
}

/* Language toggle */
.language-toggle {
    position: relative;
    display: inline-block;
}

.current-flag {
    font-size: 28px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.current-flag:hover {
    background: rgba(0, 0, 0, 0.1);
}

.lang-options {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    width: 140px;
    margin-top: 5px;
    padding: 6px 0;
}

.language-toggle.open .lang-options {
    display: block;
}

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-color);
    min-height: 44px;
}

.lang-option:hover {
    background: var(--hover-bg);
}

/* Field Manager Styles */
.field-manager-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.field-rows-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.field-name-input,
.field-label-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text-color);
}

.field-name-input {
    font-family: monospace;
    min-width: 120px;
}

/* Ensure add field button is clickable */
.add-field-button-container {
    margin-top: 10px;
    text-align: center;
}

#addFieldButton {
    background: var(--success-color);
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

#addFieldButton:hover {
    background: var(--success-hover);
}

#addFieldButton:active {
    transform: scale(0.98);
}

.remove-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.remove-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.remove-btn:hover:not(:disabled) {
    opacity: 1;
    background: var(--danger-color);
    color: white;
}

/* Detail specs */
.detail-specs {
    margin: 0;
    padding: 0;
    list-style: none;
}

.detail-specs li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 0;
    min-height: 48px;
    border-bottom: 1px solid var(--border-light);
    gap: 5px;
    line-height: 1 !important;
}

/* Linked computer item */
.computer-link-item {
    list-style: none;
    margin: 0 0 8px 0;
    padding: 0;
}

.clickable-computer {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    padding: 4px 0;
    border-radius: 4px;
    transition: background-color 0.2s;
    text-decoration: none;
    color: inherit;
}

.clickable-computer:hover {
    background-color: rgba(var(--primary-rgb, 170, 48, 170), 0.1);
}

.clickable-computer strong {
    min-width: 120px;
    color: var(--label-color);
    font-weight: 600;
}

.computer-link-name {
    color: var(--primary-color);
    font-weight: 500;
    flex: 1;
}

.computer-link-item:visited .computer-link-name {
    color: var(--visited-color);
}

/* Link modal components */
.link-category-section {
    background: var(--section-bg) !important;
    border-radius: 8px !important;
    padding: 12px !important;
    margin-bottom: 12px !important;
    border: 1px solid var(--border-light) !important;
}

.link-category-title {
    font-size: 20px !important;
    color: var(--title-color) !important;
    font-weight: 600 !important;
    margin: 0 0 4px 0 !important;
}

.link-subtitle {
    font-size: 16px !important;
    color: var(--label-color);
    margin: 15px 0 15px 0 !important;
    font-weight: 600;
}

.linked-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.linked-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

/* Compatibility warnings */
.compatibility-warning {
    color: var(--warning-text);
    background: var(--warning-bg);
    border: 1px solid var(--warning-border);
    padding: 5px 10px;
    border-radius: 4px;
    margin-top: 5px;
    font-size: 12px;
}

.option-incompatible:disabled {
    color: #888 !important;
    opacity: 0.6 !important;
    text-decoration: line-through !important;
}

.in-use-option {
    font-style: italic;
}

/* ============================================
   LIST VIEW STYLES
   ============================================ */

.list-header, .list-row {
    display: grid;
    gap: 10px;
    padding: 12px 15px;
    align-items: center;
}

.list-header {
    background: var(--primary-color);
    color: white;
    font-weight: bold;
    border-radius: 8px 8px 0 0;
}

.list-row {
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

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

.list-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.component-list-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

.list-cell-photo {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobil */
@media (max-width: 768px) {
    .list-header {
        display: none; /* Göm header på mobil, visa som kort istället */
    }
    
    .list-row {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 12px;
    }
    
    .list-cell {
        display: flex;
        padding: 4px 0;
        white-space: normal;
    }
    
    .list-cell:before {
        content: attr(data-label);
        font-weight: bold;
        width: 80px;
        flex-shrink: 0;
    }
}	

/* View toggle button */
.view-toggle-btn {
    padding: 10px 15px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    justify-content: space-between;
}

.view-toggle-btn:hover {
    background: var(--hover-bg);
}

.view-toggle-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-heavy);
    z-index: 100;
    min-width: 120px;
    margin-top: 5px;
}

.view-controls.open .view-toggle-dropdown {
    display: block;
}

.view-option-btn {
    display: block;
    width: 100%;
    padding: 10px 15px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-light);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.view-option-btn:last-child {
    border-bottom: none;
}

.view-option-btn:hover {
    background: var(--hover-bg);
}

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

.view-option-btn .icon {
    font-size: 18px;
    opacity: 0.8;
}

/* Detailed list view layout */
#items.list-view {
    display: block;
    margin-top: 5px;
}

#items.list-view .list-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    text-align: left;
    padding: 5px 8px;
    margin-bottom: 4px;
    width: 100%;
    max-width: none;
    transition: transform 0.2s ease, background 0.2s ease;
}

#items.list-view .list-item-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: 100%;
    gap: 8px;
    margin-top: 0;
}

/* For your compact list view */
#items.list-view .icon-row {
    width: 48px !important;
    flex: 0 0 48px !important;
}

#items.list-view .list-item .icon-row > * {
    width: 48px !important;
    height: 48px !important;
    border-radius: 4px;
    object-fit: cover;
}

#items.list-view .list-item img[src$=".svg"] {
    object-fit: contain;
    padding: 8px;
    background: var(--icon-bg);
    border: 1px solid var(--border-color);
}

#items.list-view .list-item-name {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
    color: var(--title-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#items.list-view .list-item-details {
    flex: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 14px;
    color: var(--label-color);
}

#items.list-view .detail-field {
    display: flex;
    flex-direction: column;
    min-width: 100px;
}

#items.list-view .detail-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--neutral-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

#items.list-view .detail-value {
    font-weight: 500;
    color: var(--text-color);
}

/* Card view (default) */
#items.card-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    margin-top: 5px;
}

#items.card-view .list-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 15px 10px;
    margin-bottom: 0;
}

#items.card-view .list-item-content {
    display: flex;
    flex-direction: column;
    margin-top: 2px;
    align-items: center;
}

#items.card-view .icon-row {
    margin-bottom: 10px;
}

#items.card-view .list-item .icon-row > * {
    width: 100%;
    height: 100%;
    max-width: 226px;
    max-height: 226px;
    object-fit: cover;
    border-radius: 8px;
}

#items.card-view .list-item img[src$=".svg"] {
    object-fit: contain;
    padding: 16px;
    background: var(--icon-bg);
    border: 1px solid var(--border-color);
}

#items.card-view .list-item-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--title-color);
    margin-top: 8px;
}

/* === 10. RESPONSIVE DESIGN === */
@media (max-width: 768px) {
    body { 
        font-size: 1rem;
        padding: 10px;
    }
    
    .top-controls {
        margin-bottom: 10px !important;
    }
    
    .category-menu {
        max-width: 100%;
    }
    
	/* Mobile adjustments for list view */
    #items.list-view .list-item {
        padding: 10px;
    }
    
    #items.list-view .list-item-content {
        gap: 10px;
    }
    
    #items.card-view .list-item .icon-row {
        width: 140px !important;
        height: 140px !important;
        margin: 0 auto;
    }
    
    #items.card-view .list-item .icon-row > * {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover;
        max-width: 140px;
        max-height: 140px;
    }
    
    #items.list-view .list-item-details {
        flex-direction: column;
        gap: 5px;
    }
    
    #items.list-view .detail-field {
        min-width: auto;
        flex: 1;
    }
    
	#items.card-view {
    grid-template-columns: repeat(2, 1fr);
	}

    #items {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
    }
    
    /* Images only */
    #items .list-item .icon-row > :not([src*=".svg"]) {
        object-fit: cover !important;
        border: none !important;
        padding: 0 !important;
        background: transparent !important;
    }
    
    /* SVG icons only */
    #items .list-item .icon-row > [src*=".svg"] {
        object-fit: contain !important;
        padding: 8px !important;
        border: 1px solid var(--border-color) !important;
        background: var(--icon-bg) !important;
        box-sizing: border-box !important;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95vw;
        max-width: 95vw;
        padding: 20px;
        margin: 5px auto;
        max-height: 85vh;
    }
    
    .modal-header h2 {
        font-size: 1.5rem; 
        margin-bottom: 0px;
    }
    
    /* Detail modal - mobile layout */
    #detailModal .detail-header {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    #detailModal .detail-left,
    #detailModal .detail-right {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    #detailModal .detail-left {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0;
    }
    
    #detailModal .detail-right {
        flex: 1;
        min-width: 0;
    }
    
	#detailModal .detail-left img {
        width: 300px;
        height: 300px;
        max-width: 100%;
        box-sizing: border-box; /* <-- Also here */
    }
    
    /* Adjust padding proportionally for mobile */
    #detailModal .detail-left .mfg-icon,
    #detailModal .detail-left img[src*="mfg/"] {
        padding: 12px; /* Smaller padding on mobile */
    }
    
    /* Ensure photos have no padding on mobile */
    .computer-photo {
        padding: 0 !important;
    }
    
    /* Message popup */
    #message {
        top: 70px;
        font-size: 0.9rem;
        padding: 10px 20px;
        max-width: 90vw;
    }
    
    /* Language toggle */
    .current-flag {
        font-size: 28px !important;
        padding: 12px !important;
        min-width: 60px !important;
        min-height: 60px !important;
    }
    
    /* Button groups */
    .sheet-buttons, .admin-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        padding: 4px 6px;
        font-size: 0.85rem;
    }
    
    .sheet-buttons button, 
    .admin-buttons button {
        flex: 0 0 auto;
        min-width: 80px;
        font-size: 0.9rem;
        padding: 6px 8px;
        white-space: nowrap;
    }
    .header-right button {
        min-width: 70px;
        font-size: 0.9rem;
        padding: 8px 10px;
    }
}

/* === 11. UTILITIES === */
#message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    padding: 12px 24px;
    border-radius: 6px;
    color: white;
    font-weight: bold;
    display: none;
    max-width: 80%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateX(-50%) translateY(-20px);
}

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

/* Fullscreen image viewer */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
}

.fullscreen-image {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.image-title {
    position: absolute;
    bottom: 30px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    font-size: 20px;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
    padding: 0 20px;
}

.fullscreen-close {
    position: absolute !important;
    top: 20px !important;
    right: 20px !important;
    font-size: 45px !important;
    color: white !important;
    cursor: pointer !important;
    background: rgba(0, 0, 0, 0.5) !important;
    border-radius: 50% !important;
    width: 60px !important;
    height: 60px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10000 !important;
    opacity: 0.8 !important;
    transition: opacity 0.2s !important;
    pointer-events: auto
}

.fullscreen-close:hover {
    opacity: 1 !important;
    background: rgba(0, 0, 0, 0.7) !important;
}

/* Photo upload button */
.upload-photo-btn {
    padding: 10px 15px;
    background: var(--primary-color);
    color: var(--button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    text-align: center;
}

.upload-photo-btn:hover {
    background: var(--primary-hover);
}

/* Photo mode buttons */
.photo-mode-btn {
    display: block;
    width: 100%;
    padding: 20px;
    margin: 15px 0;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    background: rgba(255, 255, 255, 0.05);
}

.bulk-mode-btn {
    border-color: rgba(156, 39, 176, 0.5);
    background: rgba(156, 39, 176, 0.1);
}

.bulk-mode-btn:hover {
    background: rgba(156, 39, 176, 0.2);
    border-color: rgba(156, 39, 176, 0.8);
    transform: translateY(-2px);
}

.single-mode-btn {
    border-color: rgba(76, 175, 80, 0.5);
    background: rgba(76, 175, 80, 0.1);
}

.single-mode-btn:hover {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.8);
    transform: translateY(-2px);
}

.mode-icon {
    font-size: 2em;
    display: block;
    margin-bottom: 10px;
}

.mode-title {
    font-size: 1.2em;
    font-weight: bold;
    color: #fff;
    display: block;
    margin-bottom: 5px;
}

.mode-desc {
    font-size: 0.9em;
    color: #aaa;
    display: block;
}

/* Form styles */
.form-select {
    width: 100%;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 4px;
    font-size: 1em;
}

.form-select option {
    background: #1a1a2e;
    color: #fff;
}
/* Photo upload in edit modal */
.photo-upload-section {
    background: rgba(255, 255, 255, 0.02);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.upload-photo-submit-btn {
    padding: 10px 20px;
    background: rgba(144, 128, 255, 0.3);
    border: 1px solid rgba(144, 128, 255, 0.5);
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.3s ease;
}

.upload-photo-submit-btn:hover:not(:disabled) {
    background: rgba(144, 128, 255, 0.5);
    border-color: rgba(144, 128, 255, 0.8);
}

.upload-photo-submit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.thumbnail-option label {
    color: #ccc;
    font-size: 0.9em;
}

.thumbnail-option input[type="checkbox"] {
    cursor: pointer;
}
/* Photo upload in edit modal */
.photo-upload-inline {
    display: flex;
    align-items: center;
    margin-top: 10px;
}

.photo-upload-label {
    display: inline-block;
    padding: 8px 15px;
    background: rgba(144, 128, 255, 0.2);
    border: 1px solid rgba(144, 128, 255, 0.4);
    border-radius: 4px;
    cursor: pointer;
    color: #9080ff;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.photo-upload-label:hover {
    background: rgba(144, 128, 255, 0.3);
    border-color: rgba(144, 128, 255, 0.6);
}

.current-photo-preview {
    margin-bottom: 10px;
}

.current-photo-preview label {
    font-size: 0.85em;
    color: #888;
    display: block;
    margin-bottom: 5px;
}
/* Klickbara modell-länkar */
.model-link {
    color: #9080ff;
    text-decoration: none;
    border-bottom: 1px dashed #9080ff;
    transition: all 0.2s ease;
}

.model-link:hover {
    color: #b0a0ff;
    border-bottom: 1px solid #b0a0ff;
}

.model-link:visited {
    color: #7060cf;
}
/* Upload progress overlay */
.upload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.upload-progress {
    background: #1a1a2e;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    color: #fff;
    min-width: 300px;
}

.upload-progress .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top: 3px solid #4CAF50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Admin buttons - force to new row */
.admin-buttons {
    clear: both;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    width: 100%;
    margin-top: 5px;
    align-items: center;
}
/* Ghostbuttons */
.detail-ghost-link {
    transition: all 0.2s ease;
}

.detail-ghost-link:hover {
    background: rgba(255, 107, 0, 0.2) !important;
    border-color: rgba(255, 107, 0, 0.5) !important;
    transform: translateY(-1px);
}
.driver-download-link {
    transition: all 0.2s ease;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255, 152, 0, 0.1);
}

.driver-download-link:hover {
    background: rgba(255, 152, 0, 0.3);
    color: #ffb366 !important;
}