/* --- 全局与变量 --- */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --navnext-color: #1abd4c;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --gradient-blue: linear-gradient(90deg, #007bff 0%, #0056b3 100%);
}

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: #f4f7f6;
    color: var(--dark-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    width: 95%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
}

main {
    flex-grow: 1;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* --- 页眉 --- */
.main-header {
    background: var(--gradient-blue);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.main-header nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.main-header .logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
}
.main-header .nav-links a {
    color: white;
    margin-left: 20px;
    font-size: 1rem;
    transition: opacity 0.2s;
}
.main-header .nav-links a:hover {
    opacity: 0.8;
    text-decoration: none;
}

/* --- 页脚 --- */
.main-footer {
    background-color: var(--dark-color);
    color: #ccc;
    padding: 1.5rem 0;
    text-align: center;
    font-size: 0.9rem;
}
.main-footer p {
    margin: 0.5rem 0;
}
.main-footer a {
    color: white;
}

/* --- 按钮 --- */
.button-primary, .button-secondary, .button-danger {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s;
}
.button-primary { background-color: var(--primary-color); }
.button-primary:hover { background-color: #0056b3; }
.button-secondary { background-color: var(--secondary-color); }
.button-secondary:hover { background-color: #5a6268; }
.button-danger { background-color: var(--danger-color); }
.button-danger:hover { background-color: #c82333; }


/* --- 欢迎页 --- */
/*
    这是修改过的部分。
    - .overlap-container 用于创建定位上下文。
    - .welcome-image 和 .icon-large 使用绝对定位在其中重叠。
*/
.welcome-container {
    text-align: center;
    padding: 2rem 1rem;
}

.overlap-container {
    position: relative; /* 为绝对定位的子元素提供基准 */
    width: 200px;
    height: 200px;
    margin: 0 auto 2rem; /* 水平居中并与下方标题产生间距 */
}

.welcome-image {
    position: absolute;
    top: -5%;
    left: 0;
    width: 100%;
    height: 105%;
    z-index: 10; /* 提高图片层级，让它在上面 */
}

.welcome-image img {
    width: 100%;
    height: 105%;
    object-fit: cover;
    border-radius: 15px;
    opacity: 1; /* 关键：给图片添加透明度，这样才能看到下面的灯泡 */
}

.welcome-container .icon-large {
    position: absolute;
    top: 43%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 5rem;
    margin-bottom: 0;
    z-index: 5;
    text-shadow: 0 0 15px rgba(0,0,0,0.5);
}

.welcome-container h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.welcome-container .welcome-text {
    font-size: 1.2rem;
    color: #555;
    max-width: 600px;
    margin: 0 auto 2rem auto;
}
/* --- 欢迎页样式结束 --- */

/* --- 预约日历页 --- */
.schedule-header {
    text-align: center;
    margin-bottom: 2rem;
}
.schedule-header h2 { font-size: 2rem; }
.date-navigation a {
    margin: 0 15px;
}
.date-range {
    font-size: 1.1rem;
    color: var(--secondary-color);
    margin-top: 0.5rem;
}

.table-container {
    overflow: auto;
    max-height: 70vh;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #ddd;
}

.schedule-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    /* 桌面端默认使用固定布局，确保列宽稳定 */
    table-layout: fixed;
    min-width: 900px;
}

.schedule-table th, .schedule-table td {
    border-bottom: 1px solid #ddd;
    border-right: 1px solid #ddd;
    padding: 4px 8px;
    text-align: center;
    vertical-align: middle;
    font-size: 0.95rem;
}
.schedule-table th {
    background-color: var(--light-color);
    font-weight: normal;
}

/* 固定行列的核心样式 */
.sticky-header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--light-color);
}
.sticky-column {
    position: -webkit-sticky;
    position: sticky;
    left: 0;
    z-index: 1;
    background-color: #ffffff;
}
thead th.sticky-header:first-child {
    left: 0;
    z-index: 3;
}


.schedule-table td {
    cursor: pointer;
    transition: background-color 0.2s;
    word-break: break-all;
}

.schedule-table td:hover {
    background-color: #e9ecef;
}
.schedule-table td:empty::after {
    content: "+";
    color: #ccc;
    font-size: 1.2rem;
}

.special-day {
    background-color: var(--warning-color) !important;
    color: var(--dark-color);
}
.special-day-name {
    display: block;
    font-size: 0.8rem;
    font-weight: bold;
    margin-top: 4px;
}

/* --- 模态框 --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.close-button {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
}
.close-button:hover { color: #333; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; }
.form-group input, .form-group textarea {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: inherit;
}
.form-actions { display: flex; justify-content: space-between; }
.modal-message { margin-top: 1rem; text-align: center; }

/* --- 日志页 --- */
.logs-table {
    width: 100%;
    border-collapse: collapse;
}
.logs-table th, .logs-table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
}
.logs-table th { background-color: var(--light-color); }
.log-create { background-color: #eaf7ed; }
.log-update { background-color: #fff8e1; }
.log-delete { background-color: #fbe9e7; }

/* --- 管理员页 --- */
.admin-form, .admin-panel {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.admin-section {
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    margin-bottom: 1.5rem;
}
.collapsible {
    background-color: var(--light-color);
    color: var(--dark-color);
    cursor: pointer;
    padding: 15px;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.collapsible:hover { background-color: #e2e6ea; }
.collapsible-content {
    padding: 15px;
    display: none; /* 改为 none，默认折叠 */
    overflow: hidden;
}
.info-box {
    background-color: #e7f3fe;
    border-left: 4px solid var(--primary-color);
    padding: 10px 15px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.inline-form, .delete-form {
    display: inline-flex;
    gap: 10px;
    align-items: center;
}
.item-list { list-style: none; padding-left: 0; }
.item-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #eee;
}
.time-slot-item {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.time-slot-item input { flex-grow: 1; }

/* --- 响应式设计 --- */
@media (max-width: 768px) {
    .main-header nav {
        flex-direction: column;
        gap: 10px;
    }
    .main-header .nav-links {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 15px;
    }
    .main-header .nav-links a { margin-left: 0; }

    /* 移动端，表格布局变为自动，以更好地适应屏幕 */
    .schedule-table {
        table-layout: auto;
        min-width: 100%;
    }

    /* 更积极地压缩表格以适应移动端 */
    .schedule-table th,
    .schedule-table td {
        padding: 2px 0; /* 极大减小行高和边距 */
        font-size: 0.8rem;
        line-height: 1.3; /* 压缩行高 */
        white-space: nowrap; /* 防止内容换行，配合 auto 布局 */
    }

    h1 { font-size: 2rem; }
    h2 { font-size: 1.6rem; }

    /* 移动端表头缩写样式 */
    .schedule-table th .full-date-display {
        display: none;
    }

    .schedule-table th[data-abbr-date]::before {
        content: attr(data-abbr-date);
        font-weight: bold;
        display: block;
        margin-bottom: 2px;
    }
}

/* --- 公告栏 (首页) --- */
.notice-board {
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.notice-board-title {
    margin-top: 0;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--dark-color);
    font-weight: 500;
}
.notice-item {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 5px;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.notice-item p {
    margin: 0;
    white-space: pre-wrap;
}
.notice-item:last-child {
    margin-bottom: 0;
}

/* --- 公告管理 (后台) --- */
.notice-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid #eee;
    border-radius: 5px;
    margin-bottom: 1.5rem;
}
.notice-form textarea {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    resize: vertical;
    font-family: inherit;
}
.notice-form input[type="color"] {
    width: 100px;
    height: 40px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
}

.notice-item-admin {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px;
}
.notice-preview {
    width: 25px;
    height: 25px;
    border-radius: 4px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}
.notice-text-admin {
    flex-grow: 1;
    word-break: break-all;
    white-space: pre-wrap;
}

/* --- 日期导航按钮样式 --- */
.date-navigation a {
    padding: 8px 15px;
    border: 1px solid var(--primary-color);
    border-radius: 5px;
    color: var(--primary-color);
    text-decoration: none;
    transition: all 0.2s ease-in-out;
    margin: 0 5px;
}
.date-navigation a:hover {
    background-color: var(--navnext-color);
    color: white;
}
.date-navigation a[href$="/schedule"], .date-navigation a:first-child[href*="start_date="] + a {
    border-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: bold;
}
.date-navigation a[href$="/schedule"]:hover, .date-navigation a:first-child[href*="start_date="] + a:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Flash 消息样式 */
.flash-error, .flash-danger {
    color: #721c24;
    background-color: #f8d7da;
    border-color: #f5c6cb;
    padding: .75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: .25rem;
}
.flash-info {
    color: #0c5460;
    background-color: #d1ecf1;
    border-color: #bee5eb;
    padding: .75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: .25rem;
}

/* --- Responsive Title Word Breaking --- */

/* Center the title text when it breaks into multiple lines */
.title-break {
  text-align: center;
}

/* By default, spans are inline and have no extra space.
   white-space: nowrap prevents breaking *within* a part like "早课共修". */
.title-break span {
  white-space: nowrap;
}

/* First breakpoint: Force a line break after "密行组" */
@media (max-width: 420px) {
  .title-break .part-1::after {
    content: "\A"; /* This is a CSS newline character */
    white-space: pre; /* This tells the browser to respect the newline */
  }
}

/* Second breakpoint: Force a line break after "早课共修" */
@media (max-width: 300px) {
  .title-break .part-2::after {
    content: "\A"; /* Add another newline */
    white-space: pre;
  }
}

/* Last resort: shrink font size on very narrow screens */
@media (max-width: 280px) {
    .welcome-container h1.title-break,
    .schedule-header h2.title-break {
        font-size: clamp(1.2rem, 10vw, 1.6rem);
        line-height: 1.3;
    }
}