/* Reset and base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    color: #e0e0e0;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(90deg, #00d2ff, #3a7bd5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    margin-top: 0.5rem;
}

/* Top bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info span {
    color: #888;
}

.btn {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-primary {
    background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(58, 123, 213, 0.4);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
}

.btn-logout {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

.btn-logout:hover {
    background: rgba(255, 107, 107, 0.1);
}

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 120px;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: #888;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card.stat-fresh {
    border-color: rgba(0, 210, 255, 0.3);
}

.stat-card.stat-fresh .stat-value {
    color: #00d2ff;
}

.stat-card.stat-used {
    border-color: rgba(255, 152, 0, 0.3);
}

.stat-card.stat-used .stat-value {
    color: #ff9800;
}

/* Last updated */
.last-updated {
    color: #666;
    font-size: 0.75rem;
    margin-bottom: 1rem;
    text-align: right;
}

/* Filters */
.filters-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.6rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: #3a7bd5;
}

.search-input::placeholder {
    color: #666;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.filter-select option {
    background: #1a1a2e;
    color: #e0e0e0;
}

/* Folders header row */
.folders-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem 0.5rem 3rem;
    color: #666;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.folders-header-left {
    flex: 1;
}

.folders-header-sort {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    color: #555;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.sort-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #666;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.sort-btn:hover {
    color: #aaa;
    background: rgba(255, 255, 255, 0.05);
}

.sort-btn.active {
    color: #00d2ff;
    background: rgba(0, 210, 255, 0.1);
    border-color: rgba(0, 210, 255, 0.25);
    cursor: default;
}

/* ============================================================================
   Folder Cards
   ============================================================================ */

#folders-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.folder-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.folder-card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.folder-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.folder-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Expand arrow */
.folder-arrow {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.folder-arrow::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-style: solid;
    border-width: 5px 0 5px 7px;
    border-color: transparent transparent transparent #666;
    transition: transform 0.2s;
}

.folder-arrow.expanded::before {
    transform: translate(-50%, -50%) rotate(90deg);
}

/* Folder info */
.folder-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.folder-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-link {
    color: #7db4ff;
    text-decoration: none;
}

.folder-link:hover {
    text-decoration: underline;
}

.folder-name {
    color: #7db4ff;
}

.folder-breadcrumb {
    display: block;
    font-size: 0.72rem;
    color: #555;
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Folder stats */
.folder-stats {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.folder-total {
    font-size: 0.8rem;
    color: #888;
    white-space: nowrap;
}

.folder-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-fresh {
    background: rgba(0, 210, 255, 0.12);
    color: #00d2ff;
}

.badge-used {
    background: rgba(255, 152, 0, 0.12);
    color: #ff9800;
}

.badge-fresh-meta {
    background: rgba(33, 150, 243, 0.12);
    color: #2196f3;
}

.badge-fresh-ig {
    background: rgba(233, 30, 99, 0.12);
    color: #e91e63;
}

.used-reel {
    background: rgba(233, 30, 99, 0.15);
    color: #e91e63;
    border-color: rgba(233, 30, 99, 0.3);
}

/* Usage percentage badge */
.folder-pct {
    font-size: 0.8rem;
    font-weight: 700;
    min-width: 38px;
    text-align: right;
}

.pct-green {
    color: #4caf50;
}

.pct-orange {
    color: #ff9800;
}

.pct-red {
    color: #f44336;
}

.folder-date {
    font-size: 0.8rem;
    color: #666;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 90px;
    text-align: right;
}

/* Folder expanded content */
.folder-content {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.folder-loading {
    padding: 1.5rem;
    text-align: center;
    color: #888;
    font-size: 0.85rem;
}

.folder-empty {
    padding: 1.5rem;
    text-align: center;
    color: #666;
    font-size: 0.85rem;
}

/* Videos table inside folder */
.folder-videos-wrapper {
    overflow-x: auto;
}

.folder-videos-table {
    width: 100%;
    border-collapse: collapse;
}

.folder-videos-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    color: #777;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    white-space: nowrap;
}

.folder-videos-table th.th-thumb {
    width: 50px;
}

.folder-videos-table td {
    padding: 0.45rem 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.85rem;
    vertical-align: middle;
}

.folder-videos-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Table common styles */
.td-thumb {
    width: 50px;
    padding: 0.3rem 0.5rem;
}

.thumb {
    width: 44px;
    height: 33px;
    object-fit: cover;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.05);
    display: block;
}

.td-name {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-videos-table td a {
    color: #7db4ff;
    text-decoration: none;
}

.folder-videos-table td a:hover {
    text-decoration: underline;
}

/* Used badge */
.used-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    border: none;
    cursor: default;
}

.used-yes {
    background: rgba(255, 152, 0, 0.15);
    color: #ff9800;
    cursor: pointer;
    transition: background 0.2s;
}

.used-yes:hover {
    background: rgba(255, 152, 0, 0.3);
}

.used-no {
    background: rgba(0, 210, 255, 0.12);
    color: #00d2ff;
}

/* Usable toggle */
.usable-toggle {
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: #555;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    outline: none;
}

.usable-toggle.active {
    background: #4caf50;
}

.usable-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
}

.usable-toggle.active::after {
    transform: translateX(16px);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 0;
}

.pagination .page-info {
    color: #888;
    font-size: 0.875rem;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    backdrop-filter: blur(10px);
}

.login-card header {
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #aaa;
    font-size: 0.875rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: #3a7bd5;
}

.login-btn {
    width: 100%;
    padding: 0.85rem;
    margin-top: 0.5rem;
    background: linear-gradient(135deg, #00d2ff 0%, #3a7bd5 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(58, 123, 213, 0.4);
}

.login-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.login-error {
    color: #ff6b6b;
    font-size: 0.875rem;
    min-height: 1.5rem;
    display: none;
}

.login-error.visible {
    display: block;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 0.5rem;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.empty-state p {
    margin-bottom: 1rem;
}

/* Duration formatting */
.duration {
    color: #888;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* ============================================================================
   Match Detail Modal
   ============================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 4rem 1rem;
    z-index: 1000;
    overflow-y: auto;
}

.modal {
    background: #1e2a3a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    width: 100%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h3 {
    font-size: 1rem;
    color: #fff;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.7rem;
    color: #888;
}

/* Individual match ad block */
.match-ad {
    margin-bottom: 1.25rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    overflow: hidden;
}

.match-ad:last-child {
    margin-bottom: 0;
}

.match-ad-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
}

.match-ad-header a {
    color: #7db4ff;
    text-decoration: none;
    font-weight: 500;
}

.match-ad-header a:hover {
    text-decoration: underline;
}

.match-ad-folder {
    display: block;
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.15rem;
}

/* Match segments table inside modal */
.match-segments-table {
    width: 100%;
    border-collapse: collapse;
}

.match-segments-table th {
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    background: rgba(255, 255, 255, 0.02);
}

.match-segments-table td {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

/* Confidence labels */
.conf-high {
    color: #4caf50;
    font-weight: 600;
}

.conf-med {
    color: #ffc107;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .stats-bar {
        gap: 0.5rem;
    }

    .stat-card {
        min-width: 80px;
        padding: 0.75rem;
    }

    .stat-card .stat-value {
        font-size: 1.2rem;
    }

    .filters-bar {
        flex-direction: column;
    }

    .folder-row {
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .folder-stats {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .folder-date {
        display: none;
    }

    .folder-breadcrumb {
        display: none;
    }

    .folders-header {
        display: none;
    }

    .folder-videos-table {
        font-size: 0.8rem;
    }

    .td-thumb, .th-thumb {
        display: none;
    }

    .td-name {
        max-width: 150px;
    }

    .modal {
        max-width: 100%;
    }
}
