/* ========================================
   CSS Variables & Reset
   ======================================== */
:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-success: #16a34a;
    --color-success-light: #dcfce7;
    --color-success-dark: #166534;
    --color-error: #dc2626;
    --color-error-light: #fee2e2;
    --color-error-dark: #991b1b;
    --color-warning: #f59e0b;
    --color-warning-light: #fef3c7;
    --color-warning-dark: #92400e;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --color-hover: #f1f5f9;
    --radius: 8px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Layout & Container
   ======================================== */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

.main-content {
    flex: 1;
    padding-top: var(--spacing-xl);
    padding-bottom: var(--spacing-2xl);
}

/* ========================================
   Header
   ======================================== */
.header {
    background: var(--color-surface);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    gap: var(--spacing-md);
}

.header-title {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 20px;
    font-weight: 600;
    color: var(--color-text);
}

.header-icon {
    font-size: 24px;
}

/* ========================================
   Section
   ======================================== */
.section {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    box-shadow: var(--shadow);
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--spacing-md);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    gap: var(--spacing-md);
}

.section-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.section-hint {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
    font-style: italic;
}

/* ========================================
   Section Groups
   ======================================== */
.section-group {
    margin-bottom: var(--spacing-2xl);
}

.section-group-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-sm);
    border-bottom: 2px solid var(--color-primary);
}

.header-buttons {
    display: flex;
    gap: var(--spacing-sm);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--color-hover);
    border-color: var(--color-primary);
}

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

.btn-danger:hover:not(:disabled) {
    background: #b91c1c;
    box-shadow: var(--shadow-md);
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    font-size: 16px;
}

/* ========================================
   Inputs & Forms
   ======================================== */
.input,
.textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s ease;
    background: var(--color-surface);
    color: var(--color-text);
}

.input:focus,
.textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.input-group {
    display: flex;
    gap: var(--spacing-sm);
}

.input-group .input {
    flex: 1;
}

/* ========================================
   Status Messages
   ======================================== */
.status-message {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-top: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.status-message.hidden {
    display: none;
}

.status-success {
    background: var(--color-success-light);
    color: var(--color-success-dark);
}

.status-error {
    background: var(--color-error-light);
    color: var(--color-error-dark);
}

.status-loading {
    background: var(--color-warning-light);
    color: var(--color-warning-dark);
}

/* ========================================
   Badge
   ======================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    background: var(--color-hover);
    color: var(--color-text);
}

.badge-info {
    background: #dbeafe;
    color: #1e40af;
}

/* ========================================
   Batch Controls
   ======================================== */
.batch-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}

.progress-info {
    flex: 1;
    font-size: 14px;
    color: var(--color-text-muted);
}

.progress-bar {
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: var(--spacing-xs);
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* ========================================
   Batch Results
   ======================================== */
.batch-results {
    margin-top: var(--spacing-md);
}

.batch-summary {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--color-hover);
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
}

.batch-summary .success {
    color: var(--color-success);
}

.batch-summary .error {
    color: var(--color-error);
}

.failed-details {
    margin-top: var(--spacing-sm);
    padding: var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.failed-details summary {
    cursor: pointer;
    font-weight: 500;
    color: var(--color-error);
    user-select: none;
}

.failed-details ul {
    margin-top: var(--spacing-sm);
    padding-left: var(--spacing-lg);
    font-size: 13px;
    color: var(--color-text-muted);
}

/* ========================================
   Search Bar
   ======================================== */
.search-bar {
    margin-bottom: var(--spacing-md);
}

/* ========================================
   Table
   ======================================== */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    background: var(--color-hover);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.data-table tbody tr {
    transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
    background: var(--color-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table .itemcode,
.data-table .modelcode,
.data-table .modelid {
    font-family: 'Courier New', monospace;
    font-weight: 500;
    color: var(--color-primary);
}

.data-table .itemname,
.data-table .modelname {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table .ean {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--color-text-muted);
}

.data-table .actions {
    display: flex;
    gap: var(--spacing-xs);
    white-space: nowrap;
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
    text-align: center;
    padding: var(--spacing-2xl);
    color: var(--color-text-muted);
}

.empty-state p {
    font-size: 16px;
}

.empty-state .hint {
    font-size: 14px;
    margin-top: var(--spacing-xs);
}

.empty-state.hidden {
    display: none;
}

/* ========================================
   Image Preview
   ======================================== */
.image-preview.hidden {
    display: none;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--spacing-md);
}

.image-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
}

.image-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.image-card .image-number {
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-hover);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.image-card a {
    display: block;
    position: relative;
    background: #f8fafc;
}

.image-card img {
    width: 100%;
    height: 180px;
    object-fit: contain;
    display: block;
    transition: transform 0.3s ease;
}

.image-card a:hover img {
    transform: scale(1.02);
}

.image-card .image-url {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 11px;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-top: 1px solid var(--color-border);
}

/* ========================================
   Spinner
   ======================================== */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   Footer
   ======================================== */
.footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--spacing-lg) 0;
    margin-top: auto;
}

.footer p {
    text-align: center;
    font-size: 14px;
    color: var(--color-text-muted);
}

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

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 1024px) {
    .image-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 var(--spacing-md);
    }

    .header-content {
        flex-direction: column;
        height: auto;
        padding: var(--spacing-md) 0;
        gap: var(--spacing-sm);
    }

    .header-title {
        font-size: 18px;
    }

    .input-group {
        flex-direction: column;
    }

    .batch-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .image-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .section {
        padding: var(--spacing-md);
    }

    .data-table {
        font-size: 13px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 12px;
    }

    .data-table .itemname {
        max-width: 200px;
    }

    .data-table .actions {
        flex-direction: column;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding-top: var(--spacing-lg);
    }

    .header-title {
        font-size: 16px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .image-grid {
        grid-template-columns: 1fr;
    }

    .table-container {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 6px 8px;
    }
}
