/* =========================================
   1. 全域與核心設定 (優先讀取)
   ========================================= */
body {
    margin: 0;
    padding: 0;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    background-color: #fcf8f2;
    color: #4e342e;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding-top: 130px; /* 增加頂部空間，避免被導覽列遮擋 */
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

a { text-decoration: none; color: inherit; transition: 0.3s; }

/* --- 關鍵修正：Modal 預設隱藏 (移到最上方防止失效) --- */
.post-modal, .crop-modal {
    display: none; /* 預設隱藏 */
    position: fixed;
    z-index: 9999;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(62, 39, 35, 0.8);
    justify-content: center;
    align-items: center;
}
.modal-content {
    background: white;
    width: 600px; max-width: 90%; max-height: 85vh;
    border-radius: 12px; padding: 20px;
    overflow-y: auto; position: relative;
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
}
.close-modal { position: absolute; top: 10px; right: 20px; font-size: 2em; cursor: pointer; color: #999; }

/* =========================================
   2. 導覽列 (Navbar) - 米色雙層版
   ========================================= */
.navbar {
    width: 100%;
    background-color: #fffdf5;
    padding: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    box-shadow: 0 4px 10px rgba(139, 115, 85, 0.15);
    z-index: 1000;
    border-bottom: 1px solid #e6d7b9;
}

.nav-top {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    border-bottom: 1px solid #f0e6d2;
    height: 60px;
}

.nav-brand {
    font-size: 1.5em;
    font-weight: bold;
    color: #d4af37 !important;
    text-shadow: 1px 1px 0px rgba(0,0,0,0.05);
}

/* 登出按鈕 (強制樣式) */
.btn-logout {
    background-color: #d7ccc8 !important;
    color: #5d4037 !important;
    padding: 6px 15px !important;
    border-radius: 6px !important;
    font-weight: bold !important;
    font-size: 0.9em !important;
    border: none !important;
    display: inline-block;
    line-height: 1.5;
}
.btn-logout:hover {
    background-color: #bcaaa4 !important;
    color: white !important;
}

.nav-bottom {
    width: 100%;
    background-color: #fffbf5;
    height: 50px;
}

.nav-links {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    margin: 0;
}

.nav-links a {
    flex: 1;
    text-align: center;
    line-height: 50px; /* 垂直置中 */
    font-size: 1em;
    color: #5d4037;
    font-weight: 500;
    border-right: 1px solid #f0e6d2;
}
.nav-links a:last-child { border-right: none; }
.nav-links a:hover { background-color: #fff8e1; color: #d4af37; }

/* =========================================
   3. 版面容器 (Containers)
   ========================================= */
/* 首頁/登入用 */
.container {
    display: flex;
    width: 900px;
    max-width: 95%;
    background: white;
    box-shadow: 0 10px 25px rgba(139, 115, 85, 0.1);
    border-radius: 12px;
    overflow: hidden;
    margin: 0 auto 50px auto;
    border: 1px solid #f3e5f5;
}

/* 話題/活動/宣言用 (單欄) */
.column-layout {
    flex-direction: column !important;
    align-items: center;
    width: 800px;
    max-width: 95%;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    margin: 0 auto; /* 置中 */
    padding-bottom: 50px;
    display: flex;
}

/* 訊息/個人頁用 (特定容器) */
.message-container, .profile-container {
    width: 900px;
    max-width: 95%;
    background: white;
    border-radius: 12px;
    border: 1px solid #f3e5f5;
    box-shadow: 0 5px 20px rgba(139, 115, 85, 0.1);
    margin: 0 auto 30px auto; /* 置中 */
    display: flex;
    overflow: hidden;
}

/* =========================================
   4. 元件 (Buttons & Forms)
   ========================================= */
button, .btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s;
    font-weight: bold;
    display: inline-block;
}

.btn-primary { background: linear-gradient(135deg, #d4af37, #c5a028); color: white; }
.btn-primary:hover { background: linear-gradient(135deg, #eec956, #d4af37); }
.btn-success { background-color: #8bc34a; color: white; }
.btn-danger { background-color: #ef5350; color: white; }
.btn-warning { background-color: #ffca28; color: #5d4037; }
.btn-secondary { background-color: #d7ccc8; color: #5d4037; }
.btn-disabled { background-color: #efebe9; cursor: not-allowed; color: #bdbdbd; }

.btn-submit { padding: 8px 25px; border-radius: 20px; background: linear-gradient(135deg, #8d6e63, #6d4c41); color: white; }
.btn-reply-small { padding: 5px 15px; border-radius: 15px; font-size: 0.9em; background-color: #a1887f; color: white; }
.btn-upload {
    display: inline-flex; align-items: center; gap: 5px;
    background-color: #fffbf5; color: #5d4037; padding: 8px 15px; border-radius: 20px;
    border: 1px solid #d4af37; font-size: 0.9em;
}

input, select, textarea {
    width: 100%; padding: 10px; border: 1px solid #e0e0e0; border-radius: 4px;
    background-color: #fffbf5; color: #4e342e;
}
input:focus, textarea:focus { border-color: #d4af37; outline: none; background-color: white; }

.form-group { margin-bottom: 15px; }
.form-row { display: flex; gap: 15px; }
.form-group.half { flex: 1; }

.text-male { color: #42a5f5 !important; }
.text-female { color: #f06292 !important; }

/* =========================================
   5. 各頁面專屬樣式
   ========================================= */

/* Login / Register */
.info-section { flex: 1.5; padding: 40px; background: linear-gradient(135deg, #fff8e1, #ffecb3); color: #5d4037; } 
.login-section { flex: 1; padding: 40px; display: flex; align-items: center; justify-content: center; }
.register-card { width: 600px; max-width: 100%; margin: 0 auto; background: white; padding: 30px; border-radius: 10px; }

/* Profile */
.profile-sidebar { flex: 0 0 300px; background: #fffbf5; padding: 30px; text-align: center; border-right: 1px solid #f0e6d2; }
.profile-content { flex: 1; padding: 40px; background: white; }
.avatar { width: 150px; height: 150px; object-fit: cover; border-radius: 50%; border: 4px solid white; box-shadow: 0 5px 15px rgba(0,0,0,0.1); margin-bottom: 15px; }
.info-block { margin-bottom: 25px; border-bottom: 1px solid #eee; padding-bottom: 15px; }
.info-block h3 { color: #d4af37; margin-bottom: 10px; }
.photo-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-item { width: 100px; height: 100px; background-size: cover; border-radius: 5px; cursor: pointer; }

/* Messages */
.message-container { height: calc(100vh - 140px); } /* 固定高度 */
.chat-sidebar { width: 280px; flex: 0 0 280px; background: #fffbf5; border-right: 1px solid #f0e6d2; display: flex; flex-direction: column; }
.chat-window { flex: 1; display: flex; flex-direction: column; background: white; }
.sidebar-header { padding: 15px; background: #fff8e1; border-bottom: 1px solid #f0e6d2; font-weight: bold; color: #5d4037; }
.contact-item { padding: 15px; border-bottom: 1px solid #f0f0f0; cursor: pointer; display: flex; align-items: center; }
.contact-item:hover, .contact-item.active { background: #ffecb3; }
.contact-avatar { width: 40px; height: 40px; border-radius: 50%; margin-right: 10px; background: #ddd; }
.chat-header { padding: 10px 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.chat-box { flex: 1; overflow-y: auto; padding: 20px; background: #fcf8f2; }
.message-row { display: flex; margin-bottom: 10px; }
.message-row.sent { justify-content: flex-end; }
.message-row.received { justify-content: flex-start; }
.message-bubble { padding: 10px 15px; max-width: 70%; border-radius: 10px; font-size: 0.95em; position: relative; }
.sent .message-bubble { background: #fff9c4; color: #3e2723; border: 1px solid #fff176; }
.received .message-bubble { background: white; border: 1px solid #eee; }
.chat-input-area { padding: 15px; border-top: 1px solid #eee; display: flex; gap: 10px; }

/* Board & Events */
.board-header-card, .event-header-card { width: 100%; background: white; border-radius: 10px; overflow: hidden; margin-bottom: 20px; border: 1px solid #f3e5f5; box-shadow: 0 5px 15px rgba(0,0,0,0.05); }
.bg-purple, .bg-green, .bg-teal { background: linear-gradient(135deg, #d4af37, #eec956); color: white; padding: 20px; }
.tab-btn { margin-right: 5px; margin-bottom: 5px; border: 1px solid #d4af37; background: white; color: #d4af37; padding: 5px 15px; border-radius: 20px; }
.tab-btn.active { background: #d4af37; color: white; }
.post-creation-card { width: 100%; background: white; padding: 20px; border-radius: 10px; margin-bottom: 20px; border: 1px solid #f3e5f5; }
.desktop-post-card { background: white; border: 1px solid #f0e6d2; margin-bottom: 20px; padding: 20px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.mobile-grid-item { display: none; }

/* Events Grid */
.event-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; width: 100%; }
.event-grid-item { background: white; border-radius: 10px; overflow: hidden; border: 1px solid #f0e6d2; box-shadow: 0 2px 5px rgba(0,0,0,0.05); cursor: pointer; }
.ev-thumb { width: 100%; aspect-ratio: 1/1; background-size: cover; position: relative; }
.ev-content { padding: 10px; }
.ev-status { position: absolute; top: 10px; right: 10px; padding: 3px 8px; border-radius: 4px; color: white; font-size: 0.8em; }
/* 各種狀態的背景色 */
.ev-status.open { background-color: #28a745; }       /* 報名中：綠色 */
.ev-status.processing { background-color: #ff9800; } /* 抽籤/計價：橘色 */
.ev-status.payment { background-color: #009688; }    /* 繳費中：藍綠色 */
.ev-status.active { background-color: #e91e63; }     /* 進行中：桃紅色 (這就是漏掉的) */
.ev-status.finished { background-color: #757575; }   /* 已結束：灰色 (這也是漏掉的) */
.ev-status.cancelled { background-color: #333; }     /* 已取消：深黑色 */

/* RWD - Mobile */
@media (max-width: 768px) {
    body { padding-top: 120px; }
    .container, .message-container, .profile-container { 
        width: 100%; max-width: 100%; 
        border-radius: 0; border: none; margin: 0; box-shadow: none; 
        flex-direction: column;
    }
    .profile-sidebar, .chat-sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid #ddd; }
    .chat-window { height: calc(100vh - 180px); } /* 手機版聊天視窗高度調整 */
    .mobile-back-btn { display: block; }
    .chat-sidebar { display: flex; height: calc(100vh - 120px); }
    .message-container.mobile-chat-active .chat-sidebar { display: none; }
    .message-container.mobile-chat-active .chat-window { display: flex; height: calc(100vh - 120px); }
    .desktop-post-card { display: none; }
    .mobile-grid-item { display: flex; flex-direction: column; background: white; border: 1px solid #eee; margin-bottom: 10px; border-radius: 8px; overflow: hidden; }
}