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

.chourei-viewer {
    font-family: 'Inter', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
    /* v5.3.75: 画像幅に合わせて縮む (元は max-width:100% でコンテンツ列幅一杯)。
       これでページ送り矢印が画像の左右端に寄る。画像が列より広い場合は
       max-width:100% でクランプされ、内部 container が overflow:auto で横スクロール。 */
    width: fit-content;
    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);
    /* ページ送りボタン等の absolute 配置基準 (元は fullscreen 時のみ relative) */
    position: relative;
}

.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;
    }
}

/* ページ送りボタン (カウンタ両側に細いシェブロン) — 図面が複数枚の時のみ表示 */
/* v5.3.77: 画像左右の絶対配置 → 画像下のカウンタ行に水平並びへ変更。
   prev / counter / next を .chourei-viewer-page-nav で flex 配置する。 */
.chourei-viewer-page-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin-top: 4px;
}
.chourei-viewer-page-prev,
.chourei-viewer-page-next {
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
    flex: 0 0 auto;
}
.chourei-page-arrow {
    display: block;
    width: 14px;
    height: 14px;
    border-top: 2.5px solid #64748b;
    border-right: 2.5px solid #64748b;
    background: transparent;
    /* v5.3.77: 画像から外れて白背景上に置かれるので drop-shadow 不要 */
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.chourei-viewer-page-prev .chourei-page-arrow {
    transform: rotate(-135deg);
    margin-left: 4px; /* 回転後の視覚中心補正 */
}
.chourei-viewer-page-next .chourei-page-arrow {
    transform: rotate(45deg);
    margin-right: 4px;
}
.chourei-viewer-page-prev:hover:not(:disabled) .chourei-page-arrow {
    border-color: #1e293b;
    transform: rotate(-135deg) scale(1.15);
}
.chourei-viewer-page-next:hover:not(:disabled) .chourei-page-arrow {
    border-color: #1e293b;
    transform: rotate(45deg) scale(1.15);
}
.chourei-viewer-page-prev:disabled,
.chourei-viewer-page-next:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}
/* SP: タップ領域 36 / chevron 11、カウンタ行内なので少し詰める */
@media (max-width: 768px) {
    .chourei-viewer-page-nav {
        gap: 12px;
    }
    .chourei-viewer-page-prev,
    .chourei-viewer-page-next {
        width: 36px;
        height: 36px;
    }
    .chourei-page-arrow {
        width: 11px;
        height: 11px;
        border-top-width: 2px;
        border-right-width: 2px;
    }
}

/* ページカウンタ + 現在ページタイトル — .chourei-viewer-page-nav の中央 */
/* v5.3.77: 矢印と同じ行に並ぶので display は flex のままだが縦並び → 横並びに。
   タイトルとカウントを 2 行構成のままにしたいので flex-direction:column は維持。 */
.chourei-viewer-page-counter {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    font-size: 12px;
    color: #475569;
    text-align: center;
    min-width: 80px;
}
.chourei-viewer-page-title {
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.2;
}
.chourei-viewer-page-count {
    font-size: 11px;
    color: #64748b;
    line-height: 1.2;
}

/* 全画面中のページナビ (矢印 + カウンタ) は下部コントロールバーと被らないよう
   下から少し浮かせて中央配置 */
.chourei-viewer:fullscreen .chourei-viewer-page-nav,
.chourei-viewer.is-pseudo-fullscreen .chourei-viewer-page-nav {
    position: absolute;
    left: 50%;
    bottom: 64px;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.85);
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    padding: 4px 10px;
    z-index: 2;
}
@media (max-width: 768px) {
    .chourei-viewer:fullscreen .chourei-viewer-page-nav,
    .chourei-viewer.is-pseudo-fullscreen .chourei-viewer-page-nav {
        bottom: max(env(safe-area-inset-bottom, 0px) + 64px, 116px);
    }
}
/* 全画面中はコントロールバーを画像の下に固定し常に見えるように */
.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;
    /* pre-wrap で textarea で入力された改行 (\n) を保持しつつ、
       長い行は枠内で自動折返しする */
    white-space: pre-wrap;
    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;
}
