/* PokeTracker Dark Theme */
:root {
    --bg: #121212;
    --surface: #1E1E1E;
    --card: #2A2A2A;
    --card-hover: #333333;
    --primary: #E53935;
    --primary-dark: #B71C1C;
    --text: #FFFFFF;
    --text-secondary: #B0B0B0;
    --text-muted: #757575;
    --green: #4AD98A;
    --border: #3A3A3A;
    --sidebar-width: 220px;
}

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

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

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--primary); }

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    padding: 20px 16px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.sidebar-nav {
    list-style: none;
    padding: 8px 0;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
    font-size: 0.95rem;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--card);
    color: var(--text);
}

.sidebar-nav a.active {
    border-left: 3px solid var(--primary);
    padding-left: 13px;
}

.sidebar-nav .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-nav .nav-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 16px;
}

/* Main content */
.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 24px 32px;
    max-width: 1200px;
}

/* Page header */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* Search */
.search-bar {
    margin-bottom: 20px;
}

.search-bar input {
    width: 100%;
    max-width: 400px;
    padding: 10px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}

.search-bar input:focus {
    border-color: var(--primary);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

/* Filter chips */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.chip {
    display: inline-block;
    padding: 6px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.chip:hover, .chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text);
}

/* Card grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.card-item {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.15s, background 0.15s;
    cursor: pointer;
}

.card-item:hover {
    transform: translateY(-2px);
    background: var(--card-hover);
}

.card-item a {
    display: block;
}

.card-item .card-image {
    width: 100%;
    aspect-ratio: 0.72;
    object-fit: cover;
    background: var(--surface);
    display: block;
}

.card-item .card-info {
    padding: 10px 12px;
}

.card-item .card-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-item .card-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.card-item .card-price {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--green);
    margin-top: 4px;
}


.card-item .card-image-placeholder {
    background: var(--surface);
}

.card-toggles {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    border-top: 1px solid var(--border);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.78rem;
    flex: 1;
    justify-content: center;
}


/* Collection progress bar */
.progress-bar-wrap {
    margin-bottom: 20px;
}

.progress-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.progress-bar-track {
    height: 8px;
    background: var(--card);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 2px;
}

/* Pokemon grid */
.pokemon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}

.pokemon-item {
    background: var(--card);
    border-radius: 10px;
    padding: 12px 10px;
    text-align: center;
    transition: transform 0.15s, background 0.15s;
    cursor: pointer;
    position: relative;
}

.pokemon-item:hover {
    transform: translateY(-2px);
    background: var(--card-hover);
}

.pokemon-item.collected {
    border: 1px solid var(--green);
}

.collected-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    background: var(--green);
    color: #000;
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ar-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: #4A148C;
    color: #CE93D8;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 4px;
}

.pokemon-sprite {
    width: 68px;
    height: 68px;
    image-rendering: pixelated;
    display: block;
    margin: 0 auto 4px;
}

.pokemon-item .pokemon-dex {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: monospace;
}

.pokemon-item .pokemon-name {
    font-size: 0.82rem;
    font-weight: 600;
    margin-top: 4px;
    word-break: break-word;
}

.pokemon-item .pokemon-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Pokemon detail card list */
.pokemon-card-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pokemon-card-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 14px;
    background: var(--card);
    border-radius: 10px;
    transition: background 0.15s;
    flex-wrap: wrap;
}

.pokemon-card-row:hover {
    background: var(--card-hover);
}

.pokemon-card-link {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.card-thumb {
    width: 52px;
    height: 72px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--surface);
    flex-shrink: 0;
}

.card-thumb-empty {
    display: block;
    background: var(--surface);
    border-radius: 4px;
}

.pokemon-card-info {
    flex: 1;
    min-width: 0;
}

.pokemon-card-info .card-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pokemon-card-info .card-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.pokemon-card-info .card-artist {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.pokemon-card-info .card-price {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--green);
    margin-top: 2px;
}

/* Debug image URL display */
.card-image-url {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    word-break: break-all;
    max-width: 300px;
    line-height: 1.3;
    opacity: 0.7;
}

/* Card thumb wrapper for fallback badge */
.card-thumb-wrapper {
    position: relative;
    flex-shrink: 0;
}

.card-thumb-wrapper .card-thumb {
    width: 52px;
    height: 72px;
}

.fallback-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #4A90D9;
    color: #fff;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 1px 3px;
    border-radius: 2px;
    line-height: 1;
}

/* Card detail fallback badge */
.card-image-lg-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.card-image-lg-wrapper .card-image-lg {
    width: 100%;
}

.fallback-badge-lg {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #4A90D9;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Pokemon detail right section (prices + buttons) */
.pokemon-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.pokemon-card-right .btn-group {
    margin-top: 0;
}

/* Price table on pokemon detail */
.price-table-wrap {
    overflow-x: auto;
}

.price-table {
    border-collapse: collapse;
    font-size: 0.8rem;
}

.price-table thead th {
    padding: 2px 8px 6px;
    text-align: center;
    font-weight: 400;
}

.price-table .bucket-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    padding: 3px 10px 3px 0;
    white-space: nowrap;
    text-align: right;
    font-weight: 500;
}

.price-table .price-cell {
    padding: 3px 8px;
    text-align: center;
    min-width: 60px;
}

.price-table .price-value {
    font-weight: 600;
    color: var(--green);
    white-space: nowrap;
}

.price-table .price-link {
    font-weight: 600;
    color: var(--green);
    white-space: nowrap;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.price-table .price-link:hover {
    color: #6fffb0;
}

.price-table .price-na {
    color: var(--text-muted);
}

/* Language-specific price colors */
.lang-price-ja { color: #ff8a80; }
.lang-price-en { color: #82b1ff; }
.lang-price-cn { color: #69f0ae; }

/* Set list */
.set-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.set-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: var(--card);
    border-radius: 10px;
    transition: background 0.15s;
}

.set-item:hover {
    background: var(--card-hover);
}

.set-thumb {
    width: 50px;
    height: 65px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
}

.set-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
}

.set-thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--surface);
}

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

.set-item .set-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.set-item .set-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* Detail pages */
.detail-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.detail-header img {
    width: 80px;
    height: 80px;
    image-rendering: pixelated;
}

.detail-header .detail-title {
    font-size: 1.4rem;
    font-weight: 700;
}

.detail-header .detail-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* Card detail */
.card-detail {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 32px;
}

.card-detail .card-image-lg {
    width: 100%;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.card-detail .card-meta-table {
    width: 100%;
    border-collapse: collapse;
}

.card-detail .card-meta-table td {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.card-detail .card-meta-table td:first-child {
    color: var(--text-secondary);
    width: 120px;
    font-size: 0.85rem;
}

/* Price section */
.price-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.price-card {
    background: var(--card);
    border-radius: 10px;
    padding: 14px;
}

.price-card .price-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.price-card .price-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--green);
}

.price-card .price-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

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

.btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text);
}

.btn-group {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* Rarity badge */
.rarity-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--border);
    color: var(--text-secondary);
}

.rarity-badge.art-rare { background: #1A237E; color: #90CAF9; }
.rarity-badge.special-art-rare { background: #4A148C; color: #CE93D8; }
.rarity-badge.hyper-rare { background: #B71C1C; color: #EF9A9A; }
.rarity-badge.mega-attack-rare { background: #E65100; color: #FFCC80; }

/* Language badge */
.lang-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--border);
    color: var(--text-secondary);
}

.lang-badge.lang-ja { background: #D94A4A; color: #fff; }
.lang-badge.lang-en { background: #4A90D9; color: #fff; }
.lang-badge.lang-cn { background: #4AD98A; color: #fff; }

/* Wishlist list */
.wishlist-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wishlist-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--card);
    border-radius: 10px;
    transition: background 0.15s;
}

.wishlist-row:hover {
    background: var(--card-hover);
}

.wishlist-thumb img {
    width: 56px;
    height: 78px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--surface);
    flex-shrink: 0;
}

.wishlist-thumb-empty {
    width: 56px;
    height: 78px;
    background: var(--surface);
    border-radius: 4px;
    flex-shrink: 0;
}

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

.wishlist-row .card-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wishlist-row .card-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Multi-language price columns */
.wishlist-prices {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.wishlist-lang-price {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 52px;
}

.lang-price-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.lang-price-badge.lang-ja { background: #B71C1C; color: #FFCDD2; }
.lang-price-badge.lang-en { background: #0D47A1; color: #BBDEFB; }
.lang-price-badge.lang-cn { background: #1B5E20; color: #C8E6C9; }

.lang-price-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--green);
    white-space: nowrap;
}

.lang-price-na {
    color: var(--text-muted);
    font-weight: 400;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 1rem;
}

/* Loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.back-link:hover { color: var(--text); }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border);
    }

    .sidebar-brand { display: none; }

    .sidebar-nav {
        display: flex;
        padding: 0;
        width: 100%;
    }

    .sidebar-nav a {
        flex: 1;
        flex-direction: column;
        gap: 4px;
        padding: 10px 8px;
        font-size: 0.75rem;
        text-align: center;
        justify-content: center;
    }

    .sidebar-nav a.active {
        border-left: none;
        border-top: 2px solid var(--primary);
        padding-left: 8px;
    }

    .main {
        margin-left: 0;
        margin-bottom: 70px;
        padding: 16px;
    }

    .card-detail {
        grid-template-columns: 1fr;
    }

    .card-detail .card-image-lg {
        max-width: 280px;
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .wishlist-prices {
        gap: 8px;
    }

    .wishlist-lang-price {
        min-width: 44px;
    }

    .lang-price-value {
        font-size: 0.78rem;
    }
}

@media (max-width: 480px) {
    .wishlist-row {
        flex-wrap: wrap;
    }

    .wishlist-prices {
        width: 100%;
        justify-content: space-evenly;
        padding-top: 8px;
        margin-top: 4px;
        border-top: 1px solid var(--border);
    }

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

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

/* Collection quantity control (+/-) */
.collection-qty-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
}

.collection-qty-ctrl .qty-badge {
    min-width: 20px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-qty {
    padding: 4px 8px;
    min-width: 28px;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
}
