:root {
    --primary: #2c3e50;
    --accent: #3498db;
    --accent-hover: #2980b9;
    --danger: #e74c3c;
    --success: #27ae60;
    --bg-light: #f8f9fa;
    --text-main: #34495e;
    --text-muted: #7f8c8d;
    --border: #dcdde1;
    --radius: 8px;
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f6f8;
    color: var(--text-main);
    margin: 0;
    padding-bottom: 50px;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* -- Typography -- */
h1, h2, h3 { margin-top: 0; color: var(--primary); }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -- Cards -- */
.card, .welcome-card, .add-item-form {
    background: white;
    border-radius: var(--radius);
    padding: 25px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* -- Header -- */
header {
    background: white;
    padding: 15px 25px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

/* -- Tabs -- */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 5px;
}
.tab-btn {
    background: white;
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.tab-btn svg { width: 18px; height: 18px; fill: currentColor; }
.tab-btn:hover { background: var(--bg-light); color: var(--primary); }
.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* -- Forms -- */
.input-group, .form-row { margin-bottom: 15px; }
.form-row { display: flex; gap: 15px; flex-wrap: wrap; }
.form-col { flex: 1; min-width: 200px; }

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}
label.required::after {
    content: " *";
    color: var(--danger);
}

input[type="text"],
input[type="number"],
input[type="url"],
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    transition: border 0.2s;
    box-sizing: border-box; 
    /* Box sizing fix */
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Validation States */
.has-error label { color: var(--danger); }
.has-error input, .has-error select {
    border-color: var(--danger);
    background-color: #fdfafa;
}
.error-msg {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 4px;
    display: none;
}
.has-error .error-msg { display: block; }

/* -- Buttons -- */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.95rem;
}
.btn:hover { background-color: var(--accent-hover); text-decoration: none; }
.btn-block { width: 100%; }
.btn-secondary { background-color: #95a5a6; }
.btn-secondary:hover { background-color: #7f8c8d; }
.btn-success { background-color: var(--success); }

/* -- Color Picker -- */
.color-picker-grid {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    background: white; 
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(0,0,0,0.1);
    position: relative;
    transition: transform 0.2s;
}
.color-option:hover { transform: scale(1.1); }
.color-option.selected {
    transform: scale(1.1);
    box-shadow: 0 0 0 3px var(--accent);
    border-color: transparent;
}
/* Tick implementation for accessibility */
.color-option.selected::after {
    content: '✓';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.color-option[data-color="#ffffff"].selected::after { color: black; text-shadow: none; }


/* -- Products Grid -- */
.products-grid {
    display: grid;
    gap: 15px;
    grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 768px) {
    .products-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1200px) {
    .products-grid { grid-template-columns: repeat(4, 1fr); }
}

.product-card {
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
    border: 1px solid rgba(0,0,0,0.05);
}

/* -- Modal -- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.85); z-index: 2000;
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
    opacity: 0; transition: opacity 0.3s;
}
.modal-overlay.open { display: flex; opacity: 1; }

.modal-content {
    background: white; 
    width: 95vw; height: 90vh; max-width: 1200px;
    border-radius: 12px; overflow: hidden; position: relative;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    display: flex; flex-direction: column;
}
.modal-header {
    padding: 15px 20px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: #fff; z-index: 10;
    flex-shrink: 0;
}
.modal-body {
    flex: 1; overflow: hidden; /* Prevent body scroll */
    display: flex; 
    flex-direction: row;
}

/* Modal Layouts */
.modal-media-section {
    flex: 1;
    background: #f8f9fa;
    padding: 20px;
    overflow-y: auto; /* Internal scroll */
}
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.media-item-container {
    position: relative;
    aspect-ratio: 1/1;
    border-radius: 8px;
    overflow: hidden;
    background: #eee;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}
.media-item-container:hover { border-color: var(--accent); }
.media-item-container img, .media-item-container video {
    width: 100%; height: 100%; object-fit: cover;
}
.media-item-container.is-video::after {
    content: "▶";
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: white; font-size: 2rem;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
    pointer-events: none;
}

.modal-info-sidebar {
    width: 320px;
    padding: 20px;
    background: white;
    border-left: 1px solid var(--border);
    overflow-y: auto; /* Internal scroll */
    display: flex; flex-direction: column;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .modal-content { width: 100vw; height: 100vh; border-radius: 0; }
    .modal-body { flex-direction: column-reverse; } /* Info on bottom or top? User usually wants photos first. Let's do Photos Top (Column), Info Bottom. Actually column-reverse puts info at bottom? No, generic default is column. */
    .modal-body { flex-direction: column; } 
    .modal-media-section { height: 60%; }
    .modal-info-sidebar { width: 100%; height: 40%; border-left: none; border-top: 1px solid var(--border); }
    .media-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Gallery */
.gallery-container { text-align: center; }
.gallery-main-viewport {
    width: 100%; height: 400px; background: #f0f2f5;
    display: flex; justify-content: center; align-items: center;
    border-radius: 8px; margin-bottom: 15px; overflow: hidden;
}
.gallery-main-img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gallery-thumbs {
    display: flex; gap: 10px; overflow-x: auto; justify-content: flex-start;
    padding-bottom: 5px; scrollbar-width: thin;
}
.gallery-thumb {
    width: 70px; height: 70px; object-fit: cover; border-radius: 6px;
    cursor: pointer; opacity: 0.5; border: 2px solid transparent; transition: all 0.2s;
}
.gallery-thumb:hover, .gallery-thumb.active { opacity: 1; border-color: var(--accent); }
.product-card:hover { transform: translateY(-3px); }
.scrape-img { width: 100%; height: 200px; object-fit: cover; }
.product-details { padding: 15px; }
.product-price { font-size: 1.2rem; color: var(--danger); font-weight: bold; }
.product-meta { font-size: 0.85rem; color: var(--text-muted); margin-top: 8px; }

/* -- Empty State -- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-icon { width: 64px; height: 64px; margin-bottom: 20px; opacity: 0.3; }

/* -- Responsive -- */
@media (max-width: 768px) {
    .header { flex-direction: column; align-items: flex-start; }
    .tabs { justify-content: flex-start; }
    .form-row { flex-direction: column; gap: 0; }
    .form-col { margin-bottom: 15px; }
}

/* -- Flash Messages -- */
@keyframes highlight {
    0% { border-color: var(--success); box-shadow: 0 0 10px rgba(39, 174, 96, 0.3); }
    100% { border-color: var(--border); box-shadow: var(--shadow); }
}
.flash-highlight { animation: highlight 1.5s ease-out; }

/* -- SVGs -- */
.icon {


    border-radius: 50%;
    border-top: 3px solid var(--accent);
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* Form Modal Overrides for Mobile */
@media (max-width: 768px) {
    .form-modal-content {
        max-width: 100% !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        display: flex;
        flex-direction: column;
    }
    .form-modal-content .modal-body {
        flex: 1;
    }
}


@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    /* Tabs: Hide text, center icons */
    .tabs {
        justify-content: space-between;
    }
    
    .tabs .tab-btn, .tabs .btn {
        padding: 10px 12px;
        min-width: 0;
        justify-content: center;
        flex: 1;
    }

    .tabs .tab-btn span, .tabs .btn span {
        display: none;
    }

    .tabs .tab-btn svg, .tabs .btn svg {
        margin-right: 0 !important;
        font-size: 1.2rem;
    }
    
    /* Product Grid Mobile - 2 cols */
    .products-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .product-card .product-details {
        padding: 5px;
    }
    
    /* Modal adaptations */
    .modal-content {
        margin: 5% auto;
        width: 95%;
        flex-direction: column;
        max-height: 90vh; /* Better for mobile viewport logic */
        overflow-y: auto; /* Allow full modal scroll */
    }
    
    .modal-media-section {
        border-right: none;
        border-bottom: 1px solid var(--border);
        height: auto;
        min-height: 250px;
        max-height: 40vh;
    }
    
    .modal-info-sidebar {
        padding: 15px;
        height: auto;
    }
}

/* -- Loading Animation (Bouncy Box) -- */
@keyframes box-bounce {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-15px) rotate(-5deg); }
  50% { transform: translateY(0) rotate(0deg); }
  75% { transform: translateY(-5px) rotate(5deg); }
}

.loading-box-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
}

.funny-box {
    font-size: 3rem;
    display: inline-block;
    animation: box-bounce 1.2s infinite ease-in-out;
    margin-bottom: 15px;
}

.loading-text-styled {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: 600;
    color: var(--accent);
    margin-top: 10px;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

/* -- Responsive Fixes -- */
#select-btn-container .btn, .modal-info-sidebar .btn {
    white-space: normal;
    text-align: center;
    height: auto;
    padding: 10px;
    line-height: 1.3;
    width: 100%; /* Ensure full width on mobile */
}

/* -- Session Creation / Welcome Styles -- */
.welcome-card {
    background: white;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
    max-width: 450px !important;
    margin: 8vh auto !important;
    padding: 40px 30px !important;
    border-radius: 16px;
    text-align: center;
}

.welcome-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--accent), var(--success));
}

.welcome-card h1 {
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0.5rem;
}

.welcome-card .input-group label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-weight: 700;
}

.welcome-card input {
    background-color: #f8fafc;
    border-color: #e2e8f0;
}

.welcome-card input:focus {
    background-color: #fff;
}

