/* src/public/css/app-mode.css
 *
 * アプリモード（/app-mode）の見た目。
 *
 * 💡 ヘッダーは常に縮んだ形（.is-compact）で固定表示、フッターの代わりに
 *    画面下へ5分割のタブバーを固定表示します。本文はその間を埋めます。
 */

:root { --app-tabbar-h: 64px; }

/* 💡 変更：アプリモードは「スクロールしない」ことを前提にした画面です。
        以前は .app-slot の高さを min-height にしていたため、中身が長い枠があると
        ページ全体（body）がその分だけ縦に伸びてスクロールできてしまっていました。
        画面の高さぴったりに収まるよう、body を固定し、本文の高さも
        「画面の高さ − ヘッダー − タブバー」ちょうどに決めます。 */
.app-mode-body {
    background: #f4f6fb;
    height: 100dvh;
    overflow: hidden;
}

/* =========================================
   本文（5つの枠）
   ========================================= */
.app-main {
    height: calc(100dvh - var(--header-h, 60px) - var(--app-tabbar-h) - env(safe-area-inset-bottom, 0px));
    overflow: hidden;
    position: relative;
}

.app-slot {
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    /* 💡 基本は画面の高さに収まる設計ですが、文字を大きくしている端末など
            どうしても収まりきらない場合の保険として、枠の中だけスクロールできるようにします
            （ページ全体は動きません） */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 💡 追加：ツール本体の上下に置く広告。GoogleアドセンスでもAdMaxでも、
        設定（config('ads.provider')）に合わせてどちらかが自動で出ます。
        広告が設定されていない・広告オフのときは中身が空になり、高さ0で自然に消えます。 */
.app-slot-ad {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

/* 💡 アプリモード専用の広告（320x50想定）。AdMax側は枠のサイズを保証してくれず、
        大きいネイティブ広告（画像＋見出し）が選ばれることがあり、そのままだと
        「画面の高さぴったり」で作っているアプリモードのレイアウトが崩れてしまいます。
        そのため、こちら側で320x50の枠に固定し、はみ出した分は隠します。 */
.ad-unit-admax-app {
    width: 320px;
    max-width: 100%;
    height: 50px;
    min-height: 50px;
    margin: 4px auto;
    overflow: hidden;
}

/* 💡 追加：320x100版（上の枠で使用。下の枠はこれまでどおり320x50） */
.ad-unit-admax-app-lg {
    width: 320px;
    max-width: 100%;
    height: 100px;
    min-height: 100px;
    margin: 4px auto;
    overflow: hidden;
}

/* 💡 追加：縦向きで余白がたっぷりある端末（iPadなど）で使う300x250版。
        枠そのもの（.ad-unit-admax-rect）は public/css/style.css で
        300x250に固定していますが、外側の余白（.ad-unit の margin:24px auto）
        だけはアプリモード用に詰めます。 */
.app-slot-ad .ad-unit-admax-rect {
    margin: 4px auto;
}

/* 💡 追加：ツール本体を入れる箱。上下の広告を除いた残りの高さいっぱいに広がり、
        中身（.ac-wrap や未設定の案内など）はこれまでどおり縦横中央に置きます。 */
.app-slot-content {
    flex: 1;
    min-height: 0;
    display: flex;
    width: 100%;
    padding: 16px 20px;
    box-sizing: border-box;
    /* 💡 画面の低い端末（iPhone SE など）では、上下の広告を除いた高さに
            ツールが入りきらないことがあります。そのときは、この箱の中だけで
            スクロールさせます（はみ出して広告に重なってしまわないようにするため）。 */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 💡 上下の中央寄せは align-items ではなく margin で行います。
        align-items: center だと、入りきらないときに上へはみ出した分が
        スクロールしても見えなくなってしまうためです。 */
.app-slot-content > * {
    margin: auto;
}

/* 💡 [hidden] は本来 display:none になりますが、上の .app-slot が
        display:flex を指定しているため、そのままでは負けてしまいます。
        明示的に上書きします。 */
.app-slot[hidden] { display: none !important; }

/* --- 未設定の枠 --- */
.app-slot-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 320px;
    text-align: center;
    color: #64748b;
}

.app-slot-empty i.fa-circle-info {
    font-size: 2.4rem;
    color: #94a3b8;
}

.app-slot-empty-text {
    font-size: 1rem;
    font-weight: bold;
    color: #334155;
    margin: 0;
}

.app-slot-empty-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 8px;
    background: #2a5298;
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: bold;
    text-decoration: none;
    transition: background-color 0.2s;
}

.app-slot-empty-link:hover { background: #1e3c72; }

/* --- ツールを割り当てたが、アプリ版が準備中の枠 --- */
.app-slot-coming {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 320px;
    text-align: center;
    color: #64748b;
}

.app-slot-coming i { font-size: 2.4rem; color: #2a5298; }

.app-slot-coming-title {
    font-size: 1.15rem;
    color: #1e3c72;
    margin: 0;
}

.app-slot-coming-body {
    font-size: 0.88rem;
    line-height: 1.7;
    margin: 0;
}

/* =========================================
   下のタブバー（フッターの代わり・5分割）
   ========================================= */
.app-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 500;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 9px 4px;
    border: none;
    background: none;
    color: #94a3b8;
    font-size: 0.68rem;
    line-height: 1.3;
    cursor: pointer;
    min-width: 0;
}

.app-tab-icon { font-size: 1.15rem; }

.app-tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-tab[aria-current="true"] { color: #1e3c72; font-weight: bold; }

/* =========================================
   履歴モーダル
   ========================================= */
.app-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(15, 23, 42, 0.5);
}

.app-modal-overlay[hidden] { display: none !important; }

.app-modal {
    position: fixed;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    z-index: 901;
    width: 100%;
    max-width: 480px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-modal[hidden] { display: none !important; }

.app-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid #f1f3f5;
}

.app-modal-head h2 {
    margin: 0;
    font-size: 1.05rem;
    color: #1e3c72;
}

.app-modal-close {
    border: none;
    background: none;
    font-size: 1.4rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
}

.app-modal-body {
    padding: 16px 18px 20px;
    overflow-y: auto;
}

.app-history-empty {
    color: #64748b;
    font-size: 0.9rem;
    text-align: center;
    margin: 12px 0;
}

.app-history-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.app-history-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid #f1f3f5;
    font-size: 0.9rem;
    color: #334155;
}

.app-history-list li:last-child { border-bottom: none; }

.app-history-item-text { flex: 1; min-width: 0; }

.app-history-apply-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1px solid #2a5298;
    border-radius: 6px;
    background: #ffffff;
    color: #2a5298;
    font-size: 0.8rem;
    font-weight: bold;
    cursor: pointer;
}

.app-history-apply-btn:hover { background: #2a5298; color: #ffffff; }

/* === スマホ・タブレット対応 === */
@media (max-width: 480px) {
    .app-tab { font-size: 0.62rem; }
    .app-tab-icon { font-size: 1.05rem; }
}

/* =========================================
   商品比較（PocketCalc「商品比較」の計算ロジックのみを使った、アプリ版の見た目）
   ========================================= */
.ac-wrap {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* --- 商品Aと商品Bを横並び（VSなし） ---
   💡 商品Cは画面の広さに関わらず足せます（スマホでもOK）。
        .has-c が付いたときは3列になるため、どの画面幅でも
        3列で崩れないよう、文字やすき間はあらかじめ小さめにしています。 */
.ac-products {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.ac-products.has-c { grid-template-columns: repeat(3, 1fr); }

.ac-product {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.ac-product.ac-winner { border-color: #2a5298; box-shadow: 0 0 0 2px rgba(42, 82, 152, 0.18); }

.ac-product-title {
    margin: 0;
    font-size: 0.78rem;
    font-weight: bold;
    color: #1e3c72;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.ac-field label {
    font-size: 0.6rem;
    color: #64748b;
}

.ac-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 6px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    /* 💡 変更：iPhoneのSafariは、入力欄の文字サイズが16px未満だと
            タップしたときに勝手に画面を拡大してしまうため、16px未満にしません */
    font-size: 16px;
}

.ac-count-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    font-size: 0.6rem;
    color: #64748b;
}

.ac-count-row input[type="checkbox"] { flex-shrink: 0; }

.ac-count-row .ac-count-input {
    /* 💡 変更：文字サイズを16pxに上げた分、数字が収まるよう少し幅を広げています */
    width: 56px;
    box-sizing: border-box;
    padding: 3px 5px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    /* 💡 変更：iPhoneのSafariの自動拡大を防ぐため16px未満にしません */
    font-size: 16px;
}

.ac-count-row .ac-count-input:disabled { background: #f1f5f9; color: #94a3b8; }

.ac-result {
    margin: 2px 0 0;
    font-size: 0.76rem;
    font-weight: bold;
    color: #1e3c72;
    text-align: center;
}

/* --- 商品Cを追加する（右上・テキスト→チェックボックスの順、画面の広さに関わらず使えます） --- */
.ac-addc-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    font-size: 0.78rem;
    color: #475569;
    cursor: pointer;
}

.ac-addc-text { text-align: right; }

.ac-product-c[hidden] { display: none !important; }

/* --- 比較するボタン --- */
.ac-compare-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: #2a5298;
    color: #ffffff;
    font-size: 0.92rem;
    font-weight: bold;
    cursor: pointer;
}

.ac-compare-btn:hover { background: #1e3c72; }

/* --- 判定結果 --- */
.ac-winner-text {
    margin: 0;
    text-align: center;
    font-size: 0.9rem;
    font-weight: bold;
    color: #1e3c72;
    min-height: 1.3em;
}

.ac-diff-text {
    margin: 0;
    text-align: center;
    font-size: 0.76rem;
    color: #64748b;
    min-height: 1.1em;
}

/* --- クリア（A）／履歴／クリア（B） --- */
.ac-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.ac-actions button {
    padding: 8px 4px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #475569;
    font-size: 0.76rem;
    cursor: pointer;
}

.ac-actions button:hover { background: #f1f5f9; }
.ac-actions .ac-history-btn { color: #2a5298; border-color: #2a5298; }

/* =========================================
   アプリ版ツール共通の入力まわり
   （.app- で始まるものは、ガソリン代計算・消費税計算など
     どのアプリ版ツールからも同じ見た目で使えます）
   ========================================= */
/* 💡 上下に広告が入るぶん、中身を置ける高さが限られます。
        1行＝「項目名／入力欄／単位」の3列で、縦に短くまとめています。 */
.app-tool-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 320px;
}

/* --- オプション（チェックボックス・ラジオボタンの並び） --- */
.app-options {
    display: flex;
    gap: 14px;
    justify-content: center;
    font-size: 0.82rem;
    color: #475569;
}

.app-option {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

/* --- 入力の1行（項目名／入力欄／単位） --- */
.app-field {
    display: grid;
    grid-template-columns: 44px 1fr 46px;
    align-items: center;
    gap: 8px;
}

/* 💡 .app-field は display:grid のため、hidden 属性だけでは隠れません */
.app-field[hidden] { display: none; }

.app-field-label {
    font-size: 0.82rem;
    color: #475569;
}

.app-field-unit {
    font-size: 0.76rem;
    color: #64748b;
}

/* 💡 font-size は16px以上にします。これより小さいと、iPhoneのSafariで
        入力欄を触ったときに画面が勝手に拡大されてしまいます。 */
.app-input {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 16px;
    text-align: right;
    box-sizing: border-box;
}

/* --- クリア／計算／履歴 --- */
.app-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-top: 2px;
}

.app-actions button {
    padding: 9px 4px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #475569;
    font-size: 0.8rem;
    cursor: pointer;
}

.app-actions button:hover { background: #f1f5f9; }

.app-actions .app-calc-btn {
    border-color: #2a5298;
    background: #2a5298;
    color: #ffffff;
    font-weight: bold;
}

.app-actions .app-calc-btn:hover { background: #1e3c72; }
.app-actions .app-history-btn { color: #2a5298; border-color: #2a5298; }

/* --- 結果（ボタンを押すと内訳のモーダルが出ます） --- */
.ag-result-btn {
    width: 100%;
    padding: 8px;
    border: 1px solid #2a5298;
    border-radius: 8px;
    background: #ffffff;
    color: #2a5298;
    font-size: 0.8rem;
    cursor: pointer;
}

.ag-result-btn:hover:not(:disabled) { background: #f1f5f9; }

/* まだ一度も計算していないときは押せません */
.ag-result-btn:disabled {
    border-color: #dbe3ec;
    color: #a8b3c1;
    cursor: default;
}

.ag-result-text {
    margin: 0;
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    min-height: 1.4em;
}

/* 「総額」。金額より控えめにして、数字のほうを目立たせます */
.ag-result-label {
    font-size: 0.82rem;
    color: #64748b;
}

.ag-result-value {
    font-size: 1.05rem;
    font-weight: bold;
    color: #1e3c72;
}

/* 💡 画面の低い端末（iPhone SE など）では、上下の広告を除いた高さに
        そのままでは入りきらないため、すき間と余白だけ詰めます。
        入力欄の文字は16pxのままにします（小さくすると、iPhoneのSafariで
        触ったときに画面が勝手に拡大されてしまうため）。 */
@media (max-height: 700px) {
    .app-slot-content { padding: 8px 20px; }

    .app-tool-wrap { gap: 5px; }

    .app-input { padding: 6px 10px; }

    .app-actions button { padding: 7px 4px; }

    .ag-result-btn { padding: 6px; }

    .ag-result-value { font-size: 1rem; }
}

/* =========================================
   消費税・軽減税率計算（アプリ版）
   ========================================= */
/* 💡 3つの結果（税抜価格・消費税額・税込価格）を、項目名と金額の2列で並べます */
.at-results {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 6px 12px;
    margin: 2px 0 0;
    padding: 12px 14px;
    border-radius: 8px;
    background: #f4f7fc;
}

.at-result-label {
    font-size: 0.82rem;
    color: #64748b;
}

.at-result-value {
    margin: 0;
    text-align: right;
    font-size: 0.95rem;
    font-weight: bold;
    color: #1e3c72;
}

/* 税込価格（いちばん下）は、ひと目で分かるよう大きく出します */
.at-results .at-res-included { font-size: 1.1rem; }

/* =========================================
   計算結果モーダルの中身
   ========================================= */
.app-result-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    margin: 0;
}

.app-result-label {
    font-size: 0.82rem;
    color: #64748b;
}

.app-result-value {
    margin: 0;
    text-align: right;
    font-size: 0.92rem;
    font-weight: bold;
    color: #1e3c72;
}

/* 1行目（合計金額）は、ひと目で分かるよう大きく出します */
.app-result-list .app-result-value:first-of-type { font-size: 1.1rem; }

/* =========================================
   横向き（スマホ）の案内
   ========================================= */
/* 💡 いつもは隠しておき、スマホを横向きにしたときだけ出します */
.app-rotate-notice { display: none; }

/* 💡 「横向き」かつ「画面の高さが低い」＝スマホを横向きにしたとき、を狙った条件です。
        タブレットを横向きにしたときは高さに余裕があるため、これには当てはまりません。 */
@media (orientation: landscape) and (max-height: 500px) {
    /* 中身は表示せず、案内だけを出します */
    .app-main { display: none; }

    .app-rotate-notice {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 14px;
        text-align: center;
        padding: 32px 24px;
        color: #475569;
        font-size: 0.92rem;
    }

    .app-rotate-notice i { font-size: 2.4rem; color: #2a5298; }

    /* 💡 中身を出さない代わりに、フッター（タブバー）の固定表示を解除します。
            固定のままだと、案内がフッターの下に隠れて読めなくなるためです。
            解除することで、普通に上から下へ並び、必要なら画面全体がふつうに
            スクロールして案内とタブバーの両方が見えるようになります。 */
    .app-tabbar {
        position: static;
        box-shadow: none;
    }

    /* 💡 スクロールしない前提を外し、必要なら画面全体で普通にスクロールできるようにします */
    .app-mode-body {
        height: auto;
        min-height: 100dvh;
        overflow: auto;
    }
}
