/* ===========================================================================
   Online Driver License Scanner — Codepool demo styles
   =========================================================================== */

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

html,
body {
    width: 100%;
    /* Fallback for browsers without dvh support. */
    height: 100%;
    /* 100dvh follows the visible viewport, so mobile browser chrome does not
       push the camera out of view. */
    height: 100dvh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

.demo-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: calc(8px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
}

/* ---------------------------------------------------------------------------
   Header
   --------------------------------------------------------------------------- */

.demo-header {
    flex: 0 0 auto;
    text-align: center;
}

.demo-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    line-height: 1.25;
}

.demo-header .subtitle {
    margin-top: 2px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
}

/* ---------------------------------------------------------------------------
   Scanner
   --------------------------------------------------------------------------- */

#scanner-app {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    min-height: 0;
    gap: 8px;
}

#tip-message {
    flex: 0 0 auto;
    max-width: 100%;
    font-size: 0.9rem;
    color: #fff;
    text-align: center;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1.1rem;
    border-radius: 25px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: 5;
}

/* Mode Switch Toggle */
.mode-switch {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50px;
    padding: 4px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.mode-options {
    display: flex;
    position: relative;
    z-index: 2;
    width: 100%;
}

.mode-option {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.4rem;
    border-radius: 46px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
    font-size: 0.9rem;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
}

.mode-option.active {
    color: #fff;
    font-weight: 600;
}

.mode-icon {
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 2;
    transition: all 0.3s ease;
    flex: 0 0 auto;
}

.mode-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: linear-gradient(135deg, #fe8e14 0%, #ff6b35 100%);
    border-radius: 42px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 16px rgba(254, 142, 20, 0.3);
}

.mode-switch[data-active="image"] .mode-slider {
    transform: translateX(100%);
}

.mode-switch[data-active="image"] .mode-option[data-mode="image"] {
    color: #fff;
    font-weight: 600;
}

.mode-switch[data-active="image"] .mode-option[data-mode="camera"] {
    color: rgba(255, 255, 255, 0.7);
    font-weight: 500;
}

/* Camera / image view */
#main-container {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    /* min-height:0 lets the flex item shrink, keeping the view in the viewport. */
    min-height: 0;
    width: min(100%, 680px);
    position: relative;
}

#camera-view {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ---------------------------------------------------------------------------
   Upload drop zone
   Replaces the SDK's own image picker so switching to Upload mode never opens
   the OS file dialog on its own.
   --------------------------------------------------------------------------- */

.upload-zone {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: min(100%, 680px);
    min-height: 0;
    padding: 24px;
    border: 2px dashed rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.18);
    color: #fff;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

/* `display:flex` above would otherwise beat the [hidden] attribute. */
.upload-zone[hidden] {
    display: none;
}

.upload-zone:hover,
.upload-zone:focus-visible,
.upload-zone.dragover {
    border-color: #fe8e14;
    background: rgba(254, 142, 20, 0.18);
    outline: none;
}

.upload-zone-icon {
    width: 42px;
    height: 42px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.9;
}

.upload-zone-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.upload-zone-hint {
    margin: 0;
    max-width: 36ch;
    font-size: 0.83rem;
    line-height: 1.5;
    opacity: 0.9;
}

.upload-zone kbd {
    padding: 1px 5px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85em;
}

/* ---------------------------------------------------------------------------
   Footer
   --------------------------------------------------------------------------- */

.demo-footer {
    flex: 0 0 auto;
    padding: 6px 10px;
    background-color: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    font-size: 0.8em;
    text-align: center;
}

.demo-footer p {
    margin: 0;
}

.demo-footer a {
    color: #ffd7a8;
    text-decoration: none;
    margin: 0 5px;
}

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

.demo-footer-cta {
    font-weight: 600;
}

/* Cross-link to the sample licence generator, shown under the main footer line. */
.demo-footer-note {
    margin-top: 4px;
    font-size: 0.95em;
    opacity: 0.92;
}

/* ---------------------------------------------------------------------------
   Results overlay
   --------------------------------------------------------------------------- */

.results-container {
    display: none;
    flex-direction: column;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(92vw, 700px);
    max-height: min(80vh, 80dvh);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    z-index: 100;
    overflow: hidden;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;
    padding: 0.9rem 1.25rem;
    background: #333;
    color: #fff;
    font-weight: 600;
    font-size: 15px;
}

.results-body {
    flex: 1 1 auto;
    max-height: calc(min(80vh, 80dvh) - 56px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem;
    color: #333;
}

.results-body>p {
    color: #333;
    font-size: 0.95rem;
}

.result-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 0.85rem;
    padding: 0.7rem;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #fe8e14;
}

.result-item label {
    font-weight: 600;
    color: #555;
    margin-bottom: 0.2rem;
    font-size: 0.85rem;
}

.result-item span {
    color: #222;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.close-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.results-header .close-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ---------------------------------------------------------------------------
   Loading / error overlay
   --------------------------------------------------------------------------- */

.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-overlay p {
    max-width: 520px;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #fff;
}

.spinner {
    width: 46px;
    height: 46px;
    border: 5px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fe8e14;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ---------------------------------------------------------------------------
   Responsive design
   --------------------------------------------------------------------------- */

/* Tablets and small laptops */
@media only screen and (max-width: 768px) {
    .demo-header h1 {
        font-size: 1.2rem;
    }

    .demo-header .subtitle {
        font-size: 0.78rem;
    }

    .mode-option {
        padding: 0.6rem 1.1rem;
        font-size: 0.85rem;
        gap: 0.4rem;
    }

    .mode-icon {
        width: 18px;
        height: 18px;
    }

    #main-container {
        width: 100%;
    }

    .results-container {
        width: 100%;
    }
}

/* Phones */
@media only screen and (max-width: 480px) {
    .demo-shell {
        padding: calc(6px + env(safe-area-inset-top)) 8px calc(6px + env(safe-area-inset-bottom));
        gap: 6px;
    }

    /* The camera is the point of this demo, so trim the header on phones. */
    .demo-header .subtitle {
        display: none;
    }

    .demo-header h1 {
        font-size: 1.05rem;
    }

    #scanner-app {
        gap: 6px;
    }

    .mode-switch {
        width: 100%;
        max-width: 300px;
    }

    .mode-option {
        padding: 0.5rem 0.7rem;
        font-size: 0.8rem;
    }

    #tip-message {
        font-size: 0.78rem;
        padding: 0.4rem 0.8rem;
    }

    .demo-footer {
        font-size: 0.7em;
        padding: 5px 8px;
    }

    /* Bottom sheet so the camera stays visible behind the results. */
    .results-container {
        top: auto;
        bottom: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-height: 85dvh;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .results-body {
        max-height: calc(85dvh - 52px);
        padding: 1rem;
    }

    .result-item {
        padding: 0.5rem;
        margin-bottom: 0.7rem;
    }
}

/* Landscape phones: every pixel of height counts. */
@media only screen and (max-height: 460px) and (orientation: landscape) {
    .demo-header .subtitle,
    .demo-footer {
        display: none;
    }

    .demo-header h1 {
        font-size: 1rem;
    }

    #tip-message {
        font-size: 0.75rem;
        padding: 0.3rem 0.7rem;
    }

    .mode-option {
        padding: 0.35rem 0.85rem;
        font-size: 0.75rem;
    }
}
