/* 基础重置 */
* { box-sizing: border-box; }
body {
    margin: 0;
    padding: 0;
    font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 14px;
    color: #333;
    background: #f7f7f7;
}
a { text-decoration: none; color: inherit; }

/* 容器 */
.container {
    width: 1200px;
    margin: 0 auto;
}

/* 顶部导航占位 */
.site-header {
    background: #7b1fa2;
    color: #fff;
    padding: 12px 0;
}
.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.site-header .logo {
    display: flex;
    align-items: center;
    font-size: 22px;
    font-weight: bold;
}
.site-header .logo img {
    height: 36px;
    margin-right: 10px;
}
.top-nav a {
    color: #fff;
    margin-left: 28px;
    font-size: 15px;
}
.top-nav a.active,
.top-nav a:hover {
    text-decoration: underline;
}

/* 面包屑 */
.main-wrap { padding: 16px 0 40px; }
.breadcrumb {
    font-size: 13px;
    color: #666;
    margin-bottom: 16px;
}
.breadcrumb a { color: #7b1fa2; }

/* 左右布局 */
.layout {
    display: flex;
    gap: 18px;
}

/* 左侧栏目 */
.sidebar {
    width: 180px;
    flex-shrink: 0;
}
.category-tabs {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #fff;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.category-tabs li a,
.category-tabs li span {
    display: block;
    padding: 16px 20px;
    color: #555;
    font-size: 15px;
    border-left: 4px solid transparent;
    transition: all .2s;
}
.category-tabs li a:hover,
.category-tabs li span:hover {
    background: #f3e5f5;
    color: #7b1fa2;
}
.category-tabs li.active a,
.category-tabs li.active span {
    background: #7b1fa2;
    color: #fff;
    border-left-color: #4a148c;
}

/* 右侧内容 */
.content {
    flex: 1;
    background: #fff;
    border-radius: 4px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.content h2 {
    margin: 0 0 18px;
    font-size: 20px;
    color: #7b1fa2;
    border-left: 4px solid #7b1fa2;
    padding-left: 12px;
}

/* 搜索栏 */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding: 14px;
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 4px;
}
.search-title {
    font-weight: bold;
    color: #7b1fa2;
    margin-right: 8px;
}
.search-input {
    width: 170px;
    padding: 7px 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 13px;
}
.search-btn {
    padding: 7px 22px;
    background: #7b1fa2;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
}
.search-btn:hover { background: #6a1b9a; }

/* 信息提示 */
.info-line {
    margin-bottom: 14px;
    color: #666;
    font-size: 13px;
}
.icon-sound {
    display: inline-block;
    width: 16px;
    height: 16px;
    background: #7b1fa2;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 6px;
}

/* 顶部门诊类型筛选按钮（南京院区页面） */
.type-filter {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.type-btn {
    min-width: 80px;
    padding: 6px 16px;
    font-size: 14px;
    color: #7b1fa2;
    background: #fff;
    border: 1px solid #9c27b0;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.type-btn:hover {
    background: #f3e5f5;
}
.type-btn.active {
    color: #fff;
    background: #7b1fa2;
    border-color: #7b1fa2;
}
.type-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 排班表格（双向冻结：表头日期行固定 + 科室/时段/诊间三列固定） */
.schedule-table-wrap {
    overflow: auto;
    max-height: calc(100vh - 340px);
    min-height: 220px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}
.schedule-table {
    width: 100%;
    border-collapse: separate; /* sticky 与 border-collapse: collapse 在部分浏览器不兼容 */
    border-spacing: 0;
    table-layout: fixed;
    font-size: 13px;
}
.schedule-table th,
.schedule-table td {
    border: 1px solid #e0e0e0;
    border-left: none;
    border-top: none;
    padding: 8px;
    vertical-align: top;
    text-align: center;
}
.schedule-table thead th {
    background: #f3e5f5;
    color: #7b1fa2;
    font-weight: bold;
}
/* 冻结表头：垂直滚动时日期行始终固定在表格区顶部 */
.schedule-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    border-top: 1px solid #e0e0e0;
    border-bottom: 1px solid #d1c4e9;
}
/* 恢复最左列与空数据行的上/左边框（改用 separate 后补回） */
.schedule-table th:first-child,
.schedule-table td:first-child {
    border-left: 1px solid #e0e0e0;
}
.schedule-table .no-data {
    border-top: 1px solid #e0e0e0;
}
.schedule-table .date { font-size: 13px; }
.schedule-table .week { font-size: 12px; color: #888; margin-top: 2px; }
.schedule-table .col-dept { width: 110px; background: #fafafa; font-weight: bold; }
.schedule-table .col-slot { width: 60px; background: #fafafa; color: #666; }
.schedule-table .col-clinic { width: 70px; background: #fafafa; color: #666; }
.schedule-table .dept-name {
    background: #fff;
    color: #7b1fa2;
    font-weight: bold;
    vertical-align: middle;
}
.schedule-table .slot-name {
    background: #fafafa;
    color: #666;
}
.schedule-table .clinic-name {
    background: #fafafa;
    color: #666;
}
.schedule-table .cell {
    min-height: 40px;
    text-align: left;
    padding: 6px;
}

/* ---- 冻结左侧列：科室 / 时段 / 诊间（横向滚动时固定） ---- */
.schedule-table .col-dept,
.schedule-table .dept-name {
    position: sticky;
    left: 0;
    z-index: 2;
}
.schedule-table .col-slot,
.schedule-table .slot-name {
    position: sticky;
    left: 110px;   /* 110 = 科室列宽 */
    z-index: 2;
}
.schedule-table .col-clinic,
.schedule-table .clinic-name {
    position: sticky;
    left: 170px;   /* 170 = 110 + 60 */
    z-index: 2;
}
/* 冻结区与滚动区之间加分隔线，提示冻结边界 */
.schedule-table .col-clinic,
.schedule-table .clinic-name {
    border-right: 1px solid #c8c8c8;
}
/* 表头冻结列（交叉区域）始终置顶 */
.schedule-table thead .col-dept,
.schedule-table thead .col-slot,
.schedule-table thead .col-clinic {
    z-index: 4;
}
.doctor-line {
    margin-bottom: 4px;
    line-height: 1.8;
}
.doctor-line .disease {
    color: #666;
    font-size: 12px;
    margin-top: -2px;
}
.doctor-line .name {
    color: #333;
    margin-right: 4px;
}
.doctor-line a.name:hover {
    color: #7b1fa2;
    text-decoration: underline;
}
/* 停诊行：底色与其他行一致，仅保留红色"停诊"标签 */
.tag {
    display: inline-block;
    padding: 0 5px;
    border-radius: 2px;
    font-size: 11px;
    margin-left: 3px;
    color: #fff;
}
.tag.famous { background: #7b1fa2; }
.tag.special { background: #00acc1; }
.tag.stop { background: #e53935; }
/* 门诊类型标记：专/特/多（统一调小，与停诊一致） */
.tag.o1, .tag.o2, .tag.o3, .tag.stop {
    padding: 0 3px;
    font-size: 10px;
    line-height: 1.4;
}
.tag.o1 { background: #7b1fa2; }
.tag.o2 { background: #00acc1; }
.tag.o3 { background: #e67e22; }

.no-data {
    padding: 40px 0;
    color: #999;
    text-align: center;
}

/* 分页 */
.pager-bar {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
}
.page-btn {
    padding: 6px 14px;
    border: 1px solid #7b1fa2;
    color: #7b1fa2;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
}
.page-btn:hover { background: #f3e5f5; }
.page-info { color: #666; }

/* 顶部工具条：翻页 + 图例 同一行 */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 14px;
    border-top: 1px dashed #eee;
    border-bottom: 1px dashed #eee;
    padding: 10px 0;
}
.top-bar .top-pager {
    margin-top: 0;
    justify-content: flex-start;
    flex: 1;
}
.top-bar .legend {
    margin-top: 0;
    justify-content: flex-end;
    flex-shrink: 0;
}



/* 图例 */
.legend {
    margin-top: 18px;
    display: flex;
    gap: 20px;
    justify-content: flex-end;
    align-items: center;
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #666;
}
.legend-item .tag {
    margin: 0;
    width: 14px;
    height: 14px;
    padding: 0;
    flex-shrink: 0;
}

/* 分页按钮（原生 button 样式重置 + 禁用态） */
.page-btn {
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
}
.page-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    background: #f5f5f5;
}
.page-btn:disabled:hover {
    background: #f5f5f5;
}
.search-input:focus {
    outline: none;
    border-color: #7b1fa2;
    box-shadow: 0 0 0 2px rgba(123, 31, 162, .12);
}

/* 加载与错误提示 */
.loading {
    padding: 30px 0;
    text-align: center;
    color: #999;
    font-size: 14px;
}
.error-box {
    margin: 14px 0;
    padding: 12px 16px;
    background: #fdecea;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #c0392b;
    font-size: 13px;
}

/* ==========================================================================
   响应式适配（同时支持网页版与手机端）
   原则：只调整布局与尺寸，不改动 HTML 结构与 JS 渲染逻辑；
        移动端仍使用同一张排班表，靠"左侧三列冻结 + 横向滚动"查看 7 天。
   断点：<=1200px 容器自适应 / <=992px 中等屏 / <=768px 手机 / <=480px 小屏
   ========================================================================== */

/* ---- <=1200px：容器不再定宽，避免小屏出现整页横向滚动 ---- */
@media (max-width: 1200px) {
    .container {
        width: 100%;
        padding-left: 14px;
        padding-right: 14px;
    }
    /* 表格设最小宽度：宽度不足时在表格区域内横向滚动，列不被压扁 */
    .schedule-table {
        min-width: 900px;
    }
}

/* ---- <=992px：搜索栏与工具条允许换行，输入框自适应 ---- */
@media (max-width: 992px) {
    .content { padding: 18px; }
    .search-bar { flex-wrap: wrap; }
    .search-input {
        flex: 1 1 150px;
        width: auto;
        min-width: 0;
    }
    .search-btn { flex: 0 0 auto; }
    .top-bar { flex-wrap: wrap; }
    .top-bar .legend {
        flex: 1 1 100%;
        justify-content: flex-start;
        margin-top: 8px;
    }
}

/* ---- <=768px：手机端（左侧栏目改为顶部横向标签） ---- */
@media (max-width: 768px) {
    body { font-size: 13px; }

    .main-wrap { padding: 10px 0 24px; }

    /* 左右布局 → 上下堆叠 */
    .layout {
        flex-direction: column;
        gap: 10px;
    }

    /* 左侧栏目 → 顶部横向标签栏（少量标签时平分整行） */
    .sidebar { width: 100%; }
    .category-tabs {
        display: flex;
        overflow-x: auto;
    }
    .category-tabs li { flex: 1 0 auto; }
    .category-tabs li a,
    .category-tabs li span {
        padding: 12px 16px;
        text-align: center;
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
        font-size: 14px;
    }
    .category-tabs li.active a,
    .category-tabs li.active span {
        border-left-color: transparent;
        border-bottom-color: #4a148c;
    }

    .content { padding: 14px 12px; }
    .content h2 {
        font-size: 17px;
        margin-bottom: 12px;
        padding-left: 10px;
    }

    /* 搜索栏：标题独占一行，两个输入框并排，按钮整行便于点按 */
    .search-bar {
        padding: 10px;
        gap: 8px;
    }
    .search-title {
        flex: 0 0 100%;
        margin-right: 0;
        font-size: 14px;
    }
    .search-input {
        flex: 1 1 40%;
        padding: 9px 10px;
        font-size: 16px; /* 16px 可避免 iOS 聚焦输入框时自动放大页面 */
    }
    .search-btn {
        flex: 0 0 auto;
        padding: 11px 22px;
        font-size: 15px;
    }

    .info-line { font-size: 12px; }

    /* 顶部工具条：翻页独占一行，图例换行展示 */
    .top-bar {
        padding: 8px 0;
        gap: 8px;
    }
    .top-bar .top-pager {
        flex: 1 1 100%;
        justify-content: space-between;
        gap: 8px;
    }
    .top-bar .legend {
        flex: 1 1 100%;
        gap: 14px;
        margin-top: 0;
    }
    .legend-item { font-size: 12px; }

    /* 翻页按钮加大点击区域 */
    .pager-bar {
        gap: 10px;
        margin-top: 14px;
    }
    .page-btn {
        padding: 9px 12px;
        font-size: 14px;
    }
    .page-info { font-size: 13px; }

    /* 表格区：横向滑动 + iOS 惯性滚动 */
    .schedule-table-wrap {
        max-height: calc(100vh - 320px);
        min-height: 200px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .schedule-table {
        min-width: 864px; /* 192(冻结三列) + 7 × 96(日期列) */
        font-size: 12px;
    }
    .schedule-table th,
    .schedule-table td { padding: 6px 4px; }
    .schedule-table .cell {
        padding: 4px;
        min-height: 36px;
    }
    .schedule-table .date { font-size: 12px; }
    .schedule-table .week { font-size: 11px; }

    /* 冻结三列收窄：科室 84 / 时段 52 / 诊间 56（合计 192px），给日期列留出空间 */
    .schedule-table .col-dept,
    .schedule-table .dept-name { width: 84px; }
    .schedule-table .col-slot,
    .schedule-table .slot-name {
        width: 52px;
        left: 84px;          /* 84 = 科室列宽 */
    }
    .schedule-table .col-clinic,
    .schedule-table .clinic-name {
        width: 56px;
        left: 136px;         /* 136 = 84 + 52 */
    }

    .doctor-line {
        margin-bottom: 3px;
        line-height: 1.6;
    }
    .doctor-line .disease { font-size: 11px; }
}

/* 说明：手机端卡片视图样式见文件末尾"手机端卡片视图"，不放在断点内
   —— 卡片只由 JS 在手机版渲染路径下生成，PC 端不会出现。 */

/* ---- <=480px：小屏手机微调 ---- */
@media (max-width: 480px) {
    .category-tabs li a,
    .category-tabs li span {
        padding: 10px 8px;
        font-size: 13px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .search-btn { flex: 1 1 100%; }
    .schedule-table-wrap { max-height: calc(100vh - 300px); }
}

/* 支持动态视口高度时用 dvh，避免移动端地址栏收起/展开导致表格高度跳动 */
@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .schedule-table-wrap { max-height: calc(100dvh - 320px); }
    }
}

/* ==========================================================================
   手机端卡片视图
   渲染结构：.schedule-cards > .dept-card > .dept-card-head + .dept-card-body
            > .day-block > .day-header + .slot-row > .slot-label + .slot-doctors > .doctor-line
   卡片仅在 schedule.js / schedule-nj.js 判定为手机版时渲染，PC 端不会出现这些元素，
   因此不放进媒体查询（同时保证被宽 iframe 嵌入的手机也能拿到完整卡片样式）。
   ========================================================================== */
/* 卡片容器接管时，外部表格容器不再限高，由整页自然滚动 */
.schedule-table-wrap.is-cards {
    max-height: none;
    min-height: 0;
    border: none;
    overflow: visible;
}
.schedule-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.schedule-cards .cards-empty {
    padding: 30px 0;
    text-align: center;
    color: #999;
    font-size: 13px;
}
.schedule-cards .dept-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .04);
}
.schedule-cards .dept-card-head {
    padding: 10px 14px;
    background: linear-gradient(90deg, #7b1fa2, #9c27b0);
    color: #fff;
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 0.5px;
}
.schedule-cards .dept-card-body { padding: 2px 0; }
.schedule-cards .day-block {
    padding: 8px 0 6px;
    border-top: 1px dashed #eee;
}
.schedule-cards .day-block:first-child { border-top: none; }
.schedule-cards .day-header {
    padding: 0 14px 6px;
    font-size: 13px;
    color: #7b1fa2;
    font-weight: bold;
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.schedule-cards .day-header .day-date { font-size: 13px; }
.schedule-cards .day-header .day-week {
    color: #999;
    font-weight: normal;
    font-size: 12px;
}
.schedule-cards .slot-row {
    padding: 8px 14px;
    border-top: 1px solid #f5f5f5;
}
.schedule-cards .slot-row:first-child { border-top: none; }
.schedule-cards .slot-label {
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}
.schedule-cards .slot-doctors {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.schedule-cards .doctor-line {
    min-height: 28px;
    line-height: 1.5;
    font-size: 14px;
    margin: 0;
    padding: 2px 0;
}
.schedule-cards .doctor-line .name {
    color: #7b1fa2;
    font-weight: 500;
    font-size: 14px;
}
.schedule-cards .doctor-line .disease {
    color: #888;
    font-size: 12px;
    margin-top: 1px;
}
.schedule-cards .doctor-line .tag { font-size: 10px; }

/* ==========================================================================
   手机版布局（按设备判定，覆盖"被官网 iframe 以固定宽度嵌入"的手机场景）
   schedule-mobile.js 在 <head> 中同步判定：窄视口（<=768px）或移动设备 UA 时
   给 <html> 加 is-mobile，本段规则随即生效；PC 浏览器不会有该标记，保持网页版。
   规则与上面的 @media (max-width: 768px) 断点保持一致（断点用于 JS 未生效时兜底），
   修改移动端布局时请两处同步。
   ========================================================================== */
html.is-mobile body { font-size: 13px; }
html.is-mobile .main-wrap { padding: 10px 0 24px; }
/* 内容宽度占满：被官网 iframe 以桌面宽度嵌入时，避免 max-width:768px 居中
   造成左侧大片空白、右侧被截断的视觉偏移。手机视口本身较窄，100% 宽度
   配合 padding 仍保持舒适边距。 */
html.is-mobile .container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding-left: 14px;
    padding-right: 14px;
}
/* 左右布局 → 上下堆叠；左侧栏目 → 顶部横向标签栏 */
html.is-mobile .layout {
    flex-direction: column;
    gap: 10px;
}
html.is-mobile .sidebar { width: 100%; }
html.is-mobile .category-tabs {
    display: flex;
    overflow-x: auto;
}
html.is-mobile .category-tabs li { flex: 1 0 auto; }
html.is-mobile .category-tabs li a,
html.is-mobile .category-tabs li span {
    padding: 12px 16px;
    text-align: center;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    font-size: 14px;
}
html.is-mobile .category-tabs li.active a,
html.is-mobile .category-tabs li.active span {
    border-left-color: transparent;
    border-bottom-color: #4a148c;
}
html.is-mobile .content { padding: 14px 12px; }
html.is-mobile .content h2 {
    font-size: 17px;
    margin-bottom: 12px;
    padding-left: 10px;
}
/* 搜索栏：标题独占一行，输入框自适应，按钮便于点按 */
html.is-mobile .search-bar {
    padding: 10px;
    gap: 8px;
    flex-wrap: wrap;
}
html.is-mobile .search-title {
    flex: 0 0 100%;
    margin-right: 0;
    font-size: 14px;
}
html.is-mobile .search-input {
    flex: 1 1 150px;
    width: auto;
    min-width: 0;
    padding: 9px 10px;
    font-size: 16px; /* 16px 可避免 iOS 聚焦输入框时自动放大页面 */
}
html.is-mobile .search-btn {
    flex: 0 0 auto;
    padding: 11px 22px;
    font-size: 15px;
}
html.is-mobile .info-line { font-size: 12px; }
/* 顶部工具条：翻页与图例各占一行 */
html.is-mobile .top-bar {
    padding: 8px 0;
    gap: 8px;
    flex-wrap: wrap;
}
html.is-mobile .top-bar .top-pager {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: 8px;
}
html.is-mobile .top-bar .legend {
    flex: 1 1 100%;
    justify-content: flex-start;
    gap: 14px;
    margin-top: 0;
}
html.is-mobile .legend-item { font-size: 12px; }
/* 翻页按钮加大点击区域 */
html.is-mobile .pager-bar {
    gap: 10px;
    margin-top: 14px;
}
html.is-mobile .page-btn {
    padding: 9px 12px;
    font-size: 14px;
}
html.is-mobile .page-info { font-size: 13px; }
