/* ============================================================
   Simple GPX Route Viewer — Pilgrimage Tracker Styles
   Version: 2.0.0
   ============================================================ */

/* ── Google Font ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Cinzel:wght@600;700&display=swap');

/* ── CSS Custom Properties (Dark Theme) ──────────────────────── */
.sgpx-theme-dark {
    --pil-bg:           #0d1117;
    --pil-surface:      #161b22;
    --pil-surface-2:    #1f2937;
    --pil-border:       #30363d;
    --pil-accent:       #f59e0b;
    --pil-accent-dark:  #d97706;
    --pil-accent-glow:  rgba(245, 158, 11, 0.25);
    --pil-route-full:   rgba(245, 158, 11, 0.22);
    --pil-route-day:    #f59e0b;
    --pil-route-dim:    rgba(245, 158, 11, 0.06);
    --pil-text:         #e6edf3;
    --pil-text-muted:   #8b949e;
    --pil-text-faint:   #484f58;
    --pil-green:        #3fb950;
    --pil-red:          #f85149;
    --pil-radius:       12px;
    --pil-shadow:       0 8px 32px rgba(0,0,0,.45);
    --pil-font:         'Inter', system-ui, sans-serif;
    --pil-title-font:   'Cinzel', serif;
}

/* ── CSS Custom Properties (Light / White Theme) ─────────────── */
.sgpx-theme-light {
    --pil-bg:           #ffffff;
    --pil-surface:      #ffffff;
    --pil-surface-2:    #f8fafc;
    --pil-border:       #e2e8f0;
    --pil-accent:       #d97706;
    --pil-accent-dark:  #b45309;
    --pil-accent-glow:  rgba(217, 119, 6, 0.15);
    --pil-route-full:   rgba(217, 119, 6, 0.25);
    --pil-route-day:    #d97706;
    --pil-route-dim:    rgba(217, 119, 6, 0.06);
    --pil-text:         #0f172a;
    --pil-text-muted:   #64748b;
    --pil-text-faint:   #94a3b8;
    --pil-green:        #16a34a;
    --pil-red:          #dc2626;
    --pil-radius:       12px;
    --pil-shadow:       0 4px 20px rgba(0,0,0,.06);
    --pil-font:         'Inter', system-ui, sans-serif;
    --pil-title-font:   'Cinzel', serif;
}

/* ── Wrapper ─────────────────────────────────────────────────── */
.sgpx-pilgrimage {
    font-family: var(--pil-font);
    background: var(--pil-bg);
    border-radius: var(--pil-radius);
    overflow: hidden;
    box-shadow: var(--pil-shadow);
    color: var(--pil-text);
    margin: 20px 0;
    border: 1px solid var(--pil-border);
    width: 100%;
    box-sizing: border-box;
}

.sgpx-pilgrimage * {
    box-sizing: border-box;
}

/* ── Hero Header ─────────────────────────────────────────────── */
.sgpx-pil-header {
    background: linear-gradient(135deg, #0d1117 0%, #1a1d2e 40%, #1f1a0d 100%);
    padding: 34px 32px 26px;
    position: relative;
    overflow: hidden;
    border-bottom: 1px solid var(--pil-border);
}

.sgpx-pil-header::before {
    content: '';
    position: absolute;
    top: -60px; right: -60px;
    width: 280px; height: 280px;
    background: radial-gradient(circle, rgba(245,158,11,.18) 0%, transparent 70%);
    pointer-events: none;
}

.sgpx-pil-header::after {
    content: '🏔';
    position: absolute;
    right: 28px; bottom: 16px;
    font-size: 64px;
    opacity: .07;
    user-select: none;
    pointer-events: none;
}

.sgpx-pil-header-inner {
    position: relative;
    z-index: 1;
}

.sgpx-pil-badge {
    display: inline-block;
    background: var(--pil-accent);
    color: #ffffff;
    font-size: .65em;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    padding: 4px 11px;
    border-radius: 20px;
    margin-bottom: 10px;
}

.sgpx-theme-dark .sgpx-pil-badge {
    color: #000000;
}

.sgpx-pil-title {
    font-family: var(--pil-title-font);
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 6px;
    line-height: 1.15;
    letter-spacing: .02em;
    text-shadow: 0 2px 8px rgba(0,0,0,.5);
}

.sgpx-pil-subtitle {
    font-size: clamp(.85rem, 2vw, 1.05rem);
    color: var(--pil-text-muted);
    margin: 0;
    letter-spacing: .01em;
}

/* Light Theme Header Override */
.sgpx-theme-light .sgpx-pil-header {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 50%, #fef3c7 100%);
}

.sgpx-theme-light .sgpx-pil-header::before {
    background: radial-gradient(circle, rgba(217,119,6,.12) 0%, transparent 70%);
}

.sgpx-theme-light .sgpx-pil-title {
    color: #0f172a;
    text-shadow: none;
}

.sgpx-theme-light .sgpx-pil-subtitle {
    color: #64748b;
}

/* ── Map Wrap ────────────────────────────────────────────────── */
.sgpx-pil-map-wrap {
    position: relative;
    width: 100%;
}

.sgpx-pil-map {
    width: 100%;
    min-height: 400px;
    display: block;
}

.sgpx-pil-map .leaflet-container {
    width: 100%;
    height: 100%;
    font-family: var(--pil-font);
}

/* ── Map Overlay (loading) ───────────────────────────────────── */
.sgpx-pil-map-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(13,17,23,.78);
    backdrop-filter: blur(6px);
    z-index: 800;
    gap: 14px;
    transition: opacity .3s;
}

.sgpx-theme-light .sgpx-pil-map-overlay {
    background: rgba(255,255,255,.88);
}

.sgpx-pil-map-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Cooperative Gesture Prompt (Google Maps Style) ──────────── */
.sgpx-pil-gesture-prompt {
    position: absolute;
    inset: 0;
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.40);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sgpx-theme-light .sgpx-pil-gesture-prompt {
    background: rgba(15, 23, 42, 0.35);
}

.sgpx-pil-gesture-prompt.visible {
    opacity: 1;
}

.sgpx-pil-gesture-prompt span {
    background: rgba(15, 23, 42, 0.90);
    color: #ffffff;
    padding: 11px 22px;
    border-radius: 30px;
    font-family: var(--pil-font);
    font-size: 0.90rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.18);
    transform: translateY(4px);
    transition: transform 0.25s ease;
}

.sgpx-pil-gesture-prompt.visible span {
    transform: translateY(0);
}


.sgpx-pil-spinner {
    width: 44px; height: 44px;
    border: 3px solid var(--pil-border);
    border-top-color: var(--pil-accent);
    border-radius: 50%;
    animation: sgpx-spin 0.9s linear infinite;
}

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

.sgpx-pil-overlay-text {
    color: var(--pil-text-muted);
    font-size: .88em;
    letter-spacing: .04em;
    font-weight: 500;
}

/* ── Map Legend (in controls bar, aligned right) ─────────────── */
.sgpx-pil-legend {
    margin-left: auto;
    background: var(--pil-surface-2);
    border: 1px solid var(--pil-border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: .78em;
    font-weight: 600;
    color: var(--pil-text-muted);
    display: flex;
    align-items: center;
    gap: 14px;
}

.sgpx-theme-light .sgpx-pil-legend {
    background: #f8fafc;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    color: #334155;
    border-color: #e2e8f0;
}

.sgpx-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.sgpx-legend-line {
    display: inline-block;
    width: 18px;
    height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

.sgpx-legend-day {
    background: #ea580c;
    height: 5px;
}

.sgpx-theme-dark .sgpx-legend-day {
    background: #fbbf24;
}

.sgpx-legend-other {
    background: #334155;
    height: 4px;
}

.sgpx-theme-dark .sgpx-legend-other {
    background: #94a3b8;
}

.sgpx-legend-ferry {
    background: repeating-linear-gradient(90deg, #0284c7, #0284c7 4px, transparent 4px, transparent 8px);
    height: 3px;
}

.sgpx-theme-dark .sgpx-legend-ferry {
    background: repeating-linear-gradient(90deg, #38bdf8, #38bdf8 4px, transparent 4px, transparent 8px);
}



/* ── Controls ────────────────────────────────────────────────── */
.sgpx-pil-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 20px;
    background: var(--pil-surface);
    border-bottom: 1px solid var(--pil-border);
}

.sgpx-pil-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid var(--pil-border);
    background: var(--pil-surface-2);
    color: var(--pil-text-muted);
    font-family: var(--pil-font);
    font-size: .85em;
    font-weight: 600;
    cursor: pointer;
    transition: all .18s ease;
    outline: none;
    white-space: nowrap;
}

.sgpx-pil-btn:hover {
    border-color: var(--pil-accent);
    color: var(--pil-accent);
    background: var(--pil-accent-glow);
}

.sgpx-pil-btn.active,
.sgpx-pil-btn:focus-visible {
    border-color: var(--pil-accent);
    color: var(--pil-accent);
    background: var(--pil-accent-glow);
    box-shadow: 0 0 0 2px var(--pil-accent-glow);
}

.sgpx-pil-btn-play {
    background: linear-gradient(135deg, var(--pil-accent), var(--pil-accent-dark));
    color: #ffffff !important;
    border-color: transparent;
    animation: sgpx-play-pulse 2.5s ease-in-out infinite;
}

.sgpx-theme-dark .sgpx-pil-btn-play {
    color: #000000 !important;
}

@keyframes sgpx-play-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--pil-accent-glow); }
    50%       { box-shadow: 0 0 0 6px transparent; }
}

.sgpx-pil-btn-play:hover {
    background: linear-gradient(135deg, var(--pil-accent-dark), #92400e);
    color: #ffffff !important;
}

.sgpx-pil-btn-play.playing {
    animation: none;
    background: var(--pil-red);
    color: #ffffff !important;
    border-color: var(--pil-red);
}

/* Play progress bar */
.sgpx-pil-play-progress {
    flex: 1;
    height: 6px;
    background: var(--pil-border);
    border-radius: 3px;
    overflow: hidden;
    display: none;
    min-width: 80px;
}

.sgpx-pil-play-progress.visible { display: block; }

.sgpx-pil-play-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--pil-accent), #ef4444);
    border-radius: 3px;
    transition: width .4s ease;
    width: 0%;
}

/* ── Day Post Link Button (controls bar) ─────────────────────── */
.sgpx-pil-btn-post {
    background: linear-gradient(135deg, #1a2a3a 0%, #1f2a3a 100%);
    border-color: var(--pil-accent);
    color: var(--pil-accent) !important;
    font-weight: 700;
    letter-spacing: .01em;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--pil-accent);
    font-size: .85em;
    cursor: pointer;
    transition: background .18s ease, box-shadow .18s ease, transform .15s ease;
    opacity: 0;
    transform: translateY(2px);
    white-space: nowrap;
}

.sgpx-pil-btn-post-label {
    white-space: nowrap;
    display: inline-block;
}

.sgpx-pil-btn-post.sgpx-pil-post-fade-in {
    opacity: 1;
    transform: translateY(0);
    transition: opacity .22s ease, transform .22s ease, background .18s ease, box-shadow .18s ease;
}

.sgpx-pil-btn-post:hover {
    background: var(--pil-accent);
    color: #000000 !important;
    box-shadow: 0 0 0 3px var(--pil-accent-glow), 0 4px 14px rgba(0,0,0,.25);
    transform: translateY(-1px);
    text-decoration: none;
}

.sgpx-theme-light .sgpx-pil-btn-post {
    background: #fffbeb;
    color: var(--pil-accent-dark) !important;
    border-color: var(--pil-accent-dark);
}

.sgpx-theme-light .sgpx-pil-btn-post:hover {
    background: var(--pil-accent);
    color: #ffffff !important;
    box-shadow: 0 0 0 3px var(--pil-accent-glow), 0 4px 14px rgba(0,0,0,.10);
}

.sgpx-pil-btn-post[hidden] { display: none !important; }

/* ── Days Section ────────────────────────────────────────────── */
.sgpx-pil-days-section {
    padding: 24px 20px 20px;
    background: var(--pil-surface);
    border-bottom: 1px solid var(--pil-border);
}

.sgpx-pil-section-title {
    font-size: .82em;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--pil-text-muted);
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sgpx-pil-section-icon {
    font-size: 1.2em;
}

/* ── Day Grid ────────────────────────────────────────────────── */
.sgpx-pil-days-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sgpx-pil-day-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 36px;
    border-radius: 7px;
    border: 1px solid var(--pil-border);
    background: var(--pil-surface-2);
    color: var(--pil-text-muted);
    font-family: var(--pil-font);
    font-size: .78em;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
    position: relative;
    outline: none;
}

.sgpx-pil-day-btn:hover {
    border-color: var(--pil-accent);
    color: var(--pil-accent);
    background: var(--pil-accent-glow);
    transform: translateY(-1px);
    z-index: 1;
}

.sgpx-pil-day-btn.active {
    background: var(--pil-accent);
    border-color: var(--pil-accent);
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 0 10px var(--pil-accent-glow);
    transform: translateY(-1px);
    z-index: 2;
}

.sgpx-theme-dark .sgpx-pil-day-btn.active {
    color: #000000;
}

.sgpx-pil-day-btn:focus-visible {
    box-shadow: 0 0 0 2px var(--pil-accent-glow), 0 0 0 4px var(--pil-accent);
}

/* Skeleton placeholders */
.sgpx-pil-grid-skeleton {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sgpx-pil-skeleton-pill {
    width: 42px;
    height: 36px;
    border-radius: 7px;
    background: var(--pil-surface-2);
    animation: sgpx-skeleton 1.4s ease-in-out infinite;
}

@keyframes sgpx-skeleton {
    0%, 100% { opacity: .4; }
    50%       { opacity: .9; }
}

/* ── Stats Panel ─────────────────────────────────────────────── */
.sgpx-pil-stats-panel {
    padding: 0 20px;
    background: var(--pil-surface);
    overflow: hidden;
    max-height: 0;
    transition: max-height .35s ease, padding .35s ease;
}

.sgpx-pil-stats-panel.open {
    padding: 22px 20px;
    max-height: 500px;
    border-top: 1px solid var(--pil-border);
}

.sgpx-pil-stats-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.sgpx-pil-stats-day-num {
    font-family: var(--pil-title-font);
    font-size: 1.5em;
    font-weight: 700;
    color: var(--pil-accent);
    letter-spacing: .04em;
}

.sgpx-pil-stats-day-name {
    font-size: .9em;
    color: var(--pil-text-muted);
    font-style: italic;
}

/* View full post link inside stats panel header */
.sgpx-pil-stats-post-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    padding: 5px 12px;
    background: var(--pil-accent-glow);
    border: 1px solid var(--pil-accent);
    border-radius: 20px;
    color: var(--pil-accent);
    font-size: .78em;
    font-weight: 700;
    text-decoration: none;
    letter-spacing: .02em;
    transition: background .18s, color .18s, box-shadow .18s;
    white-space: nowrap;
}

.sgpx-pil-stats-post-link:hover {
    background: var(--pil-accent);
    color: #000000;
    box-shadow: 0 2px 10px var(--pil-accent-glow);
    text-decoration: none;
}

.sgpx-theme-light .sgpx-pil-stats-post-link {
    color: var(--pil-accent-dark);
    border-color: var(--pil-accent-dark);
    background: rgba(217,119,6,.08);
}

.sgpx-theme-light .sgpx-pil-stats-post-link:hover {
    background: var(--pil-accent);
    color: #ffffff;
}

.sgpx-pil-stats-post-day {
    font-weight: 800;
}

.sgpx-pil-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.sgpx-pil-stat {
    background: var(--pil-surface-2);
    border: 1px solid var(--pil-border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: border-color .2s, box-shadow .2s;
}

.sgpx-pil-stat:hover {
    border-color: var(--pil-accent);
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.sgpx-pil-stat-icon {
    font-size: 1.1em;
}

.sgpx-pil-stat-value {
    font-size: 1.35em;
    font-weight: 700;
    color: var(--pil-text);
    line-height: 1.1;
}

.sgpx-pil-stat-label {
    font-size: .72em;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--pil-text-muted);
}

/* ── Error Banner ────────────────────────────────────────────── */
.sgpx-pil-error {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 20px;
    padding: 12px 16px;
    background: rgba(248,81,73,.1);
    border: 1px solid rgba(248,81,73,.35);
    border-radius: 8px;
    color: var(--pil-red);
    font-size: .87em;
}

.sgpx-pil-error[hidden] { display: none; }

/* ── Leaflet marker overrides ────────────────────────────────── */
.sgpx-pil-marker-start,
.sgpx-pil-marker-end {
    width: 14px !important;
    height: 14px !important;
    border-radius: 50%;
    border: 3px solid #ffffff;
    box-shadow: 0 0 6px rgba(0,0,0,.5);
    margin-left: -7px !important;
    margin-top: -7px !important;
}

.sgpx-pil-marker-start { background: #3fb950; }
.sgpx-pil-marker-end   { background: #f85149; }

/* ── Leaflet tile layer dark filter (Dark mode only) ─────────── */
.sgpx-theme-dark .sgpx-pil-map .leaflet-tile-pane {
    filter: brightness(.85) saturate(.9) invert(1) hue-rotate(180deg);
}

/* In Light mode, OpenStreetMap displays natural and crisp */
.sgpx-theme-light .sgpx-pil-map .leaflet-tile-pane {
    filter: none;
}

/* ── Elevation Profile Section ───────────────────────────────── */
.sgpx-pil-elevation-section {
    padding: 22px 20px 20px;
    background: var(--pil-surface);
    border-top: 1px solid var(--pil-border);
}

.sgpx-pil-elev-badge {
    margin-left: auto;
    background: var(--pil-surface-2);
    border: 1px solid var(--pil-border);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: .78em;
    font-weight: 600;
    color: var(--pil-accent);
    letter-spacing: .04em;
    text-transform: none;
}

.sgpx-pil-elevation-wrap {
    position: relative;
    height: 170px;
    background: var(--pil-surface-2);
    border: 1px solid var(--pil-border);
    border-radius: 10px;
    overflow: hidden;
    margin-top: 12px;
}

.sgpx-pil-elev-canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.sgpx-pil-elev-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--pil-surface-2);
    z-index: 10;
    gap: 8px;
    transition: opacity .25s;
}

.sgpx-pil-elev-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.sgpx-pil-elev-unavailable {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--pil-text-muted);
    font-size: .85em;
    font-style: italic;
}

.sgpx-pil-elev-unavailable[hidden] { display: none; }

.sgpx-pil-elev-highlight {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(245, 158, 11, 0.15);
    border-left: 2px solid rgba(245, 158, 11, 0.75);
    border-right: 2px solid rgba(245, 158, 11, 0.75);
    pointer-events: none;
    z-index: 5;
    transition: left .3s ease, width .3s ease;
}

/* ── Scrollbars ─────────────────────────────────────────────── */
.sgpx-theme-dark .sgpx-pil-days-grid::-webkit-scrollbar { height: 4px; }
.sgpx-theme-dark .sgpx-pil-days-grid::-webkit-scrollbar-track { background: var(--pil-surface); }
.sgpx-theme-dark .sgpx-pil-days-grid::-webkit-scrollbar-thumb { background: var(--pil-border); border-radius: 2px; }

.sgpx-theme-light .sgpx-pil-days-grid::-webkit-scrollbar { height: 4px; }
.sgpx-theme-light .sgpx-pil-days-grid::-webkit-scrollbar-track { background: #f1f5f9; }
.sgpx-theme-light .sgpx-pil-days-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
    .sgpx-pil-header {
        padding: 24px 18px 20px;
    }

    .sgpx-pil-header::after {
        display: none;
    }

    .sgpx-pil-controls {
        padding: 10px 14px;
    }

    .sgpx-pil-btn {
        padding: 7px 13px;
        font-size: .8em;
    }

    .sgpx-pil-days-section {
        padding: 18px 14px;
    }

    .sgpx-pil-day-btn {
        width: 36px;
        height: 32px;
        font-size: .72em;
    }

    .sgpx-pil-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sgpx-pil-stats-panel.open {
        padding: 16px 14px;
    }

    .sgpx-pil-elevation-wrap {
        height: 130px;
    }

    .sgpx-pil-legend {
        margin-left: 0;
        width: 100%;
        justify-content: space-around;
        padding: 6px 10px;
        font-size: .72em;
        gap: 8px;
    }
    .sgpx-legend-line {
        width: 14px;
    }
}

@media (max-width: 380px) {
    .sgpx-pil-day-btn {
        width: 32px;
        height: 30px;
    }

    .sgpx-pil-stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}
