/* ========================================================================================================== */
/* Variables */
:root {
    --mainColor: #2096f3;
    --secondColor: #4cafef;
    --bg1: rgba(184, 184, 184, 0.68);
    --bg2: rgba(255, 255, 255, 0.87);
    --bg3: rgba(255, 255, 255, 0.31);
    --btow: #000;
    --wtob: #fff;
    --bshdaow: rgb(0 0 0 / 40%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg1: rgb(18, 18, 18);
        --bg2: rgb(0, 0, 0);
        --bg3: #2a2a2a;
        --btow: #fff;
        --wtob: #000;
        --bshdaow: rgb(255 255 255 / 40%);
    }
}

/* ========================================================================================================== */
/* Global Rules */
html {
    scroll-behavior: smooth;
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg1);
}

.container {
    padding: 0 15px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .container {
        width: 750px;
    }
}

@media (min-width: 992px) {
    .container {
        width: 970px;
    }
}

@media (min-width: 1200px) {
    .container {
        width: 1170px;
    }
}

.image>img {
    width: 100%;
}

.flex {
    display: flex;
    justify-content: center;
    align-items: center;
}

ul {
    list-style-type: none;
}

button {
    margin-right: 30px;
    padding: 20px 40px;
    border: none;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    transition: all 0.3s ease-in-out;
}

/* ========================================================================================================== */
/* Header */
.start-header {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100px;
    padding: 10px 0;
    background-color: var(--bg2);
    color: var(--wtob);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.title-autograph {
    font-family: "Neonderthaw", cursive;
    font-size: 2.5rem;
    margin: 0;
    color: var(--mainColor);
    text-shadow: 0 0 10px var(--bshdaow);
    transition: transform 1s ease-in-out, text-shadow 1s ease-in-out;
}

.go-to-options {
    position: absolute;
    right: 25px;
    display: flex;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.6s ease-in-out, visibility 0.6s;
}

.options-btn {
    margin: auto 20px;
    padding: 10px 20px;
    font-size: 40px;
    background-color: transparent;
    color: var(--mainColor);
    border: 2px solid var(--mainColor);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.options-btn:hover {
    background-color: var(--mainColor);
    color: var(--wtob);
}

@media (max-width: 768px) {
    .start-header {
        flex-direction: column;
        height: auto;
        padding: 15px 10px;
    }

    .title-autograph {
        font-size: 2.5rem;
        margin-bottom: 12px;
        transform: none !important;
        text-align: center;
    }

    .go-to-options {
        position: static;
        flex-direction: row;
        visibility: visible !important;
        opacity: 1 !important;
        margin: 0;
    }

    .options-btn {
        font-size: 20px;
        margin: 0 10px;
        padding: 5px 10px;
    }
}

/* ========================================================================================================== */
/* Upload Box */
.upload-box {
    display: grid;
    width: 500px;
    margin: 50px auto;
    padding: 40px;
    text-align: center;
    border: 2px dashed #666;
    border-radius: 8px;
    background-color: var(--bg2);
    cursor: pointer;
    transition: border-color 0.3s, background-color 0.3s;
}

.upload-box:hover {
    border-color: #999;
    background-color: var(--bg3);
}

.upload-box.dragover {
    border-color: var(--secondColor);
    background-color: #222;
}

.upload-box i {
    margin-bottom: 10px;
    font-size: 40px;
    color: #aaa;
}

.upload-box span {
    margin: 5px 0;
    color: #aaa;
}

.upload-box .btn {
    margin-top: 10px;
    padding: 8px 20px;
    display: inline-block;
    background: #333;
    border-radius: 5px;
    color: #ccc;
    transition: background 0.3s;
}

.upload-box .btn:hover {
    background: var(--secondColor);
    color: #fff;
}

.upload-box input[type="file"] {
    display: none;
}

@media (max-width: 768px) {
    .upload-box {
        width: 90%;
        margin: 20px 5%;
    }
}

/* ========================================================================================================== */
/* Scan Box & Viewer */
.scan-box {
    display: none;
    width: 750px;
    height: 600px;
    margin: 20px auto;
    background: #111;
    border: 2px solid #444;
    border-radius: 12px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#scanImage {
    /* user-drag: none; */
    -webkit-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
}

.viewer-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1000px;
    height: 100%;
    background-color: var(--bg2);
    border: 2px solid var(--mainColor);
    border-radius: 10px;
    box-shadow: 0 0 20px var(--bshdaow);
    overflow: hidden;
}

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

.viewer-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--mainColor);
}

.viewer-tools button {
    padding: 6px 12px;
    font-size: 1rem;
    background: none;
    border: 1px solid var(--mainColor);
    border-radius: 6px;
    color: var(--mainColor);
    cursor: pointer;
}

.viewer-tools button:hover {
    background-color: var(--mainColor);
    color: var(--wtob);
}

.viewer-image {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #000;
    overflow: hidden;
}

.viewer-image img {
    display: block;
    max-width: none;
    max-height: none;
}

.viewer-footer {
    padding: 12px 20px;
    text-align: right;
    background-color: var(--bg3);
    border-top: 1px solid var(--mainColor);
}

.diagnose-btn {
    padding: 10px 20px;
    font-size: 1rem;
    background-color: var(--mainColor);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.diagnose-btn:hover {
    background-color: #1976d2;
}

/* (Responsive breakpoints for scan box remain same — omitted here for brevity) */

/* ========================================================================================================== */
/* Uploaded State Overrides */
body.uploaded .start-header .go-to-options {
    display: flex;
    visibility: visible;
    opacity: 1;
}

body.uploaded .upload-box {
    display: none;
}

body.uploaded .scan-box {
    display: flex;
}

body.uploaded .start-header .title-autograph {
    transform: translateX(calc(-50vw + 150px));
}

/* ========================================================================================================== */
/* Scan + Results Layout */
.scan-results-wrapper {
    display: block;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
    margin: 20px;
}

@media (max-width: 1000px) {
    .scan-results-wrapper {
        grid-template-columns: 1fr;
    }
}

/* ========================================================================================================== */
.results-box {
    display: none;
    flex-direction: column;
    gap: 12px;
    margin: auto;
    padding: 50px 25px;
    max-width: 600px;
    width: 100%;
    border-radius: 16px;
    background: var(--bg2);
    color: var(--btow);
    font-family: "Arial", sans-serif;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    cursor: default;
}

.results-box *::selection {
    background: var(--mainColor);
    color: var(--wtob);
}

.results-box *::-moz-selection {
    background: var(--mainColor);
    color: var(--wtob);
}

.result-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
}

.confidence-badge {
    align-self: flex-start;
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    background: #e6f7ef;
    color: #0f9d58;
    border: 1px solid #b3e6c8;
    border-radius: 9999px;
}

.result-summary {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.result-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.result-actions button {
    flex: 1;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease-in-out;
}

.preview-btn {
    background: rgb(209 213 223 / 92%);
    color: var(--mainColor);
}

.preview-btn:hover {
    background: rgba(209, 213, 223, 0.55);
}

.download-btn {
    background: var(--mainColor);
    color: #fff;
}

.download-btn:hover {
    background: var(--secondColor);
}

/* ========================================================================================================== */
/* Results Modal */
/* ========================================================================================================== */
/* Results Modal & Finder Modal (Shared) */
.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    /* Slight dim */
    backdrop-filter: blur(5px);
    z-index: 1200;
}

.modal.show {
    display: flex;
}

#results-modal .viewer {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 920px;
    height: 85vh;
    background: var(--bg2);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

/* ========================================================================================================== */
/* Finder Style Explorer */

.finder-window {
    width: 800px;
    height: 500px;
    background: #f5f5f7;
    /* macOS light gray */
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #333;
    animation: popIn 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    .finder-window {
        background: #1e1e1e;
        color: #fff;
        border: 1px solid #333;
    }
}

/* Header (Traffic Lights) */
.finder-header {
    height: 40px;
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 0 15px;
    position: relative;
}

@media (prefers-color-scheme: dark) {
    .finder-header {
        background: rgba(40, 40, 40, 0.9);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
}

.finder-controls {
    display: flex;
    gap: 8px;
    z-index: 10;
}

.close-dots {
    width: 12px;
    height: 12px;
    min-width: 12px;
    /* Prevent squashing */
    min-height: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    padding: 0;
    /* Critical: remove default button padding */
    appearance: none;
    /* Remove OS specific styling */
    -webkit-appearance: none;
    display: inline-block;
}

.close-dots.red {
    background: #ff5f56;
}

.close-dots.yellow {
    background: #ffbd2e;
}

.close-dots.green {
    background: #27c93f;
}

.close-dots:hover {
    opacity: 0.8;
}

.finder-title {
    position: absolute;
    width: 100%;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: inherit;
    pointer-events: none;
}

/* Navigation Bar (Breadcrumbs) */
.finder-nav {
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 15px;
    background: rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    gap: 5px;
    overflow-x: auto;
}

.crumb-btn {
    background: none;
    border: none;
    font-size: 0.9rem;
    color: #666;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.crumb-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
}

.crumb-btn.active {
    font-weight: 600;
    color: #007aff;
}

.crumb-separator {
    color: #aaa;
    font-size: 0.8rem;
}

@media (prefers-color-scheme: dark) {
    .crumb-btn {
        color: #aaa;
    }

    .crumb-btn:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    .crumb-btn.active {
        color: #0a84ff;
    }
}

/* Content Area (Grid) */
.finder-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    grid-auto-rows: 110px;
    gap: 15px;
}

.finder-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
    text-align: center;
}

.finder-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.finder-item.folder-item:hover {
    background: rgba(0, 122, 255, 0.1);
}

@media (prefers-color-scheme: dark) {
    .finder-item:hover {
        background: rgba(255, 255, 255, 0.1);
    }
}

.finder-icon {
    font-size: 40px;
    margin-bottom: 8px;
    color: #87ceeb;
    /* Folder Blue */
}

.finder-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.finder-label {
    font-size: 0.8rem;
    word-break: break-word;
    line-height: 1.2;
    max-width: 100%;
}


/* Upload Actions Group */
.upload-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 15px;
}

/* Matching the Load Sample button to Navbar Options Button */
.sample-load-btn {
    /* Inherits .options-btn properties from style.css lines 125-139 */
    /* Resizing to fit context */
    font-size: 1rem !important;
    /* Override large navbar size */
    padding: 8px 20px !important;
    margin: 0 !important;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: auto;
}

.sample-load-btn i {
    font-size: 1.1rem;
    margin: 0;
    color: inherit;
}


#results-modal .viewer iframe {
    flex: 1;
    width: 100%;
    border: none;
}

#results-modal .modal-controls {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem;
    background: var(--bg1);
}

#results-modal .close-btn {
    margin: 10px auto;
    padding: 0.4rem 0.7rem;
    font-size: 2rem;
    background: var(--mainColor);
    color: var(--btow);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s ease;
}

#results-modal .close-btn:hover {
    background: var(--secondColor);
}

/* =======================
Advanced Loader Styles
======================= */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(12, 18, 28, 0.85);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    z-index: 9999;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;

}

.global-loader.show {
    opacity: 1;
    pointer-events: all;
}

.loader-content {
    text-align: center;
    color: #fff;
    font-family: 'Poppins', sans-serif;
    animation: popIn 0.5s ease forwards;
}

.loader-subtext {
    margin-top: 15px;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    animation: fadeIn 1s ease 2s forwards;
    opacity: 0;
}

/* ======================= 
   Error Modal Styles 
======================= */
.error-window {
    background: var(--bg2);
    width: 400px;
    max-width: 90%;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    animation: popIn 0.3s ease forwards;
    overflow: hidden;
    text-align: center;
    border: 1px solid rgba(255, 0, 0, 0.2);
}

.error-header {
    background: #ff5f56;
    padding: 20px;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.error-header .error-icon {
    font-size: 3rem;
    margin-bottom: 5px;
}

.error-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.error-body {
    padding: 25px;
    color: var(--btow);
    font-size: 1rem;
    line-height: 1.5;
}

.error-footer {
    padding: 0 20px 20px;
}

.error-footer button {
    background: #ff5f56;
    color: white;
    padding: 10px 30px;
    border-radius: 6px;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
    margin: 0;
}

.error-footer button:hover {
    background: #ff3b30;
}



.loader-spinner {
    border: 5px solid rgba(255, 255, 255, 0.2);
    border-top: 5px solid #00c2ff;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
    box-shadow: 0 0 20px #00c2ff;
}

.loader-text {
    font-size: 1.2rem;
    letter-spacing: 0.5px;
    animation: pulse 1.5s ease-in-out infinite;
}

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

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

@keyframes pulse {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.85);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========================================================================================================== */
/* MOBILE LAYOUT — COMPLETE OVERRIDE (max-width: 768px) */
/* Desktop styles remain untouched */
/* ========================================================================================================== */

@media (max-width: 768px) {

    /* -------------------------------
       GLOBAL
       ------------------------------- */
    body {
        overflow-x: hidden;
    }

    .container {
        width: 100% !important;
        padding: 0 12px;
    }

    /* -------------------------------
       HEADER / NAVBAR
       ------------------------------- */
    .start-header {
        width: 100%;
        height: auto;
        padding: 12px 10px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 8px;
    }

    .title-autograph {
        max-width: 100%;
        font-size: 1.8rem;
        line-height: 1.1;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        transform: none !important;
    }

    body.uploaded .start-header .title-autograph {
        transform: none !important;
    }

    .go-to-options {
        position: static;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        visibility: visible;
        opacity: 1;
        margin: 0;
    }

    .options-btn {
        font-size: 1.1rem;
        padding: 6px 14px;
        margin: 0;
    }

    /* -------------------------------
       UPLOAD BOX
       ------------------------------- */
    .upload-box {
        width: 100%;
        margin: 16px 0;
        padding: 20px;
    }

    .upload-box i {
        font-size: 32px;
    }

    .upload-actions {
        flex-direction: column;
        gap: 10px;
    }

    .sample-load-btn {
        width: 100%;
        justify-content: center;
    }

    /* -------------------------------
       SCAN + RESULTS WRAPPER
       ------------------------------- */
    .scan-results-wrapper {
        display: flex;
        flex-direction: column;
        gap: 16px;
        margin: 12px 0;
    }

    /* -------------------------------
       SCAN BOX / VIEWER
       ------------------------------- */
    .scan-box {
        width: 100%;
        height: auto;
        margin: 0;
        border-radius: 10px;
    }

    .viewer-container {
        width: 100%;
        height: auto;
        border-radius: 10px;
    }

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

    .viewer-header h2 {
        font-size: 1rem;
    }

    .viewer-tools {
        width: 100%;
        display: flex;
        gap: 6px;
    }

    .viewer-tools button {
        flex: 1;
        font-size: 0.85rem;
        padding: 6px;
    }

    .viewer-image {
        min-height: 240px;
    }

    .viewer-footer {
        padding: 10px;
        text-align: center;
    }

    .diagnose-btn {
        width: 100%;
        padding: 12px;
    }

    /* -------------------------------
       RESULTS BOX
       ------------------------------- */
    .results-box {
        padding: 20px 16px;
        margin: 0;
        border-radius: 12px;
    }

    .result-title {
        font-size: 1.25rem;
    }

    .confidence-badge {
        font-size: 0.8rem;
    }

    .result-summary {
        font-size: 0.9rem;
    }

    .result-actions {
        flex-direction: column;
        gap: 8px;
    }

    .result-actions button {
        width: 100%;
    }

    /* -------------------------------
       MODALS
       ------------------------------- */
    #results-modal .viewer {
        width: 95%;
        height: 90vh;
    }

    #results-modal .close-btn {
        font-size: 1.5rem;
    }

    /* -------------------------------
       SAMPLE EXPLORER (FINDER)
       ------------------------------- */
    .finder-window {
        width: 96vw;
        height: 88vh;
        max-width: none;
        max-height: none;
        border-radius: 10px;
    }

    .finder-header {
        height: 44px;
        padding: 0 12px;
    }

    .finder-title {
        font-size: 0.85rem;
    }

    .finder-nav {
        height: auto;
        padding: 6px 10px;
    }

    .finder-content {
        padding: 14px;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        grid-auto-rows: 110px;
        gap: 12px;
    }

    .finder-icon {
        font-size: 42px;
    }

    .finder-thumb {
        width: 56px;
        height: 56px;
    }

    .finder-label {
        font-size: 0.75rem;
        line-height: 1.2;
    }

    /* -------------------------------
       GLOBAL LOADER
       ------------------------------- */
    .loader-spinner {
        width: 50px;
        height: 50px;
    }

    .loader-text {
        font-size: 1rem;
    }
}