html,
body {
    height: 100%;
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
    background-color: #f5f5f5;
    overflow: hidden;
}

.page {
    height: 100dvh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* 検索バー（上部） */
.search-header {
    flex: 0 0 auto;
    background-color: #ffffff;
    border-bottom: 1px solid #ddd;
    padding: 10px 10px 6px;
}

.search-title {
    font-size: 18px;
    margin: 0 0 8px;
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.search-field {
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.search-label {
    font-size: 12px;
    margin-bottom: 0;
    flex: 0 0 44px;
    text-align: center;
}

.search-input {
    flex: 1;
    min-width: 0;
    height: 34px;
    padding: 6px 8px;
    box-sizing: border-box;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-building {
    flex: none;
}

.search-button {
    flex: 0 0 44px;
}

.search-button button {
    width: 100%;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 4px;
    font-size: 18px;
    background-color: #007bff;
    color: #fff;
    cursor: pointer;
}

/* Keep both dropdowns compact on mobile */
#building_id,
#room_option_id {
    font-size: 12px;
}

.error {
    color: #d32f2f;
    font-size: 13px;
    padding: 3px 10px 0;
}

.public-empty-state {
    margin-top: 5px;
    padding: 5px 8px;
    border: 1px solid #c8dce5;
    border-radius: 5px;
    background: #f3f8fa;
    color: #526a73;
    font-size: 11px;
    line-height: 1.35;
    min-width: 0;
    overflow: hidden;
}

.map-header-row .map-title {
    min-width: 0;
}

.gps-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    min-width: 0;
    max-width: 52%;
    color: #526a73;
    font-size: 10px;
    line-height: 1.2;
    text-align: right;
}

#gps-status-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gps-status[data-state="available"] {
    color: #2f6b45;
}

.gps-status[data-state="denied"],
.gps-status[data-state="unavailable"],
.gps-status[data-state="timeout"],
.gps-status[data-state="unsupported"] {
    color: #a34832;
}

.gps-status[data-state="stale"] {
    color: #7b6500;
}

.gps-retry-button {
    flex: 0 0 auto;
    border: 1px solid currentColor;
    border-radius: 4px;
    padding: 2px 5px;
    background: #fff;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.gps-retry-button:hover,
.gps-retry-button:focus-visible {
    background: rgba(255, 255, 255, 0.75);
}

/* Container for Floor Map + Controls */
.floor-map-container {
    display: flex;
    flex: 1;
    min-height: 0;
    align-items: stretch;
    gap: 8px;
}

/* Floor Controls (Right Side) */
.floor-controls {
    flex: 0 0 72px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
}

.floor-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 64px;
    min-width: 64px;
    height: 38px;
    border: 1px solid #0d5f78;
    border-radius: 6px;
    background-color: #0f6f88;
    color: white;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.floor-btn:hover:not(:disabled) {
    background-color: #0b566b;
    border-color: #08475a;
}

.floor-btn:focus-visible {
    outline: 3px solid rgba(25, 118, 210, 0.35);
    outline-offset: 2px;
}

.floor-btn:disabled,
.floor-btn.disabled {
    background-color: #e0e0e0;
    color: #aaa;
    border-color: #d0d0d0;
    pointer-events: none;
    box-shadow: none;
}

.current-floor-label {
    font-size: 15px;
    font-weight: bold;
    color: #333;
}

/* マップ部分（下部） */
.content {
    flex: 1;
    min-height: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

.map-card-all,
.map-card-floor {
    background-color: #ffffff;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.map-card-all {
    flex: 53;
}

.map-card-floor {
    flex: 47;
}

.map-title {
    font-size: 14px;
    margin: 0 0 2px;
    flex: 0 1 auto;
}

.map-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    min-width: 0;
}

.map-title {
    margin: 0;
}

.map-wrapper-all {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    background-color: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    touch-action: none;
}

.map-wrapper-floor {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    background-color: #fafafa;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    touch-action: none;
}

.map-wrapper-inner {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: move;
}

.map-wrapper-inner img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cursor-dot {
    position: absolute;
    display: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: transparent;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: none;
    z-index: 10;
}

.drop-pin {
    position: absolute;
    width: 30px;
    height: 42px;
    transform: translate(-50%, -100%);
    pointer-events: none;
    z-index: 10;
    animation: pinFloat 2s ease-in-out infinite;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.drop-pin-shadow {
    position: absolute;
    width: 14px;
    height: 6px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 9;
    animation: pinShadow 2s ease-in-out infinite;
}

@keyframes pinFloat {
    0%, 100% { transform: translate(-50%, -100%) translateY(0); }
    50% { transform: translate(-50%, -100%) translateY(-5px); }
}

@keyframes pinShadow {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.25; }
    50% { transform: translate(-50%, -50%) scale(0.7); opacity: 0.15; }
}

.gps-dot {
    width: 18px;
    height: 18px;
    background: transparent;
    border: none;
    box-shadow: none;
    transform: translate(-50%, -50%) rotate(var(--heading-deg, 0deg));
    transform-origin: center center;
}

.gps-arrow {
    display: block;
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

.gps-dot.no-heading {
    opacity: 0.95;
}

.gps-dot.stale {
    opacity: 0.55;
}

.target-dot {
    width: 20px;
    height: 28px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    transform: translate(-50%, -100%);
    z-index: 11;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.target-dot::before,
.target-dot::after {
    display: none;
}

.target-dot-label {
    position: absolute;
    left: 50%;
    bottom: 100%;
    margin-bottom: 2px;
    transform: translateX(-50%);
    background: rgba(20, 20, 20, 0.82);
    color: #fff;
    font-size: 8px;
    line-height: 1;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 999px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.cursor-dot::before,
.cursor-dot::after {
    display: none;
}

@media (min-width: 768px) {
    .content {
        max-width: 520px;
        margin: 0 auto;
        width: 100%;
    }
}

@media (orientation: landscape) and (pointer: coarse),
    (orientation: landscape) and (any-pointer: coarse),
    (orientation: landscape) and (hover: none) and (min-width: 744px) and (max-width: 1366px) and (min-height: 481px) and (max-height: 1024px) {
    .content {
        max-width: none;
        width: auto;
        margin: 0;
        flex-direction: row;
        gap: 8px;
        align-items: stretch;
    }

    .overlay {
        padding: 10px 0;
        box-sizing: border-box;
    }

    .overlay-content {
        max-height: calc(100dvh - 20px);
        display: flex;
        flex-direction: column;
    }

    .overlay-body {
        min-height: 0;
        margin-bottom: 12px;
        overflow-y: auto;
        padding-right: 6px;
        -webkit-overflow-scrolling: touch;
    }
}

@media (orientation: landscape) and (pointer: coarse) and (max-height: 500px),
    (orientation: landscape) and (any-pointer: coarse) and (max-height: 500px) {
    .search-header {
        padding: 7px 8px 4px;
    }

    .header-row {
        margin-bottom: 4px;
    }

    .search-title {
        font-size: 15px;
    }

    .help-btn {
        padding: 2px 7px;
        font-size: 11px;
    }

    .search-form {
        display: grid;
        grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
        gap: 4px 6px;
        align-items: center;
    }

    .search-field {
        gap: 5px;
    }

    .search-label {
        flex: 0 0 38px;
        font-size: 11px;
    }

    .search-input {
        height: 30px;
        padding: 4px 7px;
        font-size: 12px;
    }

    #building_id,
    #room_option_id {
        font-size: 11px;
    }

    .error {
        padding: 2px 8px 0;
        font-size: 12px;
    }

    .content {
        gap: 8px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }

    .map-card-all,
    .map-card-floor {
        padding: 5px;
    }

    .map-card-all {
        flex: 1.08;
        min-width: 0;
    }

    .map-card-floor {
        flex: 0.92;
        min-width: 0;
    }

    .map-header-row {
        margin-bottom: 3px;
    }

    .map-title {
        font-size: 13px;
    }

    .floor-map-container {
        gap: 6px;
    }

    .floor-controls {
        flex: 0 0 64px;
        gap: 8px;
    }

    .floor-btn {
        width: 58px;
        min-width: 58px;
        height: 32px;
        font-size: 10px;
    }

    .current-floor-label {
        font-size: 13px;
    }

    .gps-status {
        max-width: 48%;
        font-size: 9px;
    }
}

@media (orientation: landscape) and (pointer: coarse) and (min-width: 744px) and (min-height: 481px),
    (orientation: landscape) and (any-pointer: coarse) and (min-width: 744px) and (min-height: 481px),
    (orientation: landscape) and (hover: none) and (min-width: 744px) and (max-width: 1366px) and (min-height: 481px) and (max-height: 1024px) {
    .search-header {
        padding: 9px 14px 7px;
    }

    .header-row {
        margin-bottom: 6px;
    }

    .search-form {
        display: grid;
        grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
        gap: 8px 10px;
        align-items: center;
    }

    .search-field {
        gap: 8px;
    }

    .search-label {
        flex: 0 0 44px;
    }

    .search-input {
        height: 36px;
        padding: 6px 10px;
        font-size: 13px;
    }

    .content {
        gap: 10px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .map-card-all,
    .map-card-floor {
        padding: 8px;
    }

    .map-card-all {
        flex: 1.12;
        min-width: 0;
    }

    .map-card-floor {
        flex: 0.88;
        min-width: 0;
    }

    .map-title {
        font-size: 15px;
    }

    .floor-map-container {
        gap: 8px;
    }

    .floor-controls {
        flex: 0 0 70px;
        gap: 10px;
    }

    .floor-btn {
        width: 64px;
        min-width: 64px;
        height: 34px;
        font-size: 11px;
    }

    .current-floor-label {
        font-size: 14px;
    }

    .gps-status {
        max-width: 50%;
        font-size: 10px;
    }
}

/* Header Layout */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.search-title {
    font-size: 17px;
    margin: 0;
}

.help-btn {
    background-color: transparent;
    border: 1px solid #007bff;
    color: #007bff;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}

.help-btn:hover {
    background-color: #e7f1ff;
}

/* Modal Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
}

.overlay.active {
    visibility: visible;
    opacity: 1;
}

.overlay-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.overlay-title {
    margin-top: 0;
    font-size: 18px;
    color: #333;
}

.overlay-body {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    text-align: left;
    line-height: 1.6;
}

.overlay-body a {
    color: #005ecb;
    text-decoration: underline;
    word-break: break-all;
}

.close-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 8px 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}
