:root {
    --bg-color: #1e1e1e;
    --panel-bg: #252526;
    --accent: #007acc;
    --text: #cccccc;
    --border: #3e3e42;
}

body {
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
    height: 100vh;
    /* dvh keeps the full-height layout inside the visible area on mobile
       browsers whose toolbars change the viewport height. */
    height: 100dvh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    padding: 10px 20px;
    background-color: #333333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.subtitle {
    margin: 0;
    color: #999;
    font-size: 0.9em;
}

button {
    padding: 6px 12px;
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #005a9e;
}

button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.demo-footer {
    padding: 8px 20px;
    background-color: #333333;
    border-top: 1px solid var(--border);
    font-size: 0.85em;
    text-align: center;
}

.demo-footer p {
    margin: 0;
}

.demo-footer a {
    color: #4daafc;
    text-decoration: none;
    margin: 0 6px;
}

.demo-footer a:hover {
    text-decoration: underline;
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.left-panel {
    flex: 2;
    border-right: 1px solid var(--border);
}

.right-panel {
    flex: 1;
    background-color: var(--panel-bg);
    overflow-y: auto;
}

.toolbar {
    margin-bottom: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

/* Loading Spinner */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s;
}

.spinner-overlay.visible {
    visibility: visible;
    opacity: 1;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

.viewer-container {
    flex: 1;
    background-color: #000;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px dashed #444;
    overflow: hidden;
}

.viewer-container.drag-over {
    border-color: var(--accent);
    background-color: #2d2d30;
}

#cameraView {
    width: 100%;
    height: 100%;
}

#cameraView video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/*
  Image + overlay alignment strategy:
  - Both image and canvas fill the container with object-fit: contain
  - Canvas backing store matches image natural dimensions
  - CSS object-fit scales both identically since they have same aspect ratio
*/
#imageView {
    position: relative;
    width: 100%;
    height: 100%;
}

#displayImage {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#overlayCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.hidden {
    display: none !important;
}

.placeholder-text {
    position: absolute;
    color: #666;
    text-align: center;
    pointer-events: none;
}

.result-group {
    margin-bottom: 20px;
    padding: 10px;
    background: #2d2d30;
    border-radius: 6px;
}

h3 {
    margin-top: 0;
    color: white;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

.face-container {
    text-align: center;
}

#faceCropCanvas {
    border: 2px solid var(--accent);
    border-radius: 4px;
    background-color: #000;
}

.data-box {
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    white-space: pre-wrap;
    color: #dcdcdc;
    overflow-x: auto;
}

.ocr-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ocr-line {
    padding: 2px 0;
}

.ocr-num {
    color: #00ffff;
    font-weight: bold;
    margin-right: 5px;
}

.highlight {
    color: #4ec9b0;
}

.label {
    color: #569cd6;
}

/* ------------------------------------------------------------------
   Responsive layout
   Below 768px the side-by-side panels stack vertically and the page
   scrolls, so the results panel is never squeezed into a sliver.
   ------------------------------------------------------------------ */
@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 12px 15px;
    }

    header h1 {
        margin: 0;
        font-size: 1.35rem;
        line-height: 1.3;
    }

    .subtitle {
        font-size: 0.82em;
        line-height: 1.4;
    }

    main {
        flex-direction: column;
        overflow: visible;
    }

    .left-panel,
    .right-panel {
        flex: none;
    }

    .left-panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .right-panel {
        overflow-y: visible;
    }

    .toolbar {
        gap: 8px;
    }

    .toolbar button {
        flex: 1 1 auto;
        min-height: 40px;
    }

    #status {
        flex: 1 1 100%;
        font-size: 0.85em;
        line-height: 1.4;
    }

    .viewer-container {
        flex: none;
        height: 45vh;
        min-height: 280px;
    }

    /* MRZ lines are long unbroken strings: wrap them instead of forcing a
       horizontal scrollbar inside the result box. */
    .data-box {
        font-size: 0.82em;
        overflow-wrap: anywhere;
    }
}