/* 龙门山猛禽迁徙观察 — 图表小部件样式 v1.0
 * 所有选择器使用 .bw- 前缀，避免与主题冲突
 * 配色跟随 html.light / html.dark */

.bw-widget {
    width: 100%;
    max-width: var(--theme-normal-container-max-width, 1290px);
    margin: 0 auto 20px;
    padding: 12px 14px 10px;
    border: 1px solid rgba(128, 128, 128, 0.18);
    border-radius: 10px;
    background: rgba(128, 128, 128, 0.04);
    box-sizing: border-box;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

.bw-widget * { box-sizing: border-box; }

/* ===== 头部 ===== */
.bw-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.bw-head-left { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; min-width: 0; }

.bw-title {
    margin: 0;
    font-size: 1.05em;
    font-weight: 600;
    line-height: 1.3;
    /* 标题层级现在是 h5（站点目录插件要提取层级）。主题常对 h1-h6 统一加
       大写作 / 字距 / 字体族，这里显式还原，保证换成 h5 后视觉与原来一致 */
    text-transform: none;
    letter-spacing: normal;
    font-family: inherit;
}

.bw-sub {
    font-size: 0.82em;
    opacity: 0.65;
    white-space: nowrap;
}

.bw-png {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 2px 4px;
    opacity: 0.6;
    color: inherit;
}
.bw-png:hover { opacity: 1; }

.bw-note {
    font-size: 0.8em;
    opacity: 0.7;
    margin: 0 0 4px;
}

.bw-canvas { width: 100%; }

.bw-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 0.9em;
    opacity: 0.6;
}

/* ===== 移动端横屏阅读：部件整体顺时针旋转 90° =====
 * 具体尺寸由 chart-widgets.js 的 applyRotation() 按视口计算后内联设置，
 * 这里只保证外层占位宽度与页面一致 */
.bw-rot-wrap { width: 100%; }

/* ===== 物候指标表（[birding_species_stats]）=====
 * ⚠️ 站点主题有自定义 CSS：`table tbody { display: block }`（见 display.css 里
 *    .birding-summary-table 的注释），thead 与 tbody 会各算各的列宽 → 表头与数据列错位。
 *    必须把 table / thead / tbody / tr / th / td 的 display 全部重置回表格模型并加 !important。
 */
.bw-table {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    display: table !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    font-size: 0.88em;
}

.bw-table thead {
    display: table-header-group !important;
    width: auto !important;
    background-color: transparent !important;
    color: inherit !important;
}

.bw-table tbody {
    display: table-row-group !important;
    width: 100% !important;
    max-height: none !important;
    overflow-y: visible !important;
}

.bw-table tr {
    display: table-row !important;
    width: 100% !important;
}

.bw-table th,
.bw-table td {
    display: table-cell !important;
    box-sizing: border-box !important;
    float: none !important;
    position: static !important;
    margin: 0 !important;
    padding: 6px 8px !important;
    border: none !important;
    border-bottom: 1px solid rgba(128, 128, 128, 0.18) !important;
    font-family: inherit !important;
    font-size: inherit !important;
    font-weight: normal !important;
    line-height: 1.5 !important;
    vertical-align: middle !important;
    text-align: left;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* 首列给名称，其余列由 fixed 布局均分剩余宽度 */
.bw-table th:first-child,
.bw-table td:first-child {
    width: 22% !important;
    text-align: left !important;
}

/* 表头吸顶：表格在旋转视图内纵向滚动时仍能看到列名
 * （背景需不透明，否则内容会透出来；站点若定义了 --bw-surface 则跟随主题） */
.bw-table thead th {
    position: sticky !important;
    top: 0;
    z-index: 2;
    background: var(--bw-surface, #f7f7f8) !important;
    font-weight: 600 !important;
    opacity: 0.85;
}
html.dark .bw-table thead th { background: var(--bw-surface, #26262b) !important; }
.bw-table th.bw-num,
.bw-table td.bw-num {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.bw-table tbody tr:last-child td { border-bottom: none !important; }

/* 观察点当季数据表（[birding_point_stats]）：鸟种列更宽，数字列均分 */
.bw-ptable th:first-child,
.bw-ptable td:first-child { width: 40% !important; }
.bw-ptable tbody tr:hover td { background: rgba(128, 128, 128, 0.08) !important; }
/* 合计行吸底：与表头一样固定在可视区（表格内部滚动时始终可见） */
/* 表格「滚动区 + 固定底栏」布局
 * ⚠️ 合计行不能用 <tfoot> + position:sticky:bottom —— 浏览器对 table-row-group 的
 *    bottom 吸附支持很差（thead 的 top 吸附却成熟，所以表头看起来正常）。
 *    这里让底栏在**结构上**不参与滚动：box 用 flex 纵向排布，滚动区 flex:1，底栏 flex:0。 */
.bw-ptable-box {
    display: flex !important;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
.bw-ptable-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.bw-ptable-foot {
    flex: 0 0 auto;
    width: 100%;
}
.bw-ptable-foot td {
    font-weight: 600 !important;
    border-top: 2px solid rgba(128, 128, 128, 0.28) !important;
    border-bottom: none !important;
    background: var(--bw-surface, #f7f7f8) !important;
}
html.dark .bw-ptable-foot td { background: var(--bw-surface, #26262b) !important; }
.bw-zero { opacity: 0.4; }

/* ===== 监测日天气表（[birding_weather]）=====
 * 画布固定高度：摘要条固定，表体内部滚动（与 point_stats 的「滚动区 + 固定底栏」同思路） */
.bw-wx-box {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
.bw-wx-summary {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    padding: 2px 2px 9px;
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(128, 128, 128, 0.18);
    font-size: 0.86em;
}
.bw-wx-item { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.bw-wx-item > span { opacity: 0.6; }
.bw-wx-item > b { font-weight: 600; font-variant-numeric: tabular-nums; }
.bw-wx-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.bw-wxtable th:first-child,
.bw-wxtable td:first-child { width: 18% !important; }
.bw-wxtable th:nth-child(2),
.bw-wxtable td:nth-child(2) { width: 14% !important; }
.bw-wxtable th:nth-child(3),
.bw-wxtable td:nth-child(3) { width: 20% !important; }
.bw-wxtable th:nth-child(4),
.bw-wxtable td:nth-child(4) { width: 12% !important; }
.bw-wxtable th:nth-child(5),
.bw-wxtable td:nth-child(5) { width: 14% !important; }
.bw-wxtable th:nth-child(6),
.bw-wxtable td:nth-child(6) { width: 22% !important; }

/* 窄屏放不下时横向滚动，而不是被挤压 */
.bw-canvas { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* 细滚动条（旋转视图下表格需要纵向滚动，粗滚动条太抢眼） */
.bw-canvas::-webkit-scrollbar { width: 6px; height: 6px; }
.bw-canvas::-webkit-scrollbar-track { background: transparent; }
.bw-canvas::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.45);
    border-radius: 3px;
}
.bw-canvas::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.7); }

/* ===== 猛禽档案卡（[birding_raptor_profile]）=====
 * 样式全部走 CSS 变量，短代码参数会注入到根元素 style 上：
 *   --rp-cols        列数（cols）
 *   --rp-min         自动列数时的最小卡宽（min_width）
 *   --rp-img         缩略图边长（img_size，card / chip 有效）
 *   --rp-radius      卡片圆角（radius）
 *   --rp-img-radius  图片圆角（img_radius / round）
 *   --rp-gap         卡片间距（gap）
 *   --rp-align       文字对齐（align）
 */
.bw-rp {
    display: grid;
    gap: var(--rp-gap, 10px);
    grid-template-columns: 1fr;
    text-align: var(--rp-align, left);
}
.bw-rp-grid,
.bw-rp-chip {
    grid-template-columns: repeat(auto-fill, minmax(var(--rp-min, 150px), 1fr));
}
.bw-rp-grid[style*="--rp-cols"],
.bw-rp-chip[style*="--rp-cols"] {
    grid-template-columns: repeat(var(--rp-cols), minmax(0, 1fr));
}

.bw-rp-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid rgba(128, 128, 128, 0.18);
    border-radius: var(--rp-radius, 10px);
    background: rgba(128, 128, 128, 0.03);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}
.bw-rp-item:hover {
    border-color: rgba(128, 128, 128, 0.4);
    background: rgba(128, 128, 128, 0.08);
}

/* 1:1 图片（img 绝对定位盖住首字占位；加载失败则露占位） */
.bw-rp-img {
    position: relative;
    flex: 0 0 auto;
    overflow: hidden;
    border-radius: var(--rp-img-radius, 8px);
    background: rgba(128, 128, 128, 0.12);
    aspect-ratio: 1 / 1;
}
.bw-rp-img img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* 盖住同层的首字占位 —— .bw-rp-ph 在 DOM 里排在 img 之后，不加这行会被压在图上面 */
    z-index: 1;
}
.bw-rp-img img.bw-rp-img-fail { display: none; }
.bw-rp-ph {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    font-weight: 600;
    opacity: 0.3;
    user-select: none;
}
.bw-rp-body { min-width: 0; flex: 1 1 auto; }
.bw-rp-name {
    margin: 0;
    font-size: 1.02em;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bw-rp-meta {
    margin: 6px 0 0;
    font-size: 0.85em;
    opacity: 0.72;
}
.bw-rp-meta b { font-size: 1.35em; font-weight: 600; opacity: 1; }
.bw-rp-none { opacity: 0.55; font-style: normal; }

/* A · 横排大卡 */
.bw-rp-card .bw-rp-img { width: var(--rp-img, 84px); }

/* B · 宫格卡（图上文下） */
.bw-rp-grid .bw-rp-item {
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    overflow: hidden;
    gap: 0;
}
/* 宫格图：默认铺满列宽；设了 img_size 就变成固定尺寸居中（可配合 round 做圆图） */
.bw-rp-grid .bw-rp-img {
    width: var(--rp-img, 100%);
    margin-left: auto;
    margin-right: auto;
    border-radius: var(--rp-img-radius, 0);
}
.bw-rp-grid .bw-rp-body { padding: 10px 12px; }
.bw-rp-grid .bw-rp-name { white-space: normal; }

/* C · 紧凑条（小圆图，一行多个） */
.bw-rp-chip .bw-rp-item { padding: 8px 10px; gap: 8px; }
.bw-rp-chip .bw-rp-img {
    width: var(--rp-img, 40px);
    border-radius: var(--rp-img-radius, 50%);
}
.bw-rp-chip { gap: var(--rp-gap, 8px); }
.bw-rp-chip .bw-rp-ph { font-size: 1.05em; }
.bw-rp-chip .bw-rp-name { font-size: 0.92em; }
.bw-rp-chip .bw-rp-meta { margin-top: 2px; font-size: 0.8em; }
.bw-rp-chip .bw-rp-meta b { font-size: 1em; }

/* ===== 单物种 + rhythm="1"：节律折线装在卡片内，占右侧剩余宽度、与缩略图等高 ===== */
.bw-rp-rhythm {
    /* flex-basis:0 —— 让槽宽只由弹性分配决定、与内容无关，
       这样「渲染前测量的宽度」就等于「塞入 SVG 后的实际宽度」，图表才能精确等高 */
    flex: 1 1 0;
    min-width: 0;
}
/* 内联 SVG：尺寸按实际像素绘制（width/height 已与卡片对齐），此处只做兜底缩放 */
.bw-rh-svg { display: block; width: 100%; height: auto; }
/* 带节律图时：正文列按内容宽度即可，剩余宽度全部让给图表（否则两者平分、左侧空一大片） */
.bw-rp-item-rhy .bw-rp-body { flex: 0 1 auto; }
.bw-rh-sep { stroke: rgba(128, 128, 128, 0.22); stroke-width: 1; stroke-dasharray: 3 3; }
.bw-rh-axis { stroke: rgba(128, 128, 128, 0.45); stroke-width: 1; }
.bw-rh-tick { stroke: rgba(128, 128, 128, 0.35); stroke-width: 1; }
/* 区间带（点际 / 年际离散）→ 淡线（各点 / 各年·季）→ 主曲线 → 数据点，逐层加重 */
.bw-rh-band { fill: #5b8ff9; opacity: 0.16; stroke: none; }
.bw-rh-faint { fill: none; stroke: #5b8ff9; stroke-width: 1; opacity: 0.28; }
.bw-rh-line { fill: none; stroke: #5b8ff9; stroke-width: 2; stroke-linecap: round; }
.bw-rh-dot { fill: #5b8ff9; stroke: #fff; stroke-width: 1.2; }
html.dark .bw-rh-dot { stroke: #1b1e24; }
/* 峰值候：略大 + 换色，一眼看到过境高峰 */
.bw-rh-dot.bw-rh-peak { fill: #e8684a; }
.bw-rh-xtick { font-size: 11px; fill: rgba(128, 128, 128, 0.95); text-anchor: middle; }
.bw-rh-tag { font-size: 9px; fill: rgba(128, 128, 128, 0.9); }

/* 窄屏：节律图换到卡片内第二行、占满整宽 */
@media (max-width: 700px) {
    .bw-rp-item { flex-wrap: wrap; }
    .bw-rp-rhythm { flex: 1 1 100%; margin-top: 8px; }
}

@media (max-width: 480px) {
    .bw-rp-grid,
    .bw-rp-chip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bw-rp-card .bw-rp-img { width: var(--rp-img, 68px); }
}

/* ===== iOS 导出保底浮层：直接展示成图，长按存相册 ===== */
#bw-img-overlay { position: fixed; inset: 0; z-index: 99999; }
#bw-img-overlay .bw-ov-back {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
}
#bw-img-overlay .bw-ov-box {
    position: absolute;
    top: 10px; right: 10px; bottom: 10px; left: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    overflow: auto;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
html.dark #bw-img-overlay .bw-ov-box { background: #1b1e24; color: #e9ecef; }
#bw-img-overlay .bw-ov-tip { margin: 0; font-size: 13px; line-height: 1.5; opacity: 0.75; }
#bw-img-overlay img { display: block; width: 100%; border-radius: 6px; }
#bw-img-overlay .bw-ov-close {
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: rgba(128, 128, 128, 0.22);
    color: inherit;
    font-size: 14px;
    cursor: pointer;
}

/* ===== 选择器 ===== */
.bw-selector {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* [birding_date_range]：拆出来的独立日期控件不吸顶 ——
   否则与 [birding_selector] 两个 sticky 都停在 top:0，会互相遮挡 */
.bw-date-range { position: static; }

.bw-sel-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.bw-sel-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    min-width: 0;
}

.bw-sel-item > span { opacity: 0.7; white-space: nowrap; }

.bw-sel-item select,
.bw-sel-item input[type="date"] {
    padding: 5px 10px;
    border: 1px solid rgba(128, 128, 128, 0.4);
    border-radius: 6px;
    font-size: 0.95em;
    font-family: inherit;
    color: inherit;
    background: rgba(128, 128, 128, 0.06);
    max-width: 100%;
}

.bw-sel-item.bw-date input { min-width: 130px; }

.bw-btn {
    padding: 5px 12px;
    border: 1px solid rgba(128, 128, 128, 0.4);
    border-radius: 6px;
    background: rgba(128, 128, 128, 0.06);
    color: inherit;
    font-size: 0.85em;
    font-family: inherit;
    cursor: pointer;
}
.bw-btn:hover { background: rgba(128, 128, 128, 0.16); }
.bw-sum-range { opacity: 0.7; font-size: 0.92em; }

.bw-summary {
    margin: 4px 0 0;
    font-size: 0.88em;
    opacity: 0.85;
}

/* ===== 暗色 ===== */
html.dark .bw-widget {
    border-color: rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.04);
}

html.dark .bw-sel-item select,
html.dark .bw-sel-item input[type="date"] {
    border-color: rgba(255, 255, 255, 0.24);
    background: rgba(255, 255, 255, 0.06);
    color-scheme: dark;
}

/* ===== 移动端 ===== */
@media (max-width: 768px) {
    .bw-widget { padding: 10px 10px 8px; border-radius: 8px; }
    .bw-selector { position: static; }
    .bw-title { font-size: 1em; }
    .bw-sel-row { gap: 8px; }
    .bw-sel-item { flex: 1 1 100%; }
    .bw-sel-item.bw-date { flex: 1 1 calc(50% - 4px); }
    .bw-sub { font-size: 0.76em; }
    .bw-wx-summary { gap: 3px 10px; font-size: 0.8em; padding-bottom: 8px; }
    .bw-wxtable { font-size: 0.8em; }
    .bw-wxtable th,
    .bw-wxtable td { padding: 5px 4px !important; }
}

/* ===== 打印 ===== */
@media print {
    .bw-selector { position: static; }
    .bw-png { display: none; }
}
