:root {
    --bg: #101216;
    --panel: #171a20;
    --panel-2: #1e222a;
    --line: #2a2f39;
    --text: #e6e9ef;
    --muted: #8e97a6;
    --accent: #6ea8fe;
    --accent-2: #4d8ef7;
    --danger: #ff8a8a;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    overflow-x: hidden;
}

/* Telegram Mini App: the client draws its own top controls, so keep the header
   below the content safe area and respect the bottom gesture area. */
html.tg-mini .topbar {
    padding-top: calc(12px + var(--tg-viewport-content-safe-area-inset-top, 0px));
}
html.tg-mini .wrap {
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}
html.tg-mini .order-card {
    max-height: calc(90vh - var(--tg-viewport-content-safe-area-inset-top, 0px));
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 12px 22px;
    background: rgba(16, 18, 22, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.home-link {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--muted);
    background: var(--panel);
}
.home-link:hover {
    color: var(--text);
    border-color: var(--accent-2);
    text-decoration: none;
}
.home-link svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.search-mini {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    min-width: 0;
}

input[type="text"] {
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
}
input[type="text"]:focus { border-color: var(--accent-2); }

button {
    padding: 9px 16px;
    border: 1px solid var(--accent-2);
    border-radius: 9px;
    background: var(--accent-2);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
button:hover { background: #3f7fe4; }

.search-mini input[type="text"] { flex: 1 1 auto; width: auto; }

.file-label {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--muted);
    font-size: 0.92rem;
    cursor: pointer;
    white-space: nowrap;
}
.file-label:hover { border-color: var(--accent-2); color: var(--text); }
.file-label input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.file-label.big { padding: 10px 16px; }

.wrap { max-width: 1480px; margin: 0 auto; padding: 26px 22px 80px; }

.hero { margin: 10px 0 22px; }
.hero h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: -0.02em; }
.hero p { margin: 0; color: var(--muted); }
.hero .stats { font-variant-numeric: tabular-nums; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    align-items: start;
}

.card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.thumbs {
    position: relative;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    max-height: 480px;
    overflow: hidden;
    background: #0b0c0f;
}
.thumbs.single { grid-template-columns: 1fr; }
.thumbs img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    cursor: zoom-in;
    background: #0b0c0f;
    transition: filter 120ms ease;
}
/* A long posting is capped at four tiles; the rest are available in the
   fullscreen gallery. The max-height above also protects against a very wide
   card. */
.thumbs img:nth-child(n + 5) { display: none; }
.thumbs img:hover { filter: brightness(1.08); }
.thumbs .more {
    position: absolute;
    right: 9px;
    bottom: 9px;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.72);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    pointer-events: none;
}

.order-btn {
    display: block;
    width: calc(100% - 20px);
    margin: 10px;
    padding: 10px 16px;
    border: 1px solid var(--accent-2);
    border-radius: 10px;
    background: var(--accent-2);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.order-btn:hover { background: #3f7fe4; }

.order-modal[hidden] { display: none; }
.order-modal {
    position: fixed;
    inset: 0;
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(4, 5, 7, 0.78);
}
.order-card {
    position: relative;
    width: min(460px, 100%);
    max-height: 90vh;
    overflow: auto;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: 0 24px 90px rgba(0, 0, 0, 0.55);
}
.order-card h2 { margin: 0 0 18px; font-size: 1.25rem; }
.order-card form { display: flex; flex-direction: column; gap: 14px; }
.order-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 0.9rem; }
.order-card input,
.order-card select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 0.95rem;
}
.order-card button[type="submit"] { margin-top: 4px; }
.order-card button[type="submit"]:disabled { opacity: 0.6; cursor: wait; }
.order-close {
    position: absolute;
    top: 10px;
    right: 14px;
    padding: 0 6px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1.8rem;
    line-height: 1;
}
.order-close:hover { background: transparent; color: var(--text); }
.order-status { min-height: 1.2em; margin: 0; font-size: 0.88rem; color: var(--muted); }
.order-status.ok { color: #6fd48b; }
.order-status.error { color: var(--danger); }

.order-detail {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
    margin-bottom: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--line);
}
.order-detail-row {
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--panel);
}
.order-detail-row span { color: var(--muted); }
.order-detail-row strong { text-align: right; word-break: break-word; }
.section-title { margin: 24px 0 12px; font-size: 1.1rem; }
.order-photos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}
.order-photos img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    cursor: zoom-in;
    background: var(--panel);
}
.order-archives {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0;
    list-style: none;
}
.order-archives li {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    word-break: break-word;
}
.order-archives a { flex: 0 0 auto; }

.debug-id {
    padding: 8px 12px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
}
.debug-id a {
    color: var(--accent);
    font-family: inherit;
}

.empty, .result-note { color: var(--muted); }
.error { color: var(--danger); }

.query-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px;
    margin: 0 0 22px;
    border: 1px solid var(--accent-2);
    border-radius: var(--radius);
    background: rgba(77, 142, 247, 0.07);
    color: var(--muted);
}
.query-preview img {
    width: 92px;
    height: 92px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--line);
}

.gallery[hidden] { display: none; }
.gallery {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(4, 5, 7, 0.96);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}
.gallery-stage {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.gallery-stage img {
    max-width: 96vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.55);
}
.gallery-close {
    position: absolute;
    top: 12px;
    right: 18px;
    padding: 2px 10px;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 2rem;
    line-height: 1;
}
.gallery-close:hover { background: transparent; color: var(--accent); }
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 92px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: rgba(40, 44, 54, 0.55);
    color: #fff;
    font-size: 3rem;
    line-height: 1;
}
.gallery-nav:hover { background: rgba(60, 66, 80, 0.8); }
.gallery-nav.prev { left: 12px; }
.gallery-nav.next { right: 12px; }
.gallery-nav[hidden] { display: none; }
.gallery-counter {
    position: absolute;
    bottom: 18px;
    left: 0;
    right: 0;
    text-align: center;
    color: #cfd5df;
    font-size: 0.9rem;
    letter-spacing: 0.03em;
}

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; padding: 10px 14px; }
    .search-mini { width: 100%; margin-left: 0; flex-wrap: wrap; }
    .search-mini input[type="text"] { flex: 1 1 100%; width: auto; }
    .wrap { padding: 18px 14px 64px; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
    .gallery-nav { width: 42px; height: 72px; font-size: 2.2rem; }
}
