:root {
    --bg: #f0f2f5;
    --card: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --yellow: #ca8a04;
    --yellow-bg: #fef9c3;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
}

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

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

header {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: white;
    padding: 24px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: baseline;
    gap: 16px;
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.8;
}

main {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Upload area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: #f0f6ff;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.upload-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: var(--primary);
    font-weight: 300;
}

/* Catalog list */
.catalog-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
}

.catalog-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.catalog-name {
    font-weight: 500;
    font-size: 14px;
}

.catalog-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.catalog-actions {
    display: flex;
    gap: 8px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.badge-green {
    background: var(--green-bg);
    color: var(--green);
}

.badge-yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}

/* Buttons */
.btn {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

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

.btn-primary:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

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

.btn-secondary:hover {
    background: #e2e8f0;
}

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

.btn-danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #fca5a5;
}

.btn-danger:hover {
    background: #fca5a5;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0;
}

.tab {
    padding: 8px 20px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Search */
.search-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.search-row textarea {
    flex: 1;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.15s;
}

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

/* Batch */
.batch-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
}

.progress-bar {
    width: 200px;
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}

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

#progress-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* Search progress */
.search-progress {
    margin-top: 14px;
    padding: 14px 16px;
    background: #f0f6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
}

.search-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
    color: #1e40af;
    font-weight: 500;
}

.progress-bar-wide {
    width: 100%;
    height: 10px;
    border-radius: 5px;
}

.progress-fill-animated {
    transition: width 0.5s ease;
}

/* Stage indicator (batch) */
.stage-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin-top: 16px;
    background: #f0f6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    font-size: 14px;
    color: #1e40af;
}

.spinner-dark {
    border-color: #1e40af;
    border-top-color: transparent;
}

/* Results */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.position-block {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}

.position-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: #f8fafc;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.position-header:hover {
    background: #f1f5f9;
}

.position-title {
    font-weight: 500;
    font-size: 14px;
    flex: 1;
}

.position-num {
    color: var(--primary);
    font-weight: 600;
    margin-right: 10px;
    min-width: 28px;
}

.position-verdict-summary {
    display: flex;
    gap: 6px;
    margin-left: 12px;
}

.verdict-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.verdict-dot.green { background: var(--green); }
.verdict-dot.yellow { background: var(--yellow); }
.verdict-dot.red { background: var(--red); }

.expand-icon {
    font-size: 18px;
    color: var(--text-muted);
    margin-left: 12px;
    transition: transform 0.2s;
}

.position-block.open .expand-icon {
    transform: rotate(180deg);
}

.position-body {
    display: none;
    padding: 0;
}

.position-block.open .position-body {
    display: block;
}

/* Candidate card */
.candidate {
    display: flex;
    gap: 16px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    align-items: flex-start;
}

.candidate:hover {
    background: #fafbfc;
}

.candidate-rank {
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.candidate-rank.green {
    background: var(--green-bg);
    color: var(--green);
}

.candidate-rank.yellow {
    background: var(--yellow-bg);
    color: var(--yellow);
}

.candidate-rank.red {
    background: var(--red-bg);
    color: var(--red);
}

.candidate-info {
    flex: 1;
    min-width: 0;
}

.candidate-name {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
}

.candidate-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.candidate-details span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.candidate-comment {
    font-size: 13px;
    padding: 8px 12px;
    border-radius: 6px;
    margin-top: 6px;
}

.candidate-comment.green {
    background: var(--green-bg);
    color: #166534;
}

.candidate-comment.yellow {
    background: var(--yellow-bg);
    color: #854d0e;
}

.candidate-comment.red {
    background: var(--red-bg);
    color: #991b1b;
}

.candidate-score {
    min-width: 60px;
    text-align: right;
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.candidate-score .score-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
}

.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* No results */
.no-results {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Responsive */
@media (max-width: 640px) {
    .header-inner {
        flex-direction: column;
        gap: 4px;
    }
    .search-row {
        flex-direction: column;
    }
    .results-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    .candidate {
        flex-direction: column;
    }
    .candidate-score {
        text-align: left;
    }
}
