/* ============================================================
   7 Days to Die 服务器配置生成器 —— 浅色主题
   ============================================================ */
:root {
  --bg: #f4f6fa;
  --bg-elev: #ffffff;
  --bg-soft: #eef1f6;
  --border: #dde3ec;
  --border-strong: #c7d0dd;
  --text: #1f2937;
  --text-dim: #6b7280;
  --text-faint: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --accent: #0d9488;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --ok: #16a34a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --font: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", "JetBrains Mono", monospace;
}

* { box-sizing: border-box; }

html {
  height: 100%;
}

html, body {
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- 顶部栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { font-size: 26px; }
.brand-text h1 { margin: 0; font-size: 17px; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lang-switch {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.lang-btn.active { background: var(--bg-elev); color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- 操作栏 ---------- */
.actionbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-basis: 100%; /* 在 sticky 顶栏内独占一行，滚动时随顶栏吸顶 */
  padding: 10px 0 2px;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-small { font-size: 12px; padding: 4px 10px; }

.view-filter select {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
}

/* ---------- 拖拽上传遮罩 ---------- */
.drop-zone {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, .08);
  border: 3px dashed var(--primary);
  pointer-events: none;
}
.drop-zone p {
  background: var(--bg-elev);
  padding: 18px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

/* ---------- 三列布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) minmax(0, 440px);
  gap: 14px;
  padding: 14px 20px;
  align-items: start;
  flex: 1;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  position: sticky;
  top: 132px;
  max-height: calc(100vh - 152px);
  overflow: auto;
}
.search-input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  margin-bottom: 8px;
}
.section-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  background: var(--bg-soft);
  color: var(--text-faint);
  border-radius: 999px;
  padding: 1px 7px;
}
.nav-item.active .count { background: var(--primary); color: #fff; }

/* ---------- 表单区 ---------- */
.form-area { min-width: 0; }

.section-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  scroll-margin-top: 144px;
}
.section-head {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-head .en { font-weight: 400; font-size: 12px; color: var(--text-faint); }

.field {
  padding: 12px 16px;
  border-bottom: 1px solid var(--bg-soft);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 8px 20px;
  align-items: center;
}
.field:last-child { border-bottom: 0; }
.field.is-changed { background: var(--warn-soft); }

.field-label { min-width: 0; }
.field-label .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-label .name::before {
  content: "●";
  font-size: 9px;
  color: var(--warn);
  opacity: 0;
  transition: opacity .15s;
}
.field.is-changed .field-label .name::before { opacity: 1; }
.field-label .key { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-left: 2px; }
.field-label .default-hint { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.field-label .default-hint code { font-family: var(--mono); }

.field-control { min-width: 0; }
.field-help { font-size: 12px; color: var(--text-dim); line-height: 1.55; margin-top: 6px; grid-column: 2; }

.field-error {
  grid-column: 2;
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  margin-top: 6px;
}
.field.has-error .field-control input,
.field.has-error .field-control select { border-color: var(--danger); background: var(--danger-soft); }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="number"] { font-family: var(--mono); }

/* 布尔开关 */
.switch-row { display: flex; align-items: center; gap: 10px; }
.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  transition: background .15s;
  cursor: pointer;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch-val { font-size: 12px; color: var(--text-dim); font-family: var(--mono); }

/* 多选勾选组 */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }

/* UserDataFolder 控件 */
.udf-wrap { display: flex; flex-direction: column; gap: 8px; }
.udf-wrap input[type="text"] { width: 100%; }
.udf-wrap input[type="text"]:disabled { background: var(--bg-soft); color: var(--text-faint); }
.udf-note { font-size: 12px; color: var(--text-faint); }
.checkbox-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 5px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  background: var(--bg-elev);
  transition: background .15s, border-color .15s;
}
.checkbox-item.checked { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.checkbox-item input { accent-color: var(--primary); }

/* 隐藏条件字段的提示条 */
.hidden-field-note {
  grid-column: 2;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
}

/* 空搜索提示 */
.empty-hint {
  text-align: center;
  color: var(--text-faint);
  padding: 40px 0;
  font-size: 13px;
}

/* ---------- 预览区 ---------- */
.preview-pane {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky;
  top: 132px;
  max-height: calc(100vh - 152px);
  display: flex;
  flex-direction: column;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.xml-preview {
  margin: 0;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  flex: 1;
  color: #334155;
  background: #fbfcfe;
}

/* ---------- 状态栏 ---------- */
.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 20px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  position: sticky;
  bottom: 0;
}
.statusbar .stat-errors { color: var(--danger); font-weight: 600; }

/* ---------- 遮罩（弹窗） ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .4);
  z-index: 50;
}

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, 92vw);
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 52;
  padding: 18px 20px;
}
.modal h3 { margin: 0 0 10px; font-size: 15px; }
.modal-body { font-size: 13px; line-height: 1.6; max-height: 50vh; overflow: auto; color: var(--text); }
.modal-body ul { margin: 6px 0; padding-left: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  z-index: 70;
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 响应式 ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: 210px minmax(0, 1fr); }
  .preview-pane {
    position: fixed;
    right: 14px;
    top: 132px;
    width: 420px;
    max-width: 90vw;
    z-index: 40;
    max-height: 60vh;
  }
  .preview-pane.collapsed { display: none; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
  .sidebar { position: static; max-height: none; }
  .section-nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item .count { display: none; }
  .field { grid-template-columns: 1fr; }
  .field-help, .field-error, .hidden-field-note { grid-column: 1; }
  .preview-pane { position: fixed; right: 8px; left: 8px; width: auto; top: auto; bottom: 60px; max-height: 55vh; }
  .topbar { flex-wrap: wrap; }
  .brand-text p { display: none; }
}
