/* ───────────────────── Variables & Reset ───────────────────── */

:root {
    --bg: #f0f4f8;
    --bg-subtle: #e8eef5;
    --surface: #ffffff;
    --border: #e1e7ef;
    --border-light: #f0f3f7;
    --text: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-glow: rgba(79, 70, 229, 0.12);
    --success: #10b981;
    --success-light: #ecfdf5;
    --error: #ef4444;
    --error-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
    --shadow-primary: 0 4px 14px rgba(79, 70, 229, 0.25);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* ───────────────────── Background decoration ───────────────────── */

.bg-decoration {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 400px;
    background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 30%, #f0f4f8 100%);
    z-index: -1;
}

.bg-decoration::after {
    content: '';
    position: absolute;
    top: 60px;
    right: -100px;
    width: 400px;
    height: 400px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(79, 70, 229, 0.04) 0%, transparent 70%);
}

/* ───────────────────── Layout ───────────────────── */

.app-container {
    max-width: 880px;
    margin: 0 auto;
    padding: 24px 20px;
    position: relative;
}

.section {
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ───────────────────── Header ───────────────────── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 40px;
}

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

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-primary);
}

.logo h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--primary);
    background: var(--primary-light);
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid rgba(79, 70, 229, 0.1);
}

/* ───────────────────── Cards ───────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px;
    box-shadow: var(--shadow);
    position: relative;
}

.card-narrow {
    max-width: 440px;
    margin: 0 auto;
}

.card-wide {
    max-width: 100%;
}

.card-login {
    padding: 44px 40px;
    text-align: center;
}

.card-login h2 {
    text-align: center;
}

.card-login .text-muted {
    text-align: center;
}

.card-login form {
    text-align: left;
}

.card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--primary-light);
    color: var(--primary);
    margin-bottom: 20px;
}

.card h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
    color: var(--text);
}

.card-success {
    text-align: center;
    border-color: var(--success);
    border-width: 1.5px;
}

.card-error {
    text-align: center;
    border-color: var(--error);
    border-width: 1.5px;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* ───────────────────── Typography ───────────────────── */

.text-muted {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* ───────────────────── Forms ───────────────────── */

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

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.input-wrapper {
    position: relative;
}

.input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 14px 12px 44px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: all var(--transition);
    outline: none;
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.input-wrapper input:hover {
    border-color: #c7d2e0;
}

.input-wrapper input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: all var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* ───────────────────── Buttons ───────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: var(--shadow-primary);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--bg-subtle);
    color: var(--text);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
}

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

.btn-full {
    width: 100%;
}

.btn-lg {
    padding: 13px 24px;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 5px 10px;
    font-size: 0.75rem;
}

/* ───────────────────── Dropzone ───────────────────── */

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 52px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    background: linear-gradient(180deg, #fafbfd 0%, var(--surface) 100%);
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.dropzone-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    margin-bottom: 4px;
}

.dropzone-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.dropzone-subtext {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ───────────────────── File info ───────────────────── */

.file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--primary-light);
    border: 1px solid rgba(79, 70, 229, 0.12);
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.file-info-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.file-icon-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 4px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.file-name {
    font-size: 0.88rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

/* ───────────────────── Progress ───────────────────── */

.progress-container {
    text-align: center;
    padding: 32px 0;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 24px;
}

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

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-subtle);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 24px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #818cf8);
    border-radius: 3px;
    width: 0%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ───────────────────── Detections Header ───────────────────── */

.detections-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

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

/* ───────────────────── Page Sections ───────────────────── */

.detections-pages {
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 4px;
}

.detections-pages::-webkit-scrollbar {
    width: 6px;
}

.detections-pages::-webkit-scrollbar-track {
    background: transparent;
}

.detections-pages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.page-section {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: border-color var(--transition);
}

.page-section:hover {
    border-color: #c7d2e0;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.page-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text);
}

.page-icon {
    font-size: 1rem;
}

.page-count {
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid rgba(79, 70, 229, 0.1);
}

/* ───────────────────── Type Sections ───────────────────── */

.type-section {
    margin-bottom: 14px;
}

.type-section:last-child {
    margin-bottom: 0;
}

.type-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.type-icon {
    font-size: 0.85rem;
}

.type-label {
    font-weight: 600;
}

.type-count {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
}

.type-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 6px;
}

/* ───────────────────── Detection Items ───────────────────── */

.detection-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xs);
    transition: all var(--transition);
    flex-wrap: wrap;
}

.detection-item:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.detection-item input[type="checkbox"] {
    margin-top: 4px;
    width: 17px;
    height: 17px;
    accent-color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
    border-radius: 4px;
}

.detection-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

.detection-value {
    font-size: 0.88rem;
    font-weight: 500;
    word-break: break-word;
    color: var(--text);
}

.detection-context {
    width: 100%;
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding-left: 27px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-style: italic;
}

/* ───────────────────── Detection Badges (type) ───────────────────── */

.detection-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 5px;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-PERSON_NAME       { background: #fee2e2; color: #b91c1c; }
.badge-DATE_OF_BIRTH     { background: #ffedd5; color: #c2410c; }
.badge-BIRTH_PLACE       { background: #f3e8ff; color: #7c3aed; }
.badge-ADDRESS           { background: #ede9fe; color: #6d28d9; }
.badge-PHONE             { background: #dbeafe; color: #1d4ed8; }
.badge-FAX               { background: #dbeafe; color: #1d4ed8; }
.badge-EMAIL             { background: #cffafe; color: #0e7490; }
.badge-IBAN              { background: #d1fae5; color: #047857; }
.badge-SSN               { background: #fce7f3; color: #be185d; }
.badge-ID_NUMBER         { background: #fce7f3; color: #9d174d; }
.badge-NATIONALITY       { background: #ecfdf5; color: #059669; }
.badge-DATE              { background: #ffedd5; color: #c2410c; }
.badge-AMOUNT            { background: #d1fae5; color: #047857; }
.badge-REFERENCE         { background: #f1f5f9; color: #475569; }
.badge-ORGANIZATION      { background: #ccfbf1; color: #0f766e; }
.badge-PROFESSIONAL_INFO { background: #fef3c7; color: #b45309; }

/* ───────────────────── Confidence badge ───────────────────── */

.confidence-badge {
    font-size: 0.58rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.confidence-high {
    background: #d1fae5;
    color: #047857;
}

.confidence-medium {
    background: #fef3c7;
    color: #b45309;
}

/* ───────────────────── No detections ───────────────────── */

.no-detections {
    text-align: center;
    padding: 48px 0;
    color: var(--text-muted);
}

/* ───────────────────── Success / Download ───────────────────── */

.success-icon {
    color: var(--success);
    margin-bottom: 20px;
}

.download-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 28px;
}

/* ───────────────────── Error ───────────────────── */

.error-icon {
    color: var(--error);
    margin-bottom: 16px;
}

.error-message {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 14px;
    text-align: center;
    min-height: 20px;
    font-weight: 500;
}

#errorSection .card {
    color: var(--text);
}

#errorSection h2 {
    color: var(--error);
}

#errorSection p {
    color: var(--text-secondary);
    margin: 12px 0 24px;
    font-size: 0.9rem;
}

/* ───────────────────── Responsive ───────────────────── */

@media (max-width: 600px) {
    .app-container {
        padding: 16px 14px;
    }

    .card {
        padding: 28px 20px;
    }

    .card-login {
        padding: 36px 24px;
    }

    .dropzone {
        padding: 36px 16px;
    }

    .detections-header {
        flex-direction: column;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .detection-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .card-footer {
        flex-direction: column;
        gap: 12px;
    }

    .card-footer .btn {
        width: 100%;
    }

    .detections-pages {
        max-height: none;
    }

    .logo h1 {
        font-size: 1.1rem;
    }
}
