:root {
    --bg: var(--tg-theme-bg-color, #f5f5f5);
    --surface: var(--tg-theme-secondary-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #202124);
    --muted: var(--tg-theme-hint-color, #777777);
    --accent: var(--tg-theme-button-color, #229ed9);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --border: rgba(0, 0, 0, .09);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

body {
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

.app-shell {
    width: min(100%, 760px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
}

.site-header {
    padding: 8px 2px 14px;
}

.site-brand {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.site-brand strong {
    font-size: 24px;
    line-height: 1.1;
    letter-spacing: -.02em;
}

.site-brand span {
    color: var(--muted);
    font-size: 12px;
}

.search-area {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 12px;
}

.search-area input {
    min-width: 0;
    height: 44px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.search-area input:focus {
    border-color: var(--accent);
}

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

.search-area button {
    height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    cursor: pointer;
}

.category-list {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    margin: 0 -14px 18px;
    padding: 0 14px 3px;
    scrollbar-width: none;
}

.category-list::-webkit-scrollbar {
    display: none;
}

.category-item {
    flex: 0 0 auto;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.category-item.active {
    border-color: var(--accent);
    color: var(--accent);
}

.list-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 9px;
}

.list-header > div {
    display: flex;
    align-items: baseline;
    gap: 7px;
}

.list-header h1 {
    margin: 0;
    font-size: 17px;
}

.list-header span {
    color: var(--muted);
    font-size: 11px;
}

.reset-link {
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
}

.listing-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.listing-item {
    display: grid;
    grid-template-columns: 116px minmax(0, 1fr);
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
}

.listing-photo {
    position: relative;
    overflow: hidden;
    width: 116px;
    height: 100px;
    border-radius: 8px;
    background: #ececec;
}

.listing-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-empty {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    background: #ececec;
    color: #888;
    font-size: 12px;
}

.featured-label {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 4px 6px;
    border-radius: 5px;
    background: rgba(0, 0, 0, .72);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
}

.listing-info {
    min-width: 0;
}

.listing-category {
    overflow: hidden;
    margin-bottom: 4px;
    color: var(--accent);
    font-size: 10px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.listing-info h2 {
    display: -webkit-box;
    overflow: hidden;
    margin: 0 0 5px;
    font-size: 14px;
    line-height: 1.3;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.listing-info p {
    display: -webkit-box;
    overflow: hidden;
    margin: 0 0 9px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.listing-meta {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 8px;
}

.listing-meta strong {
    font-size: 14px;
}

.listing-meta span {
    color: var(--muted);
    font-size: 9px;
    white-space: nowrap;
}

.empty-box {
    padding: 42px 20px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    text-align: center;
}

.empty-box h2 {
    margin: 0 0 7px;
    font-size: 17px;
}

.empty-box p {
    margin: 0 auto 13px;
    max-width: 360px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.empty-box a {
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
}

.detail-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 48px;
    margin-bottom: 10px;
}

.detail-header > span {
    font-size: 13px;
    font-weight: 600;
}

.back-link {
    justify-self: start;
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}

.detail-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin: 0 -14px 10px;
    padding: 0 14px 4px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.detail-gallery::-webkit-scrollbar {
    display: none;
}

.detail-gallery img {
    flex: 0 0 min(88vw, 560px);
    width: min(88vw, 560px);
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    object-fit: cover;
    scroll-snap-align: center;
}

.detail-photo-empty {
    display: grid;
    height: 240px;
    margin-bottom: 10px;
    place-items: center;
    border-radius: 10px;
    background: #ececec;
    color: #888;
    font-size: 12px;
}

.detail-main,
.detail-description-box {
    margin-bottom: 9px;
    padding: 15px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
}

.detail-labels {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.detail-category,
.detail-featured {
    padding: 4px 7px;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 600;
}

.detail-category {
    background: rgba(34, 158, 217, .10);
    color: var(--accent);
}

.detail-featured {
    background: #f3f3f3;
    color: #555;
}

.detail-main h1 {
    margin: 0 0 10px;
    font-size: 23px;
    line-height: 1.25;
    letter-spacing: -.02em;
}

.detail-price {
    margin-bottom: 7px;
    font-size: 22px;
    font-weight: 700;
}

.detail-date {
    color: var(--muted);
    font-size: 11px;
}

.detail-description-box h2 {
    margin: 0 0 9px;
    font-size: 15px;
}

.detail-description {
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.contact-panel {
    position: fixed;
    z-index: 20;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: min(calc(100% - 20px), 740px);
    margin: 0 auto;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 6px 24px rgba(0,0,0,.12);
}

.contact-panel > div {
    min-width: 0;
}

.contact-panel span {
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 9px;
}

.contact-panel strong {
    display: block;
    overflow: hidden;
    max-width: 140px;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-panel button {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.contact-bottom-space {
    height: 82px;
}

@media (min-width: 620px) {
    .listing-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .listing-item {
        grid-template-columns: 130px minmax(0, 1fr);
    }

    .listing-photo {
        width: 130px;
        height: 108px;
    }
}

@media (max-width: 380px) {
    .listing-item {
        grid-template-columns: 96px minmax(0, 1fr);
    }

    .listing-photo {
        width: 96px;
        height: 92px;
    }

    .listing-meta {
        align-items: start;
        flex-direction: column;
        gap: 3px;
    }
}
