/* style.css */

/* === БАЗА === */
.pt-safe { padding-top: env(safe-area-inset-top); }
.pb-safe { padding-bottom: env(safe-area-inset-bottom); }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ВАЖНО: Блокируем нативный "пружинистый" эффект iOS, чтобы работал наш PTR */
html {
    transition: font-size 0.3s ease;
    background-color: #ffffff;
}
body {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    overscroll-behavior-y: none;
    background-color: #f8fafc;
    min-height: 100%;
    min-height: 100dvh;
}
html.dark {
    background-color: #0f172a;
    color-scheme: dark;
}
html.dark body {
    background-color: #0f172a;
}

/* === SPLASH SCREEN === */
.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff !important;
    color-scheme: only light;
    overflow: hidden;
    transition: opacity 0.45s ease, visibility 0.45s ease;
}
/* Закрываем возможный зазор status bar / rubber-band на iOS */
.splash-screen::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -40vh;
    height: 40vh;
    background: #ffffff !important;
    pointer-events: none;
}
.splash-screen.splash-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.splash-glow {
    position: absolute;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.18) 0%, rgba(250, 204, 21, 0.12) 45%, transparent 70%);
    filter: blur(8px);
    animation: splash-glow-pulse 2.8s ease-in-out infinite;
}
.splash-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 24px;
}
.splash-logo-wrap {
    position: relative;
    margin-bottom: 20px;
    animation: splash-logo-in 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.splash-logo {
    width: 112px;
    height: 112px;
    border-radius: 26px;
    object-fit: cover;
    background: #fff;
    box-shadow:
        0 18px 40px -16px rgba(37, 99, 235, 0.45),
        0 8px 16px -8px rgba(15, 23, 42, 0.18);
    animation: splash-logo-float 2.4s ease-in-out 0.7s infinite;
}
.splash-title {
    margin: 0 0 18px;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #0f172a !important;
    animation: splash-fade-up 0.55s ease 0.2s both;
}
.splash-dots {
    display: flex;
    gap: 7px;
    margin-bottom: 28px;
    animation: splash-fade-up 0.55s ease 0.35s both;
}
.splash-dots span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #3b82f6;
    opacity: 0.35;
    animation: splash-dot 1.2s ease-in-out infinite;
}
.splash-dots span:nth-child(2) {
    background: #eab308;
    animation-delay: 0.15s;
}
.splash-dots span:nth-child(3) {
    background: #22c55e;
    animation-delay: 0.3s;
}
.splash-version {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8 !important;
    font-variant-numeric: tabular-nums;
    animation: splash-fade-up 0.55s ease 0.45s both;
}

@keyframes splash-logo-in {
    from { opacity: 0; transform: scale(0.72) translateY(14px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes splash-logo-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
@keyframes splash-fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes splash-dot {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0) scale(1); }
    40% { opacity: 1; transform: translateY(-3px) scale(1.15); }
}
@keyframes splash-glow-pulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.12); opacity: 1; }
}

/* === INSTALL SCREEN (browser) === */
.install-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    background: #ffffff;
    overflow: auto;
    text-align: center;
}
.install-screen:not(.hidden) {
    display: flex;
}
html.dark .install-screen { background: #0f172a; }
.install-glow {
    position: absolute;
    width: 320px;
    height: 320px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.16) 0%, rgba(34, 197, 94, 0.1) 40%, transparent 70%);
    filter: blur(10px);
    pointer-events: none;
}
.install-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.install-logo {
    width: 104px;
    height: 104px;
    border-radius: 24px;
    object-fit: cover;
    background: #fff;
    margin-bottom: 18px;
    box-shadow:
        0 18px 40px -16px rgba(37, 99, 235, 0.4),
        0 6px 14px -8px rgba(15, 23, 42, 0.16);
    animation: splash-logo-in 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.install-title {
    margin: 0 0 6px;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #0f172a;
}
html.dark .install-title { color: #f8fafc; }
.install-lead {
    margin: 0 0 22px;
    font-size: 0.95rem;
    line-height: 1.45;
    color: #64748b;
    max-width: 16rem;
}
html.dark .install-lead { color: #94a3b8; }
.install-platforms {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.install-platform {
    width: 100%;
    text-align: left;
    padding: 14px;
    border-radius: 18px;
    background: #fff;
    border: 1px solid #e2e8f0;
}
html.dark .install-platform {
    background: #1e293b;
    border-color: #334155;
}
.install-platform-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
}
html.dark .install-platform-title { color: #94a3b8; }
.install-platform-title i {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    background: #0f172a;
}
.install-platform-title .fa-android {
    background: #16a34a;
}
.install-steps {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}
.install-step {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    padding: 10px 12px;
    border-radius: 14px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #334155;
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.35;
}
html.dark .install-step {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}
.install-step b { font-weight: 800; color: #0f172a; }
html.dark .install-step b { color: #fff; }
.install-step i { color: #3b82f6; margin-left: 2px; }
.install-step-num {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #1d4ed8;
    background: #dbeafe;
}
html.dark .install-step-num {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.2);
}
.install-cta {
    margin-top: 10px;
    width: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 18px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    box-shadow: 0 12px 24px -10px rgba(37, 99, 235, 0.55);
    transition: transform 0.15s ease, opacity 0.15s ease;
}
.install-cta:not(.hidden) {
    display: inline-flex;
}
.install-cta:active { transform: scale(0.98); }
.install-cta:disabled { opacity: 0.65; }
.install-version {
    margin: 28px 0 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}
html.dark .install-version { color: #64748b; }

/* === АНИМАЦИИ СТРАНИЦ === */
#app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

section[data-page] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    /* ВАЖНО: Это позволяет нашему PTR работать внутри секции */
    overscroll-behavior-y: contain; 
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), opacity 0.3s ease;
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
    z-index: 1;
    padding-bottom: 80px; 
}

section[data-page].active {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
    z-index: 10;
}

/* === UI КНОПКИ === */
.btn-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.2);
}

.nav-btn {
    position: relative;
    transition: all 0.2s ease;
}
.nav-btn-active { color: #4F46E5 !important; }

/* === PULL TO REFRESH (Исправлено) === */
#ptr {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 15px;
    z-index: 50; /* Поверх контента */
    pointer-events: none;
    transform: translateY(-100%);
    /* Убираем opacity, управляем через JS */
}

.ptr-icon-box {
    background: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    color: #4F46E5;
    margin-bottom: 5px;
    transition: transform 0.2s;
    z-index: 51;
}
html.dark .ptr-icon-box { background: #1E293B; color: #818CF8; border: 1px solid #334155; }

.ptr-text {
    font-size: 11px;
    font-weight: 700;
    color: #94A3B8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}
html.dark .ptr-text { text-shadow: none; }

/* === МОДАЛКА И ТОСТЫ === */
.ios-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex; align-items: flex-end;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s;
}
.ios-modal-overlay.open { opacity: 1; pointer-events: auto; }

.ios-modal {
    background: white;
    width: 100%;
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 30px 20px 40px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.ios-modal-overlay.open .ios-modal { transform: translateY(0); }
html.dark .ios-modal { background: #1E293B; color: white; }

.toast {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    color: white;
    padding: 14px 18px;
    border-radius: 14px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 100;
    width: 90%;
    max-width: 350px;
    border: 1px solid rgba(255,255,255,0.1);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: rgba(220, 38, 38, 0.95); border-color: rgba(254, 202, 202, 0.2); }
.toast.success { background: rgba(22, 163, 74, 0.95); border-color: rgba(187, 247, 208, 0.2); }

/* === КОНСОЛЬ ОТЛАДКИ === */
.debug-console {
    background: #000;
    color: #0f0;
    font-family: monospace;
    font-size: 10px;
    padding: 10px;
    border-radius: 8px;
    margin-top: 20px;
    max-height: 200px;
    overflow-y: auto;
    word-break: break-all;
    border: 1px solid #333;
}
.debug-console div { margin-bottom: 4px; border-bottom: 1px solid #111; padding-bottom: 2px; }
.debug-console .error { color: #f55; }
.debug-console .warn { color: #fa0; }

/* === FLATPICKR === */
/* Жёстко не шире экрана при любом размере шрифта (Android / large text) */
.flatpickr-calendar {
    font-family: inherit;
    border: none !important;
    border-radius: 20px !important;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2) !important;
    padding: 10px !important;
    box-sizing: border-box !important;
    width: min(320px, calc(100vw - 24px)) !important;
    max-width: calc(100vw - 24px) !important;
    overflow: hidden !important;
}
html.dark .flatpickr-calendar { background: #1E293B !important; box-shadow: 0 20px 40px rgba(0,0,0,0.5) !important; }

.flatpickr-calendar .flatpickr-months {
    width: 100% !important;
    align-items: center;
}
.flatpickr-calendar .flatpickr-month {
    width: 100% !important;
    overflow: hidden;
}
.flatpickr-calendar .flatpickr-current-month {
    width: auto !important;
    max-width: calc(100% - 70px);
    left: 50% !important;
    transform: translateX(-50%);
    font-size: clamp(13px, 3.6vw, 17px) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.flatpickr-calendar .flatpickr-current-month .cur-month,
.flatpickr-calendar .flatpickr-current-month input.cur-year {
    font-size: inherit !important;
}

.flatpickr-calendar .flatpickr-innerContainer,
.flatpickr-calendar .flatpickr-rContainer,
.flatpickr-calendar .flatpickr-days,
.flatpickr-calendar .flatpickr-weekdays,
.flatpickr-calendar .flatpickr-weekdaycontainer {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
}
.flatpickr-calendar .flatpickr-weekdaycontainer {
    display: flex !important;
}
.flatpickr-calendar .dayContainer {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: flex-start;
}
.flatpickr-calendar .flatpickr-weekday {
    flex: 0 0 calc(100% / 7);
    max-width: calc(100% / 7);
    width: calc(100% / 7) !important;
    font-size: clamp(10px, 2.8vw, 13px) !important;
    overflow: hidden;
    text-overflow: clip;
}
.flatpickr-calendar .flatpickr-day {
    flex: 0 0 calc(100% / 7);
    max-width: calc(100% / 7) !important;
    width: calc(100% / 7) !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    line-height: normal !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: clamp(12px, 3.2vw, 15px) !important;
    box-sizing: border-box !important;
}

.flatpickr-day.selected { background: #4F46E5 !important; border-color: #4F46E5 !important; border-radius: 10px !important; }
.flatpickr-day.has-tasks { background: #E0E7FF; border: 1px solid #C7D2FE; color: #4338CA; font-weight: 800; }
html.dark .flatpickr-day { color: #E2E8F0; }
html.dark .flatpickr-day:hover { background: #334155; }
html.dark .flatpickr-day.has-tasks { background: #312E81; border-color: #4338CA; color: #C7D2FE; }

/* 2. Точка в календаре (если есть задачи) */
.flatpickr-day.has-task {
    position: relative;
    font-weight: bold;
    color: #4f46e5; /* Indigo-600 */
}
.flatpickr-day.has-task::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background-color: #4f46e5;
    border-radius: 50%;
}
.dark .flatpickr-day.has-task { color: #818cf8; }
.dark .flatpickr-day.has-task::after { background-color: #818cf8; }

/* При выборе даты точку делаем белой, чтобы было видно на синем фоне */
.flatpickr-day.selected.has-task::after {
    background-color: #fff;
}

@keyframes card-pulse-yellow {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.0); border-color: #fbbf24; }
    50% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25); border-color: #f59e0b; }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.0); border-color: #fbbf24; }
}

.card-active-pulse {
    animation: card-pulse-yellow 2s infinite ease-in-out;
    border-width: 1px;
}

/* Для темной темы */
.dark .card-active-pulse {
    border-color: #b45309; 
    box-shadow: none; /* В темной теме можно без тени, или сделать тусклее */
}
/* === БАННЕРЫ УВЕДОМЛЕНИЙ (Action Banners) === */
.action-banner-container {
    position: fixed;
    top: 80px; /* Отступ от хедера */
    left: 0;
    width: 100%;
    z-index: 40;
    padding: 0 16px;
    pointer-events: none; /* Чтобы клики проходили сквозь пустое место */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-banner {
    pointer-events: auto; /* Сами баннеры кликабельны */
    border-radius: 16px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
    transform: translateY(-20px);
    opacity: 0;
    animation: banner-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
}

/* Баннер "Незакрытые задачи" (Красный) */
.action-banner.urgent {
    background: rgba(220, 38, 38, 0.95); /* Red-600 */
    backdrop-filter: blur(8px);
    color: white;
}

/* Баннер "Новая задача" (Синий) */
.action-banner.info {
    background: rgba(79, 70, 229, 0.95); /* Indigo-600 */
    backdrop-filter: blur(8px);
    color: white;
}

@keyframes banner-slide-in {
    to { transform: translateY(0); opacity: 1; }
}

/* === БАННЕР ОБНОВЛЕНИЯ === */
@keyframes update-progress {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.update-banner-progress {
    width: 40%;
    animation: update-progress 1.4s ease-in-out infinite;
    border-radius: 999px;
}

/* === ЗАПРАВКА === */

/* Кнопки типа топлива (сегмент) */
.fuel-type-btn {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #475569;
}
html.dark .fuel-type-btn {
    background: rgba(30, 41, 59, 0.5);
    border-color: #334155;
    color: #cbd5e1;
}
.fuel-type-btn.active {
    background: linear-gradient(135deg, #10b981 0%, #0d9488 100%);
    border-color: #059669;
    color: #fff;
    box-shadow: 0 8px 18px -6px rgba(16, 185, 129, 0.5);
}

/* Элементы списка автомобилей */
.fuel-car-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.15s ease;
}
.fuel-car-item:last-child { border-bottom: none; }
.fuel-car-item:active { background: #f1f5f9; }
html.dark .fuel-car-item { border-bottom-color: #1e293b; }
html.dark .fuel-car-item:active { background: #1e293b; }

.fuel-car-item .fuel-car-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #eef2ff;
    color: #4f46e5;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
html.dark .fuel-car-item .fuel-car-avatar {
    background: rgba(79, 70, 229, 0.2);
    color: #a5b4fc;
}

.fuel-car-item.selected .fuel-car-avatar {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    color: #fff;
}

/* Анимация пульсации для новой задачи в списке */
.highlight-task {
    animation: highlight-pulse 2s ease-in-out infinite;
    border-color: #6366f1 !important; /* Indigo-500 */
}
@keyframes highlight-pulse {
    0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}