/* ===== EPG 节目单时间轴（浅色主题，复刻参考稿） ===== */
:root {
  --ch-w: 190px;      /* 频道列宽 */
  --hour-w: 120px;    /* 每小时格宽 */
  --row-h: 56px;      /* 频道行高 */
  --tick-h: 30px;     /* 时间刻度行高 */
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e0e0e0;
  --divider: #e8e8e8;
  --text: #333333;
  --text-sub: #999999;
  --text-ch: #555555;
  --tick-text: #aaaaaa;
  --accent: #e60000;       /* 当前时间线 */
  --live-bg: #dce4f8;      /* 播出中卡片背景 */
  --live-bar: #4a5fc1;     /* 播出中卡片底边 */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  z-index: 100;
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.brand i {
  font-style: normal; font-size: 12px; font-weight: 400;
  color: var(--text-sub); margin-left: 6px;
}
.stats { color: var(--text-sub); font-size: 12px; white-space: nowrap; }
.flex-spacer { flex: 1; }

.date-nav { display: flex; align-items: center; gap: 6px; }
.date-nav button {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  width: 28px; height: 28px; border-radius: 4px; cursor: pointer;
  font-size: 15px; line-height: 1;
}
.date-nav button.ghost { width: auto; padding: 0 10px; font-size: 12px; }
.date-nav button:hover { border-color: #bbb; background: #fafafa; }
#dateInput {
  border: 1px solid var(--border); border-radius: 4px;
  height: 28px; padding: 0 8px; font-size: 12px; color: var(--text);
  font-family: inherit;
}

button.primary {
  border: none; background: #e60000; color: #fff;
  height: 28px; padding: 0 14px; border-radius: 4px;
  font-size: 12px; cursor: pointer; font-family: inherit;
}
button.primary:hover { background: #c70000; }
button.primary:disabled { background: #d0d0d0; cursor: not-allowed; }

.admin-link {
  color: var(--text-sub); font-size: 12px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 4px;
  height: 28px; display: inline-flex; align-items: center; padding: 0 12px;
}
.admin-link:hover { color: #e60000; border-color: #e60000; }

/* 顶栏「接口复制」按钮（外观与 .admin-link 一致） */
.top-link {
  border: 1px solid var(--border); background: #fff; color: var(--text-sub);
  border-radius: 4px; height: 28px; padding: 0 12px;
  font-size: 12px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.top-link:hover { color: #e60000; border-color: #e60000; }

/* ===== 接口地址弹窗 ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 250;            /* 位于详情浮层之上、toast 之下 */
  background: rgba(0, 0, 0, .35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-mask[hidden] { display: none; }
.api-modal {
  width: min(560px, calc(100vw - 32px));
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .18);
  padding: 16px 18px 18px;
}
.api-head { display: flex; align-items: center; }
.api-head b { font-size: 15px; flex: 1; }
#apiModalClose {
  cursor: pointer; color: var(--text-sub);
  font-size: 12px; padding: 2px 4px; border-radius: 3px;
}
#apiModalClose:hover { background: #f0f0f0; }
.api-item + .api-item { margin-top: 16px; }
.api-label {
  font-size: 13px; color: var(--text);
  margin: 14px 0 6px; font-weight: 600;
}
.api-modal .api-item:first-child .api-label { margin-top: 10px; }
.api-label span {
  display: block; font-weight: 400;
  font-size: 11px; color: var(--text-sub); margin-top: 2px;
}
.api-row { display: flex; gap: 8px; }
.api-row input {
  flex: 1; min-width: 0; height: 30px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 4px;
  font-size: 12px; color: var(--text); font-family: inherit;
  background: #fafafa; outline: none;
}
.api-row input:focus { border-color: #e60000; }
.api-row .copy-btn { flex-shrink: 0; }

/* ===== 网格视口 ===== */
#viewport {
  flex: 1;
  overflow: auto;
  position: relative;
}
#grid { position: relative; width: calc(var(--ch-w) + 24 * var(--hour-w)); }

/* 时间刻度行（sticky top） */
#headerRow {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  height: var(--tick-h);
  background: var(--bg);
}
.corner {
  position: sticky;
  left: 0;
  z-index: 9;
  width: var(--ch-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding-left: 14px;
  font-size: 12px;
  color: var(--tick-text);
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}
.ticks { display: flex; position: relative; }
.tick {
  width: var(--hour-w);
  flex-shrink: 0;
  font-size: 12px;
  color: var(--tick-text);
  padding: 6px 0 0 6px;
  border-left: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  height: var(--tick-h);
}

/* 频道行 */
.row { display: flex; height: var(--row-h); background: var(--card); }
.row + .row { border-top: 1px solid var(--divider); }
.ch {
  position: sticky;
  left: 0;
  z-index: 5;
  width: var(--ch-w);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 14px;
  color: var(--text-ch);
  font-size: 13px;
  background: var(--card);
  border-right: 1px solid var(--divider);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch .logo {
  width: 22px; height: 22px; border-radius: 3px;
  object-fit: contain; background: #f0f0f0; flex-shrink: 0;
}
.ch .name { overflow: hidden; text-overflow: ellipsis; }

/* overflow hidden：裁掉跨 00:00 / 24:00 边界溢出的卡片部分，保持网格整齐 */
.lane {
  position: relative;
  width: calc(24 * var(--hour-w));
  overflow: hidden;
}

/* 节目卡片：left/width 由 JS 按时间比例定位 */
.prog {
  position: absolute;
  top: 7px;
  bottom: 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  padding: 4px 7px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}
.prog .t {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prog .h {
  font-size: 11px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prog:hover { border-color: #aaa; }
.prog.live {
  background: var(--live-bg);
  border-color: #c4cdf0;
  box-shadow: inset 0 -3px 0 var(--live-bar);
}

/* 当前时间红线 */
#nowLine {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 6;
  width: 0;
  border-left: 1.5px solid var(--accent);
  pointer-events: none;
}
#nowLine i {
  position: absolute;
  top: -1px;
  left: -4.5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

/* ===== 空态 ===== */
#emptyState {
  position: sticky;
  left: var(--ch-w);
  margin: 60px 0 0 40px;
  max-width: 420px;
  color: var(--text-sub);
}
#emptyState h3 { color: var(--text); margin-bottom: 8px; font-size: 15px; }

/* ===== 节目详情浮层 ===== */
#popup {
  position: fixed;
  z-index: 200;
  width: 300px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .12);
  padding: 12px 14px;
}
.pop-head { display: flex; align-items: flex-start; gap: 8px; }
.pop-head b { font-size: 14px; flex: 1; line-height: 1.4; }
#popClose {
  cursor: pointer; color: var(--text-sub);
  font-size: 12px; padding: 2px 4px; border-radius: 3px;
}
#popClose:hover { background: #f0f0f0; }
.pop-time { margin-top: 6px; font-size: 12px; color: var(--text-sub); }
.pop-cat {
  margin-top: 6px; display: inline-block;
  background: #f0f2f8; color: #4a5fc1;
  font-size: 11px; padding: 1px 8px; border-radius: 10px;
}
.pop-desc {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.6;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ===== 轻提示 ===== */
#toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  z-index: 300;
  background: rgba(40, 40, 40, .92);
  color: #fff;
  padding: 8px 18px;
  border-radius: 6px;
  font-size: 12px;
}

/* ===== 显示开关（body class 控制，状态存 localStorage） ===== */
body.hide-prog-text .prog .t,
body.hide-prog-text .prog .h { display: none; }
body.hide-icons .ch .logo { display: none; }

#chSearch {
  border: 1px solid var(--border); border-radius: 4px;
  height: 28px; padding: 0 10px; font-size: 12px; color: var(--text);
  font-family: inherit; width: 140px; outline: none;
}
#chSearch:focus { border-color: #e60000; }

/* 搜索命中的频道行高亮 */
.row.hl .ch { background: #fff7e6; color: #d46b08; font-weight: 600; }

.switch {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-sub);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.switch input { accent-color: #e60000; cursor: pointer; margin: 0; }

/* 滚动条 */
#viewport::-webkit-scrollbar { height: 10px; width: 10px; }
#viewport::-webkit-scrollbar-thumb {
  background: #cfcfd4; border-radius: 5px; border: 2px solid var(--bg);
}
#viewport::-webkit-scrollbar-track { background: transparent; }
