:root {
  --bg: #e8eef4;
  --card: #fff;
  --line: #d5dee8;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --danger: #b91c1c;
  --warn: #b45309;
  --panel: #f7fafc;
  --accent: #ccfbf1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(900px 380px at 0% -10%, #d1fae5 0%, transparent 55%),
    radial-gradient(800px 320px at 100% 0%, #e0f2fe 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 20px 8px;
  max-width: 1680px;
  margin: 0 auto;
}
.top h1 { margin: 0; font-size: 1.28rem; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 0.82rem; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.smtp-status {
  font-size: 0.78rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--muted);
}
.smtp-status.ok { background: #d1fae5; color: #065f46; }
.smtp-status.bad { background: #fee2e2; color: #991b1b; }

.smtp-panel {
  max-width: 1680px;
  margin: 0 auto 8px;
  padding: 12px 14px !important;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 12px;
  padding: 6px 20px 24px;
  max-width: 1680px;
  margin: 0 auto;
  min-height: calc(100vh - 80px);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}
.editor-card {
  min-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
}
.list-card { position: sticky; top: 8px; align-self: start; max-height: calc(100vh - 28px); }
.card-head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; font-size: 0.92rem; flex: 1; }
.card-head input {
  flex: 1.2;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.82rem;
}

.portal-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}
.portal-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.portal-item:hover { border-color: #99f6e4; background: #f0fdfa; }
.portal-item.active { border-color: var(--primary); background: var(--accent); }
.portal-item .name { font-weight: 600; font-size: 0.88rem; }
.portal-item .meta { color: var(--muted); font-size: 0.72rem; margin-top: 2px; }

.empty-hint { color: var(--muted); padding: 64px 12px; text-align: center; }
.hidden { display: none !important; }

#editor-form { display: flex; flex-direction: column; gap: 10px; flex: 1; }

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}
.panel-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--primary);
  line-height: 1.2;
}
.sub-title {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--muted);
  margin: 8px 0 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  margin-bottom: 0;
}
.form-grid.dense label { gap: 3px; font-size: 0.76rem; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid input,
.form-grid textarea,
.form-grid select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.86rem;
  color: var(--text);
  font-family: inherit;
  background: #fff;
}
.form-grid textarea { resize: vertical; min-height: 140px; line-height: 1.4; }
.multi-select { min-height: 88px; }

.inline-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
  font-size: 0.86rem;
}
.inline-label { color: var(--muted); font-size: 0.76rem; margin-right: 4px; }
.inline-checks label { color: var(--text); display: flex; align-items: center; gap: 5px; }

.report-tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.report-tabs .tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
}
.report-tabs .tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.report-tabs .tab.disabled { opacity: 0.35; pointer-events: none; }

.field-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.field-checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 8px;
  max-height: 168px;
  overflow: auto;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
}
.field-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text);
  padding: 2px 0;
  cursor: pointer;
  user-select: none;
}
.field-check input { width: 14px; height: 14px; flex-shrink: 0; }
.field-check .lvl2 { color: var(--muted); }

.preview-head {
  font-size: 0.76rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.preview-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  max-height: 220px;
}
.preview-table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 0.78rem;
}
.preview-table th,
.preview-table td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0;
  white-space: nowrap;
  vertical-align: middle;
}
.preview-table th {
  background: #ecfdf5;
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 600;
}
.preview-table th.dragging { opacity: 0.45; }
.preview-table th.drag-over { box-shadow: inset 3px 0 0 var(--primary); }
.preview-th {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  min-width: 110px;
  cursor: grab;
}
.preview-th:active { cursor: grabbing; }
.preview-th .drag-handle {
  color: #94a3b8;
  font-size: 0.7rem;
  letter-spacing: -1px;
}
.preview-th input {
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  width: 100%;
  min-width: 72px;
  padding: 1px 3px;
  border-radius: 3px;
}
.preview-th input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
.preview-th .col-ops {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.preview-th .col-ops button {
  border: none;
  background: #e2e8f0;
  color: var(--text);
  width: 18px;
  height: 18px;
  border-radius: 3px;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.preview-table td {
  padding: 6px 8px;
  color: #94a3b8;
  background: #fff;
}
.preview-empty {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.push-hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}
.push-hint code {
  background: #eef2f7;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.72rem;
}
.check-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}
.check-row input[type="checkbox"] { width: 15px; height: 15px; }
.share-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.share-row.tight { margin-top: 8px; }
.share-row input {
  flex: 1;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  font-size: 0.82rem;
}

.action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 30%);
  padding-bottom: 4px;
  z-index: 2;
}
.tip { color: var(--muted); font-size: 0.78rem; }

.btn {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.84rem;
  cursor: pointer;
}
.btn-sm { padding: 4px 8px; font-size: 0.74rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-default { background: #e2e8f0; color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-warn { background: #ffedd5; color: var(--warn); }
.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 0 3px;
  font-size: inherit;
  text-decoration: underline;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; padding: 8px 12px 24px; }
  .list-card { position: static; max-height: none; }
  .field-checks { grid-template-columns: repeat(2, 1fr); }
}
