/* =========================================
   1. ZMIENNE I BAZA
========================================= */
:root {
    --main: #28a745;
    --accent: #f59e0b;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --step-line: #cbd5e1;
    --start-node: #007bff;
    --end-node: #28a745;
    --live-label-text: #000000;
    --live-blue: #007bff;
    --live-green: #28a745;
    --live-red: #dc3545;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --input-bg: #1e293b;
    --step-line: #475569;
}

body { 
    background: var(--bg); 
    font-family: 'Segoe UI', sans-serif; 
    color: var(--text); 
    transition: background 0.3s, color 0.3s; 
    padding-bottom: 80px; 
padding-top: env(safe-area-inset-top);
}
.app-card {
    background: var(--card); border-radius: 24px; padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05); max-width: 500px; margin: 15px auto;
    position: relative; /* Dodane dla guzika motywu */
}

/* =========================================
   2. POLA WYSZUKIWANIA I FORMULARZE
========================================= */
.input-label { font-size: 0.75rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; margin-bottom: 5px; }
.form-control { background: var(--input-bg); color: var(--text); border: 2px solid var(--border); border-radius: 12px; padding: 12px; }
.form-control:focus { border-color: var(--main); box-shadow: none; background: var(--input-bg); color: var(--text); }

/* POPRAWKA: Widoczność placeholderów w Dark Mode */
.form-control::placeholder { color: var(--text-muted); opacity: 0.8; }
[data-theme="dark"] .form-control::placeholder { color: #94a3b8; opacity: 0.7; }

.has-icon-padding { padding-left: 45px !important; padding-right: 48px !important; }

.input-type-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 20px; height: 20px; z-index: 5; opacity: 0.8; pointer-events: none;
}

.clear-input-btn {
    position: absolute !important; right: 15px !important; left: auto !important;
    top: 50% !important; transform: translateY(-50%) !important;
    width: 24px; height: 24px; background: #adb5bd; color: white; border-radius: 50%;
    border: none; display: none; align-items: center; justify-content: center;
    font-size: 16px; font-weight: bold; z-index: 20; cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15); transition: background 0.2s;
}
.clear-input-btn.visible { display: flex !important; }
.clear-input-btn:hover { background: #6c757d; }

.custom-switch-box { background: rgba(0,0,0,0.03); padding: 10px 15px; border-radius: 12px; display: flex; align-items: center; justify-content: space-between; flex-direction: row-reverse; cursor: pointer; }
.custom-switch-box .form-check-label { cursor: pointer; width: 100%; text-align: left; padding-right: 10px; }
.form-check-input { margin: 0 !important; cursor: pointer; }
.form-check-input:checked { background-color: var(--main) !important; border-color: var(--main) !important; box-shadow: 0 0 10px rgba(40, 167, 69, 0.4); }
input[type="time"]::-webkit-calendar-picker-indicator { opacity: 0; position: absolute; right: 0; width: 40px; height: 100%; cursor: pointer; }

/* =========================================
   3. PRZYCISKI GŁÓWNE
========================================= */
.swap-btn {
    background: none; border: none; color: var(--main);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.2s;
}
.swap-btn:hover { transform: scale(1.1); opacity: 0.8; }

.btn-via-toggle {
    background: none; border: none; color: var(--main); font-size: 0.8rem;
    font-weight: 800; cursor: pointer; text-transform: uppercase; padding: 0; transition: color 0.2s;
}
.btn-via-toggle:hover { color: var(--accent); }

/* Panel przycisków na górze karty */
.top-actions {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    align-items: center; /* Centrowanie w pionie */
    gap: 10px;
    z-index: 100;
}

.action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    border-radius: 8px;
    padding: 0;
}

.action-btn:hover {
    color: var(--main);

    background: rgba(40, 167, 69, 0.1);
}

[data-theme="dark"] .action-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.action-btn:hover {
    color: var(--main);
    transform: scale(1.1);
}

/* Ukrywamy przycisk udostępniania, dopóki nie ma wyników (opcjonalnie) */
#shareBtnTop {
    display: none; /* Funkcja renderPage go pokaże */
}

/* =========================================
   4. AUTOUZUPEŁNIANIE I KALENDARZ
========================================= */
.autocomplete-box { 
    position: absolute; width: 100%; background: var(--card); z-index: 1000; 
    border-radius: 12px; max-height: 250px; overflow-y: auto; display: none; 
    border: 2px solid var(--border); top: 100%; margin-top: 4px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.s-item { padding: 10px 15px; cursor: pointer; border-bottom: 1px solid rgba(0,0,0,0.05); }
.s-item:last-child { border-bottom: none; }
.s-item:hover { background: var(--main); color: white; }
.s-item:hover span { color: white !important; }

.calendar-wrapper { position: relative; }
.custom-calendar {
    position: absolute; top: 100%; left: 0; z-index: 2000; background: var(--card);
    border: 2px solid var(--border); border-radius: 20px; padding: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.2); display: none; width: 320px;
}
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; font-weight: 800; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-day-name { text-align: center; font-size: 0.7rem; font-weight: 800; color: var(--text-muted); padding-bottom: 5px; }
.cal-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 10px; cursor: pointer; font-size: 0.9rem; font-weight: 600; transition: 0.2s; }
.cal-day:hover { background: var(--border); }
.cal-day.selected { background-color: var(--main); color: white; border-radius: 50%; font-weight: bold; }
.cal-day.today:not(.selected) { border: 2px solid var(--main); border-radius: 50%; color: var(--main); font-weight: bold; }
.cal-day.other-month { opacity: 0.3; }
.cal-btn { background: none; border: none; color: var(--main); font-size: 1.2rem; cursor: pointer; }

/* =========================================
   5. WYNIKI WYSZUKIWANIA I TRASA
========================================= */
.res-card {
    background: var(--card); border-radius: 20px; padding: 15px; margin-top: 15px;
    border: 1px solid var(--border); cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
}
.res-card:active { transform: scale(0.98); }
.no-results { color: var(--text-muted); font-size: 0.85rem; margin-top: 3rem; text-align: center; font-weight: bold; }

.route-main-relation { font-size: 0.95rem; font-weight: 700; color: var(--text); margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid rgba(0,0,0,0.05); }
.travel-time-label { font-size: 0.70rem; color: var(--text); font-weight: 800; margin-top: 2px; }
.transfer-info-small { font-size: 0.75rem; color: var(--text); opacity: 0.8; font-weight: 500; text-transform: uppercase; }
.transfer-via-list { font-size: 0.75rem; color: var(--text); opacity: 0.7; font-style: italic; margin-top: 4px; line-height: 1.2; }

.live-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; margin-top: 4px; display: inline-block; }
.live-blue { color: var(--live-blue); }
.live-green { color: var(--live-green); }
.live-red { color: var(--live-red); }

.badge-skm, .badge-polregio, .badge-ztm, .badge-line {
    padding: 2px 6px; border-radius: 6px; font-weight: 800; font-size: 0.8rem; 
    display: inline-block; vertical-align: middle; line-height: 1.1; text-transform: uppercase;
}
.badge-line { background: var(--main); color: white; }
.badge-skm { background-color: #ffcc00; color: #003399; border: 1px solid #003399; }
.badge-polregio { background-color: #e30613; color: white; }
.badge-ztm { background-color: #e02f2f; color: white; margin-left: 4px; }

/* Nawigacja w wynikach */
.nav-row { display: flex; justify-content: center; align-items: center; width: 100%; margin: 15px 0; }
.nav-btn { background: var(--main); color: white; border: none; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; font-weight: bold; }
.nav-text { font-weight: bold; font-size: 0.9rem; color: var(--text); opacity: 0.8; }

/* Widok detali trasy */
.route-view { display: none; margin-top: 15px; padding: 15px 15px 15px 45px; background: rgba(0,0,0,0.03); border-radius: 15px; position: relative; }
.route-view::before { content: ''; position: absolute; left: 25px; top: 33px; bottom: 33px; width: 2px; background: var(--step-line); z-index: 1; }
.route-step { display: flex; justify-content: space-between; padding: 8px 0; font-size: 0.85rem; position: relative; }
.route-step span { max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-step::after { content: ''; position: absolute; left: -24px; top: 13px; width: 10px; height: 10px; background: var(--step-line); border-radius: 50%; z-index: 2; }
.route-step.start-node::after { border: 3px solid var(--start-node); background: var(--start-node); }
.route-step.end-node::after { border: 3px solid var(--end-node); background: var(--end-node); }
.route-step.start-node { color: var(--start-node); font-weight: 700; }
.route-step.end-node { color: var(--end-node); font-weight: 700; }

.transfer-info-block { background: rgba(0,0,0,0.05); border-left: 4px solid var(--accent); margin: 12px 0 12px -15px; padding: 10px 15px; border-radius: 0 10px 10px 0; font-size: 0.8rem; }
.leg-intermediate { display: none; padding-left: 10px; }
.expand-triangle { position: absolute; left: -34px; top: 13px; width: 0; height: 0; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 8px solid var(--text-muted); cursor: pointer; transition: transform 0.2s; z-index: 5; }
.expand-triangle.expanded { transform: rotate(90deg); border-left-color: var(--main); }

/* =========================================
   6. IKONY I DARK MODE
========================================= */
.transport-icon { height: 24px; width: auto; vertical-align: middle; margin-right: 4px; transition: filter 0.3s ease; }
.ac-icon { height: 18px; width: auto; opacity: 0.7; margin-left: 8px; }
.mode-icon { font-size: 1.4rem; margin-right: 2px; vertical-align: middle; display: inline-block; line-height: 1; }
.map-link-btn { display: inline-flex; align-items: center; justify-content: center; margin-left: 8px; width: 24px; height: 24px; text-decoration: none; border-radius: 6px; transition: background 0.2s; }
.map-link-btn:hover { background-color: #e5e5ea; }

/* POPRAWKA: Wszystkie ikony w Dark Mode (w tym input-type-icon) */
[data-theme="dark"] .transport-icon,
[data-theme="dark"] .ac-icon,
[data-theme="dark"] .input-type-icon { filter: invert(1) brightness(1.2); }
[data-theme="dark"] .mode-icon { filter: grayscale(1) brightness(10); }

/* =========================================
   7. INTERFEJS GŁÓWNY
========================================= */
#loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(8px); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 9999; transition: opacity 0.3s ease; }
#loading-overlay.d-none { display: none !important; }
.spinner-border { color: var(--main); width: 3.5rem; height: 3.5rem; border-width: 0.25em; }
#loading-overlay div:last-child { font-size: 1.1rem; letter-spacing: 1px; animation: pulseText 1.5s infinite ease-in-out; }
@keyframes pulseText { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

.btn-loader { width: 20px; height: 20px; border: 3px solid rgba(255, 255, 255, 0.3); border-radius: 50%; border-top-color: #fff; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }
.nav-btn .btn-loader { margin-right: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.share-fab { position: fixed; bottom: 25px; right: 25px; width: 56px; height: 56px; background: var(--accent); color: white; border-radius: 50%; display: none; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(0,0,0,0.3); cursor: pointer; z-index: 2000; border: none; font-size: 24px; transition: transform 0.2s; }
.share-fab.visible { display: flex; animation: fabPop 0.3s ease-out; }
.share-fab:hover { transform: scale(1.1); background: var(--main); }

/* OPTYMALIZACJA MOBILNA */
@media (max-width: 576px) {
    .app-card { padding: 18px; margin: 10px; border-radius: 20px; }
    .form-control { font-size: 16px !important; }
}
/* =========================================
   9. MOBILNA REWOLUCJA (RWD)
========================================= */

@media (max-width: 576px) {
    /* 1. Kontener główny - lepsze wykorzystanie miejsca */
    .app-card {
        margin: 10px;
        padding: 18px;
        border-radius: 20px;
        width: auto;
    }

    /* 2. Nagłówek - mniejszy, żeby nie zabierał pół ekranu */
    h2 {
        font-size: 1.6rem !important;
        margin-bottom: 20px !important;
    }

    /* 3. Naprawa "Top Actions" - żeby ikony nie uciekały */
    .top-actions {
        top: 12px;
        right: 12px;
        gap: 8px;
    }

    .action-btn {
        width: 38px;
        height: 38px;
    }

    /* 4. Formularz - powiększone pola pod palec (min. 44px wysokości) */
    .form-control {
        height: 50px;
        font-size: 16px !important; /* Blokuje irytujący zoom na iPhone */
    }

    /* 5. Wyniki wyszukiwania - czytelność na małym ekranie */
    .res-card {
        padding: 12px;
        margin-top: 10px;
    }

    .route-main-relation {
        font-size: 0.85rem;
        white-space: normal; /* Pozwalamy na łamanie nazw długich przystanków */
    }

    .text-success.h4 {
        font-size: 1.1rem !important; /* Godziny przyjazdu */
    }

    .transfer-info-small, .travel-time-label {
        font-size: 0.65rem;
    }

    /* 6. Kalendarz na telefonie - żeby nie wychodził poza ekran */
    .custom-calendar {
        width: calc(100vw - 30px);
        left: -5px; /* Centrowanie względem ekranu */
        padding: 15px;
    }

    .cal-grid {
        gap: 2px;
    }

    .cal-day {
        font-size: 0.8rem;
    }

    /* 7. Nawigacja "Wcześniejsze/Późniejsze" - duże, wygodne guziki */
    .nav-btn {
        width: 50px;
        height: 50px;
        font-size: 1.4rem;
    }

    .nav-text {
        font-size: 0.75rem;
    }

    /* 8. Detale trasy (te kropki i linie) */
    .route-view {
        padding-left: 35px;
        font-size: 0.8rem;
    }

    .route-view::before {
        left: 20px;
    }

    .route-step::after {
        left: -20px;
    }
}

/* Zapobieganie przesuwaniu strony na boki (overflow-x) */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}