:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --danger: #ef4444;
    --green: #22c55e;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 24px 12px;
}

.app-container {
    width: 100%;
    max-width: 680px;
    background: var(--surface-color);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--accent), #e879f9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

main {
    position: relative;
    flex: 1;
}

.view-section {
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: opacity 0.3s ease;
}

.view-section.hidden {
    display: none;
    opacity: 0;
}

/* Viewfinder */
.viewfinder {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    overflow: hidden;
}

.viewfinder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.id-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 60%;
    border: 2px dashed rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
}

.id-guide span {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 4px;
}

#flash {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease-out;
}

#flash.active {
    opacity: 1;
    transition: none;
}

.controls {
    padding: 24px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--surface-color);
}

.shutter-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: transparent;
    border: 4px solid var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 4px;
}

.shutter-btn:active { transform: scale(0.95); }

.shutter-inner {
    width: 100%;
    height: 100%;
    background: var(--text-color);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.shutter-btn:hover .shutter-inner { background: #e2e8f0; }
.shutter-btn:active .shutter-inner { transform: scale(0.9); }

.upload-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.upload-label {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.upload-label:hover { background: rgba(255, 255, 255, 0.2); }

#file-upload { display: none; }

/* ──────────────────────────────────────
   RESULTS CARD
   ────────────────────────────────────── */
.result-card {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Card type row */
.card-type-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-type-row h2 {
    font-size: 1.1rem;
    font-weight: 600;
    flex: 1;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: rgba(255,255,255,0.1);
    color: var(--text-muted);
}

.badge-ine {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
    border: 1px solid rgba(34, 197, 94, 0.35);
}

.badge-desconocida {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ── Main layout: face + table side by side ── */
.result-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Face column */
.face-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.face-frame {
    width: 110px;
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.face-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.face-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}

.face-placeholder svg {
    width: 40px;
    height: 40px;
    opacity: 0.5;
}

.face-placeholder span {
    font-size: 0.7rem;
    opacity: 0.6;
}

.face-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

/* Data column */
.data-col {
    flex: 1;
    min-width: 0;
}

/* ID Table */
.id-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.id-table th,
.id-table td {
    padding: 9px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: top;
}

.id-table th {
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    width: 130px;
}

.id-table td {
    color: var(--text-color);
    font-weight: 600;
    word-break: break-word;
}

.id-table tr:last-child th,
.id-table tr:last-child td {
    border-bottom: none;
}

.mono {
    font-family: 'Courier New', monospace;
    letter-spacing: 0.04em;
    font-size: 0.82rem !important;
    color: var(--accent) !important;
}

/* Image thumbnail */
.image-preview-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preview-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.image-preview-container img {
    width: 100%;
    border-radius: 10px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    max-height: 220px;
    object-fit: cover;
}

details {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 10px 14px;
}

summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.raw-text {
    margin-top: 8px;
    font-family: monospace;
    font-size: 0.78rem;
    color: #cbd5e1;
    max-height: 100px;
    overflow-y: auto;
    line-height: 1.6;
}

.sec-button {
    width: 100%;
    padding: 14px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.sec-button:hover { background: rgba(255, 255, 255, 0.2); }

/* Hidden utility */
.hidden { display: none !important; }

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

#loading-overlay.hidden { display: none; }

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.1);
    border-left-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 420px) {
    .result-layout {
        flex-direction: column;
        align-items: center;
    }
    .face-col { flex-direction: row; gap: 12px; align-items: center; }
    .face-frame { width: 80px; height: 100px; }
    .data-col { width: 100%; }
}
