:root {
  --bg: #0b0d12;
  --bg-2: #12151d;
  --panel: #171b25;
  --panel-2: #1d2230;
  --line: #262c3d;
  --text: #e8ecf5;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #37e0c0;
  --danger: #ff5c7a;
  --warn: #ffc85c;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 10% -10%, #1a1530 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #0f222a 0%, transparent 55%), var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system,
    "Segoe UI", sans-serif;
  font-size: 14px;
  padding-bottom: 72px;
}

a {
  color: inherit;
}

/* ---------------- 顶栏 / 标签 ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 12, 18, 0.75);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
}

.brand .logo {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #4b8dff);
  font-size: 12px;
  color: #fff;
}

.brand .sep {
  color: var(--muted);
  font-weight: 400;
}

.brand .muted {
  color: var(--muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 22px 0;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 57px;
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(10px);
  z-index: 15;
  overflow-x: auto;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: #fff;
  border-bottom-color: var(--accent);
}

/* ---------------- 布局 ---------------- */

.shell {
  padding: 20px 22px;
  max-width: 1400px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.5px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.card .k {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.card .v {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card .s {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.now-playing {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
}

.now-playing .np-poster {
  width: 96px;
  height: 144px;
  border-radius: 10px;
  object-fit: cover;
  background: #0e1119;
  border: 1px solid var(--line);
  flex: none;
}

.now-playing .np-main {
  min-width: 220px;
  flex: 1;
}

.now-playing .np-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.now-playing .np-sub {
  margin-top: 4px;
}

/* ---------------- 表单 ---------------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 12px 16px;
}

/* 所有栅格表单：允许收缩 + 控件撑满格子（否则 datetime-local / time 会溢出压住右侧控件） */
.form-grid > label,
.seg-grid > label,
.seg-row > label {
  min-width: 0;
}
.form-grid input:not([type='checkbox']):not([type='radio']),
.form-grid select,
.form-grid textarea,
.seg-grid input:not([type='checkbox']):not([type='radio']),
.seg-grid select,
.seg-grid textarea,
.seg-row input:not([type='checkbox']):not([type='radio']),
.seg-row select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  background: #0e1219;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: rgba(124, 92, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.14);
}

input[readonly] {
  color: var(--muted);
}

textarea {
  min-height: 90px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  line-height: 1.5;
}

.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.check input {
  width: auto;
}

.check.inline {
  align-self: end;
  padding-bottom: 9px;
}

.mt {
  margin-top: 10px;
}

.row-gap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.grow {
  flex: 1;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  margin: 8px 0 0;
}

/* ---------------- 按钮 ---------------- */

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  border-color: #3a4460;
}

.btn.small {
  padding: 6px 11px;
  font-size: 12px;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #4b8dff);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.pill.ok {
  color: var(--accent-2);
  border-color: rgba(55, 224, 192, 0.4);
  background: rgba(55, 224, 192, 0.08);
}

.pill.warn {
  color: var(--warn);
  border-color: rgba(255, 200, 92, 0.35);
  background: rgba(255, 200, 92, 0.08);
}

.pill.bad {
  color: var(--danger);
  border-color: rgba(255, 92, 122, 0.35);
  background: rgba(255, 92, 122, 0.08);
}

/* ---------------- 扫描进度 ---------------- */

.scan-status {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: #0e1119;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s ease;
}

/* ---------------- 保存条 ---------------- */

.save-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(10, 12, 18, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  z-index: 30;
}

/* ---------------- 媒体库 ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar input[type="search"],
.toolbar select {
  width: auto;
  min-width: 200px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.series-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: 0.15s;
}

.series-card:hover {
  border-color: #3a4460;
  transform: translateY(-1px);
}

.series-card.selected {
  border-color: rgba(124, 92, 255, 0.8);
  box-shadow: 0 0 0 1px rgba(124, 92, 255, 0.35), 0 10px 30px -18px rgba(124, 92, 255, 0.9);
}

.series-card .poster {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: #0e1119;
  display: block;
}

.series-card .poster-empty {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: linear-gradient(160deg, #1a1f2c, #10141d);
  display: grid;
  place-items: center;
  color: #39405a;
  font-size: 26px;
  font-weight: 700;
}

.series-card .body {
  padding: 9px 10px 11px;
}

.series-card .name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 35px;
}

.series-card .meta {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.series-card .tick {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(8, 10, 14, 0.6);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: transparent;
  backdrop-filter: blur(4px);
}

.series-card.selected .tick {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.series-card .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(8, 10, 14, 0.72);
  border: 1px solid var(--line);
  color: var(--muted);
  backdrop-filter: blur(4px);
}

.series-card .badge.auto {
  color: var(--accent-2);
  border-color: rgba(55, 224, 192, 0.35);
}

/* ---------------- 编排 ---------------- */

.split {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  height: fit-content;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.side-head h2 {
  margin: 0;
  font-size: 14px;
}

.side-foot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.channel-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.channel-item {
  text-align: left;
  border: 1px solid transparent;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.channel-item:hover {
  border-color: #3a4460;
}

.channel-item.active {
  border-color: rgba(124, 92, 255, 0.7);
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.2), rgba(75, 141, 255, 0.1));
}

.channel-item .cn {
  font-weight: 600;
  font-size: 13px;
}

.channel-item .cm {
  font-size: 11px;
  color: var(--muted);
}

.editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-height: 300px;
}

.seg {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--panel-2);
}

.seg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.seg-head .idx {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: rgba(124, 92, 255, 0.18);
  color: #cbbdff;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.seg-head input {
  max-width: 240px;
}

.seg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 12px 14px;
}

/* 关键：grid 子项默认 min-width:auto，input[type=time] 会比格子宽，压到右边控件上 */
.seg-grid > label,
.seg-row > label {
  min-width: 0;
}
.seg-grid input,
.seg-grid select,
.seg-grid textarea,
.seg-row input,
.seg-row select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
}
.seg-grid textarea {
  grid-column: span 2;
  min-height: 84px;
}

.slot-row {
  display: grid;
  grid-template-columns: 90px 90px minmax(150px, 1.2fr) 120px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.slot-row input,
.slot-row select {
  padding: 6px 8px;
  font-size: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.preset {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  padding: 12px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.preset:hover {
  border-color: rgba(124, 92, 255, 0.6);
}

.preset .pt {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.preset .pd {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------------- 预览 ---------------- */

.preview-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.epg {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.epg th,
.epg td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.epg th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  position: sticky;
  top: 0;
  background: var(--panel);
}

.epg tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.epg .time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.epg .name {
  font-weight: 600;
}

.epg .sub {
  color: var(--muted);
  font-size: 12px;
}

.epg .seg-tag {
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--muted);
  white-space: nowrap;
}

.epg tr.live td {
  background: rgba(124, 92, 255, 0.12);
}

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 80px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.9);
  z-index: 50;
  font-size: 13px;
  line-height: 1.5;
}

.toast.ok {
  border-color: rgba(55, 224, 192, 0.5);
}

.toast.err {
  border-color: rgba(255, 92, 122, 0.5);
  color: #ffb3c0;
}

.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty {
  padding: 40px 10px;
  text-align: center;
  color: var(--muted);
}

/* 留空时段 */
.epg tr.gap-row td {
  color: var(--muted, #8b8b93);
  background: repeating-linear-gradient(45deg, rgba(127, 127, 127, 0.04), rgba(127, 127, 127, 0.04) 6px, transparent 6px, transparent 12px);
}
.epg .gap-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px dashed currentColor;
  font-size: 12px;
  opacity: 0.8;
}

/* 编排段：更清晰的分区 */
.seg-head .seg-name {
  max-width: 220px;
}
.seg-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.seg-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 12px 14px;
}
@media (max-width: 720px) {
  .seg-row,
  .seg-grid {
    grid-template-columns: 1fr;
  }
  .seg-grid textarea {
    grid-column: auto;
  }
}
.field-hint {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  min-height: 1em;
}
.seg-params {
  margin-top: 12px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(127, 127, 127, 0.04);
}
.seg-params-title {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}
.seg-summary {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(124, 92, 255, 0.10);
  border: 1px solid rgba(124, 92, 255, 0.22);
  font-size: 12.5px;
  line-height: 1.65;
  color: #cfc7ff;
}
.seg-summary::before {
  content: '摘要 · ';
  opacity: 0.8;
}

/* 预览：按天分隔 */
.epg tr.day-sep td {
  background: rgba(124, 92, 255, 0.10);
  color: #cfc7ff;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 6px 10px;
}
.toolbar input[type='datetime-local'] {
  width: auto;
  min-width: 200px;
}

/* 分时段里子规则的参数（例如时间网格） */
.slot-params {
  margin: 6px 0 14px;
  padding: 10px 12px;
  border-left: 2px solid rgba(124, 92, 255, 0.45);
  background: rgba(127, 127, 127, 0.05);
  border-radius: 0 8px 8px 0;
}

/* 编排：时段卡片与剧集列表 */
.slot-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--panel-2);
}
.slot-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.slot-card-head input[type="time"] { width: auto; min-width: 96px; }
.slot-card-head .sep { color: var(--muted); }
.slot-card-head .slot-label { max-width: 200px; }
.slot-card-sub {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill.tiny { font-size: 11px; padding: 1px 7px; }
.pool-box { margin-top: 8px; }
.pool-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-height: 180px;
  overflow: auto;
}
.pool-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  background: rgba(127, 127, 127, 0.06);
}
.pool-del {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.pool-del:hover { color: #ff6b6b; }
.pool-search-panel { margin-top: 10px; }
.pool-search { width: 100%; }
.pool-search-results {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-height: 160px;
  overflow: auto;
}
.pool-add {
  border: 1px solid var(--line);
  background: rgba(124, 92, 255, 0.1);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.grid-summary { white-space: pre-line; }
