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

:root {
    /* Modern Color Palette */
    --primary-color: #6366f1;
    --primary-hover: #5b5bd6;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    /* Background Colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-light: #f8fafc;
    --bg-card: #ffffff;
    
    /* Text Colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-light: #f1f5f9;
    
    /* Border Colors */
    --border-light: #e2e8f0;
    --border-medium: #cbd5e1;
    --border-dark: #475569;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-secondary: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--gradient-bg);
    min-height: 100vh;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    width: 100%;
    max-width: 1600px;
    padding: 24px;
}

/* Header */
header {
    text-align: center;
    padding: 16px 0;
    position: relative;
}

header h1 {
    color: white;
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 1rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1.2rem;
    font-weight: 500;
    max-width: 600px;
    margin: 0 auto;
    opacity: 0.8;
}

/* Form styles */
form {
    margin-bottom: 32px;
}

/* Compact Form Container */
.form-container {
    background: var(--bg-card);
    border-radius: 20px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
}
/* Top controls */
.top-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    align-items: end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.control-group.reranking-group label{
    height: 3rem;
}

.control-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group input,
.control-group select {
    padding: 14px 16px;
    border: 2px solid var(--border-light);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-light);
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.control-group input:focus,
.control-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    transform: translateY(-1px);
}

.control-group input:hover,
.control-group select:hover {
    border-color: var(--border-medium);
    transform: translateY(-1px);
}

.control-group small {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    margin-top: 4px;
}

/* Modern Checkbox styling */
.control-group label input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-medium);
    border-radius: 6px;
    background: var(--bg-card);
    cursor: pointer;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-right: 0;
}

.control-group label input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.control-group label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.control-group label input[type="checkbox"]:hover {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

/* Items container */
#itemsContainer {
    margin-bottom: 20px;
}

/* Items Table */
.items-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

.items-table thead th {
    background: var(--bg-light);
    padding: 16px 20px;
    text-align: left;
    border-bottom: 2px solid var(--border-light);
    vertical-align: top;
}

.header-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.header-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    letter-spacing: 0.01em;
}

.header-hint {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
}

.items-table tbody td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

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

.items-table tbody tr {
    transition: all 0.2s ease;
}

.items-table tbody tr:hover {
    background: var(--bg-light);
}

.table-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-light);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.table-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: var(--bg-card);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), var(--shadow-md);
    transform: translateY(-1px);
}

.table-input:hover {
    border-color: var(--border-medium);
    transform: translateY(-1px);
}

.table-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}


/* Buttons */
.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.01em;
    box-shadow: var(--shadow-md);
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn:hover::before {
    left: 100%;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: 2px solid transparent;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary:active {
    transform: translateY(0);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, #dc2626 100%);
    color: white;
    padding: 10px 16px;
    font-size: 12px;
    border-radius: 8px;
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    filter: brightness(1.1);
}

.btn-danger:active {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: var(--shadow-sm) !important;
}

.btn:disabled::before {
    display: none;
}

/* Form Actions */
.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* Plus Button */
.btn-plus {
    width: 40px;
    height: 40px;
    padding: 0 !important;
    flex-shrink: 0;
    flex-grow: 0;
    border-radius: 50%;
    background: var(--secondary-color);
    color: white;
    border: none;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.btn-plus:hover {
    background: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-plus:active {
    transform: translateY(0);
}

/* Upload Button */
.btn-upload {
    background: var(--success-color);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: auto; /* Push to the left */
    box-shadow: var(--shadow-md);
}

.btn-upload:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-upload:active {
    transform: translateY(0);
}

/* Loading spinner */
.loading-spinner {
    animation: spin 1s linear infinite;
    font-size: 18px;
    color: white;
}

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

/* Match Indicator Styles */
.match-cell {
    text-align: center;
    padding: 12px 16px !important;
    width: 60px;
}

.match-indicator {
    font-size: 18px;
    font-weight: bold;
    display: inline-block;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 50%;
}

.match-success {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.match-partial {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.match-fail {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.match-na {
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
}

.match-success-cell {
    background: rgba(16, 185, 129, 0.05);
}

.match-fail-cell {
    background: rgba(239, 68, 68, 0.05);
}

/* Accuracy Statistics Section */
.accuracy-section {
    margin-bottom: 32px;
}

.accuracy-section h3 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
}

.accuracy-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.accuracy-table th,
.accuracy-table td {
    padding: 12px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.accuracy-table th {
    background: var(--bg-light);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.accuracy-table td {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.accuracy-table tbody tr:hover {
    background: var(--bg-light);
}

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

.accuracy-first-match {
    background: rgba(16, 185, 129, 0.05);
}

.accuracy-non-first-match {
    background: rgba(245, 158, 11, 0.05);
}

.accuracy-no-match {
    background: rgba(239, 68, 68, 0.05);
}

.accuracy-total {
    background: var(--bg-light);
    font-weight: 600;
}

.accuracy-total td {
    color: var(--text-primary);
    font-weight: 600;
}

/* Results section */
.results-section {
    margin-top: 48px;
    padding: 32px;
    background: var(--bg-card);
    border-radius: 24px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-xl);
    position: relative;
    overflow: hidden;
}

.results-section h3 {
    color: var(--text-primary);
    margin-bottom: 32px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    text-align: center;
}

.result-item {
    margin-bottom: 32px;
    border: 1px solid var(--border-light);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.result-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

/* Unified Results Table */
.unified-results {
    margin-top: 0;
}

.item-cell {
    vertical-align: top;
    padding: 16px 20px !important;
    min-width: 200px;
}

/* Color variants for alternating result groups */
.item-cell.group-color-1 {
    background: linear-gradient(135deg, var(--primary-light) 0%, rgba(139, 92, 246, 0.1) 100%);
    border-right: 2px solid var(--primary-color);
}

.item-cell.group-color-2 {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(5, 150, 105, 0.1) 100%);
    border-right: 2px solid var(--success-color);
}

.item-cell.group-color-3 {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(217, 119, 6, 0.1) 100%);
    border-right: 2px solid var(--warning-color);
}

.item-cell.group-color-4 {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(220, 38, 38, 0.1) 100%);
    border-right: 2px solid var(--danger-color);
}

.item-cell.group-color-5 {
    background: linear-gradient(135deg, rgba(100, 116, 139, 0.15) 0%, rgba(71, 85, 105, 0.1) 100%);
    border-right: 2px solid var(--secondary-color);
}

.item-cell.group-color-6 {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, rgba(147, 51, 234, 0.1) 100%);
    border-right: 2px solid #a855f7;
}

.item-info {
    font-size: 14px;
    line-height: 1.4;
}

.item-info strong {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 15px;
}

.item-desc {
    color: var(--text-secondary);
    font-weight: 500;
    font-style: italic;
}

.item-info small {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
}

.result-table th,
.result-table td {
    padding: 16px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.result-table th {
    background: var(--bg-light);
    font-weight: 700;
    color: var(--text-primary);
    font-size: 14px;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    font-size: 12px;
}

.result-table td {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.result-table tbody tr {
    transition: all 0.2s ease;
}

.result-table tbody tr:hover {
    background: var(--bg-light);
}

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

.score-cell {
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

/* First prediction highlighting */
.result-table tbody tr.first-prediction {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-left: 3px solid var(--primary-color);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.1);
}

.result-table tbody tr.first-prediction:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.08) 100%);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.15);
}

.result-table tbody tr.first-prediction td {
    font-weight: 600;
    color: var(--text-primary);
}

.client-match-true {
    color: var(--success-color);
    font-weight: 700;
}

.client-match-false {
    color: var(--text-muted);
    font-weight: 500;
}

/* Error section */
.error-section {
    margin-top: 32px;
    padding: 24px 32px;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(220, 38, 38, 0.1) 100%);
    border: 2px solid rgba(239, 68, 68, 0.2);
    border-radius: 16px;
    color: var(--danger-color);
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.error-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--danger-color), #dc2626);
}

.error-section h3 {
    margin-bottom: 16px;
    color: var(--danger-color);
    font-weight: 700;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-section h3::before {
    content: '⚠️';
    font-size: 1.5rem;
}

#errorMessage {
    font-weight: 500;
    line-height: 1.6;
    background: rgba(255, 255, 255, 0.8);
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid var(--danger-color);
}

/* Responsive design */
@media (max-width: 1200px) {
    .items-table {
        font-size: 13px;
    }
    
    .table-input {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .header-title {
        font-size: 13px;
    }
    
    .header-hint {
        font-size: 11px;
    }
}

@media (max-width: 1024px) {
    .container {
        margin: 16px;
        padding: 20px;
        border-radius: 20px;
        min-height: calc(100vh - 32px);
    }
    
    .top-controls {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 20px;
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .items-table,
    .result-table,
    .accuracy-table {
        font-size: 12px;
    }
    
    .items-table th,
    .items-table td,
    .result-table th,
    .result-table td,
    .accuracy-table th,
    .accuracy-table td {
        padding: 8px 12px;
    }
    
    .match-indicator {
        font-size: 16px;
        width: 20px;
        height: 20px;
        line-height: 20px;
    }

    .container {
        margin: 12px;
        padding: 16px;
        border-radius: 16px;
        min-height: calc(100vh - 24px);
    }
    
    header {
        padding: 24px 0;
        margin-bottom: 32px;
    }
    
    header h1 {
        font-size: 2.5rem;
    }
    
    .top-controls {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 20px;
    }
    
    .item-row {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 20px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 20px 24px;
    }
    
    .submit-section {
        padding: 24px;
    }
    
    .submit-section .btn {
        padding: 16px 32px;
        min-width: 160px;
    }
    
    .results-section {
        padding: 24px;
        margin-top: 32px;
    }
    
    .result-table {
        font-size: 13px;
    }
    
    .result-table th,
    .result-table td {
        padding: 12px 16px;
    }
    
    .score-cell {
        padding: 6px 10px !important;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .container {
        margin: 8px;
        padding: 12px;
        border-radius: 12px;
        min-height: calc(100vh - 16px);
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .top-controls {
        padding: 16px;
        gap: 12px;
    }
    
    .control-group input,
    .control-group select {
        padding: 12px 14px;
        font-size: 13px;
    }
    
    .item-row {
        padding: 16px;
        gap: 12px;
    }
    
    .item-row .field-group input {
        padding: 10px 14px;
        font-size: 13px;
    }
    
    .section-header {
        padding: 16px 20px;
    }
    
    .section-header h3 {
        font-size: 1.25rem;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 13px;
    }
    
    .btn-danger {
        padding: 8px 12px;
        font-size: 11px;
    }
    
    .submit-section {
        padding: 20px;
    }
    
    .submit-section .btn {
        padding: 14px 24px;
        font-size: 14px;
        min-width: 140px;
    }
    
    .results-section {
        padding: 20px;
    }
    
    .results-section h3 {
        font-size: 1.5rem;
    }
    
    .result-item-header {
        padding: 16px 20px;
        font-size: 14px;
    }
    
    .result-table {
        font-size: 12px;
    }
    
    .result-table th,
    .result-table td {
        padding: 10px 12px;
    }
    
    .score-cell {
        padding: 4px 8px !important;
        font-size: 11px;
    }
    
    .error-section {
        padding: 20px 24px;
    }
    
    .error-section h3 {
        font-size: 1.1rem;
    }
}

/* Modern scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 4px;
    transition: background 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Selection styling */
::selection {
    background: var(--primary-light);
    color: var(--primary-color);
}

::-moz-selection {
    background: var(--primary-light);
    color: var(--primary-color);
}