/* Global Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary-color: #3b82f6;
    --accent-color: #8b5cf6;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: rgba(148, 163, 184, 0.1);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    --font-heading: 'Outfit', 'Inter', sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.15) 0%, transparent 40%);
    min-height: 100vh;
    overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    margin-bottom: 0.5em;
    letter-spacing: -0.02em;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    position: relative;
}

.app-title {
    font-size: 3rem;
    background: linear-gradient(135deg, #60a5fa 0%, #c084fc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
}

.app-subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 0.5rem;
}

/* Upload Zone */
.upload-section {
    max-width: 600px;
    margin: 0 auto 4rem;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 1rem;
    padding: 3rem;
    text-align: center;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
}

.drop-zone-content {
    pointer-events: none;
}

.icon-upload {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: block;
}

.drop-text {
    font-size: 1.2rem;
    font-weight: 500;
}

.drop-subtext {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.file-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.preview-container {
    margin-top: 2rem;
    display: none;
    text-align: center;
}

.preview-image {
    max-width: 200px;
    border-radius: 0.5rem;
    box-shadow: var(--glass-shadow);
    border: 1px solid var(--border-color);
}

.btn-search {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 0.5rem;
    cursor: pointer;
    margin-top: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}

.btn-search:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

/* Results Grid */
.results-section {
    display: none;
    /* Hidden by default */
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    display: inline-block;
}

.matches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 2rem;
}

.match-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    /* Clickable */
}

.match-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border-color: rgba(59, 130, 246, 0.3);
}

.match-img-container {
    height: 220px;
    overflow: hidden;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    background: rgba(0, 0, 0, 0.2);
}

.match-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.5s ease;
}

.match-card:hover .match-img {
    transform: scale(1.05);
}

.match-info {
    padding: 1.5rem;
}

.match-score {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #4ade80;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.9rem;
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.info-row {
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.info-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.info-value {
    font-weight: 600;
    text-align: right;
}

.similarity-bar-bg {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-top: 1rem;
    overflow: hidden;
}

.similarity-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), #4ade80);
    border-radius: 3px;
    width: 0%;
    transition: width 1s ease-out;
}

.load-more-container {
    text-align: center;
    margin-top: 3rem;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.8rem 2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}


/* Tab Buttons */
.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 1rem;
    font-size: 1rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
    font-weight: 500;
}

.tab-btn:hover {
    color: var(--text-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}

/* Lightbox Styles */
.lightbox {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(5px);
    overflow: auto;
}

.lightbox-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 80vh;
    border-radius: 5px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    animation-name: zoom;
    animation-duration: 0.3s;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    font-size: 1.2rem;
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
}

#caption.caption-centered {
    position: relative;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
    /* Inner div has background */
    padding: 0;
    width: 90%;
    max-width: 700px;
}

/* Popup Table Styles */
.user-table {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
}

.user-table td {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: normal;
}

/* Custom Multi-Select Dropdown */
.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem;
    font-size: 1rem;
    color: white;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s;
}

.custom-select-trigger:hover {
    border-color: var(--primary-color);
}

.custom-select-trigger:after {
    content: '\f078';
    /* FontAwesome Chevron Down */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 0.8rem;
    transition: transform 0.3s;
}

.custom-select.open .custom-select-trigger:after {
    transform: rotate(180deg);
}

.custom-options {
    position: absolute;
    display: block;
    top: 100%;
    left: 0;
    right: 0;
    border: 1px solid var(--border-color);
    border-top: 0;
    background: var(--bg-color);
    /* Opaque background to read clearly */
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-15px);
    transition: all 0.3s opacity, all 0.3s transform;
    max-height: 200px;
    overflow-y: auto;
}

.custom-select.open .custom-options {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
    transform: translateY(0);
}

.custom-option {
    position: relative;
    display: block;
    padding: 0.8rem 1rem 0.8rem 2.5rem;
    /* space for check */
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.custom-option:last-of-type {
    border-bottom: 0;
}

.custom-option:hover {
    background: rgba(59, 130, 246, 0.1);
    color: white;
}

.custom-option.selected {
    color: white;
    background: rgba(59, 130, 246, 0.2);
}

.custom-option.selected:before {
    content: '\f00c';
    /* Check */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary-color);
}

.close-lightbox {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    z-index: 1010;
}

.close-lightbox:hover,
.close-lightbox:focus {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
}

@keyframes zoom {
    from {
        transform: translateY(-50%) scale(0)
    }

    to {
        transform: translateY(-50%) scale(1)
    }
}


/* Compact Upload UI */
.upload-compact {
    text-align: center;
    padding: 1.5rem;
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    max-width: 400px;
    margin: 0 auto 2rem auto;
}

.upload-compact i {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    display: block;
}

.upload-compact h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    color: white;
}

.standard-file-input {
    width: 100%;
    max-width: 300px;
    color: var(--text-muted);
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.standard-file-input::file-selector-button {
    margin-right: 1rem;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    padding: 0.6rem 1.2rem;
    border-radius: 0.4rem;
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s ease;
}

.standard-file-input::file-selector-button:hover {
    opacity: 0.9;
}

/* Mobile & Tablet Optimization */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .app-title {
        font-size: 2rem;
    }

    .app-subtitle {
        font-size: 0.9rem;
    }

    /* Mobile Menu Fixes */
    .user-controls {
        position: relative !important;
        top: auto;
        right: auto;
        margin-top: 1.5rem;
        width: 100%;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .user-controls span {
        margin-right: 0 !important;
        margin-bottom: 0.5rem;
        font-weight: bold;
    }

    .user-controls a {
        margin: 0 !important;
        width: 100%;
        max-width: 200px;
        text-align: center;
    }

    .upload-section {
        margin-bottom: 2rem;
    }

    .drop-zone {
        padding: 2rem 1rem;
        position: relative;
        /* Ensure context for absolute input */
    }

    .file-input {
        z-index: 100;
        /* Force overlay on mobile */
        display: block;
    }

    .tab-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .tab-btn {
        width: 100%;
        text-align: center;
        padding: 1rem;
        /* Larger tap area */
        border-bottom: 1px solid var(--border-color);
        border-left: 4px solid transparent;
    }

    .tab-btn.active {
        border-bottom: 1px solid var(--border-color);
        border-left: 4px solid var(--primary-color);
    }

    .matches-grid {
        grid-template-columns: 1fr;
        /* Stack results on mobile */
        gap: 1.5rem;
    }

    .lightbox-content {
        max-width: 95%;
        width: 95%;
    }

    #caption {
        width: 95%;
        font-size: 1rem;
        padding: 1rem;
        margin-top: 1rem;
    }

    .custom-select-trigger {
        padding: 1rem;
        /* Larger tap target */
    }

    .btn-search {
        padding: 1rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .matches-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #1e293b;
    margin: 10% auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

/* Close Button for Modal */
.close {
    color: var(--text-muted);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
    white-space: nowrap;
}

.action-btn {
    width: 100%;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    white-space: nowrap;
    text-align: center;
}

/* Filename Truncation */
.filename-cell {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

@media (max-width: 768px) {

    .history-table th,
    .history-table td {
        padding: 0.5rem 0.25rem;
    }

    .action-buttons {
        gap: 0.3rem;
    }

    .action-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
}