/* ─── Reset & Base ─── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: row;
}

/* ─── Sidebar Navbar ─── */
.navbar {
    width: 220px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    z-index: 100;
    box-shadow: var(--shadow);
    box-sizing: border-box;
    overflow-y: auto;
    transition: width 0.2s ease, padding 0.2s ease, border 0.2s ease;
}

/* 사이드바 안의 접기 버튼 */
.nav-collapse {
    position: absolute;
    top: 12px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    z-index: 101;
}
.nav-collapse:hover { background: #f1f5f9; color: var(--text); }

/* 사이드바 밖, 접혔을 때만 보이는 펴기 버튼 */
.nav-expand {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}
.nav-expand:hover { background: #f1f5f9; color: var(--text); }

/* 접힌 상태 */
body.sidebar-collapsed .navbar {
    width: 0;
    padding: 0;
    border-right: 0;
    overflow: hidden;
}
body.sidebar-collapsed .nav-collapse { display: none; }
body.sidebar-collapsed .nav-expand { display: inline-flex; }
body.sidebar-collapsed .main-content { padding-left: 56px; }

.nav-container {
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    gap: 20px;
}

.nav-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
    padding: 6px 8px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 0 auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
}

.nav-link:hover {
    background: #f1f5f9;
    color: var(--text);
}

.nav-link.active {
    background: #eef2ff;
    color: var(--primary);
}

.nav-icon {
    font-size: 16px;
}

.nav-country {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.nav-country label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.nav-country select {
    width: 100%;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface);
    cursor: pointer;
    outline: none;
}

.nav-country select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

/* 로그인된 사용자 정보 + 로그아웃 — 사이드바 하단 */
.nav-user {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.nav-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-user-form { margin: 0; }
.nav-user-logout {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.nav-user-logout:hover { background: #f1f5f9; color: var(--text); border-color: #cbd5e1; }

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    min-width: 0;
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ─── Mobile fallback: 사이드바를 다시 상단 가로 navbar로 ─── */
@media (max-width: 768px) {
    body { flex-direction: column; }
    .navbar {
        width: 100%; height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding: 0 24px;
        position: sticky; top: 0;
        align-self: stretch;
        overflow-y: visible;
    }
    .nav-container {
        flex-direction: row;
        align-items: center;
        height: 64px;
        gap: 32px;
    }
    .nav-logo { padding: 0; border: 0; }
    .nav-links { flex-direction: row; flex: 1; }
    .nav-country {
        flex-direction: row; align-items: center; gap: 8px;
        padding: 0; border: 0;
    }
    .nav-country select { width: auto; }

    /* 모바일에서는 사이드바 토글 비활성화 (상단 nav로 펼쳐져 있음) */
    .nav-collapse, .nav-expand { display: none !important; }
    body.sidebar-collapsed .navbar {
        width: 100%; padding: 0 24px;
        border-right: 0; border-bottom: 1px solid var(--border);
    }
    body.sidebar-collapsed .main-content { padding-left: 24px; }
}

/* ─── Hero / Home ─── */
.hero {
    text-align: center;
    padding: 60px 0 40px;
}

.hero h1 {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 12px;
}

.hero-desc {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 48px;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    max-width: 960px;
    margin: 0 auto;
}

.home-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 28px;
    text-decoration: none;
    color: var(--text);
    transition: all .2s;
    box-shadow: var(--shadow);
}

.home-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.home-card-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.home-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.home-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
}

/* ─── Page Header ─── */
.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-header p {
    color: var(--text-secondary);
}

/* ─── Upload Area ─── */
.content-layout {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.upload-section {
    max-width: 640px;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all .2s;
    background: var(--surface);
    position: relative;
    overflow: hidden;
}

.upload-area.compact {
    padding: 32px 24px;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: #fafafe;
}

.upload-placeholder {
    pointer-events: none;
}

.upload-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.upload-hint {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.upload-preview {
    max-width: 100%;
    max-height: 400px;
    border-radius: 8px;
    object-fit: contain;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    margin-top: 16px;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-capture {
    background: #dc2626;
    color: white;
    padding: 14px 32px;
    font-size: 16px;
    border-radius: 50px;
    margin: 0;
}

.btn-capture:hover:not(:disabled) {
    background: #b91c1c;
}

.capture-icon {
    font-size: 20px;
}

/* ─── Results & Products ─── */
.results-section {
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.results-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.result-count {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all .2s;
    box-shadow: var(--shadow);
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.product-card a {
    text-decoration: none;
    color: inherit;
}

.product-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: #f1f5f9;
}

.product-info {
    padding: 14px;
}

.product-name {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.product-similarity {
    font-size: 12px;
    color: var(--text-secondary);
}

.similarity-bar {
    height: 4px;
    background: #e2e8f0;
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.similarity-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width .3s;
}

/* ─── Scene Match Layout ─── */
.scene-layout {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.video-section {
    max-width: 800px;
}

.scene-player {
    width: 100%;
    border-radius: var(--radius);
    background: #000;
    max-height: 480px;
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
    justify-content: center;
}

.timestamp {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.captured-frames {
    display: none;
    gap: 12px;
    margin-top: 20px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.frame-thumb {
    flex-shrink: 0;
    width: 120px;
    text-align: center;
}

.frame-thumb img {
    width: 120px;
    height: 68px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid var(--border);
}

.frame-thumb span {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: block;
}

.scene-results-section {
    border-top: 1px solid var(--border);
    padding-top: 24px;
}

.scene-result-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.scene-result-header h2 {
    font-size: 20px;
}

.captured-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.captured-thumbnail {
    width: 80px;
    height: 45px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid var(--primary);
}

.captured-time {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .home-grid {
        grid-template-columns: 1fr;
    }

    .nav-container {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 0;
        gap: 8px;
    }

    .nav-links {
        order: 3;
        width: 100%;
        overflow-x: auto;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}
