:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel2: #1e252d;
  --line: #2a333d;
  --text: #e7edf3;
  --muted: #93a1b0;
  --brand: #3ba55d;
  --brand2: #2e8b4f;
  --warn: #d9a13b;
  --danger: #d4574a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #1b2a22 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; backdrop-filter: blur(10px);
  background: rgba(15,18,22,.82); z-index: 10;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--muted); font-weight: 400; font-size: 14px; margin-left: 8px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chipwrap { display: flex; gap: 10px; flex-wrap: wrap; }
#wxState { cursor: pointer; }
.chip { background: var(--panel2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.chip b { color: var(--text); font-size: 15px; margin-left: 4px; }
.chip.on { border-color: var(--brand); color: var(--text); background: rgba(59,165,93,.12); }

.tabs { display: flex; gap: 6px; padding: 14px 28px 0; }
.tabs button {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 10px 18px; border-radius: 12px 12px 0 0; cursor: pointer; font-size: 15px;
}
.tabs button.active { background: var(--panel); color: var(--text); border-color: var(--line); border-bottom-color: var(--panel); }

main { padding: 18px 28px 60px; max-width: 1100px; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button {
  background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
}
.filters button.active { background: rgba(59,165,93,.16); border-color: var(--brand); color: var(--text); }
#search { flex: 1; min-width: 220px; background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 10px 14px; border-radius: 12px; outline: none; }
#search:focus { border-color: var(--brand); }

.hint { color: var(--muted); font-size: 13px; margin: 8px 0 16px; }

.queue { display: grid; gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; display: grid; gap: 10px;
}
.card .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card .name { font-size: 17px; font-weight: 700; }
.card .wx { color: var(--muted); font-family: ui-monospace, Consolas, monospace; background: var(--panel2); padding: 3px 8px; border-radius: 8px; cursor: pointer; }
.card .note { color: var(--muted); font-size: 13px; }
.card .msg { background: var(--panel2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; color: #cfe0d5; white-space: pre-wrap; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  padding: 9px 14px; border-radius: 11px; font-size: 14px;
}
.btn:hover { border-color: #3d4a57; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #07130b; font-weight: 700; }
.btn.primary:hover { background: var(--brand2); }
.btn.ghost { background: transparent; }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.panel h2 { margin: 0; font-size: 17px; }
textarea, input[type=number] {
  width: 100%; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: 12px; font: inherit; outline: none;
}
textarea:focus, input:focus { border-color: var(--brand); }
.row { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.row label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.row input { width: 140px; }
.muted { color: var(--muted); font-size: 13px; }
code { background: var(--panel2); padding: 1px 6px; border-radius: 6px; }

.logs { display: grid; gap: 8px; font-size: 13px; color: var(--muted); }
.logs div { border-bottom: 1px dashed var(--line); padding-bottom: 6px; }
.logs b { color: var(--text); }

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

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #0b1a10; border: 1px solid var(--brand); color: #d9ffe6;
  padding: 12px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 50;
}

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 6px; border-radius: 999px; background: #d9a13b; color: #1a1206; font-size: 12px; font-weight: 700; }
.banner { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; margin: 0 0 14px; padding: 12px 16px; border: 1px solid #6b4f1f; background: rgba(217,161,59,.12); color: #f0d9a8; border-radius: 12px; font-size: 14px; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.card.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(59,165,93,.25); }
kbd { background: var(--panel2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; font-size: 12px; color: var(--text); }
.tag { padding: 2px 10px; border-radius: 999px; background: rgba(59,165,93,.15); color: #9fe3b8; font-size: 12px; }
.tag.over { background: rgba(212,87,74,.15); color: #f0a79f; }
.tablewrap { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table.preview { width: 100%; border-collapse: collapse; font-size: 13px; }
table.preview th, table.preview td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.preview th { position: sticky; top: 0; background: var(--panel2); color: var(--muted); font-weight: 600; }
tr.warnrow td { color: #d9a13b; }
tr.bad td { color: #f08a7f; text-decoration: line-through; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(480px, 92vw); display: grid; gap: 14px; }
.modal-card h3 { margin: 0; font-size: 18px; }
.reasons { display: flex; gap: 10px; flex-wrap: wrap; }
.reasons button { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 12px 16px; border-radius: 12px; cursor: pointer; font-size: 15px; }
.reasons button:hover { border-color: var(--brand); }
.toast button { margin-left: 12px; }

.modal[hidden] { display: none !important; }
.toast[hidden] { display: none !important; }

.mt { margin-top: 22px; }
.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.tpllist { display: grid; gap: 12px; }
.tplrow { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: start; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tplrow .tplname { grid-column: 1; }
.tplrow .tpltext { grid-column: 1 / -1; }
.tplrow .tplDel { grid-column: 2; grid-row: 1; }

input[type=text] { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 10px 14px; border-radius: 10px; outline: none; font: inherit; }
input[type=text]:focus { border-color: var(--brand); }

.toolbar2 { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.toolbar2 select { background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 10px; }
.batchbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: rgba(59,165,93,.1); border: 1px solid var(--brand); border-radius: 12px; padding: 10px 14px; margin: 0 0 14px; }
.batchbar input { width: 180px; background: var(--panel2); border: 1px solid var(--line); color: var(--text); padding: 7px 10px; border-radius: 9px; }
.tagchip { display: inline-block; padding: 2px 9px; border-radius: 999px; background: rgba(59,165,93,.16); color: #a8e6bf; font-size: 12px; }
input.pick { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.batchbar[hidden] { display: none !important; }

@media (max-width: 820px) {
  .top { flex-wrap: wrap; padding: 12px 14px; gap: 8px; }
  .brand { font-size: 17px; }
  .brand span { font-size: 12px; }
  .stats { width: 100%; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .chip { white-space: nowrap; font-size: 12px; padding: 5px 10px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; padding: 10px 10px 0; }
  .tabs button { padding: 10px 14px; font-size: 14px; white-space: nowrap; }
  main { padding: 12px 10px 90px; max-width: 100%; }
  .toolbar { gap: 8px; }
  .filters { overflow-x: auto; flex-wrap: nowrap; width: 100%; padding-bottom: 4px; }
  .filters button { white-space: nowrap; padding: 8px 12px; }
  #search { width: 100%; min-width: 0; }
  .toolbar > .btn { width: 100%; justify-content: center; }
  .card { padding: 14px; }
  .card .head { gap: 8px; }
  .card .msg { font-size: 14px; }
  .card .actions { gap: 8px; }
  .card .actions .btn { flex: 1 1 45%; justify-content: center; padding: 12px 10px; }
  .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
  .row label { display: grid; }
  .row label input { width: 100%; }
  .row > .btn { grid-column: 1 / -1; justify-content: center; }
  .funnel { grid-template-columns: repeat(2, 1fr); }
  .tplrow { grid-template-columns: 1fr; }
  .tplrow .tplDel { grid-row: auto; grid-column: 1; justify-self: end; }
  .tablewrap { overflow-x: auto; }
  .modal-card { width: 94vw; padding: 16px; }
  .batchbar { position: sticky; bottom: 0; z-index: 20; }
  .batchbar input { width: 100%; }
  .toast { width: 92vw; left: 4vw; transform: none; bottom: 16px; }
  .hint { font-size: 12px; }
}

@media (max-width: 820px) {
  html, body { overflow-x: hidden; max-width: 100%; }
  .top { flex-direction: column; align-items: stretch; }
  .stats { width: 100%; min-width: 0; }
  .tabs, main, .toolbar, .card, .panel, .batchbar, .filters { min-width: 0; }
  .card .head { flex-wrap: wrap; }
  .card .actions .btn { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .card .msg { word-break: break-word; }
  table.preview { min-width: 520px; }
}

@media (max-width: 900px) {
  main { overflow-x: hidden; }
  .card { width: auto; max-width: 100%; overflow: hidden; }
  .card .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .card .actions .btn { width: 100%; justify-content: center; }
  .stats, .tabs { max-width: 100%; }
}

.queue { grid-template-columns: minmax(0, 1fr); }
.card, .card .head > *, .card .msg { min-width: 0; }
.card .actions .btn { white-space: normal; }

.trend { display: flex; gap: 6px; align-items: flex-end; height: 150px; padding: 8px 0; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; min-width: 0; }
.trend .bar { width: 70%; max-width: 18px; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 0; }
.trend .bar.added { background: #7fd1a1; }
.trend .lbl { font-size: 10px; color: var(--muted); white-space: nowrap; }

/* touch scroll fixes */
html, body { height: auto !important; min-height: 100%; }
body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
.tabs { overflow-x: auto !important; -webkit-overflow-scrolling: touch; scrollbar-width: none; -ms-overflow-style: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: 0 0 auto; }
.filters { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.filters button { flex: 0 0 auto; }
.queue { touch-action: pan-y; }

/* fix: body must not be its own scroll container */
html { height: auto !important; }
body { height: auto !important; min-height: 100%; overflow-y: visible !important; overflow-x: hidden; }
main { overflow: visible !important; }
