/* --- 1. Основная оболочка модалки (Backdrop) --- */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(4, 8, 16, 0.82);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden { display: none; }

/* Запрос GPS для секундомера (главная страница, один раз за сессию) */
.mx-gps-track-modal {
    z-index: 1200;
    inset: 0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    overflow-y: auto;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px))
        max(16px, env(safe-area-inset-right, 0px))
        max(16px, env(safe-area-inset-bottom, 0px))
        max(16px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
}

.mx-gps-track-prompt {
    width: min(360px, 100%);
    max-width: 100%;
    margin: 0;
    padding: 20px 18px 18px;
    box-sizing: border-box;
    text-align: center;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.mx-gps-track-title {
    margin: 0 0 10px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #f2f4f8;
}

.mx-gps-track-text {
    margin: 0 0 18px;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #b8c0d0;
}

.mx-gps-track-btn {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: "Inter", "Segoe UI", sans-serif;
    cursor: pointer;
    background: linear-gradient(180deg, #3a3a3a 0%, #2b2b2b 100%);
    color: #fff;
    border: 1px solid #4c4c4c;
    transition:
        transform var(--btn-transition-duration, 0.22s) cubic-bezier(0.33, 1, 0.68, 1),
        box-shadow var(--btn-transition-duration, 0.22s) ease,
        border-color var(--btn-transition-duration, 0.22s) ease,
        filter var(--btn-transition-duration, 0.22s) ease;
}

.mx-gps-track-btn:disabled {
    opacity: 0.55;
    cursor: wait;
    filter: none;
    transform: none;
}

/* --- 2. Контентное окно --- */
.modal-content {
    background: #121212;
    width: 98%; /* Чуть шире для 7 колонок */
    max-width: 650px; /* Увеличили макс-ширину под сектора */
    max-height: 85dvh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    border: 1px solid #2d2d2d;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* Перекрывает width: 98% у .modal-content — иначе на узком экране уезжает вправо */
.modal-content.mx-gps-track-prompt {
    width: min(360px, 100%);
    max-width: 100%;
    max-height: none;
    overflow: visible;
}

/*
 * Портрет: page1_mobile_adaptation.css вешает на .modal bottom-sheet (flex-end, 82dvh).
 * GPS — компактный диалог по центру, не шторка.
 */
@media (max-width: 768px) and (orientation: portrait) {
    .modal.mx-gps-track-modal {
        justify-content: center !important;
        align-items: center !important;
        padding: max(20px, env(safe-area-inset-top, 0px) + 12px)
            max(16px, env(safe-area-inset-right, 0px))
            max(20px, env(safe-area-inset-bottom, 0px) + 12px)
            max(16px, env(safe-area-inset-left, 0px)) !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .modal.mx-gps-track-modal .modal-content.mx-gps-track-prompt {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        bottom: auto !important;
        left: auto !important;
        width: min(360px, calc(100vw - 32px)) !important;
        max-width: calc(100vw - 32px) !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: calc(100dvh - 40px) !important;
        margin: auto !important;
        padding-bottom: 18px !important;
        border-radius: 12px !important;
        transform: none !important;
        overflow: visible !important;
        flex: 0 0 auto;
    }
}

/* Шапка */
.modal-header {
    padding: 15px 20px;
    background: linear-gradient(180deg, #232323 0%, #171717 100%);
    border-bottom: 1px solid #2d2d2d;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#modal-driver {
    font-size: 18px;
    font-weight: bold;
    color: #d8d8d8;
}

.modal-header button {
    background: none;
    border: none;
    color: #666;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    border-radius: 10px;
    padding: 4px 10px;
    transition:
        transform var(--btn-transition-duration, 0.22s) ease,
        color var(--btn-transition-duration, 0.22s) ease,
        background var(--btn-transition-duration, 0.22s) ease;
}

.modal-header button:hover {
    color: #d8d8d8;
    background: rgba(255, 255, 255, 0.06);
    transform: scale(1.06);
}

.modal-header button:active {
    transform: scale(0.94);
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
    transition-duration: var(--btn-transition-press, 0.09s);
}

/* --- 3. Скролл-зона таблицы --- */
.laps-table-container {
    overflow-x: auto; /* Добавляем горизонтальный скролл на случай очень узких экранов */
    overflow-y: auto;
    flex-grow: 1;
    background: #0d0d0d;
    -webkit-overflow-scrolling: touch;
}

/* --- 4. Таблица (7 колонок) --- */
.laps-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* Жестко фиксируем ширину */
    min-width: 500px; /* Чтобы колонки не сплющились в кашу на iPhone */
}

/* Заголовки */
.laps-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #202020 !important;
    font-size: 11px !important;
    color: #9b9b9b !important;
    text-transform: uppercase !important;
    font-weight: bold !important;
    padding: 10px 2px !important;
    border-bottom: 2px solid #2d2d2d !important;
    text-align: center !important;
}

/* Стили ячеек */
.laps-table td {
    padding: 10px 2px;
    border-bottom: 1px solid #242424;
    vertical-align: middle;
    color: #fff;
    text-align: center;
}

/* --- РАСПРЕДЕЛЕНИЕ ШИРИНЫ (Итого 100%) --- */
.laps-table th:nth-child(1) { width: 35px; }  /* LAP */
.laps-table th:nth-child(2) { width: 85px; }  /* TIME */
.laps-table th:nth-child(3) { width: 120px; } /* TELEMETRY */
.laps-table th:nth-child(4) { width: 50px; }  /* S1 */
.laps-table th:nth-child(5) { width: 50px; }  /* S2 */
.laps-table th:nth-child(6) { width: 50px; }  /* S3 */
.laps-table th:nth-child(7) { width: 75px; }  /* DIFF */

/* Специфические стили для ячеек */
.lap-num { font-size: 10px; color: #666; }
.lap-time { font-family: monospace; font-size: 14px; font-weight: bold; }
.sector-td { font-family: monospace; font-size: 12px; color: #9d9d9d; }
.lap-delta { font-size: 11px; font-weight: bold; text-align: right !important; padding-right: 10px !important; }

/* --- 5. Блок телеметрии (Минимизированный под 7 колонок) --- */
.tele-td {
    padding: 0 5px !important;
}

.telemetry-box {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tel-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.tel-row span {
    font-size: 10px;
    font-family: monospace;
    text-align: center;
}

.tel-row:first-child span { color: #e3e3e3; font-weight: bold; }
.tel-row:last-child span { color: #7a7a7a; }

/* --- 6. Адаптив для iPhone (Bottom Sheet) --- */
@media (max-width: 600px) {
    .modal { align-items: flex-end; }
    
    .modal-content {
        width: 100%;
        max-height: 85dvh;
        border-radius: 20px 20px 0 0;
    }
    
    /* На мобильных еще чуть уменьшаем шрифты, чтобы влезло */
    .laps-table thead th { font-size: 9px !important; }
    .lap-time { font-size: 13px; }
    .tel-row span { font-size: 9px; }
}

/* Стили разделителя сессий */
.session-separator td {
    background: #1a1a1a !important;
    color: #8d8d8d !important;
    font-size: 10px !important;
    font-weight: bold;
    text-align: center !important;
    padding: 8px !important;
    border-bottom: 1px solid #2d2d2d !important;
}

