/* =========================
   RESET
========================= */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: "Inter", system-ui, sans-serif;
}

/* =========================
   DESIGN TOKENS
========================= */
:root {
    --bg: #f6f7fb;
    --card: rgba(255, 255, 255, 0.9);
    --text: #111;
    --muted: #6b7280;

    --primary: #3b82f6;
    --primary-hover: #2563eb;

    --success: #16a34a;
    --danger: #ef4444;

    --radius: 18px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.15);

    --spacing: 14px;
}

/* =========================
   APP LAYOUT
========================= */
.app {
    position: relative;
    height: 100vh;
    background: var(--bg);
    overflow: hidden;
}

/* MAP = full background */
#map {
    position: absolute;
    inset: 0;
    height: 100%;
    width: 100%;
    z-index: 0;
}

/* =========================
   CARD STYLE (top panel)
========================= */
.card {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;

    width: 92%;
    max-width: 480px;

    padding: var(--spacing);

    background: var(--card);
    backdrop-filter: blur(14px);

    border-radius: var(--radius);
    box-shadow: var(--shadow);

    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* =========================
   INPUTS
========================= */
input {
    padding: 14px 16px;
    font-size: 18px;

    border-radius: 14px;
    border: none;
    min-width: 0;
    /* Allow shrinking */
    flex: 1;
    /* Grow/shrink evenly */

    background: rgba(0, 0, 0, 0.15);
    color: var(--text);

    outline: none;
}

input:focus {
    box-shadow: 0 0 0 2px var(--primary);
}

/* row */
.input-row {
    display: grid;
    grid-template-columns: 1fr 48px;
    /* full input + fixed icon */
    gap: 10px;
    width: 100%;
}

input:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* =========================
   BUTTONS
========================= */
button {
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: 0.2s;

    padding: 16px 0;
    /* większy touch target */
    font-size: 18px;
    /* wyraźny tekst */
    font-weight: 600;

    border-radius: 16px;
    background-color: var(--primary);
    color: white;

    box-shadow: 0 6px 14px rgba(59, 130, 246, 0.35);
    /* soft shadow */
}

#bottom-panel button {
    width: 200px;
}

@media (max-width: 768px) {
    #bottom-panel button {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
        border-radius: 50%;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        align-self: center;
        box-shadow: none !important;
    }

    #bottom-panel button .btn-text {
        display: none;
    }

    #bottom-panel button .btn-icon {
        display: block !important;
        width: 28px;
        height: 28px;
    }
}

/* RED DANGER BUTTON FOR STOP NAVIGATION */
#bottom-panel button.danger-btn {
    background: var(--danger);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

#bottom-panel button.danger-btn:hover {
    background: #dc2626;
}

/* HIDE WARNING BUTTON */
#show-warning-btn {
    display: none;
}

/* primary */
.primary-btn {
    padding: 14px;
    border-radius: 14px;
    font-weight: 600;

    background: var(--primary);
    color: white;

    box-shadow: 0 6px 14px rgba(59, 130, 246, 0.35);
}


.primary-btn:hover {
    background: var(--primary-hover);
}

.secondary-btn {
    padding-left: 10px;
    padding-right: 10px;
}

.secondary-btn:hover {
    background: var(--primary-hover);
}

/* outline-btn */
.outline-btn {
    padding: 14px 16px;
    border-radius: 14px;
    font-weight: 600;
    background: transparent;
    color: var(--muted);
    border: 2px solid var(--muted);
    box-shadow: none;
    transition: 0.2s;
}

.outline-btn:hover {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text);
}

/* round icon */
.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 14px;

    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.08);

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0;
    /* Clear base button padding */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.icon-btn svg {
    width: 27px;
    height: 27px;
    color: black;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}


/* warning */
.warning-btn {
    background: var(--success);
    color: white;
    padding: 10px 14px;
    border-radius: 12px;
}

/* danger */
.danger-btn {
    background: var(--danger);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
}

.danger-btn {
    box-shadow: var(--danger);
}

/* =========================
   BOTTOM SHEET
========================= */
.bottom-sheet {
    position: absolute;
    bottom: 12px;

    left: 12px;
    right: 12px;

    z-index: 10;

    padding: 18px 20px;

    background: var(--card);
    backdrop-filter: blur(16px);

    border-radius: 22px;

    box-shadow: var(--shadow);

    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .bottom-sheet {
        width: max-content;
        min-width: 140px;
        max-width: 96%;
        left: 50%;
        transform: translateX(-50%);
        padding: 12px 18px;
        bottom: 24px;
        border-radius: 20px;
        gap: 12px;
        flex-wrap: nowrap;
    }
}

@media (min-width: 768px) {
    .bottom-sheet {
        max-width: 900px;
        margin: 0 auto;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 92%;
    }
}



.trip-info {
    display: flex;
    flex-direction: column;
    font-size: 18px;
    color: var(--text);
}

.trip-info p {
    margin: 8px;
}

/* Desktop only: add colon after labels */
@media (min-width: 769px) {
    .trip-info span[data-i18n]::after {
        content: ":";
    }
}

@media (max-width: 768px) {
    .trip-info {
        flex-direction: row;
        align-items: center;
        font-size: 16px;
        flex-wrap: wrap;
        gap: 8px;
        flex: 1;
    }

    .trip-info p {
        margin: 0;
        display: flex;
        align-items: center;
        white-space: nowrap;
    }

    .trip-info p:not(:last-child)::after {
        content: "•";
        margin-left: 6px;
        color: var(--muted);
        opacity: 0.6;
    }

    /* Hide text labels on mobile for compact view */
    .trip-info span[data-i18n] {
        display: none;
    }
}

/* =========================
   MODAL
========================= */
.modal {
    position: fixed;
    inset: 0;

    background: rgba(0, 0, 0, 0.5);

    display: flex;
    justify-content: center;
    align-items: center;

    z-index: 20;
}

.modal-content {
    background: var(--card);
    backdrop-filter: blur(16px);

    padding: 24px;
    border-radius: 20px;

    text-align: center;
    max-width: 90%;

    box-shadow: var(--shadow);
}

/* =========================
   UTIL
========================= */
.hidden {
    display: none !important;
}

.fw-bold {
    font-weight: 600;
}

.font-italic {
    font-style: italic;
}

/* desktop improvements */
@media (min-width: 768px) {
    .card {
        top: 30px;
        max-width: 520px;
    }

    .bottom-sheet {
        max-width: 520px;
        margin: 0 auto;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 24px;
        bottom: 20px;
    }
}

/* Fix for Start & Destination inputs on very small screens */
@media (max-width: 367px) {
    input {
        padding: 10px 12px;
        font-size: 16px;
    }

    .form-row {
        gap: 4px;
    }

    .buttons-column {
        gap: 4px;
    }

}

/* Fix for Bottom Panel position to avoid overlapping Google attribution */
@media (max-width: 769px) {
    .bottom-sheet {
        bottom: 30px;
        /* Moved up to clear Google attribution */
    }
}

/* DARK MODE (auto) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --card: rgba(30, 41, 59, 0.85);
        --text: #f1f5f9;
        --muted: #94a3b8;
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    }

    .icon-btn svg {
        color: white;
    }

    #warning-modal p {
        color: white;
    }

    .modal-content p,
    .modal-content h3,
    .modal-content h4,
    .modal-content li {
        color: white;
    }
}

.form-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.inputs-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
    min-width: 0;
    /* Allow flex shrinking */
}

.buttons-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: stretch;
}

.buttons-column .icon-btn {
    height: auto;
    flex: 1;
    min-height: 0;
    aspect-ratio: 1 / 1;
    padding: 0;
}

#loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.hidden {
    display: none !important;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e0e0e0;
    border-top: 5px solid #1565C0;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* =========================
   NAVIGATION INSTRUCTION BAR
========================= */
.nav-bar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;

    width: 92%;
    max-width: 480px;

    padding: 14px 16px;

    background: var(--card);
    backdrop-filter: blur(14px);
    border-radius: var(--radius);
    box-shadow: var(--shadow);

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

@media (min-width: 768px) {
    .nav-bar {
        top: 30px;
        max-width: 520px;
    }
}

.nav-bar-icon {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-bar-icon svg {
    width: 22px;
    height: 22px;
    color: white;
    fill: white;
}

.nav-bar-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

#nav-step-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

.nav-step-distance {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.nav-how-btn {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.12);
    color: var(--primary);
    border: 1px solid rgba(59, 130, 246, 0.25);
    box-shadow: none;
    white-space: nowrap;
    transition: background 0.2s;
}

@media (max-width: 768px) {
    .nav-how-btn {
        display: none;
    }
}

.nav-how-btn:hover {
    background: rgba(59, 130, 246, 0.2);
}

/* =========================
   INSTRUCTIONS MODAL SHEET
========================= */
.instructions-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 72vh;
    background: var(--card);
    backdrop-filter: blur(16px);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

@media (min-width: 768px) {
    .instructions-sheet {
        max-width: 520px;
        left: calc(50% - 260px);
        right: auto;
        border-radius: 24px 24px 0 0;
    }
}

.instructions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.instructions-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.close-instructions-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.08);
    color: var(--text);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: none;
    border: none;
    line-height: 1;
}

.close-instructions-btn:hover {
    background: rgba(0, 0, 0, 0.14);
}

.instructions-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.instruction-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.instruction-item:last-child {
    border-bottom: none;
}

.instr-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    flex: 1;
    line-height: 1.4;
}

.instr-dist {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Dark mode – nav bar & instructions */
@media (prefers-color-scheme: dark) {
    .nav-how-btn {
        background: rgba(96, 165, 250, 0.15);
        color: #93c5fd;
        border-color: rgba(96, 165, 250, 0.3);
    }

    .nav-how-btn:hover {
        background: rgba(96, 165, 250, 0.25);
    }

    .instructions-header {
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .close-instructions-btn {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text);
    }

    .close-instructions-btn:hover {
        background: rgba(255, 255, 255, 0.16);
    }

    .instruction-item {
        border-bottom-color: rgba(255, 255, 255, 0.06);
    }
}

/* =========================
   LANGUAGE SELECTOR (Simplified - No Frills)
========================= */
.lang-selector {
    position: fixed;
    top: 10px;
    right: 60px;
    z-index: 15;
    /* Below modals (20) but above map */
    pointer-events: auto;
}

.lang-trigger {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 0;
    color: inherit;
    backdrop-filter: blur(12px);
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-trigger svg {
    width: 20px;
    height: 20px;
    color: #444;
}

.lang-trigger:hover {
    background: #fff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.lang-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 10001;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(14px);
    border: none;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: 320px;
    min-width: 150px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    animation: none;
}

.lang-option {
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    /* Neutral separator */
    color: #333;
    cursor: pointer;
    border-radius: 0 !important;
    /* Ensure items are square */
    box-shadow: none;
}

.lang-option:last-child {
    border-bottom: none;
}

.lang-option:hover {
    background: rgba(0, 0, 0, 0.04);
}

.lang-option.active {
    background: rgba(0, 0, 0, 0.08);
    font-weight: 600;
}

/* Dark mode overrides (Refined) */
@media (prefers-color-scheme: dark) {
    .lang-trigger {
        background: rgba(30, 41, 59, 0.8);
        border-color: rgba(255, 255, 255, 0.1);
    }

    .lang-trigger svg {
        color: #cbd5e1;
    }

    .lang-trigger:hover {
        background: rgba(51, 65, 85, 0.9);
    }

    .lang-dropdown {
        background: rgba(30, 41, 59, 0.85);
        backdrop-filter: blur(14px);
        border: none;
    }

    .lang-option {
        background: transparent;
        color: #f1f5f9;
        border-bottom-color: rgba(255, 255, 255, 0.08);
        /* Neutral for dark mode */
    }

    .lang-option:hover {
        background: rgba(255, 255, 255, 0.08);
    }

    .lang-option.active {
        background: rgba(255, 255, 255, 0.12);
    }
}

/* Mobile Overrides (Refined) */
@media (max-width: 768px) {
    .lang-selector {
        top: auto;
        bottom: 150px;
        right: 12px;
    }

    .lang-dropdown {
        top: auto;
        bottom: calc(100% + 8px);
        border: none;
    }

    /* Move to bottom-right only if NO route is active */
    body:not(.route-active) .lang-selector {
        top: auto;
        bottom: 20px;
        right: 12px;
    }

    /* Move to position slightly above panel if route is active */
    body.route-active .lang-selector {
        top: auto;
        bottom: 150px;
        right: 12px;
    }
}

/* Floating button for mobile (How to get there) */
.floating-btn {
    position: fixed;
    bottom: 200px;
    /* Above the language selector at 150px */
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: none;
    /* Only on mobile via MQ */
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 15;
    color: #444;
    cursor: pointer;
    padding: 0;
}

#recenter-btn {
    bottom: 250px;
}

@media (max-width: 768px) {
    .floating-btn {
        display: flex;
    }

    .floating-btn.hidden {
        display: none !important;
    }
}

/* Fix for ETA & Distance fields wrapping and Nav Button shrinking */
@media (max-width: 462px) {
    .trip-info p {
        white-space: nowrap;
        font-size: 15px;
        margin: 4px;
    }

    body.route-active .lang-selector {
        bottom: 130px;
    }

    .floating-btn {
        bottom: 180px;
    }

    #recenter-btn {
        bottom: 230px;
    }
}

.floating-btn svg {
    width: 20px;
    height: 20px;
}

.floating-btn:hover {
    background: #fff;
}

/* Reposition buttons to bottom-right corner for 410px-768px range */
@media (min-width: 410px) and (max-width: 768px) {
    body.route-active .lang-selector {
        bottom: 24px;
    }

    .floating-btn {
        bottom: 72px;
        /* Stacked above lang selector */
    }

    #recenter-btn {
        bottom: 122px;
    }
}

@media (prefers-color-scheme: dark) {
    .floating-btn {
        background: rgba(30, 41, 59, 0.8);
        border-color: rgba(255, 255, 255, 0.1);
        color: #cbd5e1;
    }

    .floating-btn:hover {
        background: rgba(51, 65, 85, 0.9);
    }
}