/* --- 基本設定とリセット --- */
:root {
    --primary-color: #007bff;
    --background-color: #f4f7f9;
    --header-bg: #ffffff;
    --text-color: #333;
    --light-text-color: #6c757d;
    --border-color: #dee2e6;
    --font-family: 'Noto Sans JP', sans-serif;
}
* { box-sizing: border-box; }
body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    line-height: 1.6;
}
a { color: var(--primary-color); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; }

/* --- サイト全体のコンテナ --- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 30px 20px;
}

/* --- ヘッダー --- */
.site-header {
    background-color: var(--header-bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-container {
    display: flex; /* ★これがレイアウト崩れの最も重要な修正点 */
    justify-content: space-between;
    align-items: center;
    height: 60px;
    max-width: 1100px;
    margin: 0 auto;
}
.site-logo {
    font-size: 20px;
    font-weight: 700;
}
.main-nav {
    display: flex;
    gap: 25px;
}
.main-nav a {
    color: var(--light-text-color);
    font-weight: 500;
    font-size: 15px;
}
.main-nav a:hover, .main-nav a.active {
    color: var(--primary-color);
    text-decoration: none;
}
.user-menu {
    font-size: 14px;
    color: var(--light-text-color);
}
.user-menu .logout-link {
    margin-left: 15px;
    font-size: 13px;
}

/* --- メインコンテンツとフッター --- */
.main-content {
    min-height: calc(100vh - 122px); /* フッターが最下部に表示されるように調整 */
}
.site-footer {
    background-color: #343a40;
    color: #adb5bd;
    padding: 20px;
    text-align: center;
    font-size: 13px;
}
.logo-image {
    height: 40px;
    width: auto;
}

/* --- 共通コンポーネント --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 5px;
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 500;
}
.btn-primary { background-color: var(--primary-color); color: #fff; border-color: var(--primary-color); }
.btn-secondary { background-color: #6c757d; color: #fff; border-color: #6c757d; }

/* --- ダッシュボード専用スタイル --- */
.dashboard-header {
    margin-bottom: 30px;
}

.current-school {
    color: var(--light-text-color);
}

.dashboard-grid {
    display: grid; /* ★これがカードを横並びにするための鍵です */
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 25px;
}

.widget {
    background-color: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.widget h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
}

/* 重要なお知らせウィジェット */
.widget-alert {
    background-color: #fffbe6;
    border-left: 5px solid #ffc107;
}
.widget-alert h3 .icon {
    vertical-align: middle;
}
.btn-alert {
    display: inline-block;
    margin-top: 15px;
    padding: 8px 15px;
    background-color: #ffc107;
    color: #333;
    text-decoration: none;
    border-radius: 5px;
    font-weight: 700;
}

/* 次のレッスンウィジェット */
.next-lesson {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}
.lesson-name {
    color: var(--light-text-color);
    margin-top: 5px;
}

/* ショートカットウィジェット */
.quick-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.btn-action {
    padding: 12px;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: #333;
    transition: background-color 0.2s;
}
.btn-action:hover {
    background-color: #f4f7f9;
}

/* お知らせウィジェット */
.info-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.info-list li {
    display: flex;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}
.info-list li:last-child {
    border-bottom: none;
}
.info-list .date {
    font-size: 13px;
    color: var(--light-text-color);
    margin-right: 10px;
    min-width: 70px;
}
.link-more {
    display: block;
    text-align: right;
    margin-top: 10px;
    font-size: 14px;
}

/* --- ヘッダーのレスポンシブ対応 (改善版) --- */

.hamburger-menu {
    display: none; /* PCでは非表示 */
    background: none; border: none; cursor: pointer;
    padding: 10px; z-index: 101;
}
.hamburger-line {
    display: block; width: 25px; height: 3px;
    background-color: var(--text-color); margin: 5px 0;
    transition: all 0.3s ease-in-out;
}

/* === スマホ表示用のメディアクエリ (画面幅が899px以下) === */
@media (max-width: 899px) {
    .hamburger-menu {
        display: block; /* スマホでは表示 */
    }

    /* ▼▼▼ ここからが主な修正点 ▼▼▼ */

    /* メニュー全体を囲むラッパー */
    .nav-wrapper {
        display: block; /* displayの切り替えはJSで行う */
        position: fixed; /* fixedに変更し、画面全体を覆うように */
        top: 0;
        right: -100%; /* 初期状態では画面の右側に隠す */
        width: 80%;
        max-width: 300px;
        height: 100%;
        padding-top: 60px; /* ヘッダーの高さ分、中身を下げる */
        background-color: var(--header-bg);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
        transition: right 0.4s ease-in-out;
        z-index: 100;
        overflow-y: auto;
    }
    
    /* is-openクラスが付与された時のスタイル（メニュー表示時） */
    .nav-wrapper.is-open {
        right: 0; /* 右からスライドイン */
    }

    /* メインナビゲーションのリンク */
    .main-nav {
        display: flex; /* Flexboxを使い、縦に並べる */
        flex-direction: column;
    }
    .main-nav a {
        padding: 15px 25px;
        border-bottom: 1px solid var(--border-color);
        font-size: 16px;
        text-align: left; /* 左揃えに変更 */
        font-weight: 500;
        color: #333;
    }
    .main-nav a:hover {
        background-color: #f4f7f9;
        text-decoration: none;
    }
    .main-nav a.active {
        color: var(--primary-color);
        background-color: #e9f2ff;
    }
    
    /* ユーザーメニュー */
    .user-menu {
        padding: 25px;
        text-align: left; /* 左揃えに変更 */
        font-size: 14px;
        display: flex;
        flex-direction: column; /* 縦に並べる */
        align-items: flex-start; /* 左揃え */
        gap: 15px; /* 各項目間の余白 */
    }
    .user-menu .separator {
        display: none; /* 区切り線を非表示に */
    }
    .user-menu .settings-link,
    .user-menu .logout-link {
        font-size: 16px;
        color: var(--light-text-color);
    }
    
    /* ハンバーガーボタンがis-openになった時のアニメーション（バツ印に） */
    .hamburger-menu.is-open {
        position: fixed; /* メニューに合わせて位置を固定 */
        top: 10px;
        right: 10px;
    }
    .hamburger-menu.is-open .hamburger-line { background-color: #333; }
    .hamburger-menu.is-open .hamburger-line:nth-child(1) { transform: translateY(8px) rotate(45deg); }
    .hamburger-menu.is-open .hamburger-line:nth-child(2) { opacity: 0; }
    .hamburger-menu.is-open .hamburger-line:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

    /* 背景オーバーレイ */
    body::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.4s, visibility 0.4s;
        z-index: 99;
    }
    body.no-scroll::after {
        opacity: 1;
        visibility: visible;
    }
    body.no-scroll {
        overflow: hidden; /* 背景のスクロールを禁止 */
    }
}

/* --- ページヘッダーのレスポンシブ対応 --- */
@media (max-width: 767px) {
    .page-header {
        flex-direction: column; /* 要素を縦並びにする */
        align-items: flex-start; /* 全体を左揃えにする */
        gap: 8px; /* タイトルとリンクの間に少し余白を設ける */
    }
}

/* --- チャット一覧共通スタイル --- */
.chat-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 800px;
    margin: 0 auto;
}
.chat-list-item {
    display: flex;
    align-items: center;
    padding: 15px;
    background-color: #fff;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.chat-list-item:hover {
    background-color: #f8f9fa;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.chat-list-item.unread {
    background-color: #e9f2ff;
    border-left: 5px solid var(--primary-color);
    padding-left: 10px;
}
.avatar {
    margin-right: 15px;
    flex-shrink: 0;
}
.avatar img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover; /* 画像が潰れないように */
    background-color: #e9ecef;
}
.chat-info {
    flex-grow: 1;
    overflow: hidden; /* はみ出したテキストを省略するため */
}
.chat-info-header {
    margin-bottom: 5px;
}
.parent-name, .teacher-name {
    font-weight: 700;
    font-size: 16px;
}
.student-names, .school-name {
    font-size: 14px;
    color: var(--light-text-color);
    font-weight: normal;
}
.last-message {
    font-size: 14px;
    color: var(--light-text-color);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.unread-badge {
    background-color: #dc3545;
    color: #fff;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    margin-left: 15px;
    flex-shrink: 0;
}

/* --- チャット画面共通スタイル --- */
.chat-room {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 220px); /* 画面の高さに応じて調整 */
    min-height: 450px;
    background-color: #e9ecef;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 20px;
}
.chat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.no-message {
    text-align: center;
    color: var(--light-text-color);
    margin-top: 30px;
}
.message-bubble-wrapper {
    display: flex;
    max-width: 80%;
}
.message-bubble-wrapper.outgoing {
    justify-content: flex-end;
    align-self: flex-end;
}
.message-bubble-wrapper.incoming {
    justify-content: flex-start;
    align-self: flex-start;
}
.message-bubble {
    padding: 10px 15px;
    border-radius: 18px;
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.message-bubble-wrapper.outgoing .message-bubble {
    background-color: #d1e7fd;
    border-bottom-right-radius: 4px;
}
.message-bubble-wrapper.incoming .message-bubble {
    background-color: #fff;
    border-bottom-left-radius: 4px;
}
.message-content {
    /* white-space: pre-wrap; */ /* ← この行を削除、またはコメントアウトします */
    word-wrap: break-word; /* 長い単語の折り返し */
    font-size: 15px;
}
.message-timestamp {
    font-size: 11px;
    color: #6c757d;
    text-align: right;
    margin-top: 5px;
}
.message-form {
    display: flex;
    padding: 15px;
    background-color: #fff;
    border-top: 1px solid #dee2e6;
    flex-shrink: 0;
}
.message-form textarea {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #ced4da;
    border-radius: 20px;
    resize: none;
    height: 42px; /* 初期高さ */
    line-height: 1.5;
    font-size: 15px;
    transition: height 0.2s;
    font-family: inherit;
}
.message-form textarea:focus {
    outline: none;
    border-color: #86b7fe;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}
.message-form button {
    flex-shrink: 0;
    margin-left: 10px;
    padding: 0 25px;
    border: none;
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
}