/* =========================================
   配置計画図翻訳 — フロントエンドスタイル
   melta-ui + omakase-map方式オーバーレイ
   ========================================= */

.chourei-viewer {
    font-family: 'Inter', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
    max-width: 100%;
    margin: 0 auto;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.chourei-viewer-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    color: #3d4b5f;
    transition: background-color 0.15s, color 0.15s;
}

.chourei-viewer-btn:hover {
    background: #f0f5ff;
    color: #2b70ef;
}

.chourei-viewer-btn .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

/* テキスト抽出 表示/非表示 切替ボタン */
.cr-btn-toggle-fields.is-on {
    background: #2b70ef;
    color: #ffffff;
    border-color: #2b70ef;
}
.cr-btn-toggle-fields.is-on:hover {
    background: #1e5ed1;
    color: #ffffff;
}
.cr-btn-toggle-fields.is-off {
    background: #ffffff;
    color: #64748b;
}
.cr-btn-toggle-fields.is-off:hover {
    background: #f1f5f9;
    color: #2b70ef;
}

/* コントロールバー: 全画面ボタン + 目アイコン を横並び */
.chourei-viewer-controls-bar {
    display: flex;
    gap: 8px;
}

/* 全画面ボタンが押されている時 (フルスクリーン中) は色を強調 */
.cr-btn-fullscreen[aria-pressed="true"] {
    background: #2b70ef;
    color: #ffffff;
    border-color: #2b70ef;
}
.cr-btn-fullscreen[aria-pressed="true"]:hover {
    background: #1e5ed1;
    color: #ffffff;
}

/* --- 全画面表示 (ネイティブ Fullscreen API + 擬似 fullscreen) --- */
.chourei-viewer:fullscreen,
.chourei-viewer.is-pseudo-fullscreen {
    background: #1e293b;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* controls-bar の position:absolute の基準にするため */
    position: relative;
}
.chourei-viewer.is-pseudo-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 999998;
}
.chourei-viewer:fullscreen .chourei-viewer-container,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-container {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    overflow: auto;
    /* 図面が画面より小さい時は中央寄せ、大きい時はスクロール可能。
       safe を付けることで content が container を超えても起点側 (左/上) が
       見切れず、ユーザがスクロールで全域に到達できる。 */
    display: flex;
    align-items: center;
    align-items: safe center;
    justify-content: center;
    justify-content: safe center;
    /* タッチデバイスでは2本指ピンチを JS で扱うため、ブラウザの
       ネイティブ pinch zoom は無効化 (1本指パンは許可)。 */
    touch-action: pan-x pan-y;
    /* PC では wheel をズームに割り当てているため、マウスドラッグで
       パン (画像移動) できることを cursor で示唆する。 */
    cursor: grab;
}
.chourei-viewer:fullscreen .chourei-viewer-container.chou-grabbing,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-container.chou-grabbing {
    cursor: grabbing;
}

/* 全画面コンテナ内では .chourei-viewer-content を flex item として扱うが、
   flex-shrink:0 で container 幅に縮められないようにする。これがないと
   setZoom() で width を増やしても flex shrink により縮まりズーム効果が
   見えない (v5.3.53 で発覚)。 */
.chourei-viewer:fullscreen .chourei-viewer-content,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-content {
    flex: 0 0 auto;
}

/* SP 限定: 画面上部に全画面終了ボタンを表示 (ボトムバーが届きにくい
   端末で素早く閉じられるように)。PC/タブレットでは Esc キーや下部
   コントロールバーで足りるので非表示。 */
.chourei-viewer-fs-exit-top {
    display: none;
}
.chourei-viewer:fullscreen .chourei-viewer-fs-exit-top,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-fs-exit-top {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    padding: 0;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #e2e8f0;
    border-radius: 50%;
    color: #1e293b;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
}
.chourei-viewer-fs-exit-top:hover {
    background: #ffffff;
    color: #2b70ef;
}
.chourei-viewer-fs-exit-top .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
}
@media (min-width: 769px) {
    /* PC/タブレットでは上部終了ボタンを非表示 (下部バー + Esc で十分) */
    .chourei-viewer:fullscreen .chourei-viewer-fs-exit-top,
    .chourei-viewer.is-pseudo-fullscreen .chourei-viewer-fs-exit-top {
        display: none;
    }
}
/* 全画面中はコントロールバーを画像の下に固定し常に見えるように */
.chourei-viewer:fullscreen .chourei-viewer-controls-bar,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-controls-bar {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 1;
    background: rgba(255, 255, 255, 0.85);
    padding: 6px 8px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
}
/* SP では iOS Safari の下部 URL バー (約 50-60px) や home indicator を
   避けるため余白を大きめに取る。env(safe-area-inset-bottom) は viewport-fit
   が cover の場合のみ取得できるので max() で最低 70px を保証。 */
@media (max-width: 768px) {
    .chourei-viewer:fullscreen .chourei-viewer-controls-bar,
    .chourei-viewer.is-pseudo-fullscreen .chourei-viewer-controls-bar {
        bottom: max(env(safe-area-inset-bottom, 0px) + 16px, 70px);
    }
}

/* 擬似フルスクリーン中は body スクロールをロック */
body.chourei-fs-locked {
    overflow: hidden !important;
}

.chourei-viewer-container {
    overflow: auto;
    position: relative;
    background: #1e293b;
}

.chourei-viewer-content {
    position: relative;
    display: inline-block;
}

.chourei-viewer-image,
.chourei-viewer-canvas {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
}

.chourei-viewer-overlays {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* display制御はJSで行う */
}

/* ホットスポット（omakase-map方式） */
.chourei-hotspot {
    position: absolute;
    box-sizing: border-box;
    pointer-events: auto;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 枠サイズは一括処理で抽出した値で固定。中身が大きくなっても枠は伸ばさない */
    overflow: hidden;
    transition: background-color 0.15s;
}

.chourei-hotspot:hover {
    background: rgba(43, 112, 239, 0.05);
}

/* テキストオーバーレイ（管理者側 .chourei-field-text と揃える） */
.chourei-hotspot-text {
    display: block;
    width: 100%;
    height: 100%;
    max-height: 100%;
    padding: 1px 2px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.15;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.6);
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: anywhere;
    box-sizing: border-box;
    /* iOS Safari の text autosizing を無効化 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Google Translate対応: テキストはtranslate属性を持たないので自動翻訳される */

/* 展開時は枠を非表示 */
.chourei-hotspot.is-expanded {
    visibility: hidden;
}

/* body直下のフローティングポップアップ */
.chourei-floating-popup {
    /* popup は .chourei-viewer-content の子として absolute 配置する
       (JS 側で content.appendChild してから offsetLeft/Top で位置決め)。
       こうすると画像と同じ CSS transform を被るため、ピンチズーム時も
       ホットスポット枠の真上に張り付く。 */
    position: absolute;
    z-index: 999999;
    width: max-content;
    max-width: 280px;
    padding: 6px 10px;
    font-family: 'Inter', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    white-space: pre-wrap;
    word-break: normal;
    pointer-events: none;
    /* iOS Safari の text autosizing (狭いコラム内のテキストを勝手に
       拡大する機能) を無効化。content の幅が画像 (例 1500px) と広く
       設定されているため、popup 内のテキストが iOS により数倍に
       自動拡大される現象が発生していた。 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* タブレット横画面対応（iPad等） */
@media (max-width: 1024px) {
    .chourei-hotspot-text {
        padding: 1px 2px;
        line-height: 1.15;
    }
}

/* モバイル対応 */
@media (max-width: 768px) {
    .chourei-viewer-btn {
        width: 44px;
        height: 44px;
    }

    .chourei-hotspot-text {
        font-size: 7px;
        padding: 1px 2px;
    }
}

/* モバイル用ボトムシート */
.chourei-mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    z-index: 999998;
    transition: background 0.2s ease;
}

.chourei-mobile-overlay.active {
    background: rgba(0, 0, 0, 0.4);
}

.chourei-mobile-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 40vh;
    background: #ffffff;
    z-index: 999999;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* iPad横画面: ボトムシートを2倍の高さに */
@media (min-width: 768px) and (max-width: 1366px) and (orientation: landscape) {
    .chourei-mobile-sheet {
        max-height: 80vh;
    }
}

.chourei-mobile-sheet.active {
    opacity: 1;
}

.chourei-sheet-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 10px 16px 4px;
}

.chourei-sheet-handle {
    width: 40px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    cursor: pointer;
}

.chourei-sheet-close {
    position: absolute;
    right: 12px;
    top: 6px;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.chourei-sheet-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.chourei-sheet-content {
    padding: 8px 20px 24px;
    font-family: 'Inter', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    color: #0f172a;
    white-space: pre-wrap;
    word-break: normal;
    text-align: center;
}
