html,
body.hiking-layout {
    height: 100%;
    margin: 0;
    padding: 0;
}

body.hiking-layout {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    --hiking-sidebar-width: 320px;
}

body.hiking-layout #mainNav {
    grid-row: 1;
    flex-shrink: 0;
}

body.hiking-layout .hiking-sidebar-toggle {
    display: none;
}

.hiking-page {
    grid-row: 2;
    display: grid;
    grid-template-columns: var(--hiking-sidebar-width) 4px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}

.hiking-sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.hiking-sidebar-title-row h1 {
    margin-bottom: 0;
}

.hiking-sidebar-close {
    display: none;
    background: none;
    border: 1px solid #ddd;
    border-radius: 6px;
    width: 2rem;
    height: 2rem;
    color: #666;
    cursor: pointer;
    flex-shrink: 0;
}

body.hiking-layout .hiking-sidebar {
    grid-column: 1;
    grid-row: 1;
    width: var(--hiking-sidebar-width);
    min-width: 0;
    height: 100%;
    min-height: 0;
    padding: 0;
    margin: 0;
    background: #f3f3f3;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 500;
}

.hiking-sidebar-resizer {
    grid-column: 2;
    grid-row: 1;
    width: 4px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    z-index: 501;
    flex-shrink: 0;
    touch-action: none;
}

.hiking-sidebar-resizer::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -5px;
    right: -5px;
}

.hiking-sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 1px;
    width: 1px;
    background: #e0e0e0;
    transition: background 0.15s, width 0.15s, left 0.15s;
    pointer-events: none;
}

.hiking-sidebar-resizer:hover::after,
.hiking-sidebar-resizer.is-dragging::after {
    left: 0;
    width: 2px;
    background: var(--h-title-color, #3948d2);
}

body.hiking-layout.is-resizing-sidebar {
    cursor: col-resize;
    user-select: none;
}

body.hiking-layout.is-resizing-sidebar .hiking-sidebar-resizer {
    cursor: col-resize;
}

.hiking-sidebar-header {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
    background: #ececec;
}

.hiking-sidebar-header h1 {
    font-family: "Kanit", sans-serif;
    font-size: 1.15rem;
    color: var(--h-title-color, #3948d2);
    margin: 0;
}

.hiking-sidebar-sections {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.hiking-sidebar-sections:has(.hiking-track-panel[open]) {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
}

.hiking-panel-section {
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.85rem;
    background: #f3f3f3;
}

.hiking-panel-section summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.85rem;
    user-select: none;
    background: #ececec;
    border-bottom: 1px solid transparent;
    transition: background 0.15s;
}

.hiking-panel-section summary:hover {
    background: #e4e4e4;
}

.hiking-panel-section[open] summary {
    border-bottom-color: #e0e0e0;
}

.hiking-panel-section summary::-webkit-details-marker {
    display: none;
}

.hiking-panel-section summary::before {
    content: '\F285';
    font-family: 'bootstrap-icons';
    font-size: 0.65rem;
    color: #888;
    transition: transform 0.15s;
    flex-shrink: 0;
}

.hiking-panel-section[open] summary::before {
    transform: rotate(90deg);
}

.hiking-panel-body {
    padding: 0.75rem 0.85rem;
    background: #f3f3f3;
}

.hiking-sidebar-desc {
    font-size: 0.82rem;
    color: #666;
    margin: 0 0 0.75rem;
    line-height: 1.4;
}

.hiking-map-type-control {
    position: absolute;
    right: 0.65rem;
    bottom: 1.75rem;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.hiking-map-grid-control {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    z-index: 1000;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.55rem;
    padding: 0.4rem 0.55rem;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
    font-size: 0.78rem;
    max-width: calc(100% - 1rem);
}

.hiking-map-grid-title {
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

.hiking-grid-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    cursor: pointer;
    color: #444;
    white-space: nowrap;
}

.hiking-grid-toggle input {
    cursor: pointer;
    accent-color: var(--h-title-color, #3948d2);
}

.hiking-map-grid-hint {
    flex: 1 1 100%;
    font-size: 0.72rem;
    color: #888;
}

.hiking-map-grid-style {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.65rem;
    flex: 1 1 100%;
    padding-top: 0.15rem;
    border-top: 1px solid #e8e8e8;
}

.hiking-grid-style-item {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0;
    color: #555;
    white-space: nowrap;
}

.hiking-grid-style-item input[type="color"] {
    width: 1.65rem;
    height: 1.35rem;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
    background: none;
}

.hiking-grid-style-item input[type="range"] {
    width: 4.5rem;
    cursor: pointer;
    accent-color: var(--h-title-color, #3948d2);
}

.hiking-grid-width-value {
    min-width: 0.75rem;
    text-align: center;
    color: #666;
}

.hiking-map-grid-select {
    flex: 1 1 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.55rem;
    padding-top: 0.35rem;
    border-top: 1px solid #e8e8e8;
}

.hiking-map-grid-select-title {
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}

.hiking-map-grid-select-crs {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
}

.hiking-grid-export-btn {
    font-size: 0.78rem;
}

.hiking-grid-export-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.hiking-map-grid-select-status {
    flex: 1 1 100%;
    font-size: 0.72rem;
    color: #666;
    line-height: 1.35;
}

#map.hiking-map-select-mode {
    cursor: crosshair;
}

.tm-grid-label-overlay {
    position: absolute;
    inset: 0;
    z-index: 650;
    pointer-events: none;
    overflow: visible;
}

.tm-grid-label-icon {
    background: transparent !important;
    border: none !important;
}

.tm-grid-label {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    color: var(--tm-label-color, #3948d2);
    background: rgba(255, 255, 255, 0.88);
    padding: 1px 4px;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6);
    pointer-events: none;
    user-select: none;
}

.tm-grid-label--overlay {
    position: absolute;
}

.tm-grid-label--overlay.tm-grid-label--northing {
    transform: translateY(-50%);
}

.tm-grid-label--overlay.tm-grid-label--easting {
    transform: translateX(-50%);
}

.tm-grid-label--northing {
    transform: translate(4px, -50%);
}

.tm-grid-label--easting {
    transform: translate(-50%, calc(-100% - 3px));
}

.hiking-export-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    color: #444;
    font-size: 0.95rem;
    pointer-events: all;
}

.hiking-map-type-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666;
    white-space: nowrap;
    margin: 0;
}

.hiking-map-select {
    min-width: 9.5rem;
    padding: 0.25rem 0.4rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #333;
    background: #fff;
    cursor: pointer;
}

.hiking-map-select:focus {
    outline: none;
    border-color: var(--h-title-color, #3948d2);
    box-shadow: 0 0 0 1px rgba(57, 72, 210, 0.25);
}

.hiking-upload {
    padding: 0;
}

.hiking-save-github {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.55rem;
    font-size: 0.82rem;
    color: #444;
    cursor: pointer;
}

.hiking-upload-meta {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.55rem;
}

.hiking-input {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.82rem;
    box-sizing: border-box;
    background: #fff;
}

.hiking-input:focus {
    outline: none;
    border-color: var(--h-title-color, #3948d2);
}

.hiking-status {
    margin-top: 0.55rem;
    padding: 0.45rem 0.6rem;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1.4;
}

.hiking-status-info {
    background: #e8ecff;
    color: #3948d2;
}

.hiking-status-success {
    background: #edfbf3;
    color: #1e7e45;
}

.hiking-status-error {
    background: #fef2f2;
    color: #c0392b;
}

.hiking-github-hint {
    margin: 0 0 0.65rem;
    color: #666;
    line-height: 1.45;
    font-size: 0.78rem;
}

.hiking-github-hint-list {
    margin: 0 0 0.65rem;
    padding-left: 1.15rem;
    font-size: 0.78rem;
    color: #666;
    line-height: 1.5;
}

.hiking-github-hint-list code {
    font-size: 0.72rem;
}

.hiking-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-bottom: 0.45rem;
}

.hiking-field span {
    font-size: 0.72rem;
    color: #888;
}

.hiking-github-actions {
    display: flex;
    gap: 0.45rem;
    margin-top: 0.45rem;
}

.hiking-btn-primary {
    padding: 0.35rem 0.65rem;
    border: none;
    border-radius: 4px;
    background: var(--h-title-color, #3948d2);
    color: #fff;
    font-size: 0.82rem;
    cursor: pointer;
}

.hiking-btn-primary:hover {
    opacity: 0.9;
}

.hiking-settings-status {
    margin-top: 0.45rem;
    font-size: 0.78rem;
    color: #666;
}

.hiking-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 0.85rem;
    border: 1px dashed #bbb;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #555;
    background: #fff;
    transition: border-color 0.2s, background 0.2s;
}

.hiking-upload-label:hover {
    border-color: var(--h-title-color, #3948d2);
    background: #f8f9ff;
}

.hiking-track-panel {
    min-height: 0;
}

.hiking-track-panel[open] {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.hiking-track-panel-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.hiking-track-panel-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    padding: 0.55rem 0.65rem 0.65rem;
    overflow: hidden;
}

.hiking-track-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 0.45rem;
    flex-shrink: 0;
}

.hiking-track-search-wrap {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
}

.hiking-track-search-wrap:focus-within {
    border-color: var(--h-title-color, #3948d2);
    box-shadow: 0 0 0 1px rgba(57, 72, 210, 0.2);
}

.hiking-track-search-wrap i {
    color: #999;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.hiking-track-search {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.82rem;
    background: transparent;
    min-width: 0;
}

.hiking-track-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.hiking-btn-sm {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.2rem 0.45rem;
    cursor: pointer;
    color: #555;
    font-size: 0.78rem;
    line-height: 1.3;
}

.hiking-btn-sm:hover {
    border-color: var(--h-title-color, #3948d2);
    color: var(--h-title-color, #3948d2);
}

.hiking-btn-sm.is-active {
    border-color: var(--h-title-color, #3948d2);
    color: var(--h-title-color, #3948d2);
    background: #e8ecff;
}

.hiking-track-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1 1 0;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.hiking-track-empty {
    padding: 0.75rem 0.25rem;
    font-size: 0.82rem;
    color: #999;
    line-height: 1.5;
}

.hiking-track-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.2rem;
    border-bottom: 1px solid #e8e8e8;
    position: relative;
}

.hiking-track-item.is-hidden {
    display: none;
}

.hiking-track-item input[type="checkbox"] {
    flex-shrink: 0;
    cursor: pointer;
}

.hiking-track-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin: 0;
    min-width: 0;
    padding: 0;
    border: none;
    background: none;
    text-align: left;
    font: inherit;
    color: inherit;
}

.hiking-track-label:hover .hiking-track-name {
    color: var(--h-title-color, #3948d2);
}

.hiking-track-color-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.18);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}

.hiking-track-color-btn:hover {
    box-shadow: 0 0 0 2px rgba(57, 72, 210, 0.25);
}

.hiking-track-color-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.hiking-track-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.hiking-track-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hiking-track-date {
    font-size: 0.72rem;
    color: #999;
}

.hiking-btn-remove {
    background: none;
    border: none;
    color: #bbb;
    cursor: pointer;
    padding: 0.15rem;
    line-height: 1;
    flex-shrink: 0;
}

.hiking-btn-remove:hover {
    color: #e74c3c;
}

.hiking-map-wrap {
    grid-column: 3;
    grid-row: 1;
    position: relative;
    min-height: 0;
    min-width: 0;
    height: 100%;
}

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

.hiking-draggable-scale {
    position: absolute;
    z-index: 1000;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.hiking-draggable-scale.is-dragging {
    cursor: grabbing;
}

.hiking-draggable-scale .leaflet-control-scale {
    margin: 0;
    position: static;
    float: none;
}

.hiking-waypoint-marker {
    background: none;
    border: none;
}

.hiking-waypoint-pin {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #e74c3c;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.hiking-waypoint-pin.hiking-waypoint-start {
    background: #27ae60;
}

.hiking-waypoint-pin.hiking-waypoint-end {
    background: #8e44ad;
}

.hiking-waypoint-popup .leaflet-popup-content {
    margin: 0.65rem 0.75rem;
}

.hiking-popup-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.hiking-popup-body {
    font-size: 0.85rem;
    line-height: 1.45;
    color: #444;
}

.hiking-popup-body img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0.4rem auto;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.hiking-popup-body table {
    width: 100%;
    font-size: 0.8rem;
    border-collapse: collapse;
}

.hiking-popup-body td {
    padding: 0.15rem 0.25rem;
    vertical-align: top;
}

.nav-link.active {
    color: var(--h-title-color, #3948d2) !important;
    font-weight: 600;
}

@media screen and (max-width: 768px) {
    body.hiking-layout {
        grid-template-rows: minmax(0, 1fr);
        height: 100svh;
        height: 100dvh;
    }

    body.hiking-layout #mainNav {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        z-index: 1030;
        grid-row: auto;
    }

    body.hiking-layout .hiking-sidebar-toggle {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        position: fixed;
        bottom: 1.25rem;
        left: 1rem;
        z-index: 1000;
        padding: 0.55rem 0.9rem;
        border: none;
        border-radius: 999px;
        background: var(--h-title-color, #3948d2);
        color: #fff;
        font-size: 0.9rem;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
        cursor: pointer;
    }

    .hiking-sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .hiking-page {
        grid-row: 1;
        grid-template-columns: 1fr;
        padding-top: var(--hiking-nav-height, 0px);
        box-sizing: border-box;
    }

    .hiking-sidebar-resizer {
        display: none;
    }

    .hiking-sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        min-width: unset;
        max-height: 88dvh;
        border-right: none;
        border-top: 2px solid var(--bs-blue, #3948d2);
        border-radius: 14px 14px 0 0;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
        z-index: 1100;
        display: flex;
        flex-direction: column;
        grid-column: 1;
        transform: translateY(100%);
        transition: transform 0.28s ease;
        overflow: hidden;
    }

    .hiking-sidebar-sections {
        overflow-y: auto;
    }

    .hiking-sidebar-sections:has(.hiking-track-panel[open]) {
        display: grid;
        grid-template-rows: auto auto minmax(0, 1fr);
        overflow: hidden;
    }

    .hiking-track-panel[open] {
        height: 100%;
        min-height: 0;
    }

    .hiking-sidebar.is-open {
        transform: translateY(0);
    }

    .hiking-sidebar-header {
        position: sticky;
        top: 0;
        background: #ececec;
        z-index: 1;
    }

    .hiking-map-wrap {
        grid-column: 1;
        min-height: 0;
        width: 100%;
        height: 100%;
    }

    .hiking-map-type-control {
        bottom: 0.65rem;
        right: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .hiking-map-select {
        min-width: 0;
        flex: 1 1 0;
        max-width: 10rem;
    }

    .hiking-track-list {
        flex: 1 1 0;
        min-height: 0;
    }
}
