:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 2px 4px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0, 0, 0, 0.04);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
}

.header {
    background: var(--gray-900);
    color: white;
    padding: 0 32px;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.header-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.header p {
    font-size: 0.78rem;
    color: var(--gray-400);
    margin-left: auto;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px;
}

/* Upload Cards Grid */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.upload-card {
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.upload-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.upload-card.disabled {
    opacity: 0.55;
    pointer-events: none;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-header .icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
}

.card-header .icon.clientes {
    background: var(--primary-light);
    color: var(--primary);
}

.card-header .icon.apolices {
    background: var(--warning-light);
    color: var(--warning);
}

.card-header .icon.recibos {
    background: var(--success-light);
    color: var(--success);
}

.card-header .title-area h3 {
    font-size: 1rem;
    font-weight: 600;
}

.card-header .title-area p {
    font-size: 0.8rem;
    color: var(--gray-500);
}

.badge-dev {
    margin-left: auto;
    background: var(--warning-light);
    color: #92400e;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-body {
    padding: 24px;
}

.drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    background: var(--gray-50);
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone .drop-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    color: var(--gray-400);
}

.drop-zone p {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.drop-zone p strong {
    color: var(--primary);
}

.drop-zone .formats {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 8px;
}

.drop-zone input[type="file"] {
    display: none;
}

.file-info {
    display: none;
    background: var(--success-light);
    border: 1px solid #86efac;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 12px;
    font-size: 0.85rem;
    color: #166534;
}

.file-info .file-name {
    font-weight: 600;
}

/* Mapping Section */
.mapping-section {
    display: none;
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.mapping-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.mapping-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
}

.mapping-stats {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
}

.stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.stat .dot.matched {
    background: var(--success);
}

.stat .dot.unmatched {
    background: var(--warning);
}

.stat .dot.ignored {
    background: var(--gray-300);
}

.mapping-toolbar {
    padding: 12px 24px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.search-box {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.82rem;
    outline: none;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-outline {
    background: white;
    border-color: var(--gray-300);
    color: var(--gray-700);
}

.btn-outline:hover {
    background: var(--gray-100);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 1px 4px rgba(22, 163, 74, 0.25);
}

.btn-success:hover {
    background: #15803d;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.35);
}

.btn-danger {
    background: white;
    border-color: var(--danger);
    color: var(--danger);
}

.btn-danger:hover {
    background: #fef2f2;
}

/* Mapping Table */
.mapping-table-wrapper {
    overflow-x: auto;
}

.mapping-table {
    width: 100%;
    border-collapse: collapse;
}

.mapping-table th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-400);
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 1;
}

.mapping-table td {
    padding: 9px 16px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.85rem;
    vertical-align: middle;
}

.mapping-table tr:hover td {
    background: rgba(37, 99, 235, 0.02);
}

.mapping-table .col-status {
    width: 40px;
    text-align: center;
}

.mapping-table .col-generic {
    width: 28%;
}

.mapping-table .col-description {
    width: 30%;
}

.mapping-table .col-mapping {
    width: 32%;
}

.mapping-table .col-preview {
    width: 10%;
}

.field-name {
    font-weight: 600;
    font-family: 'Cascadia Code', 'Fira Code', 'SF Mono', 'Consolas', monospace;
    color: var(--gray-800);
    font-size: 0.8rem;
}

.field-description {
    color: var(--gray-500);
    font-size: 0.8rem;
    line-height: 1.4;
}

.field-type {
    display: inline-block;
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 4px;
    font-family: monospace;
}

.status-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.status-icon.matched {
    background: var(--success-light);
    color: var(--success);
}

.status-icon.unmatched {
    background: var(--warning-light);
    color: var(--warning);
}

.mapping-select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.82rem;
    background: var(--gray-50);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.mapping-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.mapping-select.matched {
    border-color: var(--success);
    background: #f0fdf4;
}

.preview-data {
    font-size: 0.75rem;
    color: var(--gray-500);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Summary Footer */
.mapping-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.preview-section {
    display: none;
    background: white;
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-top: 24px;
}

.preview-section .mapping-header {
    border-bottom: 1px solid var(--gray-200);
}

.preview-table-wrapper {
    overflow-x: auto;
    max-height: 400px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.preview-table th {
    padding: 10px 12px;
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
    text-align: left;
    position: sticky;
    top: 0;
    font-size: 0.75rem;
}

.preview-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-100);
}

.preview-table tr:nth-child(even) td {
    background: var(--gray-50);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: 10px;
    color: white;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
    max-width: 420px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

.toast.info {
    background: var(--primary);
}

/* Back button */
.back-btn {
    display: none;
    margin-bottom: 20px;
    color: var(--gray-500);
    border-color: var(--gray-200);
    font-size: 0.8rem;
}

.back-btn:hover {
    color: var(--gray-800);
}

/* AI Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show {
    display: flex;
}

.modal-box {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 480px;
    max-width: 95vw;
    overflow: hidden;
}

.modal-box .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-box .modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-box .modal-body {
    padding: 20px;
}

.modal-box .modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group select,
.form-group input[type="password"],
.form-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.form-group .hint {
    font-size: 0.72rem;
    color: var(--gray-400);
    margin-top: 4px;
}

.proxy-info-box {
    font-size: 0.8rem;
    color: var(--gray-600, #374151);
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: var(--radius);
    padding: 10px 12px;
    line-height: 1.5;
}

.btn-ai {
    background: linear-gradient(135deg, #7c3aed, #6d28d9);
    color: white;
    border: none;
    box-shadow: 0 1px 4px rgba(109, 40, 217, 0.25);
}

.btn-ai:hover {
    background: linear-gradient(135deg, #6d28d9, #5b21b6);
    box-shadow: 0 2px 8px rgba(109, 40, 217, 0.35);
}

.btn-ai:disabled {
    opacity: 0.6;
    cursor: wait;
}

.ai-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.ai-thinking {
    display: none;
    padding: 10px 24px;
    background: linear-gradient(135deg, #f5f3ff, #ede9fe);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.8rem;
    color: #5b21b6;
    align-items: center;
    gap: 8px;
}

.ai-thinking.show {
    display: flex;
}

.ai-thinking .thinking-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #c4b5fd;
    border-top-color: #7c3aed;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    flex-shrink: 0;
}

.ai-thinking .thinking-text {
    animation: fadeInText 0.3s ease;
}

@keyframes fadeInText {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .upload-grid {
        grid-template-columns: 1fr;
    }

    .mapping-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .mapping-toolbar {
        flex-direction: column;
    }
}