/* JP Price Scout - Styles */
:root {
    --primary: #1A1A2E;
    --primary-dark: #0F0F1E;
    --primary-light: #F0F1F5;
    --accent: #4361EE;
    --accent-light: #EBF0FF;
    --bg: #F7F8FC;
    --card: #FFFFFF;
    --text: #1A1A2E;
    --text-secondary: #8B8FA3;
    --border: #E8EAF0;
    --success: #10B981;
    --warning: #F59E0B;
    --mercari: #FF4757;
    --mercari-bg: #FFF1F2;
    --mercari-border: #FFB3B8;
    --yahoo: #FF8C42;
    --yahoo-bg: #FFF5EB;
    --yahoo-border: #FFD0A8;
    --rakuma: #7C5CFC;
    --rakuma-bg: #F3F0FF;
    --rakuma-border: #C4B5FD;
    --nav-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --shadow-sm: 0 1px 3px rgba(26, 26, 46, 0.04);
    --shadow-md: 0 4px 12px rgba(26, 26, 46, 0.06);
    --shadow-lg: 0 8px 24px rgba(26, 26, 46, 0.08);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Pages */
.page {
    display: none;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
}
.page.active { display: block; }

/* Auth */
.auth-container {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #F7F8FC 0%, #E8ECFA 100%);
}
.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo-icon {
    font-size: 48px;
    margin-bottom: 8px;
}
.auth-logo h1 {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}
.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}
.auth-form {
    width: 100%;
    max-width: 360px;
    background: var(--card);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
}
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-radius: 10px;
    background: var(--bg);
    padding: 3px;
}
.auth-tab {
    flex: 1;
    padding: 9px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.auth-tab.active {
    background: var(--card);
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.auth-panel { display: none; }
.auth-panel.active { display: flex; flex-direction: column; gap: 12px; }

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    outline: none;
    transition: all 0.2s;
    background: var(--bg);
}
.auth-form input:focus {
    border-color: var(--accent);
    background: var(--card);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-primary:hover { background: #3651D4; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline {
    width: 100%;
    padding: 13px;
    background: none;
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-outline:hover { border-color: var(--text-secondary); }

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}

.error-msg {
    margin-top: 12px;
    padding: 10px;
    background: #FFF0F0;
    color: #CC0000;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}
.hidden { display: none !important; }

/* Header */
.top-bar {
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    z-index: 100;
}
.top-bar h2 {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.3px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.badge {
    background: var(--accent-light);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
}

/* Search */
.search-section {
    padding: 16px;
}
.search-box {
    display: flex;
    gap: 8px;
}
.search-box input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
    outline: none;
    background: var(--card);
    transition: all 0.2s;
}
.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}
.btn-search {
    padding: 12px 22px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.btn-search:hover { background: #3651D4; }
.btn-search:active { transform: scale(0.97); }
.btn-search:disabled { opacity: 0.5; }

.search-options {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}
.platform-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Platform Chips - Search */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    background: var(--card);
    border: 1.5px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    color: var(--text-secondary);
}
.chip input { display: none; }

.chip[data-platform="mercari"].active {
    border-color: var(--mercari);
    color: var(--mercari);
    background: var(--mercari-bg);
}
.chip[data-platform="yahoo"].active {
    border-color: var(--yahoo);
    color: var(--yahoo);
    background: var(--yahoo-bg);
}
.chip[data-platform="rakuma"].active {
    border-color: var(--rakuma);
    color: var(--rakuma);
    background: var(--rakuma-bg);
}

.chip.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.sold-toggle {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
}
.sold-toggle input {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.notice {
    margin-top: 10px;
    padding: 8px 12px;
    background: #FFFBEB;
    border: 1px solid #FDE68A;
    border-radius: 8px;
    font-size: 12px;
    color: #92400E;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Stats Card */
.stats-card {
    margin: 0 16px 12px;
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.stats-card h3 {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}
.stat-item {
    text-align: center;
    padding: 6px 2px;
    border-radius: 8px;
    background: var(--bg);
}
.stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}
.stat-value {
    display: block;
    font-size: 15px;
    font-weight: 800;
    color: var(--text);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 6px;
    padding: 0 16px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    background: var(--card);
    border: 1.5px solid var(--border);
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}
.filter-btn:active { transform: scale(0.96); }

/* All filter - active */
.filter-btn[data-filter="all"].active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* Platform filters - use platform colors when active */
.filter-btn[data-filter="mercari"].active {
    background: var(--mercari);
    border-color: var(--mercari);
    color: #fff;
}
.filter-btn[data-filter="yahoo"].active {
    background: var(--yahoo);
    border-color: var(--yahoo);
    color: #fff;
}
.filter-btn[data-filter="rakuma"].active {
    background: var(--rakuma);
    border-color: var(--rakuma);
    color: #fff;
}

.filter-count {
    font-size: 11px;
    opacity: 0.9;
    margin-left: 2px;
}

/* Results */
.results-section {
    padding: 0 16px;
}
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}
.results-header select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--card);
    outline: none;
    color: var(--text);
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.item-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: all 0.15s;
    border: 1px solid var(--border);
    border-left: 3.5px solid transparent;
}
.item-card:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-md);
}
.item-card.platform-mercari { border-left-color: var(--mercari); }
.item-card.platform-yahoo { border-left-color: var(--yahoo); }
.item-card.platform-rakuma { border-left-color: var(--rakuma); }

.item-card .thumb {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg);
    flex-shrink: 0;
}
.item-card .info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.item-card .title {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    color: var(--text);
}
.item-card .price {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary);
}
.item-card .meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Price & Profit Row */
.price-profit-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.profit-tag {
    font-size: 13px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    white-space: nowrap;
}
.profit-tag small {
    font-size: 11px;
    font-weight: 600;
    margin-left: 2px;
}
.profit-high {
    background: #ECFDF5;
    color: #059669;
}
.profit-plus {
    background: #F0FDF4;
    color: #16A34A;
}
.profit-minus {
    background: #FEF2F2;
    color: #DC2626;
}
.rate-great {
    color: #059669;
    font-weight: 700;
}
.cost-detail {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.platform-tag {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
}
.platform-tag.mercari {
    background: var(--mercari-bg);
    color: var(--mercari);
}
.platform-tag.yahoo {
    background: var(--yahoo-bg);
    color: var(--yahoo);
}
.platform-tag.rakuma {
    background: var(--rakuma-bg);
    color: var(--rakuma);
}

.sold-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: #FEE2E2;
    color: #DC2626;
    font-weight: 600;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}
.empty-state .sub {
    font-size: 13px;
    margin-top: 4px;
    opacity: 0.7;
}

/* History */
.history-list {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.history-item {
    background: var(--card);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.history-item:active { transform: scale(0.98); }
.history-keyword {
    font-weight: 600;
    font-size: 15px;
}
.history-meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Account */
.account-section {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.account-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.account-email {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
}
.plan-badge {
    display: inline-block;
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
}
.plan-badge.free {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.plan-badge.paid {
    background: linear-gradient(135deg, #F59E0B, #EF4444);
    color: #fff;
}

.upgrade-card {
    background: linear-gradient(135deg, #1A1A2E, #2D2B55);
    border-radius: var(--radius);
    padding: 24px;
    color: #fff;
}
.upgrade-card h3 {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 14px;
}
.upgrade-card ul {
    list-style: none;
    margin-bottom: 18px;
}
.upgrade-card li {
    padding: 4px 0;
    font-size: 14px;
    opacity: 0.9;
}
.upgrade-card li::before {
    content: "✓ ";
    font-weight: 700;
    color: #10B981;
}
.upgrade-card .btn-primary {
    background: #fff;
    color: var(--primary);
}
.upgrade-card .btn-primary:hover {
    background: #F0F1F5;
}

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 200;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 10px;
    padding: 6px 0;
    transition: color 0.2s;
}
.nav-item .nav-icon {
    font-size: 22px;
}
.nav-item.active {
    color: var(--accent);
}
.nav-label {
    font-weight: 600;
}

/* Settings */
.settings-section {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.settings-group {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.settings-group-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
}
.setting-row + .setting-row {
    border-top: 1px solid var(--bg);
}
.setting-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.setting-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.setting-dot.mercari { background: var(--mercari); }
.setting-dot.yahoo { background: var(--yahoo); }
.setting-dot.rakuma { background: var(--rakuma); }

.setting-input-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    transition: border-color 0.2s;
}
.setting-input-wrap:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}
.setting-input-wrap input {
    width: 72px;
    padding: 8px 0;
    border: none;
    background: transparent;
    font-size: 15px;
    font-weight: 600;
    text-align: right;
    outline: none;
    color: var(--text);
}
.setting-input-wrap input::-webkit-inner-spin-button {
    opacity: 0.3;
}
.setting-unit {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}
.setting-unit-pre {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
}

.settings-section .btn-primary {
    margin-top: 4px;
}

/* Responsive - stats grid on small screens */
@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .stat-value {
        font-size: 13px;
    }
}
