:root {
    color-scheme: light dark;
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1c1c1e);
    --hint: var(--tg-theme-hint-color, #8e8e93);
    --card: var(--tg-theme-secondary-bg-color, #f1f1f4);
    --accent: var(--tg-theme-button-color, #2ea6ff);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --danger: #e0563f;
    --ok: #2ea043;

    /* Тонкие линии и поверхности, подстраивающиеся под светлую/тёмную тему. */
    --line: color-mix(in srgb, var(--text) 10%, transparent);
    --surface: color-mix(in srgb, var(--text) 4%, transparent);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(0, 0, 0, 0.05);
    --radius: 16px;
}

* { box-sizing: border-box; }

body {
    margin: 0 auto;
    max-width: 680px;
    padding: 0 16px calc(32px + env(safe-area-inset-bottom));
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---- Шапка -------------------------------------------------------------- */
header { padding: 18px 2px 6px; }
header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin: 0;
}
.muted { color: var(--hint); font-size: 13px; margin: 4px 0 0; }

/* ---- Вкладки (сегмент-контрол) ----------------------------------------- */
.tabs {
    display: flex;
    gap: 4px;
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 8px 0 10px;
    z-index: 5;
}
.tab {
    flex: 1;
    padding: 9px 6px;
    border: none;
    border-radius: 11px;
    background: var(--card);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.tab:active { transform: scale(0.97); }
.tab.active {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent);
}

.tab-panel { display: none; animation: fade-up 0.22s ease both; }
.tab-panel.active { display: block; }

/* ---- Карточки и формы --------------------------------------------------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

input, select {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder { color: var(--hint); }
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
input[type="date"] { min-height: 46px; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: opacity(0.55); cursor: pointer; }

select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
}

.field-label { font-size: 13px; color: var(--hint); font-weight: 500; margin: 4px 0 -4px; }

/* ---- Автоподсказка городов --------------------------------------------- */
/* Обёртка позиционирует выпадающий список под полем ввода. */
.ac-wrap { position: relative; }
.ac-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 30;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    max-height: 244px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: fade-up 0.14s ease both;
}
.ac-item {
    padding: 11px 12px;
    border-radius: 9px;
    font-size: 15px;
    line-height: 1.2;
    cursor: pointer;
}
.ac-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
@media (hover: hover) {
    .ac-item:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
}

/* ---- Кастомный календарь ----------------------------------------------- */
.date-field { position: relative; }
.date-display { cursor: pointer; }
.cal-popup {
    position: fixed;
    z-index: 40;
    min-width: 280px;
    padding: 10px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    animation: fade-up 0.14s ease both;
}
.cal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.cal-title { font-weight: 600; font-size: 15px; }
.cal-nav {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-week { margin-bottom: 4px; }
.cal-week span { text-align: center; font-size: 11px; color: var(--hint); padding: 4px 0; }
.cal-day {
    text-align: center;
    padding: 8px 0;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}
.cal-day.disabled { color: var(--hint); opacity: 0.35; cursor: default; }
/* Числа соседних месяцев — приглушённые, только для контекста (не кликаются). */
.cal-day.muted { color: var(--hint); opacity: 0.4; cursor: default; }
/* Сегодняшний день — кольцо акцентом (отдельно от выбранного, который залит). */
.cal-day.today { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 600; }
.cal-day.selected { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.cal-day:not(.disabled):not(.selected):not(.muted):active {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
}
@media (hover: hover) {
    .cal-day:not(.disabled):not(.selected):not(.muted):hover {
        background: color-mix(in srgb, var(--accent) 12%, transparent);
    }
}

.row { display: flex; gap: 10px; }
.row > button { flex: 1; }

button.primary, button.secondary, button.danger {
    padding: 13px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease, background 0.15s ease;
}
button.primary, button.secondary, button.danger, button.book, .tab { -webkit-tap-highlight-color: transparent; }
button.primary:active, button.secondary:active, button.book:active { transform: translateY(1px); opacity: 0.9; }
button.primary {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 28%, transparent);
}
button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
}
button.danger { background: transparent; color: var(--danger); padding: 8px 12px; font-size: 13px; font-weight: 600; }
button.book {
    background: var(--accent);
    color: var(--accent-text);
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
}
button.book:disabled { opacity: 0.5; cursor: default; }
button.small { padding: 8px 12px; font-size: 13px; }
.contact-link { color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: none; }

/* ---- Список поездок ----------------------------------------------------- */
.list { display: flex; flex-direction: column; gap: 12px; }

.trip {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    animation: fade-up 0.22s ease both;
}
.trip .route { font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }
.trip .route .arrow { color: var(--accent); margin: 0 6px; font-weight: 600; }
/* Эмодзи 🚗 по умолчанию смотрит влево — отражаем, чтобы машина «ехала»
   в сторону города назначения (он справа). */
.trip .route .car { display: inline-block; transform: scaleX(-1); }
.trip .meta { color: var(--hint); font-size: 13px; margin-top: 5px; }
.trip .meta .price { color: var(--text); font-weight: 600; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
}
.badge-all { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge-male { background: rgba(46, 140, 255, 0.16); color: #2e8cff; }
.badge-female { background: rgba(232, 86, 160, 0.16); color: #e856a0; }
.badge-neutral { background: var(--surface); color: var(--hint); }

.trip .desc { font-size: 14px; margin-top: 10px; color: color-mix(in srgb, var(--text) 88%, transparent); }
.trip .foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.trip .id { color: var(--hint); font-size: 12px; font-variant-numeric: tabular-nums; }
.status-booked { color: var(--ok); font-size: 14px; font-weight: 600; }
.trip .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.passengers { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.passenger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
}

.empty { color: var(--hint); text-align: center; padding: 44px 16px; font-size: 14px; }

/* ---- Тост --------------------------------------------------------------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: rgba(20, 20, 22, 0.92);
    color: #fff;
    padding: 11px 18px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    max-width: 90%;
    text-align: center;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    animation: fade-up 0.2s ease both;
}
.hidden { display: none; }

/* ---- Экран входа -------------------------------------------------------- */
.auth-gate {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 32px 24px;
    text-align: center;
    animation: fade-in 0.25s ease both;
}
.auth-gate .logo {
    font-size: 60px;
    line-height: 1;
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.18));
    animation: fade-up 0.4s ease both;
}
.auth-gate h2 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -0.3px; }
.auth-gate p { margin: 0; color: var(--hint); max-width: 280px; }
.auth-gate .who { color: var(--text); font-weight: 600; }
.auth-gate button.primary { width: 100%; max-width: 280px; margin-top: 10px; }
/* Двойной класс перебивает .auth-gate{display:flex} независимо от порядка правил. */
.auth-gate.hidden { display: none; }

/* ---- Анимации ----------------------------------------------------------- */
@keyframes fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    *, .tab-panel, .trip, .toast, .auth-gate, .auth-gate .logo { animation: none !important; }
}
