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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
    color: #333;
}

/* Homepage Styles */
.homepage-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

/* MySQL setup section */
.mysql-setup-section {
    background: #f8f9fa;
    padding: 20px;
    margin: 20px 0;
    border-radius: 10px;
    border-left: 4px solid #990099;
}

.mysql-setup-section h3 {
    color: #990099;
    margin-top: 0;
}

.mysql-setup-section ol {
    text-align: left;
    margin: 15px 0;
}

.mysql-setup-section code {
    background: #e9ecef;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
}

.btn {
    background: #990099;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    margin: 5px;
    transition: background 0.3s ease;
}

.btn:hover {
    background: #7a007a;
}

.btn-mysql {
    background: #28a745;
}

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

.btn-test {
    background: #17a2b8;
}

.btn-test:hover {
    background: #138496;
}

/* Login Styles */
.login-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.login-box h2 {
    color: #990099;
    margin-bottom: 10px;
}

.login-box p {
    color: #666;
    margin-bottom: 30px;
}

.login-box .form-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-box label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.login-box input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.login-box input:focus {
    outline: none;
    border-color: #990099;
}

.btn-login {
    background: #990099;
    color: white;
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s ease;
    width: 100%;
}

.btn-login:hover {
    background: #7a007a;
}

.btn-logout {
    background: #dc3545;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 10px;
}

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

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 10px;
    border-radius: 5px;
    margin-top: 15px;
    border: 1px solid #f5c6cb;
}

.main-content {
    display: block;
}

.homepage-header {
    text-align: center;
    padding: 60px 20px 40px;
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
}

.homepage-header h1 {
    font-size: 3rem;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.homepage-header p {
    font-size: 1.3rem;
    opacity: 0.9;
}

.homepage-main {
    flex: 1;
    padding: 40px 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.action-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 60px;
}

.action-card {
    background: white;
    border-radius: 20px;
    padding: 40px 30px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(153, 0, 153, 0.1);
    border: 2px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.action-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(153, 0, 153, 0.2);
    border-color: #990099;
}

.action-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(153, 0, 153, 0.1), transparent);
    transition: left 0.5s ease;
}

.action-card:hover::before {
    left: 100%;
}

.card-icon {
    font-size: 4rem;
    color: #990099;
    margin-bottom: 20px;
    font-weight: bold;
}

.action-card h2 {
    font-size: 1.8rem;
    color: #333;
    margin-bottom: 15px;
}

.action-card p {
    color: #666;
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 20px;
}

.card-arrow {
    font-size: 2rem;
    color: #990099;
    transition: transform 0.3s ease;
}

.action-card:hover .card-arrow {
    transform: translateX(10px);
}


.homepage-footer {
    text-align: center;
    padding: 20px;
    color: #666;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

/* Page Styles */
.page-container {
    min-height: 100vh;
    background: #f8f9fa;
}

.page-header {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 2px 10px rgba(153, 0, 153, 0.2);
}

.back-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateX(-2px);
}

.page-header h1 {
    font-size: 2rem;
    margin: 0;
}

/* Add Component Page */
.add-component-main {
    padding: 30px 20px;
    max-width: 800px;
    margin: 0 auto;
}

.quick-add-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.1);
    border: 1px solid #e9ecef;
}

.quick-add-section h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.quick-add-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.quick-btn {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.quick-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.4);
}

.add-form {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.1);
    border: 1px solid #e9ecef;
}

.form-section {
    margin-bottom: 30px;
}

.form-section h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.3rem;
    padding-bottom: 10px;
    border-bottom: 2px solid #990099;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: #f8f9fa;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #990099;
    background: white;
    box-shadow: 0 0 0 3px rgba(153, 0, 153, 0.1);
}

.component-specific-fields {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid #e9ecef;
}

.component-specific-fields .form-group {
    margin-bottom: 15px;
}

.component-specific-fields .form-group:last-child {
    margin-bottom: 0;
}

.form-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

.submit-btn {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 150px;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.4);
}

.clear-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 150px;
}

.clear-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

/* Search Component Page */
.search-component-main {
    padding: 30px 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.search-section {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.1);
    border: 1px solid #e9ecef;
}

.search-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-controls input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 16px;
    background: #f8f9fa;
}

.search-controls input:focus {
    outline: none;
    border-color: #990099;
    background: white;
}

.search-controls button {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.search-controls button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.4);
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.filter-controls label {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.filter-controls select {
    padding: 8px 12px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 14px;
    background: #f8f9fa;
}

.filter-controls select:focus {
    outline: none;
    border-color: #990099;
    background: white;
}

.shelf-container {
    background: white;
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.1);
    border: 1px solid #e9ecef;
    overflow-x: auto; /* allow scroll if grid wider than screen */
}

.shelf-container h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
}

.shelf-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.5px;
    width: 100%;
    max-width: 560px; /* desktop/tablet cap */
    margin: 0 auto;
    background: #2d3748;
    padding: 4px;
    border-radius: 8px;
}

.shelf-cell {
    aspect-ratio: 1;
    background: #4a5568;
    border: 1px solid #2d3748;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    font-size: 10px;
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 25px;
}

.shelf-cell:hover {
    background: #990099;
    transform: scale(1.05);
}

.shelf-cell.occupied {
    background: #28a745;
}

.shelf-cell.occupied:hover {
    background: #218838;
}

.shelf-cell.coordinate {
    background: #2d3748;
    color: #a0aec0;
    font-size: 11px;
    cursor: default;
}

.shelf-cell.coordinate:hover {
    transform: none;
    background: #2d3748;
}

.item-tooltip {
    position: absolute;
    background: #1a202c;
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
}

.shelf-cell:hover .item-tooltip {
    opacity: 1;
}

.inventory-list {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.1);
    border: 1px solid #e9ecef;
}

.inventory-list h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5rem;
    padding-bottom: 10px;
    border-bottom: 2px solid #990099;
}

.inventory-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.inventory-controls button {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 120px;
}

.inventory-controls button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(153, 0, 153, 0.4);
}

.items-list {
    max-height: 400px;
    overflow-y: auto;
}

.component-group {
    margin-bottom: 25px;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    overflow: hidden;
}

.component-group h3 {
    background: linear-gradient(135deg, #990099 0%, #7a007a 100%);
    color: white;
    margin: 0;
    padding: 15px 20px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.component-group .item-card {
    margin: 0;
    border-radius: 0;
    border-bottom: 1px solid #e9ecef;
}

.component-group .item-card:last-child {
    border-bottom: none;
}

.component-group .item-card h4 {
    color: #2d3748;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.item-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.item-card:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.item-info h3, .item-info h4 {
    color: #2d3748;
    margin-bottom: 5px;
}

.item-info p {
    color: #718096;
    font-size: 14px;
}

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

.item-actions button {
    padding: 8px 16px;
    font-size: 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.edit-btn {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%);
    color: white;
}

.delete-btn {
    background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
    color: white;
}

.move-btn {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
}

.item-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.no-items {
    text-align: center;
    color: #718096;
    font-style: italic;
    padding: 40px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .homepage-header h1 {
        font-size: 2rem;
    }
    
    .homepage-header p {
        font-size: 1rem;
    }
    
    .action-cards {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .action-card {
        padding: 30px 20px;
    }
    
    .card-icon {
        font-size: 3rem;
    }
    
    
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    .search-controls {
        flex-direction: column;
    }
    
    .filter-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .shelf-grid {
        width: 100%;
        max-width: calc(100vw - 28px); /* tighter to container */
        gap: 1px;
        padding: 2px;
        box-sizing: border-box;
    }
    
    .shelf-cell {
        font-size: 8px;
        min-height: 22px;
    }
    
    .inventory-controls {
        flex-direction: column;
    }
    
    .inventory-controls button {
        width: 100%;
        margin-bottom: 5px;
    }
    
    .item-card {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .item-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .submit-btn, .clear-btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .homepage-main {
        padding: 20px 10px;
    }
    
    .action-card {
        padding: 25px 15px;
    }
    
    .card-icon {
        font-size: 2.5rem;
    }
    
    /* Tighter shelf layout on small phones */
    .shelf-container {
        padding: 12px;
    }
    .shelf-container h2 {
        font-size: 1.25rem;
        margin-bottom: 12px;
    }
    .shelf-grid {
        max-width: 86vw;   /* shrink overall grid width */
        gap: 0.5px;
        padding: 2px;
        border-radius: 6px;
    }
    .shelf-cell {
        font-size: 7px;
        min-height: 18px;
    }
    
    .item-actions {
        grid-template-columns: 1fr;
        gap: 5px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .shelf-cell {
        min-height: 32px; /* better fit on small screens while still tappable */
    }
    
    button {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    .quick-btn {
        min-height: 40px;
    }
    
    .item-actions button {
        min-height: 44px;
    }
    
    .form-group input, .form-group select {
        min-height: 44px;
        padding: 12px;
    }
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 12px 12px 0 0;
}

.modal-header h3 {
    margin: 0;
    color: #333;
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: #e0e0e0;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    border-radius: 0 0 12px 12px;
}

/* Edit form styles */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #990099;
    box-shadow: 0 0 0 3px rgba(153, 0, 153, 0.1);
}

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

/* Specification fields */
.spec-field {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.spec-field .spec-key,
.spec-field .spec-value {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.spec-field button {
    padding: 8px 12px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background-color 0.2s;
}

.spec-field button:hover {
    background: #d32f2f;
}

#editSpecs button[onclick*="addSpecField"] {
    background: #990099;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    align-self: flex-start;
}

#editSpecs button[onclick*="addSpecField"]:hover {
    background: #7a007a;
}

/* Mobile modal adjustments */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 10px;
    }
    
    .modal-content {
        max-height: 95vh;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }
    
    .spec-field {
        flex-direction: column;
        align-items: stretch;
    }
    
    .spec-field .spec-key,
    .spec-field .spec-value {
        margin-bottom: 8px;
    }
}