/* Reset and base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2c3e50;
    --primary-light: #3498db;
    --accent: #e74c3c;
    --bg: #f8f9fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #dee2e6;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Alert banner */
#alert-banner {
    background: #e74c3c;
    color: white;
    padding: 0;
}
.alert-item {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.6rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}
.alert-item strong { white-space: nowrap; }
.alert-dismiss {
    background: none;
    border: none;
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 0.3rem;
    opacity: 0.8;
}
.alert-dismiss:hover { opacity: 1; }
.alert-download {
    color: white;
    text-decoration: none;
    background: rgba(255,255,255,0.2);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    margin-left: auto;
}
.alert-download:hover { background: rgba(255,255,255,0.35); }

/* Navbar */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.nav-brand {
    color: white;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 700;
}
.nav-links a {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    margin-left: 1.5rem;
    font-size: 0.95rem;
}
.nav-links a:hover, .nav-links a.active {
    color: white;
}
.nav-user {
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
    margin-left: 1.5rem;
}
.nav-logout {
    color: rgba(255,255,255,0.6) !important;
    font-size: 0.85rem;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Search section */
.search-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.search-form { margin-bottom: 1rem; }
.search-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.search-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.search-field input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s;
}
.search-field input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-light);
}
.search-field-grow { flex: 1; min-width: 200px; }
.search-field-btn { flex-shrink: 0; }

.color-input-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.color-input-group input[type="color"] {
    width: 44px;
    height: 40px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 2px;
}
.color-input-group input[type="text"] {
    width: 160px;
}

/* Buttons */
.btn-primary {
    background: var(--primary-light);
    color: white;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    text-decoration: none;
    display: inline-block;
}
.btn-primary:hover { background: #2980b9; }
.btn-primary:disabled { background: #bdc3c7; cursor: not-allowed; }
.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--border);
    padding: 0.55rem 1.5rem;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--primary-light); color: var(--primary-light); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-small:hover { color: var(--accent); border-color: var(--accent); }

/* Filter sections */
.filters-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 0.75rem 0;
}
.filter-section {
    min-width: 0;
}
.filter-section label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
}
/* Colour group filter */
.color-group-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: white;
}
.color-group-chip {
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.15s;
}
.color-group-chip:hover { opacity: 0.85; transform: scale(1.03); }
.color-group-chip.selected {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* Group badges on cards */
.group-badges {
    position: absolute;
    bottom: 6px;
    left: 6px;
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}
.group-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    background: rgba(255,255,255,0.9);
    color: #333;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.color-filter-grid,
.design-filter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: white;
    max-height: 150px;
    overflow-y: auto;
}
.color-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: 20px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}
.color-chip:hover {
    opacity: 0.85;
    transform: scale(1.03);
}
.color-chip.selected {
    outline: 3px solid var(--primary);
    outline-offset: 1px;
}
.color-chip-label {
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.design-chip {
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.75rem;
    background: white;
    transition: all 0.15s;
    white-space: nowrap;
}
.design-chip:hover { border-color: var(--primary-light); }
.design-chip.selected {
    border-color: var(--primary);
    background: #e8f4fd;
    font-weight: 600;
}
.multi-select {
    width: 100%;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    padding: 0.3rem;
}
.multi-select option { padding: 0.25rem 0.4rem; }
.multi-select option:checked { background: var(--primary-light); color: white; }
.filter-select {
    width: 100%;
    padding: 0.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: white;
}

/* Quick filter chips */
.quick-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.filter-label {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 600;
}
.chip {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.chip:hover, .chip.active {
    background: var(--primary-light);
    color: white;
    border-color: var(--primary-light);
}

/* Results */
.results-info {
    margin-bottom: 1rem;
    font-size: 0.95rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

/* Image card */
.image-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.image-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.card-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: #eee;
}
.card-info {
    padding: 0.75rem;
}
.card-filename {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.4rem;
}
.card-colors {
    display: flex;
    gap: 4px;
    margin-bottom: 0.4rem;
}
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}
.card-description {
    font-size: 0.8rem;
    color: var(--text-light);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Card extras */
.card-image-wrapper {
    position: relative;
}
.video-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}
.ttw-badge {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(255,255,255,0.9);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ttw-color-badge {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    display: inline-block;
}
.card-design {
    font-size: 0.8rem;
    color: var(--primary-light);
    font-weight: 600;
    margin-bottom: 0.2rem;
}
.card-blanket-name {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-light);
    margin-bottom: 0.3rem;
}
.card-date {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 0.2rem;
}

/* Bulk edit */
.bulk-toolbar {
    background: #2c3e50;
    color: white;
    padding: 0.6rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.bulk-toolbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.bulk-toolbar-inner span { font-weight: 600; font-size: 0.9rem; }
.bulk-select {
    padding: 0.35rem 0.5rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.15);
    color: white;
    font-size: 0.85rem;
}
.bulk-select option { color: #2c3e50; background: white; }
.bulk-btn {
    padding: 0.35rem 0.8rem !important;
    font-size: 0.85rem !important;
    border-radius: 6px !important;
    width: auto !important;
}
#bulk-cancel { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3); color: white; }
#bulk-cancel:hover { background: rgba(255,255,255,0.3); }
#bulk-select-all { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.3); color: white; }
#bulk-select-all:hover { background: rgba(255,255,255,0.3); }

.image-card.select-mode { cursor: pointer; }
.image-card.select-mode:hover { outline: 2px solid #3498db; }
.image-card.selected-card { outline: 3px solid #3498db; outline-offset: -3px; }
.image-card.selected-card::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    background: #3498db;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    z-index: 5;
}
.image-card { position: relative; }

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-content {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--radius);
    max-width: 900px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-light);
    z-index: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}
.modal-close:hover { background: var(--bg); }
.modal-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
.modal-image-container {
    padding: 1rem;
}
.modal-image-container img {
    width: 100%;
    border-radius: var(--radius);
}
.modal-details {
    padding: 1.5rem 1.5rem 1.5rem 0;
}
.modal-details h3 {
    word-break: break-all;
}
/* Modal edit section */
.modal-edit-section {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}
.modal-edit-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.modal-edit-row:last-child { margin-bottom: 0; }
.modal-edit-row label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 100px;
    flex-shrink: 0;
}
.modal-edit-select, .modal-edit-input {
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.85rem;
    background: white;
}
.modal-edit-select:focus, .modal-edit-input:focus {
    outline: none;
    border-color: #3498db;
}

.modal-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}
.modal-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--bg);
}
.modal-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.modal-value {
    font-size: 0.9rem;
    text-align: right;
}
.modal-colors {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.modal-colors .color-swatch {
    width: 32px;
    height: 32px;
}
.modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.modal-tags .tag {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
}

/* Admin */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.5rem;
}
.admin-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.admin-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--bg);
}
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--bg);
}
.status-ok { color: #27ae60; font-weight: 600; }
.status-warn { color: #f39c12; font-weight: 600; }
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 1rem;
}
.progress-fill {
    height: 100%;
    background: var(--primary-light);
    transition: width 0.5s ease;
}
.progress-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}
.activity-log {
    max-height: 300px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 0.85rem;
}
.activity-log p { padding: 0.3rem 0; border-bottom: 1px solid var(--bg); }
.log-empty { color: var(--text-light); font-style: italic; }

code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Footer */
.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    color: #bdc3c7;
    font-size: 0.75rem;
}

/* Responsive */
@media (max-width: 768px) {
    .search-row { flex-direction: column; }
    .filters-two-col { grid-template-columns: 1fr; }
    .modal-body { grid-template-columns: 1fr; }
    .modal-details { padding: 0 1.5rem 1.5rem; }
    .results-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
