/* Design Tokens */
:root {
    /* Colors */
    --color-primary: #14213d;       /* Dark Blue */
    --color-primary-hover: #0a1120; /* Darker Blue */
    --color-primary-light: #fca311; /* Orange (Accent) */
    
    --color-text-main: #000000;     /* Black */
    --color-text-secondary: #14213d;/* Dark Blue (Headings/Subtitles) */
    --color-text-tertiary: #666666; /* Gray (Muted) */
    
    --color-bg-body: #e5e5e5;       /* Light Grey */
    --color-bg-surface: #ffffff;    /* White */
    --color-bg-elevated: #f8f9fa;   /* Very Light Gray */
    --color-border: #e5e5e5;        /* Light Gray */
    --color-border-strong: #14213d; /* Dark Blue */
    
    --color-success: #2e7d32;       /* Green */
    --color-warning: #fca311;       /* Orange */
    --color-error: #d32f2f;         /* Red */

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Typography */
    --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --font-size-xs: 0.75rem;     /* 12px */
    --font-size-sm: 0.875rem;    /* 14px */
    --font-size-base: 1rem;      /* 16px */
    --font-size-lg: 1.125rem;    /* 18px */
    --font-size-xl: 1.5rem;      /* 24px */
    
    /* UI Elements */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    
    --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --focus-ring: 0 0 0 3px rgba(252, 163, 17, 0.4);
    
    /* Control Height */
    --control-height: 48px;
}

/* Tom Select Overrides */
.ts-wrapper {
    width: 100%;
    min-height: var(--control-height);
    display: flex;
    align-items: center;
    position: relative; /* Ensure dropdown/clear button position correctly */
}

.ts-control {
    min-height: var(--control-height);
    line-height: var(--control-height);
    padding: 0 12px !important; /* Match form-control padding */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: none;
    font-size: var(--font-size-base);
    display: flex;
    align-items: center;
    width: 100%;
    position: relative;
    padding-right: 36px !important; /* Reserve space for clear button */
    background-color: var(--color-bg-surface);
}

/* Clear Button Styling */
.ts-wrapper .clear-button {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    font-weight: bold;
    color: var(--color-text-tertiary);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: color 0.2s, opacity 0.2s;
    z-index: 10;
    line-height: 1;
}

.ts-wrapper.has-items .clear-button {
    opacity: 1;
    pointer-events: auto;
}

.ts-wrapper .clear-button:hover {
    color: var(--color-text-main);
}

.ts-control > input {
    font-size: var(--font-size-base);
    line-height: inherit;
    min-height: calc(var(--control-height) - 2px); /* Adjust for border */
}

.ts-dropdown {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
    margin-top: 4px;
    z-index: 1000;
}

.ts-dropdown .option {
    padding: 8px 12px;
    font-size: var(--font-size-base);
}

.ts-wrapper.focus .ts-control {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

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

body {
    font-family: var(--font-family-base);
    background-color: var(--color-bg-body);
    color: var(--color-text-main);
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Utility Classes for Accessibility */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* JS Dynamic Classes */
.retry-container {
    margin-top: var(--space-md);
}

.pagination-ellipsis {
    padding: 0 var(--space-sm);
    color: var(--color-text-tertiary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Layout - Mobile First */
.container {
    width: 100%;
    padding: 0 var(--space-md);
    margin: 0 auto;
}

header {
    background-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--color-border-strong);
    padding: var(--space-sm) 0;
    margin-bottom: var(--space-xl);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    align-items: flex-start;
}

h1 {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    display: flex;
    align-items: center;
}

.logo-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    color: inherit;
}

h1 span {
    color: var(--color-primary-light);
}

.logo {
    height: 60px;
    width: auto;
    object-fit: contain;
    margin-right: var(--space-sm);
    margin-left: var(--space-md);
}

/* Static Intro Content (SEO) */
.static-intro {
    margin-bottom: var(--space-lg);
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    line-height: 1.6;
}

/* Search Section */
.search-section {
    background: var(--color-bg-surface);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    margin-bottom: var(--space-xl);
    position: relative;
    transition: all 0.3s ease;
}

/* Collapse Button */
.collapse-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-border);
    background-color: var(--color-bg-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all 0.2s ease;
    z-index: 20;
}

.collapse-btn:hover {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.collapse-btn .icon {
    font-size: 12px;
    line-height: 1;
    transition: transform 0.3s ease;
}

/* Collapsed State Logic */
/* Mobile: Show only Keyword (1) and Search (Last) */
@media (max-width: 767px) {
    .search-form.collapsed .input-group:not(:nth-of-type(1)):not(:last-child) {
        display: none !important;
    }
}

.search-form.collapsed {
    margin-bottom: 0;
}

/* Desktop: Show Keyword (1), Sort (2), and Search (Last) */
@media (min-width: 768px) {
    .search-form.collapsed .input-group:not(:nth-of-type(1)):not(:nth-of-type(2)):not(:last-child) {
        display: none !important;
    }

    .search-form.collapsed {
        display: grid;
        grid-template-columns: repeat(20, 1fr) 100px 50px;
        align-items: start;
        row-gap: var(--space-md);
        column-gap: var(--space-sm);
    }

    /* Input (1st group) */
    .search-form.collapsed > .input-group:nth-of-type(1) {
        grid-column: 1 / span 13;
        grid-row: 1;
        width: 100%;
    }

    /* Sort (2nd group) - Force display */
    .search-form.collapsed > .input-group:nth-of-type(2) {
        display: flex !important;
        grid-column: 14 / span 7;
        grid-row: 1;
        width: 100%;
    }

    /* Search Button (Last group) */
    .search-form.collapsed .btn-group {
        grid-column: 21;
        grid-row: 1;
        width: 100px;
        max-width: 100px;
        margin-top: 24px; /* Align with input box (skip label) */
        align-self: start;
        justify-self: end;
    }
    
    .search-form.collapsed .btn {
        width: 100%;
        padding: 0 8px;
    }

    /* Collapse Button */
    .search-form.collapsed .collapse-btn {
        position: static;
        grid-column: 22;
        grid-row: 1;
        width: 50px;
        height: var(--control-height);
        border-radius: var(--radius-md);
        margin-top: 24px; /* Align with input box (skip label) */
        background-color: var(--color-bg-surface);
        border: 1px solid var(--color-border);
        justify-self: end;
    }
}

/* Search Form Grid Layout */
.search-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-lg); /* Space for absolute hint if needed */
}

.input-group {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.input-label {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xs);
    font-weight: 500;
    display: flex;
    align-items: flex-end; /* text sits on same baseline */
    height: 20px; /* fixed label height */
    line-height: 1.2;
}

/* Input Wrapper for Icon/Button Positioning */
.input-wrapper {
    position: relative;
    width: 100%;
    height: var(--control-height);
}

/* Form Controls Unified Styling */
.form-control {
    width: 100%;
    height: var(--control-height);
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    color: var(--color-text-main);
    background-color: var(--color-bg-surface);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    line-height: 24px;
}

/* Search Input Specifics */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
}

/* Select Specifics (Custom Arrow) */
select.form-control {
    padding-right: 40px; /* Space for arrow */
    padding-top: 12px;
    padding-bottom: 12px;
    line-height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2314213d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
}

/* Focus States */
.form-control:focus,
.form-control:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

/* Clear Button (Inside Input) */
.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 4px;
    color: var(--color-text-tertiary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    font-size: 14px;
    transition: background-color var(--transition-base), color var(--transition-base);
}

.clear-btn:hover {
    background-color: var(--color-primary-light);
    color: var(--color-text-main);
}

.clear-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    background-color: var(--color-primary-light);
}

.clear-btn[hidden] {
    display: none !important;
}

/* Search Hint */
.search-hint {
    margin-top: 4px;
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    /* Mobile: Flow normally */
}

/* Primary Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-xl);
    height: var(--control-height);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition-base), transform var(--transition-base);
    white-space: nowrap;
    position: relative;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    z-index: 10;
}

.btn-primary {
    background-color: var(--color-primary-light);
    color: var(--color-text-main);
    width: 100%; /* Mobile First: Full width */
}

.btn-primary:hover:not(:disabled) {
    background-color: #e5940f; /* Slightly Darker Orange */
}

.btn-primary:active:not(:disabled) {
    transform: translateY(1px);
}

.btn-primary:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.8;
}

/* Loading Spinner */
.btn-loading .btn-text {
    margin-left: 8px;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

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

/* Filter Chips (Quick Filter) */
.quick-filters {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap; /* Mobile: Wrap */
    margin-top: 0; /* Adjusted via Grid/Padding in desktop */
}

.filter-chip {
    padding: 0 16px;
    height: 44px; /* Touch friendly */
    background-color: var(--color-bg-elevated);
    border: 1px solid var(--color-border-strong);
    border-radius: 22px;
    font-size: var(--font-size-sm);
    color: var(--color-text-main);
    cursor: pointer;
    transition: all var(--transition-base);
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.filter-chip:hover:not([disabled]) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background-color: var(--color-primary-light);
}

.filter-chip:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--color-primary);
}

.filter-chip[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--color-bg-body);
    pointer-events: none;
}

/* Results Grid */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.results-count {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Mobile: 2 columns */
    gap: var(--space-sm);
    list-style: none;
    padding: 0;
    margin: 0;
}

.card {
    background: var(--color-bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--color-border);
    transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
    position: relative;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary-light);
}

.card:focus-within {
    box-shadow: var(--focus-ring);
}

.card-link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card-link:focus {
    outline: none;
}

.card-link:focus-visible {
    outline: none;
    /* Focus ring handled by .card:focus-within */
}

/* Disabled/Non-clickable card state */
.card-link[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.75;
    background-color: var(--color-bg-body);
}

.card-link[aria-disabled="true"] .card-img {
    filter: grayscale(1);
    opacity: 0.8;
}

.card-link[aria-disabled="true"] .card-image-wrapper::after {
    content: "連結不可用";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: var(--font-size-xs);
    padding: 4px;
    text-align: center;
    pointer-events: none;
}

/* Aspect Ratio Box for Image */
.card-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding-top: 100%; /* 1:1 aspect ratio */
    background-color: var(--color-bg-elevated);
    overflow: hidden;
}

.card-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    padding: var(--space-sm);
}

.card:hover .card-img {
    transform: scale(1.05);
}

.card-content {
    padding: var(--space-md);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-top: 1px solid var(--color-border);
}

.card-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text-main);
    margin: 0 0 var(--space-sm) 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    height: 2.8em; /* 2 lines */
}

.card-meta {
    margin-top: auto;
}

.price-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 2px;
}

.price-value {
    font-size: var(--font-size-lg);
    font-weight: 700;
    color: var(--color-error);
    display: inline-block;
    margin-right: 4px;
}

.update-date {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
    margin-top: var(--space-xs);
    text-align: right;
}

/* Loading Skeleton */
.skeleton {
    background: linear-gradient(90deg, #e0e0e0 25%, #f5f5f5 50%, #e0e0e0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-card {
    height: 400px;
    border-radius: var(--radius-lg);
}

/* Pagination */
.pagination-container {
    margin-top: var(--space-xl);
    margin-bottom: var(--space-xl);
    display: flex;
    justify-content: center;
}

.pagination {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.page-btn {
    min-width: 40px;
    height: 40px;
    padding: 0 var(--space-sm);
    border: 1px solid var(--color-border-strong);
    background: var(--color-bg-surface);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-main);
    font-weight: 500;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background-color: var(--color-primary-light);
}

.page-btn[aria-current="page"] {
    background-color: var(--color-primary-light);
    color: var(--color-text-main);
    border-color: var(--color-primary-light);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background-color: var(--color-bg-elevated);
}

.page-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    z-index: 1;
}

/* States */
.state-message {
    text-align: center;
    padding: var(--space-xxl) 0;
    color: var(--color-text-secondary);
    grid-column: 1 / -1;
}

.state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    display: block;
}

.error-message {
    color: var(--color-error);
}

/* Responsive Breakpoints */

/* Mobile Small (<= 480px) */
@media (max-width: 480px) {
    :root {
        --space-md: 12px;
        --font-size-xl: 1.25rem;
    }

    .container {
        padding: 0 var(--space-md);
    }

    .grid {
        gap: var(--space-xs);
    }
    
    .card-content {
        padding: var(--space-sm);
    }

    .card-title {
        font-size: var(--font-size-sm);
    }

    .price-value {
        font-size: var(--font-size-base);
    }

    .page-btn {
        min-width: 44px;
        height: 44px;
        margin: 2px;
    }
    
    .search-section {
        padding: var(--space-md);
    }
}

/* Mobile Layout Adjustment (<= 767px) */
@media (max-width: 767px) {
    .search-form {
        display: grid;
        grid-template-columns: 1fr 20% 15%; /* Input | Search | Collapse */
        justify-content: start; /* Align to left */
        align-items: start; /* Align to top */
        gap: 8px;
    }

    /* Collapse Button (First Child) */
    .search-form > .collapse-btn {
        position: static;
        grid-column: 3 / 4;
        grid-row: 1;
        width: 100%;
        height: var(--control-height);
        border-radius: var(--radius-md);
        margin-top: 24px; /* Label height (20px) + margin (4px) */
        background-color: var(--color-bg-surface);
        border: 1px solid var(--color-border);
    }

    /* Keyword Input (Second Child) */
    .search-form > .input-group:nth-child(2) {
        grid-column: 1 / 2;
        grid-row: 1;
        width: 100%;
    }

    /* Search Button Group (Last Child) */
    .search-form .btn-group {
        grid-column: 2 / 3;
        grid-row: 1;
        width: 100%;
        align-self: start;
        margin-top: 24px; /* Label height (20px) + margin (4px) */
    }

    .search-form .btn-primary {
        width: 100%; 
        padding: 0 8px; /* Reduce padding to fit text */
    }

    /* Force all other inputs to span full width on next rows */
    .search-form > .input-group:not(:nth-child(2)):not(.btn-group) {
        grid-column: 1 / -1;
    }
}

/* Tablet & Desktop (>= 768px) */
@media (min-width: 768px) {
    .header-content {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    /* ===== Search Form: Desktop/Tablet alignment ===== */
    .search-form {
        display: grid;
        /* Restore original grid: 20 flexible columns + fixed buttons */
        grid-template-columns: repeat(20, 1fr) 100px 50px;
        align-items: start;
        row-gap: var(--space-md);
        column-gap: var(--space-sm);
        margin-bottom: var(--space-md);
    }

    /* Keyword Input (Row 1: Matches Collapsed) */
    .search-form > .input-group:nth-of-type(1) {
        grid-column: 1 / span 13;
        grid-row: 1;
    }
    
    /* Sort Select (Row 1: Matches Collapsed) */
    .search-form > .input-group:nth-of-type(2) {
        grid-column: 14 / span 7;
        grid-row: 1;
    }

    /* Search Button (Row 1: Fixed 100px) */
    .search-form .btn-group {
        align-self: start;
        grid-column: 21;
        grid-row: 1;
        margin-top: 24px; /* Align with input box */
        width: 100px;
        max-width: 100px;
        justify-self: end;
    }

    /* Collapse Button (Row 1: Fixed 50px) */
    .search-form .collapse-btn {
        position: static;
        grid-column: 22;
        grid-row: 1;
        width: 50px;
        height: var(--control-height);
        border-radius: var(--radius-md);
        margin-top: 24px; /* Align with input box */
        background-color: var(--color-bg-surface);
        border: 1px solid var(--color-border);
        justify-self: end;
    }

    .btn-primary {
        width: 100%;
        height: var(--control-height);
        padding: 0 8px;
    }

    .search-form > .input-group:nth-of-type(3) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: calc((100% - (var(--space-sm) * 4)) * 0.2);
        margin-left: 0;
        justify-self: start;
    }

    .search-form > .input-group:nth-of-type(4) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: calc((100% - (var(--space-sm) * 4)) * 0.25);
        margin-left: calc((100% - (var(--space-sm) * 4)) * 0.2 + var(--space-sm));
        justify-self: start;
    }

    .search-form > .input-group:nth-of-type(5) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: calc((100% - (var(--space-sm) * 4)) * 0.25);
        margin-left: calc((100% - (var(--space-sm) * 4)) * 0.45 + var(--space-sm) * 2);
        justify-self: start;
    }

    .search-form > .input-group:nth-of-type(6) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: calc((100% - (var(--space-sm) * 4)) * 0.15);
        margin-left: calc((100% - (var(--space-sm) * 4)) * 0.70 + var(--space-sm) * 3);
        justify-self: start;
    }

    .search-form > .input-group:nth-of-type(7) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: calc((100% - (var(--space-sm) * 4)) * 0.15);
        margin-left: calc((100% - (var(--space-sm) * 4)) * 0.85 + var(--space-sm) * 4);
        justify-self: start;
    }

    /* Hide toggle text on desktop and center the switch */
    .search-form .input-group--toggle .toggle__text {
        display: none;
    }

    .search-form .input-group--toggle .toggle {
        justify-content: center;
        padding: 0;
    }

    .form-control {
        height: 48px;
    }

    /* keep hint in normal flow for stable layout */
    .search-hint {
        position: static;
        margin-top: 6px;
        white-space: normal;
        line-height: 1.4;
    }

    .quick-filters {
        padding-left: 0;
        margin-top: var(--space-md);
        justify-content: flex-start;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: var(--space-lg);
    }
    
    .filter-chip {
        height: 32px; /* Compact on desktop */
        font-size: var(--font-size-xs);
        padding: 0 12px;
    }
}

/* ===== Toggle group (Accuracy Mode) ===== */
.input-group--toggle .input-label {
    display: block;
    height: auto;
    line-height: 1.5;
    margin-bottom: var(--space-xs);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 48px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
    cursor: pointer;
    user-select: none;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.toggle:focus-within {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.toggle__ui {
    position: relative;
    width: 44px;
    height: 24px;
    border-radius: 999px;
    background: var(--color-border);
    transition: background-color var(--transition-base);
    flex: 0 0 auto;
}

.toggle__ui::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-base);
}

.toggle__text {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text-main);
    white-space: nowrap;
    line-height: 1;
}

/* checked */
.toggle input:checked + .toggle__ui {
    background: var(--color-primary-light);
}

.toggle input:checked + .toggle__ui::after {
    transform: translateX(20px);
}

/* hover */
.toggle:hover {
    border-color: var(--color-primary);
}

/* Desktop (>= 1024px) */
@media (min-width: 1024px) {
    .container {
        max-width: 960px;
    }
}

/* Large Desktop (>= 1280px) */
@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =========================================
   Simple Mode (Compact View)
   ========================================= */
.grid.mode-simple {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-sm);
}

.mode-simple .card-image-wrapper {
    padding-top: 100%; /* 1:1 Aspect Ratio */
    overflow: hidden; /* Crop scale overflow */
}

.mode-simple .card-image-wrapper img {
    transform: scale(1.2); /* Zoom in to crop white borders */
}

.mode-simple .card:hover .card-img {
    transform: scale(1.2); /* Further zoom on hover */
}

.mode-simple .card-content {
    padding: var(--space-sm);
}

.mode-simple .card-title {
    font-size: var(--font-size-sm);
    margin-bottom: 2px;
    height: 1.4em; /* 1 line */
    -webkit-line-clamp: 1;
}

.mode-simple .card-meta {
    margin-top: 4px;
}

.mode-simple .price-label {
    display: none; /* Hide label to save space */
}

.mode-simple .price-value {
    font-size: var(--font-size-base); /* Smaller than lg */
}

.mode-simple .update-date {
    display: none;
}

/* Mobile Simple Mode */
@media (max-width: 480px) {
    .grid.mode-simple {
        grid-template-columns: repeat(3, 1fr); /* Force 3 columns */
        gap: 6px;
    }

    .mode-simple .card-title {
        font-size: 0.75rem; /* 12px */
        height: 1.4em;
    }

    .mode-simple .price-value {
        font-size: 0.875rem; /* 14px */
    }
}

@media (max-width: 767px) {
    .mobile-hide-title .card-title {
        display: none;
    }

    .mobile-hide-price .price-value {
        display: none;
    }

    .mobile-hide-price .condition-label {
        display: none;
    }

    .mobile-hide-title.mobile-hide-price .card-content {
        display: none;
    }

    .card-img {
        width: 100%;
        height: 100%;
        transform: scale(1.2);
        transform-origin: center center;
    }

    .card:hover .card-img {
        transform: scale(1.2);
    }
}

@media (min-width: 768px) {
    .input-group--mobile-display {
        display: none;
    }
}
