* { box-sizing: border-box; }

:root {
  --bg: #cfe9d3;
  --panel: #fbfdfb;
  --line: #d9e7dc;
  --line-soft: #eaf3ec;
  --text: #1f2a24;
  --muted: #5d6f64;
  --brand: #2e7d57;
  --brand-weak: #e3f2e8;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(32, 64, 45, .05), 0 1px 3px rgba(32, 64, 45, .04);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #bfe3c9; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 21px; margin: 0 0 16px; letter-spacing: .2px; }
h2 { font-size: 16px; margin: 0 0 14px; font-weight: 600; }
h3 { font-size: 13.5px; margin: 0 0 6px; font-weight: 500; color: var(--muted); }
small { font-size: 12.5px; }

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 24px;
  height: 74px;
  background: rgba(252, 254, 252, .92);
  backdrop-filter: saturate(180%) blur(10px);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  box-shadow: 0 6px 20px rgba(32, 64, 45, .06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabs {
  grid-column: 2;
  justify-self: center;
  display: flex;
  gap: 6px;
  padding: 6px;
  background: #eff5f0;
  border: 1px solid #e3ece5;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.tab {
  display: block;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: .3px;
  color: #3b5245;
  white-space: nowrap;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tab:hover { background: #fff; color: #16241c; text-decoration: none; }
.tab.on { background: #fff; color: #1c6b45; font-weight: 700; box-shadow: 0 1px 3px rgba(32, 64, 45, .14); }

.top-right { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 12px; }
.link { color: var(--muted); font-size: 13.5px; padding: 5px 10px; border-radius: 8px; transition: background .15s, color .15s; }
.link:hover { color: var(--text); background: #f0f5f1; text-decoration: none; }

@media (max-width: 720px) {
  .top { height: 62px; padding: 0 12px; gap: 12px; }
  .tab { padding: 7px 12px; font-size: 15px; }
  .tabs { gap: 4px; padding: 4px; }
  .top-right { gap: 8px; }
}

main { max-width: 1360px; margin: 26px auto 64px; padding: 0 24px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.flash {
  background: #e9f7ec;
  border: 1px solid #c6e6cf;
  color: #14532d;
  border-radius: 9px;
  padding: 11px 15px;
  margin-bottom: 20px;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid #f2cccc;
  background: #fdf3f3;
  color: #7f1d1d;
  border-radius: 10px;
  padding: 13px 16px;
  margin-bottom: 20px;
}
.banner b { font-weight: 600; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.card {
  display: flex;
  flex-direction: column;
  min-height: 128px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 3px 10px rgba(32, 64, 45, .09); }
.card .k { color: var(--muted); font-size: 13px; margin-bottom: 3px; }
.card .v {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.3px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.card .v small { color: var(--muted); font-weight: 400; letter-spacing: 0; font-size: 13px; }
.card .sub { margin-top: 4px; color: var(--muted); font-size: 12.5px; }

.row { display: flex; flex-wrap: wrap; gap: 12px 30px; margin-bottom: 14px; }
.row > div { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 13px; }
.accent { color: var(--brand); }

.pill {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  line-height: 20px;
  background: #edf4ef;
  color: var(--muted);
  white-space: nowrap;
}
.pill.on { background: #e3f4e8; color: var(--ok); }
.pill.off { background: #fdecec; color: var(--bad); }
.pill.warn { background: #fef3e2; color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12.5px;
  white-space: nowrap;
  background: #f6faf7;
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: #f5fbf6; }
tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.btn {
  display: inline-block;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.btn:hover { border-color: #c3d4c7; background: #f7fbf8; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 2px 4px rgba(46, 125, 87, .25); }
.btn.primary:hover { background: #266b49; border-color: #266b49; }
.btn.danger { background: var(--panel); border-color: #e5b4b4; color: var(--bad); }
.btn.danger:hover { background: #fdf6f6; }
.btn.sm { padding: 5px 13px; font-size: 13.5px; }
.win-presets { display: flex; flex-wrap: nowrap; gap: 6px; margin: 8px 0 0; }
.win-presets .btn { margin: 0; padding: 4px 8px; font-size: 12.5px; white-space: nowrap; }
@media (max-width: 1200px) { .win-presets { flex-wrap: wrap; } }

.btn:focus-visible, .tab:focus-visible, a:focus-visible { outline: 2px solid rgba(46, 125, 87, .45); outline-offset: 2px; }

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

.form label { display: block; font-size: 13.5px; color: var(--muted); }
.form label input, .form label select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  transition: border-color .15s, box-shadow .15s;
}
.form label input:focus, .form label select:focus,
.form label textarea:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(46, 125, 87, .15);
}
.form label textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  line-height: 1.6;
  color: var(--text);
  background: var(--panel);
  resize: vertical;
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.form .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; padding-top: 27px; }
.form .check input { width: auto; margin: 0; }
.form .btn { margin-top: 18px; }
.form .win-presets .btn { margin-top: 0; }

/* 多选列表：发信地址 / 模板（勾选后逐封轮流） */
.field {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px 14px;
  background: #fff;
}
.field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; flex-wrap: wrap; }
.field-title { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--text); }
.sel-count {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--brand);
  background: var(--brand-weak);
  border-radius: 999px;
  padding: 1px 9px;
}
.checklist {
  max-height: 208px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfdfb;
}
.rot-tools { display: flex; gap: 6px; margin: 7px 0; }
.field .rot-tools { margin: 0; }
.rot-tools .btn { margin: 0; padding: 3px 10px; font-size: 12.5px; }
.checklist .check { padding-top: 0; font-size: 13.5px; line-height: 24px; }
.checklist .check + .check { margin-top: 1px; }
.rot-group { font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.rot-group:first-child { margin-top: 0; }
.rot-group .muted { margin-left: 2px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }

/* 紧凑表单：一行多列，字号和内边距略小 */
.form.compact label { font-size: 12px; gap: 5px; }
.form.compact input, .form.compact select { padding: 7px 10px; font-size: 12.5px; }
.form.compact .grid3 { gap: 12px; margin-bottom: 12px; }
/* 两行同构：三个输入框各占 1/3 铺满一行，按钮固定宽度，底部对齐 */
.settings-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.settings-row label { min-width: 0; }
.settings-row input, .settings-row select, .settings-row .btn { height: 34px; box-sizing: border-box; }
.settings-row .btn { width: 92px; margin: 0; padding: 0; font-size: 14px; justify-self: end; }

.input-w { width: 320px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--panel); }
.input-w:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(46, 125, 87, .15); }

.upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.pager { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }

/* 局部提交提示：不跳转页面时在顶部浮出结果 */
.toast-wrap { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 18px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  box-shadow: 0 8px 24px rgba(20, 40, 30, .12);
  font-size: 13.5px;
  color: var(--text);
  max-width: 78vw;
  animation: toastIn .18s ease-out;
}
.toast.err { border-left-color: #c0392b; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .4s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.pager a { padding: 4px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); }
.pager a:hover { text-decoration: none; border-color: #c3d4c7; }
.pager a.on { border-color: var(--brand); color: var(--brand); background: var(--brand-weak); }

.charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.chart-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.chart-box.full, .chart-box.wide { grid-column: 1 / -1; }
.chart { width: 100%; height: 310px; }
.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 310px;
  color: var(--muted);
  font-size: 13.5px;
  background: repeating-linear-gradient(45deg, #fbfdfb, #fbfdfb 10px, #f4f9f5 10px, #f4f9f5 20px);
  border-radius: 8px;
}

.copy-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy-row input {
  flex: 1 1 420px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--muted);
  background: #f6faf7;
}

.note {
  border-left: 3px solid var(--brand);
  background: #f4faf5;
  color: #2f4036;
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  font-size: 13.5px;
  margin: 12px 0 0;
}
.note ol { margin: 6px 0 0; padding-left: 20px; }
.note li { margin: 3px 0; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(180deg, #e9f4ea, #d6e9d8);
}

.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 12px 32px rgba(30, 60, 40, .10);
}
.login-box label { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 16px; }
.login-box input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--panel);
}
.login-box input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(46, 125, 87, .15); }
.login-box .btn { width: 100%; margin-top: 8px; }
.err { color: var(--bad); font-size: 13.5px; }

@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .chart-box.full, .chart-box.wide { grid-column: auto; }
  .cards > .card { grid-column: auto !important; }
}

@media (max-width: 720px) {
  .grid3, .grid2 { grid-template-columns: 1fr; }
  .top { display: flex; gap: 10px; padding: 0 14px; overflow-x: auto; border-radius: 0; }
  main { padding: 0 14px; margin-top: 18px; }
  .input-w { width: 100%; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .win-presets { flex-wrap: wrap; }
}

.inline select {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
}

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 14px; }
.chips a { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 13px; }
.chips a:hover { text-decoration: none; border-color: #c3d4c7; }
.chips a.on { border-color: var(--brand); color: var(--brand); background: var(--brand-weak); }
.chips a b { font-weight: 600; }

/* 统一区块标题、分组与指标 */
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; }
.subhead { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.subhead::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.subhead.first { margin-top: 0; }
.metrics { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.metric { flex: 1 1 150px; min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfa; padding: 10px 14px; }
.metric .k { font-size: 12.5px; color: var(--muted); }
.metric .v { font-size: 21px; font-weight: 650; margin-top: 2px; letter-spacing: -.01em; }
.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.form-actions .btn { margin-top: 0; }
.table-wrap td { overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
@media (max-width: 860px) {
  .settings-row { grid-template-columns: repeat(2, minmax(0, 1fr)) 92px; }
}
@media (max-width: 720px) {
  .metrics { gap: 8px; }
  .metric { flex: 1 1 calc(50% - 8px); }
  .settings-row { grid-template-columns: 1fr; }
}

/* 事件表：单行省略，详情点击展开 */
.ev-table { table-layout: fixed; }
.ev-table th, .ev-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-table .detail-cell { cursor: pointer; }
.ev-table .detail-cell:hover { color: var(--text); }
.cell-tip {
  position: fixed;
  z-index: 999;
  max-width: 560px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #1f2d24;
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

/* 联系人表：单行省略，点击展开 */
.ct-table { table-layout: fixed; }
.ct-table th, .ct-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-table .detail-cell { cursor: pointer; }
.ct-table .detail-cell:hover { color: var(--text); }

/* 首页卡片自定义面板 */
#dashCustomMask {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 40, 30, .38);
  padding: 20px;
}
#dashCustomMask[hidden] { display: none; }
.dash-panel {
  width: min(540px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 16px 48px rgba(20, 40, 30, .22);
}
.dash-panel h3 { margin: 0 0 6px; font-size: 16px; }
.dash-group { margin: 12px 0 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.dash-list { overflow: auto; flex: 1; margin: 4px -6px 0; padding: 2px 6px; }
.dash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: #fff;
  font-size: 13.5px;
  cursor: grab;
  user-select: none;
}
.dash-row.drag { opacity: .4; }
.dash-row.over { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(46, 125, 87, .12); }
.dash-row .handle { color: var(--muted); letter-spacing: -2px; }
.dash-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-row select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 12.5px; background: #fff; }
.dash-row .tiny { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.dash-row input[type=checkbox] { width: 15px; height: 15px; }
.dash-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
