/* ==========================================================================
   Import Media — Unmapped folder import UI
   ========================================================================== */

/* Override apps_section global .content-section { overflow: hidden } - Import Media must scroll */
#settingsImportMediaSection.content-section.active,
#mediaHuntSettingsImportMediaSection.content-section.active {
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

#settingsImportMediaSection .import-media-settings-group,
#mediaHuntSettingsImportMediaSection .import-media-settings-group {
    padding-bottom: 40px;
}

/* Header */
.import-media-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.import-media-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 0 0 4px 0;
    color: var(--text-primary, #e2e8f0);
}

.import-media-help {
    color: var(--text-secondary, rgba(148, 163, 184, 0.8));
    font-size: 0.88rem;
    margin: 0;
    line-height: 1.5;
}

.import-media-header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.import-media-header-actions .btn-scan,
.import-media-header-actions .btn-import-all {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-scan {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.2) !important;
}

.btn-scan:hover {
    background: rgba(99, 102, 241, 0.25);
}

.btn-scan:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-import-all {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.2) !important;
}

.btn-import-all:hover {
    background: rgba(34, 197, 94, 0.25);
}

/* Status bar */
.import-media-status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 10px;
    margin-bottom: 16px;
}

.import-media-status-icon i {
    color: #a5b4fc;
    font-size: 16px;
}

.import-media-status-text {
    color: #93c5fd;
    font-size: 0.9rem;
}

/* Stats summary */
.import-media-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.import-media-stat {
    display: flex;
    align-items: center;
    gap: 6px;
}

.import-media-stat .stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #e2e8f0;
}

.import-media-stat .stat-label {
    font-size: 0.82rem;
    color: rgba(148, 163, 184, 0.7);
}

.import-media-stat.matched .stat-value { color: #4ade80; }
.import-media-stat.pending .stat-value { color: #fbbf24; }
.import-media-stat.no-match .stat-value { color: #f87171; }

.import-media-stat-last-scan {
    margin-left: auto;
    font-size: 0.82rem;
    color: rgba(148, 163, 184, 0.5);
}

/* Table Header - sticky within settings-group */
.import-media-list-header {
    display: grid;
    grid-template-columns: 45px 1.5fr 1fr 120px 200px;
    align-items: center;
    gap: 20px;
    padding: 12px 16px;
    border-left: 3px solid transparent; /* Match item card alignment */
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: -24px; /* Pull up to the top of the .settings-group padding */
    z-index: 50;
    background: #111827; /* Solid background to prevent overlap clash */
    border-radius: 10px 10px 0 0;
}

.import-media-list-header .header-col {
    font-size: 0.7rem;
    font-weight: 700;
    color: rgba(148, 163, 184, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Empty state */
.import-media-empty {
    text-align: center;
    padding: 60px 20px;
    color: rgba(148, 163, 184, 0.5);
}

.import-media-empty i {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
    opacity: 0.4;
}

.import-media-empty p {
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Item cards */
.import-media-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
}

/* Desktop: grid layout for consistent column alignment */
.import-media-item {
    display: grid;
    grid-template-columns: 45px 1.5fr 1fr 120px 200px;
    align-items: center;
    gap: 20px;
    padding: 12px 16px 12px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    margin-left: 0;
}

.import-media-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.import-media-item.status-matched {
    border-left-color: #4ade80;
}

.import-media-item.status-pending {
    border-left-color: #fbbf24;
}

.import-media-item.status-no_match {
    border-left-color: #f87171;
}

/* Poster thumbnail */
.import-media-poster {
    width: 45px;
    height: 68px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.3);
}

.import-media-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Folder info */
.import-media-info {
    min-width: 0;
}

.import-media-folder-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.import-media-folder-path {
    font-size: 0.78rem;
    color: rgba(148, 163, 184, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.import-media-file-info {
    font-size: 0.78rem;
    color: rgba(148, 163, 184, 0.6);
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.import-media-file-info span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Match info (Movie title/year) */
.import-media-match-info {
    min-width: 0;
}

.import-media-match-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #4ade80;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.import-media-match-year {
    font-size: 0.82rem;
    color: rgba(148, 163, 184, 0.6);
}

/* Match confidence */
.import-media-match-confidence {
    text-align: left;
}

.import-media-match-confidence .conf-label {
    font-size: 0.7rem;
    color: rgba(148, 163, 184, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1px;
}

.import-media-match-confidence .conf-value {
    font-size: 0.85rem;
    font-weight: 600;
}

.import-media-match-confidence .conf-value.high { color: #4ade80; }
.import-media-match-confidence .conf-value.medium { color: #fbbf24; }
.import-media-match-confidence .conf-value.low { color: #f87171; }

.import-media-no-match-text {
    font-size: 0.88rem;
    color: #f87171;
    font-style: italic;
}

.import-media-pending-text {
    font-size: 0.88rem;
    color: #fbbf24;
    font-style: italic;
}

/* Action buttons */
.import-media-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-start;
    width: 100%;
}

.import-media-actions button {
    padding: 6px 10px;
    border-radius: 6px;
    border: none;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.import-media-btn-confirm {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.import-media-btn-confirm:hover {
    background: rgba(34, 197, 94, 0.3);
}

.import-media-btn-confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.import-media-btn-search {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
}

.import-media-btn-search:hover {
    background: rgba(99, 102, 241, 0.3);
}

.import-media-btn-skip {
    background: rgba(148, 163, 184, 0.08);
    color: rgba(148, 163, 184, 0.6);
}

.import-media-btn-skip:hover {
    background: rgba(148, 163, 184, 0.15);
    color: rgba(148, 163, 184, 0.9);
}

.import-media-btn-matches {
    background: rgba(168, 85, 247, 0.15);
    color: #c084fc;
}

.import-media-btn-matches:hover {
    background: rgba(168, 85, 247, 0.3);
}

/* ===== Search Modal ===== */
.import-media-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.import-media-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.import-media-modal-content {
    position: relative;
    background: linear-gradient(135deg, rgba(20, 27, 45, 0.98), rgba(15, 20, 35, 0.98));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.import-media-modal-header {
    margin-bottom: 20px;
}

.import-media-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    color: rgba(148, 163, 184, 0.6);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.import-media-modal-close:hover {
    color: #e2e8f0;
}

.import-media-modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #e2e8f0;
    margin: 0 0 4px;
}

.import-media-modal-subtitle {
    font-size: 0.85rem;
    color: rgba(148, 163, 184, 0.6);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search form */
.import-media-search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.import-media-search-row .control-input {
    flex: 1;
}

.import-media-search-row .btn-search {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    cursor: pointer;
    font-size: 14px;
}

.import-media-search-row .btn-search:hover {
    background: rgba(99, 102, 241, 0.35);
}

/* Search results */
.import-media-search-results {
    max-height: 400px;
    overflow-y: auto;
}

.import-media-search-hint {
    text-align: center;
    color: rgba(148, 163, 184, 0.5);
    padding: 30px 0;
    font-size: 0.9rem;
}

.import-media-search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.import-media-search-result:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.15);
}

.import-media-search-result-poster {
    width: 40px;
    height: 60px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.3);
}

.import-media-search-result-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.import-media-search-result-info {
    flex: 1;
    min-width: 0;
}

.import-media-search-result-title {
    font-size: 0.92rem;
    font-weight: 500;
    color: #e2e8f0;
}

.import-media-search-result-meta {
    font-size: 0.8rem;
    color: rgba(148, 163, 184, 0.6);
    margin-top: 2px;
}

.import-media-search-result-overview {
    font-size: 0.78rem;
    color: rgba(148, 163, 184, 0.4);
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.import-media-search-result .select-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    font-size: 0.82rem;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}

.import-media-search-result .select-btn:hover {
    background: rgba(34, 197, 94, 0.3);
}

/* ===== Alternative matches dropdown ===== */
.import-media-matches-dropdown {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
    background: rgba(20, 27, 45, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 8px;
    min-width: 280px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.import-media-matches-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.import-media-matches-dropdown-item:hover {
    background: rgba(99, 102, 241, 0.1);
}

.import-media-matches-dropdown-item .poster {
    width: 30px;
    height: 45px;
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.3);
}

.import-media-matches-dropdown-item .poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.import-media-matches-dropdown-item .info {
    flex: 1;
}

.import-media-matches-dropdown-item .info .title {
    font-size: 0.85rem;
    font-weight: 500;
    color: #e2e8f0;
}

.import-media-matches-dropdown-item .info .year {
    font-size: 0.78rem;
    color: rgba(148, 163, 184, 0.5);
}

/* Responsive */
@media (max-width: 1100px) {
    .import-media-list-header {
        display: none;
    }
    
    .import-media-item {
        grid-template-columns: 45px 1.2fr 1fr auto;
        gap: 15px;
    }
    .import-media-match-confidence {
        display: none;
    }
}

@media (max-width: 900px) {
    .import-media-item {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }

    .import-media-poster {
        width: 50px;
        height: 75px;
    }

    .import-media-info {
        flex: 1;
        min-width: 0;
    }

    .import-media-match-info {
        text-align: left;
        min-width: auto;
        width: 100%;
        margin-top: 5px;
    }

    .import-media-match-title {
        white-space: normal;
    }

    .import-media-match-confidence {
        display: block;
        width: 100%;
        text-align: left;
        margin-bottom: 5px;
    }

    .import-media-actions {
        width: 100%;
        justify-content: flex-start;
        min-width: auto;
    }
}

@media (max-width: 768px) {
    .import-media-header {
        flex-direction: column;
    }

    .import-media-stats {
        gap: 10px;
    }
}
