:root
{
    --primary: #1F7B91;
    --primary-light: #2a9cb8;
    --primary-dark: #155f73;
    --accent: #E8AE2A;
    --accent-dark: #c8930e;
    --bg: #f8f9fa;
    --text: #34495e;
    --text-light: #7f8c9b;
    --border: #dfe6e9;
    --success: #00b894;
    --error: #d63031;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
}

*
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body
{
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body
{
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f0f0;
    color: var(--text);
}

#map
{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.leaflet-bottom
{
    bottom: calc(44px + max(16px, var(--safe-area-inset-bottom)) + 4px) !important;
}

.choice-overlay
{
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.55);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.choice-card
{
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    animation: choice-in 0.18s ease;
}

@keyframes choice-in
{
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.choice-title
{
    margin: 0 0 8px 0;
    color: var(--primary);
    font-size: 16px;
}

.choice-message
{
    margin: 0 0 16px 0;
    color: var(--text);
    line-height: 1.4;
    font-size: 14px;
    white-space: pre-line;
}

.choice-buttons
{
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.choice-btn
{
    padding: 12px 16px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.choice-btn:hover { background: white; border-color: var(--primary); }

.choice-btn.primary
{
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 600;
}

.choice-btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.leaflet-control-scale-line
{
    background: rgba(255,255,255,0.9);
    border-color: var(--primary);
    color: var(--text);
    padding: 1px 6px;
    font-weight: 600;
    font-size: 11px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.floating-btn
{
    position: fixed;
    bottom: calc(44px + max(16px, var(--safe-area-inset-bottom)) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 99;
    background: var(--primary);
    color: white;
    padding: 10px 18px;
    border-radius: 24px;
    border: none;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    font-size: 14px;
    font-weight: 600;
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    max-width: calc(100vw - 32px);
    line-height: 20px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.floating-btn .btn-text
{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
    margin-left: 24px;
    position: relative;
    z-index: 1;
}

.floating-btn[hidden] { display: none; }

.floating-btn:hover:not(:disabled):not(.loading)
{
    background: var(--primary-dark);
}

.floating-btn:disabled
{
    opacity: 0.85;
    cursor: not-allowed;
}

.floating-btn .btn-icon
{
    position: absolute;
    left: 18px;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    line-height: 16px;
    text-align: center;
    transform-origin: center;
    pointer-events: none;
    z-index: 1;
}

.floating-btn.loading .btn-icon
{
    animation: floating-btn-spin 0.9s linear infinite;
}

@keyframes floating-btn-spin
{
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.floating-btn .btn-progress
{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    background: var(--primary-dark);
    z-index: 0;
    pointer-events: none;
    transition: width 0.3s ease;
}

.floating-btn.loading
{
    z-index: 99;
}

.top-bar
{
    position: fixed;
    top: max(8px, env(safe-area-inset-top, 0));
    right: 8px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    border-radius: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    padding: 4px;
    transition: all 0.25s ease;
}

.top-bar.collapsed
{
    width: 48px;
    overflow: hidden;
}

.top-bar.collapsed input,
.top-bar.collapsed #address-search-btn,
.top-bar.collapsed #locate-btn
{
    display: none;
}

.top-bar.expanded
{
    left: 8px;
    width: auto;
}

.top-bar input
{
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 12px;
    font-size: 14px;
    background: transparent;
    min-width: 0;
}

.top-icon-btn
{
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.top-icon-btn:hover
{
    background: var(--bg);
}

.top-bar .address-suggestions
{
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    border-radius: var(--radius);
}

#bottom-sheet
{
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: white;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    min-height: 44px;
    max-height: 92vh;
    transition: height 0.3s ease;
    padding-bottom: max(16px, var(--safe-area-inset-bottom));
    overflow: hidden;
}

#bottom-sheet.collapsed
{
    height: 44px;
}

#bottom-sheet.card-peek
{
    height: 160px;
}

body.sheet-card-peek .floating-btn
{
    bottom: calc(160px + max(16px, var(--safe-area-inset-bottom)) + 12px);
}

body.sheet-card-peek .loops-floating-nav
{
    bottom: calc(160px + max(16px, var(--safe-area-inset-bottom)) + 70px);
}

body.sheet-card-peek .leaflet-bottom
{
    bottom: calc(160px + max(16px, var(--safe-area-inset-bottom)) + 4px) !important;
}

#bottom-sheet.expanded
{
    height: 92vh;
}

#bottom-sheet.minimal
{
    height: 55vh;
}

.bottom-sheet-handle
{
    padding: 12px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    touch-action: none;
    cursor: grab;
}

.bottom-sheet-handle:active
{
    cursor: grabbing;
}

.handle-bar
{
    width: 40px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
}

.bottom-sheet-content
{
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sheet-section
{
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sheet-section h3
{
    font-size: 0.9rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.search-row
{
    display: flex;
    gap: 6px;
}

.search-row input
{
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.search-row input:focus
{
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 4px rgba(45,106,79,0.2);
}

.icon-btn
{
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    color: var(--primary);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover
{
    background: var(--bg);
    border-color: var(--primary);
}

.address-suggestions
{
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1001;
    box-shadow: var(--shadow);
}

.address-suggestion
{
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    transition: var(--transition);
}

.address-suggestion:last-child
{
    border-bottom: none;
}

.address-suggestion:hover
{
    background: var(--bg);
}

.load-btn
{
    position: relative;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    overflow: hidden;
    min-height: 44px;
}

.load-btn:hover:not(:disabled):not(.loading)
{
    background: var(--primary-dark);
}

.load-btn:disabled:not(.loading)
{
    opacity: 0.5;
    cursor: not-allowed;
}

.load-btn .btn-content
{
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.load-btn .btn-spinner { display: none; }

.load-btn.loading .btn-icon { display: none; }

.load-btn.loading .btn-spinner { display: inline-block; }

.load-btn .btn-progress
{
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0%;
    background: var(--primary-dark);
    transition: width 0.3s ease;
    z-index: 1;
}

.load-status
{
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin-top: -4px;
    min-height: 14px;
    transition: opacity 0.25s ease;
    opacity: 0;
}

.load-status.visible
{
    opacity: 1;
}

.load-stats
{
    font-size: 12px;
    color: var(--text-light);
    padding: 8px 12px;
    background: var(--bg);
    border-radius: var(--radius);
}

.activity-select
{
    display: flex;
    gap: 8px;
}

.activity-btn
{
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.activity-btn.active
{
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.activity-btn i
{
    font-size: 18px;
}

.range-group
{
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.range-group input
{
    width: 100%;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.range-group input::-webkit-slider-thumb
{
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    margin-top: -8px;
}

.range-group input::-moz-range-thumb
{
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    cursor: pointer;
    border-color: white;
}

.range-group input::-webkit-slider-runnable-track
{
    background: var(--border);
    height: 6px;
    border-radius: 3px;
}

.range-group input::-moz-range-track
{
    background: var(--border);
    height: 6px;
    border-radius: 3px;
}

.range-group input::-moz-range-progress
{
    background: var(--primary);
    height: 6px;
    border-radius: 3px;
}

.range-labels
{
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-light);
}

.range-value
{
    color: var(--primary);
    font-weight: 600;
}

.tolerance-group
{
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.tolerance-group select
{
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;
    cursor: pointer;
}

.generate-btn
{
    padding: 12px 16px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.generate-btn:hover:not(:disabled)
{
    background: #00a878;
}

.generate-btn:disabled
{
    opacity: 0.5;
    cursor: not-allowed;
}

.stats-grid
{
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.stat
{
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-value
{
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label
{
    font-size: 11px;
    color: var(--text-light);
}

.priority-hint
{
    font-size: 12px;
    color: var(--text-light);
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.priority-hint i
{
    width: 14px;
    margin-right: 4px;
}

.priority-hint .fa-exclamation-triangle
{
    color: #f1c40f;
}

.priority-hint .fa-ban
{
    color: #e74c3c;
}

.priority-list
{
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.priority-item
{
    display: grid;
    grid-template-columns: 40px 24px 1fr 40px 60px;
    gap: 8px;
    align-items: center;
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius);
    border-left: 4px solid #27ae60;
    transition: background 0.2s ease;
}

.priority-item.pos-0 { background: #d4edda; }
.priority-item.pos-1 { background: #e8f5d0; }
.priority-item.pos-2 { background: #fff3cd; }
.priority-item.pos-3 { background: #ffe0b3; }
.priority-item.pos-4 { background: #f8d7da; }

.priority-item.priority-avoided { border-left-color: #f1c40f; }
.priority-item.priority-forbidden { border-left-color: #e74c3c; }

.priority-controls
{
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.priority-btn
{
    width: 28px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-light);
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    transition: var(--transition);
}

.priority-btn:hover
{
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.filter-icon
{
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: white;
    font-weight: 600;
}

.filter-icon.single { background: #c0392b; }
.filter-icon.forest { background: #784921; }
.filter-icon.footway { background: #2980b9; }
.filter-icon.cycle { background: #f39c12; }
.filter-icon.road { background: #555555; }

.priority-label
{
    font-size: 13px;
    font-weight: 500;
}

.priority-count
{
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
}

.priority-actions
{
    display: flex;
    gap: 4px;
}

.action-btn
{
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: var(--transition);
}

.action-btn:hover
{
    border-color: var(--primary);
    color: var(--primary);
}

.avoid-btn.active { background: #f1c40f; color: #333; border-color: #f1c40f; }
.forbid-btn.active { background: #e74c3c; color: white; border-color: #e74c3c; }

.type-breakdown
{
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.type-breakdown-row
{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 12px;
    border-left: 4px solid var(--border);
}

.type-breakdown-row.row-preferred { border-left-color: #27ae60; }
.type-breakdown-row.row-neutral { border-left-color: #95a5a6; }
.type-breakdown-row.row-avoided { border-left-color: #f39c12; }
.type-breakdown-row.row-forbidden { border-left-color: #e74c3c; }

.loops-floating-nav
{
    position: fixed;
    bottom: calc(44px + max(16px, var(--safe-area-inset-bottom)) + 70px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 99;
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    border-radius: 24px;
    padding: 4px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

.loops-floating-nav[hidden] { display: none; }

.loop-nav-btn
{
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 14px;
}

.loop-nav-btn:hover:not(:disabled)
{
    background: var(--primary);
    color: white;
}

.loop-nav-btn:disabled
{
    opacity: 0.35;
    cursor: not-allowed;
}

.loop-more-btn
{
    background: var(--accent);
    color: white;
    margin-left: 4px;
}

.loop-more-btn:hover:not(:disabled)
{
    background: var(--accent-dark);
    color: white;
}

.loops-counter
{
    font-weight: 700;
    color: var(--primary);
    font-size: 14px;
    min-width: 44px;
    text-align: center;
    padding: 0 4px;
}

.loops-list
{
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loop-card
{
    padding: 10px;
    background: var(--bg);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    border-left: 4px solid transparent;
}

.loop-card:hover
{
    background: white;
    border-color: var(--border);
}

.loop-card.selected
{
    background: white;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(45,106,79,0.15);
}

.loop-card-header
{
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.loop-card-num
{
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
}

.loop-card-stats
{
    display: flex;
    gap: 10px;
    font-size: 12px;
    color: var(--text);
}

.loop-card-stats i
{
    margin-right: 3px;
    color: var(--text-light);
}

.loop-card-elevation
{
    background: white;
    border-radius: 4px;
    overflow: hidden;
    height: 50px;
}

.elev-placeholder
{
    text-align: center;
    color: var(--text-light);
    font-size: 11px;
    padding-top: 18px;
}

.export-btn
{
    padding: 12px 16px;
    background: var(--accent);
    color: #34495e;
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.export-btn:hover
{
    background: var(--accent-dark);
}

.loading
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 20px;
}

.spinner
{
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

#loading-text
{
    font-size: 13px;
    color: var(--text-light);
}

.progress-container
{
    width: 100%;
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar
{
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.2s ease;
}

/* Desktop fallback */
@media (min-width: 768px)
{
    body
    {
        display: flex;
        flex-direction: row;
    }

    #map
    {
        position: relative;
        width: 100%;
        height: 100%;
    }

    #bottom-sheet
    {
        position: relative;
        width: 360px;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: none !important;
        border-radius: 0;
        transform: none !important;
        overflow: hidden;
        padding: 0;
        gap: 0;
        order: -1;
        flex-direction: column;
    }

    #bottom-sheet.collapsed,
    #bottom-sheet.expanded,
    #bottom-sheet.minimal
    {
        height: 100vh !important;
        transform: none;
    }

    .bottom-sheet-content
    {
        overflow-y: auto !important;
        max-height: none !important;
        padding: 16px !important;
    }

    .bottom-sheet-handle
    {
        display: none;
    }

    .sheet-section
    {
        gap: 12px;
    }

    .sheet-section h3
    {
        font-size: 0.95rem;
        margin-bottom: 8px;
    }
}
