/* モバイル幅向けの共通パッチ（2026-10-08調査の具体案にもとづく）。

   旧ページの固定幅の主因は #index-contents の width:980px であり、
   内部コンテンツはおおむね可変である。ここではその固定幅だけを解除し、
   はみ出す表やメディアは要素ごとに収める。

   旧ページでは <head> の外側に <div id="site-box"> があり、ブラウザは
   ページ側の <link>/<style> をすべて body 側へ落とすため、このファイル
   の規則は常にページ側CSSより「前」に来る。同詳細度では後勝ちで負けて
   しまうので、site.css と同じく !important で担保する。

   980px を超える幅では一切適用されないため、既存のPC表示への影響は無い。
   互換モード（quirks）のページでもメディアクエリは有効。 */

@media (max-width: 980px) {

    /* 旧レイアウトの固定幅を解除する */
    #index-contents {
        width: auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        /* URL等の長い連続文字列が本文幅を突き抜けるのを防ぐ
           （継承するプロパティなので下層のテキスト全体に効く） */
        overflow-wrap: anywhere;
    }

    /* 画像や埋め込みが画面幅を超えないようにする。
       iframe には height:auto を付けない（height 属性が潰れて
       カレンダー等が縮んでしまうため、幅だけを丸める） */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    iframe {
        max-width: 100% !important;
    }

    /* はみ出す一覧テーブルは、そのテーブル内だけで横スクロールさせる */
    #index-contents table,
    .footer-table {
        display: block !important;
        width: max-content !important;
        max-width: 100% !important;
        overflow-x: auto !important;
    }

    /* Bootstrap の .row が持つ左右 -15px の負マージンを打ち消す。
       旧ページでは適切なコンテナ内に置かれていないため、
       そのままだと画面幅 +30px にはみ出す（hakkutsu7 等）。 */
    #index-contents .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* 左右2段組（.gist + .photo 等）を縦積みにする。
       float していない要素に掛かっても無害。 */
    #index-contents .gist,
    #index-contents .photo {
        width: auto !important;
        float: none !important;
    }

    /* スライドショー等の固定幅コンテナを可変にする（中身の
       画像は上の img 規則で収まる） */
    #index-contents #slide {
        width: auto !important;
        max-width: 100% !important;
    }
}

/* スマホ試作で確認した旧ページ向けの調整 */
@media (max-width: 768px) {
    html,
    body {
        max-width: 100%;
        overflow-x: clip;
    }

    body {
        box-sizing: border-box;
        width: 100%;
        margin-right: auto;
        margin-left: auto;
        padding-right: 12px;
        padding-left: 12px;
        font-size: 16px;
    }

    #index-contents,
    #contents,
    #wrapper,
    #main,
    .contents,
    .main {
        box-sizing: border-box;
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-right: auto !important;
        margin-left: auto !important;
    }

    #index-contents .gist,
    #index-contents .photo,
    #index-contents .news,
    #index-contents .banner,
    .gist {
        box-sizing: border-box;
        float: none !important;
        max-width: 100% !important;
    }

    img,
    video,
    iframe,
    object,
    embed {
        max-width: 100% !important;
    }

    table:not(#articleList) {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #articleList {
        display: block;
        width: 100% !important;
        overflow: visible;
    }

    #articleList tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #articleList td {
        box-sizing: border-box;
        width: auto !important;
        min-width: 0;
        padding: 10px !important;
    }

    .topicpath {
        font-size: 0.85rem;
        line-height: 1.5;
        overflow-wrap: anywhere;
    }

    #index-contents .gist h3,
    #title {
        font-size: clamp(1.25rem, 5vw, 1.8rem) !important;
        line-height: 1.4;
        overflow-wrap: anywhere;
    }

    #index-contents .gist p,
    .gist p {
        font-size: 1rem !important;
        line-height: 1.65;
        overflow-wrap: anywhere;
    }

    td,
    th,
    li,
    dd,
    a {
        overflow-wrap: anywhere;
    }
}

@media (max-width: 560px) {
    #articleList tr {
        grid-template-columns: minmax(0, 1fr);
    }

    #articleList td {
        border-bottom: 1px solid #ddd;
    }
}

@media (max-width: 768px) {
    #staffList {
        display: table !important;
        box-sizing: border-box;
        width: 100% !important;
        max-width: 100%;
        table-layout: fixed;
    }

    #staffList th,
    #staffList td {
        box-sizing: border-box;
        padding: 0.45rem 0.35rem;
        line-height: 1.45;
        vertical-align: middle;
    }

    #staffList th {
        width: 42% !important;
        font-size: 0.9rem;
        overflow-wrap: anywhere;
    }

    #staffList td {
        width: 58% !important;
        font-size: 0.95rem;
        word-break: keep-all;
        overflow-wrap: normal;
    }

    #staffList td a {
        white-space: nowrap;
    }

    .kaikan-annai {
        display: flex !important;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .kaikan-annai > .kiji {
        display: contents;
    }

    .kaikan-annai > .kiji > .main-title { order: 1; }
    .kaikan-annai > .kiji > p { order: 2; }

    .kaikan-annai > .calenderDiv {
        order: 3;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        width: 100%;
        height: auto;
        margin: 0;
    }

    .kaikan-annai > .calenderDiv > .iframe {
        box-sizing: border-box;
        width: 100%;
        max-width: 25rem;
        height: 30rem;
    }

    .kaikan-annai > .kiji > .gist {
        order: 4;
        margin: 0;
    }
}
