/* ====================================================================
Version 2.2 (Ultra Compact Edition)
記述を部品毎にまとめた。
動画投稿に対応 postVideoクラス
文章を回り込ませることができる画像挿入に対応
挿入した画像を選択したときにわかりやすくした
====================================================================== */

:root {
    --schoolColor: rgb(255,128,64);
}

/* ======================================================================
   1. 共通設定・ベーススタイル (Base & General)
   ====================================================================== */
button, a, label {
    touch-action: manipulation;
}


.standalone-mode {
    width: 80vw; 
}

.embedded-mode {
    width: 100%; 
}

button:disabled {
    background-color: gray;
    color: white;
    cursor: default;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.toast-msg {
    animation: slideUp 0.3s ease-out;
    transition: opacity 0.5s ease;
}

/* ======================================================================
   2. コンテナ (Container)
   ====================================================================== */
#container {
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    border-top: 20px solid var(--schoolColor);
}

@media screen and (max-width: 767px) and (orientation: portrait) {
    #container {
        width: 100%;
    }
}


/* ----------------------------------------------------------------------
   3. ナビゲーションバー (#blognav) の修正
   ---------------------------------------------------------------------- */
#titleBox.flex--3-0-50 {
    flex: 0 1 20%;
}

#div__topmenu {
     justify-content: flex-end;
     flex: 0 1 80%;
}

/* ここで表示されている画面に応じてボタンを非有効化している */
/* 一覧表示のときは一覧表示ボタンをグレイアウト*/
#container[data-mode='list'] #listBtn {
      background-color: gray;
      color: white;
      pointer-events: none;
}
/* 新規作成中・編集中の場合は新規作成ボタンをグレイアウト*/
#container[data-mode='editor'] #createBtn {
      background-color: gray;
      color: white;
      pointer-events: none;
}

#adminBtn {
    display: flex;
    flex-direction: row;
    column-gap: 1rem;
    justify-content: flex-end;
    align-items: center;
    width: 1rem; /* 元は縮めておく */
    min-width: 1rem;
/*    background-color: #2563eb;  */
    overflow: hidden;
    transition: all 0.5s ease;
    border: 0px solid transparent;
    border-radius: 5px;
}
    
#adminBtn button {
    color: #2563eb;
    overflow: clip;
    font-weight: 600;
    white-space: nowrap;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
#adminBtn:hover{
    width : 8rem;
    min-width: 120px;
    padding: 0 0.5rem;
    background-color: white;
}

/* #adminBtn の展開時を % 指定から可変幅(auto)または固定幅に変更して圧迫を防ぐ */
#adminBtn.is-expanded,
#adminBtn:focus-within {
    width : 250px;
    min-width: 120px;
    padding: 0 0.5rem;
    background-color: white;
}

#adminBtn.is-expanded button,
#adminBtn:hover button,
#adminBtn:focus-within button {
    color: white;
}

/* ----------------------------------------------------------------------
   メディアクエリの閾値を 767px から 1024px に引き上げる（iPad縦横をカバー）
   ---------------------------------------------------------------------- */
@media screen and (max-width: 1024px) {
    #blognav {
        flex-direction: row;
        align-items: center;
        padding: 0.5rem;
	/*        flex-wrap: wrap;  不要 */
    }
    #titleBox {
        flex: 0 0 100%;
        display: none;  /* タブレット・スマホではタイトルを隠してメニュー幅を確保 */
    }
    #div__topmenu {
        max-width: 100%;
        justify-content: flex-start;
        flex: 1 1 100%;
        flex-wrap: wrap; /* ボタンが溢れた際に下段へ安全に折り返す */
        gap: 0.5rem;
        margin: 5px 0;
    }
    #div__topmenu button {
        white-space: nowrap;
        flex: 0 1 auto;
    }
    #reloadBtn {
        display: none;
    }
    #adminBtn.is-expanded,
    #adminBtn:hover, 
    #adminBtn:focus-within {
        width: auto;
        min-width: 100px;
    }

    #adminBtn button {
        white-space: nowrap;
    }
}

/* ================================================================
   4. メインコンテンツエリア (Main - #main__blog)
   ================================================================ */
#main__blog {
    flex-grow: 1;
    box-sizing: border-box;
}

/* ================================================================
   5. ツールバー (Toolbar - #toolbar)
   ================================================================ */
/* ====================================================================
   Toolbar (Pattern 2: Dashboard 2-Tier)
==================================================================== */
#toolbar {
    display: grid;
    /* エリアの名前をつけてパズルのように配置 */
    grid-template-areas:
        "action blank blank"
        "heading formatting  media";
    grid-template-columns: auto  1fr 1fr;
    gap: 0.5rem;
    padding: 0.75rem;
    position: sticky;
    top: 60px;
    z-index: 10;
    background-color: #f9fafb;
    border-radius: 8px; /* 少し丸みを持たせてモダンに */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* ====================================================================
   ツールバー「ぬるっと降りてくる」アニメーション設定
==================================================================== */
#toolbar {
    /* はみ出しを隠し、アニメーションの基点を設定 */
    overflow: hidden;
    max-height: 300px; /* ツールバーが完全に表示される十分な高さ */
    opacity: 1;
    transform: translateY(0); /* 通常の位置 */
    
    /* 高さ、透明度、位置、余白を一斉に滑らかに変化させる */
    transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1), 
                opacity 0.4s ease-out, 
                transform 0.4s ease-out, 
                padding 0.4s ease-out;
}

#toolbar.hidden {
    /* ⚠️ display: none; は絶対に書かない！代わりに物理的な空間を完全に潰す */
    max-height: 0 !important;
    opacity: 0 !important;
    transform: translateY(-20px) !important; /* -20pxの位置（少し上）に引っ込める */
    
    /* 空間を占有する余白もすべて0にする */
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    border-width: 0 !important;
    
    /* 見えない状態のときに誤ってボタンが押されるのを防ぐ */
    pointer-events: none !important; 
}

/* パズルのピース（パーティション）をエリアに割り当て */
#toolbar .partition:nth-child(1) {
    grid-area: heading;
    padding : 5px;
    background-color : #998877;
}

#toolbar .partition:nth-child(2) {
    grid-area: formatting;
    padding : 5px;
    background-color : #889977;
}
#toolbar .partition:nth-child(3) {
    grid-area: media;
    padding : 5px;
    background-color : #dd9977;
}

/* 保存ボタンエリア（縦2マス分）の装飾 */
#toolbar .partition:nth-child(4) {
    grid-area: action;
    row-gap: 0.5rem;
}

#toolbar .partition {
    display: flex;
    align-items: center;
    column-gap: 0.5rem;
}


/* スマホ用設定 */
@media screen and (max-width: 767px) and (orientation: portrait) {
    #toolbar {
        /* 1. Gridを解除して、1行のFlexboxに変更 */
        display: flex !important;
        flex-direction: row;
        flex-wrap: nowrap;
        
        /* 2. 横スクロールを有効化し、はみ出し（ブレ）をツールバー内に封じ込める */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* iOSで滑らかにスクロールさせる */
        
        /* 3. 画面幅を超えないように制御 */
        max-width: 100vw;
        box-sizing: border-box;
        
        /* 見た目の調整 */
        gap: 1rem;
        top: 50px;
        padding-bottom: 0.5rem; /* スワイプしやすくするための余白 */
        
        /* スクロールバーを非表示にしてスッキリ見せる（Firefox用） */
        scrollbar-width: none;
    }
    
    /* スクロールバーを非表示にする（Chrome, Safari用） */
    #toolbar::-webkit-scrollbar {
        display: none;
    }

    #toolbar .partition {
        /* 4. パーティション（ツール群）がスクロール時に潰れないようにする */
        flex-shrink: 0;
    }

    #toolbar .partition:nth-child(4) {
        /* 保存ボタン群は、横スクロールの終点として区切り線を残す */
        border-left: 2px dashed #e5e7eb;
        padding-left: 1rem;
        justify-content: flex-start;
    }
}

#toolbar button ,
#toolbar span {
    white-space: nowrap;       /* 絶対に途中で改行させない */
    min-width: max-content;    /* 中身の文字の長さをボタンの最小幅にする */
    flex-shrink: 0;            /* 潰れる（縮む）のを防ぐ */
}

/* ==========================================================================
   6. 記事一覧ビュー (List View - #view-list)
   ========================================================================== */
.thumb-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ==========================================================================
   7. エディタビュー (Editor View - #view-editor)
   ========================================================================== */
.editor-content {
    height: 100%;
    min-height: 450px;
    border: 1px solid #ddd;
    padding: 1.5rem;
    border-radius: 0.5rem;
    background: white;
    line-height: 1.8;
    display: flow-root;
}

.editor-content:focus {
    outline: 2px solid #000080
    border-color: transparent;
}

#draft {
    border: 1px solid red;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    height: auto;
}

.list-item-container {
    width: 100%;
    height: auto;
    display: flex;
    flex-direction: row;
    border: 1px #aaaaaa solid;
    border-radius: 5px;
    overflow: hidden;
 }

.listItem {
    display: flex;
    flex-direction: row;
    padding: 1rem;
    flex: 4 1 95%;
    overflow: hidden;
    cursor: pointer;
}

.killbtn {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 1%;
    min-width: 2rem;
    background-color: red;
    overflow: hidden;
    transition: 0.5s;
}
    
.killbtn button {
    display: flex;
    justify-content: center;
    align-items: center;
    color: red;
    overflow: hidden;
    font-weight: 600;
}

.killbtn:hover {
    width: 10%;
}

.killbtn:hover button {
    color: white;
}

@media screen and (max-width: 767px) and (orientation: portrait) {
    .killbtn:hover {
        width: 20%;
    }
}

/* ==========================================================================
   8. 記事詳細ビュー (Post Detail View - #view-post)
   ========================================================================== */
#view-post:not(.hidden) {
    display: flex;
    flex-direction: column;
    height: 100%; 
    overflow: hidden; 
}

#view-post article {
    flex-grow: 1;
    overflow-y: auto; 
    padding: 2rem;
    box-sizing: border-box;
}

#editBtn {
    white-space: nowrap;
    display: flex;
    justify-content: center;
    align-items: center;
}

#post-display-content {
    overflow-wrap: break-word;
    display: flow-root;
}

.linkInPost {
    color: blue;
    transition: 0.5s;
}

.update_p,
#post-display-update {
    display: none;
}

/* ======================================================================
   9. 記事内要素 (Content Elements - 見出し、画像関連)
   ====================================================================== */
#editor h2, #post-display-content h2 {
    font-size: 1.5rem;
    font-weight: bold;
    border-bottom: 3px solid #3b82f6;
}

#editor h3, #post-display-content h3 {
    font-size: 1.25rem;
    font-weight: bold;
    border-bottom: 2px solid #e5e7eb;
    padding-left: 0.5rem;
}

.postimg {
    margin: 10px 10px;
}

/* 選択された個別画像のスタイル */
.postimg.is-selected {
    outline: 3px solid #3b82f6; /* 青い枠線 */
    outline-offset: 2px;
}


#main__blog[data-imgsize="full"] .postimg:not(.img-float-left):not(.img-float-right) {
    width: auto;
    height: auto;
}

#main__blog[data-imgsize="half"] .postimg:not(.img-float-left):not(.img-float-right) {
    max-width: 50vw;
    width: auto;
    height: auto;
}

#main__blog[data-imgsize="quarter"] .postimg:not(.img-float-left):not(.img-float-right){
    max-width: 25vw;
    width: auto;
    height: auto;
}

/* 動画  */
.postVideo{
    border : 2px solid  darkgray;
    max-width : 300px;
    height : auto;
    transition: all 0.3s ease;
}

.postVideo.is-active{
    border : 2px dashed darkblue;
}

@media screen and (max-width: 767px) and (orientation: portrait) {
    #main__blog[data-imgsize="half"] .postimg {
        max-width: 100%;
        width: auto;
        height: auto;
    }
    #main__blog[data-imgsize="quarter"] .postimg {
        max-width: 100%;
        width: auto;
        height: auto;
    }
}


/* ==================================================================
   画像コンテナ（.image-flex-container）関連の統合設定
================================================================== */

/* 1. ベース設定（常に適用される基本デザイン） */
.image-flex-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 15px 0;
    padding: 15px;
    background: #f9fafb;
    border: 2px dashed transparent;
    border-radius: 8px;
    user-select: none; /* コンテナ内へのキャレット侵入を防ぐ */
    box-sizing: border-box; 
    transition: all 0.3s ease; 
}

/* 2. 状態による上書き設定（フォーカス時や画像追加時） */
.image-flex-container.is-active {
    border-color: var(--schoolColor);
    background: #eff6ff;
}

.image-flex-container:has(img) {
    border-color: transparent; 
}

/* ==================================================================
   画像コンテナ直下の段落（Pタグ）の空白調整
================================================================== */
/* 1. 画像コンテナのすぐ下にあるPタグは、上側の余白をゼロにする */
.image-flex-container + p {
    margin-top: 0;
}

/* ==================================================================
   画像コンテナ直下の段落（Pタグ）の空白調整
================================================================== */
/* 1. 画像コンテナのすぐ下にあるPタグは、テキスト入力時も間延びしないよう上側の余白をゼロにする */
.image-flex-container + p {
    margin-top: 0;
}

/* 2. まだ文字が入力されていない（中身がbrだけの）状態なら、高さと下側の余白も完全にゼロにして隠す */
.image-flex-container + p:has(> br:only-child) {
    margin-bottom: 0;
    height: 0;
    overflow: hidden; /* 中にあるbrの高さを外にはみ出させないため */
}

/* 子要素（画像本体）の設定 */
.image-flex-container .postimg {
    max-width: 100%;
    min-width: 0; 
    object-fit: contain;
    margin: 0px 5px;
}

/* 明示的な横並び（デフォルトの柔軟なwrapを維持しない） */
.image-flex-container.layout-row {
    flex-direction: row;
    flex-wrap : nowrap;
}

/* 明示的な縦並び（常に縦1列で中央揃え） */
.image-flex-container.layout-col {
    flex-direction: column;
    align-items: center;
}

/* 3. スマホ用（レスポンシブ）設定 ※必ず最後に書く */
@media screen and (max-width: 767px) and (orientation: portrait) {
    .image-flex-container {
        flex-direction: column;
        min-height: 50px;
    }
}



/* ====================================================================
   10. モーダル・ダイアログ (Modals & Dialogs)
   ==================================================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 50;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal.active {
    display: flex;
}

#auth-modal {
    z-index: 2000;
}


/* ======================================================================
   追加: 回り込み画像用スタイル
   ====================================================================== */

.img-float-left {
    float: left;
    margin: 5px 15px 10px 0; /* 右と下に余白を空けて文字と密着させない */
    max-width: 45%;          /* 画面の半分以下のサイズに制限 */
    height: auto;
}

.img-float-right {
    float: right;
    margin: 5px 0 10px 15px; /* 左と下に余白を空ける */
    max-width: 45%;
    height: auto;
}

/* スマホの縦画面では回り込みを解除して大きく見せる場合（任意） */
@media screen and (max-width: 767px) and (orientation: portrait) {
    .img-float-left, .img-float-right {
        float: none;
        max-width: 100%;
        margin: 10px auto;
        display: block;
    }
}
