/* ===========================
   RANGLAR (Telegram mavzusiga moslashadi)
   =========================== */
:root {
    --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
    --surface: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #0f172a);
    --hint: var(--tg-theme-hint-color, #8b93a1);
    --accent: var(--tg-theme-button-color, #2481cc);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --sep: rgba(127, 127, 127, 0.2);
    --soft: rgba(127, 127, 127, 0.11);

    --green: #1f9d55;
    --orange: #e08a00;
    --red: #e5484d;

    --radius: 14px;

    /* To'liq ekranda Telegram tugmalari va telefon "chelkasi" uchun joy */
    --safe-top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
    --safe-bottom: calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body.sheet-open {
    overflow: hidden;
}

button, input, select {
    font: inherit;
    color: inherit;
}

button {
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

[hidden] {
    display: none !important;
}

/* ===========================
   HEADER (qidiruv, yo'nalish, shaharlar)
   =========================== */
.top {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    padding: calc(12px + var(--safe-top)) 16px 0;
    box-shadow: 0 1px 0 var(--sep);
}

.top-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
}

h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.count {
    font-size: 13px;
    color: var(--hint);
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 12px;
    border-radius: 12px;
    background: var(--soft);
    color: var(--hint);
}

.search input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: none;
    color: var(--text);
    font-size: 15px;
}

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

.search input::-webkit-search-cancel-button {
    display: none;
}

.search-clear {
    flex: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--hint);
    color: var(--surface);
    font-size: 15px;
    line-height: 20px;
    opacity: 0.7;
}

/* "Qayerdan" / "Qayerga" tanlovi */
.route-picker {
    position: relative;
    display: flex;
    gap: 6px;
    margin: 10px 0 12px;
}

.route-field {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 8px 26px 9px 12px;
    border-radius: 12px;
    background: var(--soft);
    text-align: left;
    transition: background 0.15s;
}

.route-field:active {
    background: var(--sep);
}

.route-field.end {
    align-items: flex-end;
    padding: 8px 12px 9px 26px;
    text-align: right;
}

.route-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.route-value {
    max-width: 100%;
    overflow: hidden;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.route-value.muted {
    font-weight: 500;
    color: var(--hint);
}

.swap-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--sep);
    border-radius: 50%;
    background: var(--surface);
    color: var(--accent);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    transform: translate(-50%, -50%);
    transition: transform 0.25s;
}

.swap-btn:active {
    transform: translate(-50%, -50%) rotate(180deg);
}

.chips {
    display: flex;
    gap: 8px;
    margin: 0 -16px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
}

.chips::-webkit-scrollbar {
    display: none;
}

.chips.wrap {
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    overflow: visible;
}

.chip {
    flex: none;
    height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--soft);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.chip span {
    margin-left: 4px;
    font-size: 12px;
    color: var(--hint);
}

.chip.active {
    background: var(--accent);
    color: var(--accent-text);
}

.chip.active span {
    color: inherit;
    opacity: 0.75;
}

.toolbar {
    display: flex;
    gap: 8px;
    padding-bottom: 12px;
}

.select {
    position: relative;
    flex: 1;
}

.select select {
    width: 100%;
    height: 36px;
    padding: 0 32px 0 12px;
    border: 1px solid var(--sep);
    border-radius: 10px;
    background: var(--surface);
    font-size: 14px;
    font-weight: 500;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

.select svg {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--hint);
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--sep);
    border-radius: 10px;
    background: var(--surface);
    font-size: 14px;
    font-weight: 500;
}

.badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

/* ===========================
   PARVOZLAR RO'YXATI
   =========================== */
.list {
    padding: 4px 16px calc(24px + var(--safe-bottom));
}

.day {
    padding: 14px 4px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--hint);
}

.card {
    margin-bottom: 8px;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card.sold {
    opacity: 0.6;
}

.route {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pt {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pt.end {
    align-items: flex-end;
    text-align: right;
}

.pt b {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
    font-variant-numeric: tabular-nums;
}

.pt small {
    max-width: 100%;
    overflow: hidden;
    font-size: 12px;
    color: var(--hint);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.line {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--hint);
}

.line i {
    flex: 1;
    border-top: 1.5px dashed var(--sep);
}

.meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    overflow: hidden;
    font-size: 12px;
    color: var(--hint);
    white-space: nowrap;
}

.meta span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

.source {
    flex: none;
    padding: 1px 7px;
    border-radius: 6px;
    background: var(--soft);
    font-weight: 600;
}

.source.flykhiva {
    background: rgba(124, 58, 237, 0.13);
    color: #8b5cf6;
}

.source.selfie {
    background: rgba(234, 88, 12, 0.13);
    color: #ea580c;
}

.foot {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--sep);
}

.seats {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}

.seats::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.seats.ok { color: var(--green); }
.seats.few { color: var(--orange); }
.seats.none { color: var(--red); }

.date {
    font-size: 13px;
    color: var(--hint);
}

.price {
    margin-left: auto;
    font-size: 18px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.price small {
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
}

.more-btn {
    display: block;
    width: 100%;
    height: 44px;
    margin-top: 4px;
    border-radius: 12px;
    background: var(--surface);
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
}

/* ===========================
   YUKLANISH / BO'SH / XATO
   =========================== */
.skeleton {
    height: 140px;
    margin-bottom: 8px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--surface) 25%, var(--bg) 50%, var(--surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite linear;
}

.skeleton:first-child {
    margin-top: 12px;
}

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

.state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 64px 24px;
    text-align: center;
}

.state-icon {
    margin-bottom: 8px;
    font-size: 44px;
}

.state h3 {
    font-size: 17px;
    font-weight: 600;
}

.state p {
    max-width: 280px;
    font-size: 14px;
    color: var(--hint);
}

.state .btn {
    height: 40px;
    margin-top: 14px;
    padding: 0 20px;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 14px;
    font-weight: 600;
}

/* ===========================
   FILTR OYNASI (pastdan chiqadi)
   =========================== */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.2s;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 21;
    max-height: calc(100vh - var(--safe-top) - 24px);
    max-height: calc(var(--tg-viewport-stable-height, 100vh) - var(--safe-top) - 24px);
    overflow-y: auto;
    padding: 8px 16px calc(16px + var(--safe-bottom));
    border-radius: 18px 18px 0 0;
    background: var(--surface);
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

body.sheet-open .sheet { transform: none; }
body.sheet-open .sheet-backdrop { opacity: 1; }

.sheet-handle {
    width: 36px;
    height: 4px;
    margin: 0 auto 12px;
    border-radius: 2px;
    background: var(--sep);
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

/* Shahar tanlash oynasi: ro'yxat o'zi aylantiriladi, qidiruv tepada turadi */
.city-sheet {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--safe-top) - 24px);
    height: calc(var(--tg-viewport-stable-height, 100vh) - var(--safe-top) - 24px);
    padding-bottom: 0;
    overflow: hidden;
}

.city-sheet .search {
    flex: none;
    margin: 6px 0 4px;
}

.city-list {
    flex: 1;
    margin: 0 -16px;
    padding: 0 16px calc(16px + var(--safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.city-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 13px 2px;
    border-bottom: 1px solid var(--sep);
    text-align: left;
}

.city-code {
    flex: none;
    width: 42px;
    font-size: 13px;
    font-weight: 700;
    color: var(--hint);
    letter-spacing: 0.3px;
}

.city-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-size: 15px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.city-count {
    flex: none;
    min-width: 28px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--soft);
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
    text-align: center;
}

.city-row.active .city-name {
    font-weight: 600;
    color: var(--accent);
}

.city-row.active .city-count {
    background: var(--accent);
    color: var(--accent-text);
}

.city-empty {
    padding: 32px 0;
    text-align: center;
    color: var(--hint);
}

.sheet h2 {
    font-size: 18px;
    font-weight: 700;
}

.link {
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
}

.sheet section {
    padding: 16px 0;
    border-bottom: 1px solid var(--sep);
}

.sheet section:last-of-type {
    border-bottom: 0;
}

.sheet h3 {
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.range-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.range-head b {
    font-size: 14px;
    font-weight: 600;
}

.range {
    width: 100%;
    height: 28px;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
}

.range::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 100%) 100% no-repeat, var(--sep);
}

.range::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -10px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    -webkit-appearance: none;
}

.range::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--sep);
}

.range::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--accent);
}

.range::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    cursor: pointer;
}

.switch-row input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch {
    position: relative;
    flex: none;
    width: 44px;
    height: 26px;
    border-radius: 13px;
    background: var(--sep);
    transition: background 0.2s;
}

.switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s;
}

.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

.btn-primary {
    width: 100%;
    height: 48px;
    margin-top: 8px;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 15px;
    font-weight: 600;
}
