/* ===== 表单：编辑面板 / 表格单网格 / 折叠分区 / 模式切换 / 搜索栏 ===== */

/* ---------- 编辑面板（公告 / 礼包 / 告警配置） ---------- */
.editor-panel { padding: 20px; }
.editor-panel label {
  display: grid;
  gap: 7px;
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.editor-panel input,
.editor-panel textarea,
.editor-panel select { width: 100%; }
.editor-panel textarea { font: 13px Consolas, "Courier New", monospace; }
.editor-panel small { color: var(--hint); font-weight: 400; line-height: 1.5; }
.editor-panel label.check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}
.editor-panel label.check input { width: auto; }

.form-row { display: grid; grid-template-columns: 1fr 1.5fr; gap: 12px; }
.button-row { display: flex; gap: 8px; }

/* 正在编辑礼包的橙色提示条 */
.edit-banner {
  background: var(--warning-soft);
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--warning-ink);
}

/* ---------- 模式切换（卡片/JSON、周榜/总榜） ---------- */
.mode-switch {
  display: inline-flex;
  gap: 4px;
  background: var(--neutral-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  margin-left: auto;
  flex: none;
}
.mode-switch button {
  height: 28px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.mode-switch button.active {
  background: #fff;
  box-shadow: var(--shadow-sm);
}

/* ---------- 数据看板的区间控件 ---------- */

/* 起止日期 + 应用 + 三个预设。用 <form> 承载是为了免费拿到回车提交。
   不复用 .search 那套「拼接条」：那是给搜索框用的，日期控件不需要那种视觉重量，
   而且拼接条的左右互补圆角本来就是为横向充裕的场景设计的。 */
.range-picker { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* 页头的控件比表单里的低一档：它是常驻的辅助控件，不该和主操作抢注意力。
   高度与 .mode-switch 的按钮对齐（28px），两处控件在同一屏里看着是一套。 */
.range-picker button { height: 28px; padding: 0 12px; font-size: 12px; }

.range-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--hint);
  font-size: 12px;
  white-space: nowrap;
}
.range-field input { padding: 6px 8px; font-size: 12px; }

.range-sep { color: var(--hint); font-size: 12px; }

.range-presets { display: inline-flex; gap: 4px; }
.range-presets button { padding: 0 10px; }

/* 区间摘要：两张时间图共用的一行「现在画的是哪一段」。
   放在 .chart-grid 之前，是这两张图唯一共同的父级位置。 */
.range-summary {
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--neutral-soft);
  color: var(--text);
  font-size: 12px;
}

/* ---------- 存档 JSON 编辑器 ---------- */
.save-editor {
  width: 100%;
  /* 详情整宽之后 220px 显得局促：一整份存档展开有几十行，一屏看不到头就要来回滚。 */
  min-height: 320px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 12px/1.55 Consolas, "Courier New", monospace;
  resize: vertical;
  tab-size: 2;
}
.reason-row { display: flex; gap: 8px; margin-top: 10px; }
.reason-row input { flex: 1; min-width: 0; }

/* ---------- 表单模式：外层纵向排分区，分区内部字段自适应多列 ---------- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  /* 分区卡片之间留 12px：整宽之后六个分区同时在一屏里，10px 会把它们糊成一片。 */
  gap: 12px;
}
/* 280px 是按"详情已改成整宽视图"选的：以前详情挤在 0.9fr（约 400px）里，
   下限只能给 180px 才排得下两列；现在可用宽度是整栏（最宽 1500 − padding），
   280px 在 1440 屏上排 4 列、在 980px 上排 2 列、手机上一列，字段名不会被压成两行。
   外面那层 min(…, 100%) 是给窄屏兜底的：轨道下限大于容器宽时连一列都排不下、照样溢出。 */
.field-group .form-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 12px;
}
/* 分区内部滚动。**只给不含自动补全的分区开**（字段表的 scroll 标记，
   见后端 store/save_schema.go 的 SaveSection.Scroll）：
   .autocomplete-drop 是 position:absolute，祖先一旦有 overflow 就会被裁在容器边缘。
   上限跟着整宽视图放宽——以前 340px 是在窄栏里定的，现在一屏能舒服地看更多行。 */
.field-group .scroll-body { max-height: 420px; overflow-y: auto; padding-right: 4px; }
.form-field { display: grid; gap: 6px; min-width: 0; }
.form-field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.form-field input, .form-field select { width: 100%; }
.form-field .hint { font-size: 11px; color: var(--hint); font-weight: 400; }
.form-field.full { grid-column: 1 / -1; }

/* ---------- 可折叠分区 ---------- */
.field-group {
  margin: 0;
  min-inline-size: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--bg);
  transition: background .2s;
}
.field-group:hover { background: #f1f5f9; }
/* 收起态收紧上下内边距：那时整块只剩图例一行，14px 会在六个分区之间
   白白堆出 100 多像素的空白，而"默认全收起"正是它最常处的状态。 */
.field-group.collapsed { padding: 9px 16px; }
.field-group.collapsed .form-grid { display: none; }
.field-group legend {
  padding: 0 8px;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.field-group legend:hover { color: var(--primary); }
.fold-arrow {
  display: inline-block;
  width: 18px;
  font-size: 11px;
  color: var(--hint);
  text-align: center;
  transition: transform .2s;
}
.field-group.collapsed .fold-arrow { color: var(--primary); }
/* legend 是 flex + space-between，标题必须吃掉中间那段，摘要才贴得到右边。 */
.fold-title { flex: 1; min-width: 0; }
/* 分区标题右侧那行摘要：收起时也看得见"这一块大概是什么状况"。 */
.fold-summary {
  font-size: 11px;
  font-weight: 400;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}
.field-group.collapsed .fold-summary { color: var(--muted); }

/* 分区红字：**故意放在 .form-grid 外面**，收起时仍然可见——
   "这份存档存不下去"这种事不能等展开才知道。 */
.section-warning {
  margin: 8px 0 0;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: #fff1f2;
  color: var(--danger-ink);
  font-size: 11px;
  line-height: 1.6;
}
/* 不可编辑的分区（快照里没有这个存档块之类）压暗主体，说明留在标题与红字上。 */
.field-group.disabled, .field-group.disabled:hover { background: var(--bg); }
.field-group.disabled .form-grid { opacity: .55; }
.field-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- 搜索栏 ---------- */
.search { display: flex; width: min(560px, 100%); }
.search select {
  min-width: 130px;
  border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding: 0 10px;
}
.search input { border-radius: 0; width: 100%; min-width: 0; }
.search button { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; min-width: 68px; }
.search select:focus, .search input:focus { box-shadow: none; }

/* 搜索栏里的内联复选框：与两侧控件拼成一条 */
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  white-space: nowrap;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}
.inline-check input { width: auto; margin: 0; }

/* 窄屏：把横向拼条拆成能折的行。
   这些覆盖必须留在本文件末尾——同优先级下靠"后写的赢"，写进 layout.css 会被
   上面这些基础规则按文件顺序反盖（link 顺序见 index.html）。 */
@media (max-width: 640px) {
  /* 两个输入并排至少要 370px 内在宽，手机上一行放不下，直接叠起来 */
  .form-row { grid-template-columns: 1fr; }
  .editor-panel { padding: 16px; }
  /* 礼包页两个切换按钮约 180px，320px 视口下对编辑器可用宽是零余量，收一点内边距 */
  .mode-switch button { padding: 0 10px; }

  /* 看板页头现在挤了 5 组控件（起止日期 ×2 + 应用 + 三个预设 + 刷新），
     320px 下不换行就会把整页撑出横向滚动——这个坑本仓库已经修过两次。
     ≤640px 时 .page-heading 已经塌成单列，这里让这两层各自都能折行。 */
  .page-actions { flex-wrap: wrap; }
  .range-picker { width: 100%; }
  /* 预设按钮在窄屏收窄内边距：三个加起来约 200px，不收就会各占一行。 */
  .range-presets button { padding: 0 8px; }

  /* 搜索栏从"四段拼接条"改成三行网格。
     渠道那个 select 有 130px 的显式下限、压不动，拼一行必然溢出；
     拼条那套左右互补的圆角本来就是给横向充裕的场景用的，手机上放弃。 */
  .search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    width: 100%;
  }
  .search select {
    grid-area: 1 / 1 / 2 / 3;
    border-right: 1px solid var(--line);
    border-radius: var(--radius-sm);
  }
  .search input {
    grid-area: 2 / 1 / 3 / 2;
    border-radius: var(--radius-sm);
  }
  .search button {
    grid-area: 2 / 2 / 3 / 3;
    border-radius: var(--radius-sm);
  }
  .search .inline-check {
    grid-area: 3 / 1 / 4 / 3;
    justify-content: flex-start;
    padding: 0;
    border: 0;
    background: none;
  }
}
