:root {
    --bg: #f4f6f8;
    --card: #fff;
    --text: #17202a;
    --muted: #667085;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --border: #e4e7ec;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* topbar */
.topbar {
    background: #111827;
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-weight: 800;
    font-size: 20px;
}

.public-badge {
    font-size: 12px;
    background: #374151;
    padding: 6px 10px;
    border-radius: 999px;
    color: #d1d5db;
}

/* layout */
.wrap {
    max-width: 640px;
    margin: 30px auto;
    padding: 0 20px;
    min-height: calc(100vh - 30px - 64px);
    display: flex;
    flex-direction: column;
}

/* status banners */
.status-banner {
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 15px;
}

.status-banner.valid {
    background: #ecfdf3;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.status-banner.invalid {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.status-banner.expired {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
}

.status-banner.pending {
    background: #fffbeb;
    border: 1px solid #fde68a;
    color: #92400e;
}

.status-icon {
    font-size: 20px;
}

.status-text {
    flex: 1;
}

.status-text small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    margin-top: 2px;
    opacity: .75;
}

/* card */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 5px 18px rgba(16, 24, 40, .05);
    margin-bottom: 16px;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    gap: 12px;
}

.doc-id {
    font-family: monospace;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.doc-title {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.2;
}

.modalidad-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

.modalidad-badge.emitido {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.modalidad-badge.recibido {
    background: #f5f3ff;
    color: #6d28d9;
    border: 1px solid #ddd6fe;
}

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* fields */
.fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.field label {
    display: block;
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.field div {
    font-weight: 600;
    font-size: 14px;
}

.field div.expired-date {
    color: #9a3412;
}

.verify-another {
    text-align: center;
    margin-top: auto;
    padding-top: 32px;
    margin-bottom: 24px;
}

.btn-verify-another {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 13px 28px;
    background: #fff;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    color: #17202a;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn-verify-another:hover {
    background: #f9fafb;
    border-color: #98a2b3;
}

.btn-verify-another:active {
    transform: scale(0.98);
}

/* loading */
.loading-fullscreen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    z-index: 9999;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid #e4e7ec;
    border-top-color: #2563eb;
    animation: spin .8s linear infinite;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* not found / error */
.not-found {
    text-align: center;
    padding: 48px 20px;
}

.not-found .icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.not-found h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.not-found p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.protected-block {
    margin-top: 4px;
}

.protected-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 16px;
}

.protected-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 20px;
    color: #1d4ed8;
}

.protected-header strong {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.protected-header p {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
    margin: 0;
}

.btn-protected {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    background: #1e3a6e;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn-protected:hover {
    background: #1d4ed8;
}

.btn-protected:active {
    transform: scale(0.98);
}

.btn-protected .ri-lock-fill {
    font-size: 16px;
}

.doc-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.status-stamp {
    display: inline-block;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .1em;
    padding: 4px 8px;
    border-radius: 4px;
    border-width: 2px;
    border-style: solid;

    white-space: nowrap;
    font-family: monospace;
}

.stamp-valid {
    color: #166534;
    border-color: #166534;
    background: #f0fdf4;
}

.stamp-expired {
    color: #9a3412;
    border-color: #9a3412;
    background: #fff7ed;
}

.stamp-invalid {
    color: #991b1b;
    border-color: #991b1b;
    background: #fef2f2;
}

.stamp-pending {
    color: #92400e;
    border-color: #92400e;
    background: #fffbeb;
}

/* footer */
.footer-note {
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    margin-top: 24px;
    margin-bottom: 24px;
    line-height: 1.6;
}

.footer-note a {
    color: var(--accent);
    text-decoration: none;
}

/* responsive */
@media (max-width: 500px) {
    .fields {
        grid-template-columns: 1fr;
    }

    #valid-issued-field,
    #valid-expires-field,
    #expired-issued-field,
    #expired-expires-field,
    #invalid-issued-field,
    #invalid-expires-field,
    #pending-issued-field,
    #pending-expires-field {
        grid-column: span 0;
    }

    #valid-issued-field,
    #expired-issued-field,
    #invalid-issued-field,
    #pending-issued-field {
        margin-bottom: 0;
    }

    .fields {
        grid-template-columns: 1fr 1fr;
    }
}

/* CAMERA */
.camera {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.camera.hidden {
    display: none;
}

.camera-inner {
    width: 90%;
    max-width: 400px;
    background: #f1f1f1;
    border: 1px solid #1e3a6e;
    border-radius: 16px;
    padding: 16px;
    box-sizing: border-box;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.camera-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 0 2px;
}

.camera-brand {
    font-family: Inter, Segoe UI, Arial, sans-serif;
    font-size: 18px;
    font-weight: 800;
    color: #1d4ed8;
    letter-spacing: -0.02em;
}

.camera-tagline {
    font-family: Inter, Segoe UI, Arial, sans-serif;
    font-size: 11px;
    font-weight: 600;
    color: #2563eb;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    background: #1e3a6e33;
    border: 1px solid #2563eb55;
    padding: 3px 8px;
    border-radius: 999px;
}

#qrReader {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: 10px;
    position: relative;
    border: 2px solid #1e3a6e;
}

#qrReader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

.cancel-scan {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    background: transparent;
    color: #1e3a6e;
    border: 1px solid #1e3a6e;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.cancel-scan:hover {
    background: #1e3a6e;
    color: #fff;
}

.scan-overlay {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.scan-overlay.hidden {
    display: none;
}

.scan-overlay.validating {
    background: transparent;
    box-shadow: inset 0 0 40px rgba(131, 127, 126, 0.205);
}

.scan-overlay.success {
    background: radial-gradient(ellipse at center, rgba(0, 255, 100, 0.15) 0%, rgba(0, 255, 100, 0.45) 100%);
    box-shadow: inset 0 0 60px rgba(0, 255, 100, 0.5);
    animation: flashSuccess 0.7s ease forwards;
}

.scan-overlay.error {
    background: radial-gradient(ellipse at center, rgba(255, 60, 60, 0.15) 0%, rgba(255, 60, 60, 0.45) 100%);
    box-shadow: inset 0 0 60px rgba(255, 60, 60, 0.5);
    animation: flashError 0.7s ease forwards;
}

@keyframes flashSuccess {
    0% {
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes flashError {
    0% {
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

/* Suppress html5-qrcode injected UI */
#qrReader__dashboard,
#qrReader__header_message,
#qrReader__status_span,
#qrReader button,
#qrReader select,
#qrReader img[alt="Info icon"],
#qrReader__filescan_input {
    display: none !important;
}

#qrReader__scan_region {
    border: none !important;
    background: transparent !important;
}

#qrReader__scan_region img {
    display: none !important;
}

/* Scan message */
.scan-message {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    font-family: Inter, Segoe UI, Arial, sans-serif;
}

.scan-message.error {
    background: #3b0f0f;
    color: #f87171;
    border: 1px solid #7f1d1d55;
}

.scan-message.hidden {
    display: none;
}

/* Protected revealed */
.protected-revealed-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.protected-inline-error {
    margin-top: 10px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
}

/* Attachments */
.protected-attachments-section {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
}

.field-label-small {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 10px;
}

.protected-attachment {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 6px;
    background: #f9fafb;
}

.attachment-ext {
    font-size: 10px;
    font-weight: 800;
    font-family: monospace;
    background: #e0e7ff;
    color: #3730a3;
    padding: 3px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.attachment-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    word-break: break-all;
}

.no-attachments {
    font-size: 13px;
    color: var(--muted);
}

/* Button spinner */
.btn-spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
    vertical-align: middle;
}

/* Reveal animation */
@keyframes revealFadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reveal-animate {
    opacity: 0;
    animation: revealFadeUp 0.35s ease forwards;
}

/* Attachment actions */
.attachment-actions {
    margin-left: auto;
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.att-btn {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.15s, color 0.15s;
}

.att-view {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.att-view:hover {
    background: #dbeafe;
}

.att-download {
    background: #f9fafb;
    color: var(--text);
}

.att-download:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

/* Decrypt loader */
.decrypt-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 8px 0 4px;
}

.decrypt-icon {
    position: relative;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.decrypt-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2.5px solid #bfdbfe;
    border-top-color: #2563eb;
    animation: spin .9s linear infinite;
}

.decrypt-shield {
    font-size: 22px;
    color: #2563eb;
    animation: decryptPulse 1.2s ease-in-out infinite;
}

@keyframes decryptPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: .5;
        transform: scale(.88);
    }
}

.decrypt-lines {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.decrypt-line {
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    animation: decryptLineFade .3s ease forwards;
}

@keyframes decryptLineFade {
    to {
        opacity: 1;
    }
}

.decrypt-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #2563eb;
    flex-shrink: 0;
    animation: decryptDotBlink 1s ease-in-out infinite;
}

.decrypt-line:nth-child(1) .decrypt-dot {
    animation-delay: 0s;
}

.decrypt-line:nth-child(2) .decrypt-dot {
    animation-delay: .18s;
}

.decrypt-line:nth-child(3) .decrypt-dot {
    animation-delay: .36s;
}

.decrypt-line:nth-child(4) .decrypt-dot {
    animation-delay: .54s;
}

@keyframes decryptDotBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: .2;
    }
}

.decrypt-text {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: 600;
    color: #1e40af;
    letter-spacing: .02em;
}