:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --border: #2f3f55;
  --text: #e8eef6;
  --muted: #8fa3b8;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f59e0b;
  --purple: #8b5cf6;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: #121a24; }
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; }
.topbar .ver { color: var(--blue); font-size: 13px; margin-left: 8px; font-weight: 500; }
.status-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--panel2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.badge.off { opacity: .7; }
.badge.warn { color: var(--orange); border-color: #7a5a20; }
.tabs { display: flex; gap: 4px; padding: 10px 16px; overflow-x: auto;
  border-bottom: 1px solid var(--border); background: #121a24; }
.tab { background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.tab:hover { color: var(--text); background: var(--panel); }
.tab.active { color: #fff; background: var(--blue); border-color: var(--blue); }
.content { flex: 1; padding: 18px 20px 28px; max-width: 1280px; width: 100%; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }
.sub-panel { display: none; }
.sub-panel.active { display: block; }
h2 { margin: 0 0 14px; font-size: 18px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.card, .split-side.card { background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; align-items: center; }
.form-grid label { color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%; background: #0d1520; color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; }
textarea { min-height: 90px; resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0; line-height: 1.5; }
.highlight { color: var(--blue); font-weight: 600; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn { background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--blue); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.lg { padding: 12px 18px; font-size: 15px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.success { background: #15803d; border-color: #15803d; color: #fff; }
.btn.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn.warning { background: #b45309; border-color: #b45309; color: #fff; }
.btn.purple { background: var(--purple); border-color: var(--purple); color: #fff; }
.select-full, .input-md, .input-flex { width: 100%; }
.copy-links { margin: 8px 0 12px; }
.copy-link-row { display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 8px; background: #0d1520; border-radius: 8px; margin-bottom: 6px; }
.copy-link-text { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.copy-action-btn { border: 1px solid var(--border); background: var(--panel2); color: var(--text);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 12px; }
.split-layout { display: grid; grid-template-columns: 1.4fr .8fr; gap: 14px; }
.split-main { min-width: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left; }
.data-table th { color: var(--muted); font-weight: 600; }
.data-table.clickable tr { cursor: pointer; }
.data-table.clickable tr:hover td { background: rgba(59,130,246,.08); }
.check-list, .checkbox-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.progress-wrap { background: #0d1520; border-radius: 999px; height: 10px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--blue), #60a5fa); width: 0; }
.stats-line, .bottom-stats, .bottom-status { color: var(--muted); font-size: 12px; margin-top: 8px; }
.log-panel, .fw-log-box, .pwd-box, .inv-results-box {
  background: #0d1520; border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  max-height: 280px; overflow: auto; font-family: Consolas, monospace; font-size: 12px; }
.log-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.log-header-btns { display: flex; gap: 6px; }
.log-header-hint, .log-preview, .fw-filter-hint, .fw-list-label, .fw-start-title { color: var(--muted); font-size: 12px; }
.log-table-wrap { overflow: auto; max-height: 320px; }
.hidden { display: none !important; }
.sep { height: 1px; background: var(--border); margin: 12px 0; }
.step-bar { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.file-btn { display: inline-block; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; z-index: 1000; }
.modal-dialog { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  width: min(720px, 92vw); max-height: 86vh; overflow: auto; }
.modal-header, .modal-footer { padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; }
.modal-footer { border-bottom: 0; border-top: 1px solid var(--border); gap: 8px; justify-content: flex-end; }
.modal-body { padding: 16px; }
.toast-host { position: fixed; right: 16px; top: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.preset-chip-del, .preset-chip-pull { display: inline-flex; gap: 6px; align-items: center;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.fw-config-list, .fw-group-block, .fw-start-list, .inv-group-row, .fw-select-row, .fw-filter-row { margin: 8px 0; }

/* 通讯录 */
.contacts-card { margin-bottom: 14px; }
.contacts-list, .contacts-groups-list {
  margin-top: 10px; max-height: 320px; overflow: auto;
  background: #0d1520; border: 1px solid var(--border); border-radius: 10px; padding: 6px;
}
.contacts-empty { color: var(--muted); font-size: 13px; padding: 18px 12px; text-align: center; }
.contact-item, .contact-group-item {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  padding: 10px 10px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; color: var(--text); text-align: left; cursor: pointer;
}
.contact-item:last-child, .contact-group-item:last-child { border-bottom: 0; }
.contact-item:hover, .contact-group-item:hover { background: rgba(59,130,246,.08); }
.contact-group-item.active { background: rgba(59,130,246,.18); outline: 1px solid var(--blue); border-radius: 8px; }
.contact-item input { width: auto; min-height: auto; margin-top: 3px; flex: 0 0 auto; }
.contact-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact-name { font-size: 14px; font-weight: 600; }
.contact-meta { font-size: 12px; color: var(--muted); }
.contacts-confirm-bar { margin-top: 12px; align-items: center; }

/* ===== mobile / touch ===== */
.fw-group-select { width: 100%; min-height: 160px; font-size: 14px; }
.fw-select-row { display: flex; gap: 8px; align-items: flex-start; }
.fw-select-row .btn { flex: 0 0 auto; white-space: nowrap; }
.fw-filter-row { display: flex; flex-direction: column; gap: 6px; }
.fw-group-block label { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; margin-bottom: 6px; }
.fw-modal .form-grid { align-items: start; }
.fw-modal .modal-footer .btn { min-width: 96px; }

@media (max-width: 960px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 14px; }
  .topbar h1 { font-size: 17px; }
  .status-bar { width: 100%; }
  .tabs { padding: 8px 10px; gap: 6px; -webkit-overflow-scrolling: touch; }
  .tab { padding: 10px 14px; font-size: 14px; min-height: 40px; }
  .content { padding: 12px 12px 24px; }
  .card-grid { grid-template-columns: 1fr; }
  .split-layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 6px; }
  .form-grid > label { margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
  .form-grid > label:first-child { margin-top: 0; }
  input, select, textarea {
    font-size: 16px !important; /* iOS 避免自动放大 */
    padding: 12px 12px;
    min-height: 44px;
  }
  textarea { min-height: 96px; }
  .btn { padding: 12px 14px; font-size: 15px; min-height: 44px; }
  .btn.sm { padding: 10px 12px; font-size: 14px; min-height: 40px; }
  .toolbar { gap: 10px; }
  .toolbar .btn { flex: 1 1 calc(50% - 10px); text-align: center; }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
    background: rgba(0,0,0,.65);
  }
  .modal-dialog, .modal-dialog.fw-modal, .fw-detail-modal, .fw-start-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: min(92vh, 100%);
    border-radius: 16px 16px 0 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }
  .modal-header, .modal-footer {
    padding: 14px 16px;
    position: sticky;
    background: var(--panel);
    z-index: 2;
  }
  .modal-header { top: 0; }
  .modal-footer {
    bottom: 0;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    justify-content: stretch;
  }
  .modal-footer .btn { flex: 1; }
  .modal-body {
    padding: 14px 16px 20px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
  }
  .fw-select-row { flex-direction: column; }
  .fw-select-row .btn { width: 100%; }
  .fw-filter-hint { font-size: 12px; line-height: 1.4; }
  .data-table { font-size: 13px; }
  .data-table th, .data-table td { padding: 10px 8px; }
  .toast-host { left: 12px; right: 12px; top: 12px; }
}

@media (max-width: 480px) {
  .topbar .ver { display: inline; }
  .badge { font-size: 11px; padding: 4px 8px; }
  .card, .split-side.card { padding: 12px; border-radius: 10px; }
}

/* ===== forward group pickers (mobile big) ===== */
.fw-group-card {
  width: 100%;
  background: #0d1520;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.fw-sec-title { font-size: 15px !important; font-weight: 700 !important; color: #fff !important; }
.fw-group-select {
  width: 100%;
  min-height: 220px;
  font-size: 15px;
  line-height: 1.45;
}
.fw-group-select option {
  padding: 10px 8px;
  min-height: 40px;
  font-size: 15px;
}
.fw-modal .form-grid.fw-form { align-items: stretch; }

@media (max-width: 1200px) {
  /* iframe / 手机：强制竖排，源群目标群放大 */
  .fw-modal .form-grid.fw-form {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .fw-modal .form-grid.fw-form > label {
    display: block;
    width: 100%;
    margin-top: 10px;
    font-size: 16px !important;
    font-weight: 700;
    color: #fff !important;
  }
  .fw-modal .form-grid.fw-form > label:first-child { margin-top: 0; }
  .fw-modal .fw-sec-title { font-size: 18px !important; margin-top: 14px !important; }
  .fw-modal .fw-group-card {
    padding: 14px;
    border-width: 2px;
    border-color: #3b82f6;
  }
  .fw-modal .fw-group-block label {
    font-size: 16px;
    min-height: 44px;
    margin: 0 12px 10px 0;
  }
  .fw-modal .fw-group-block input[type="radio"] {
    width: 20px;
    height: 20px;
    min-height: 20px;
    transform: scale(1.15);
  }
  .fw-modal .fw-filter-row input {
    font-size: 16px !important;
    min-height: 48px !important;
    padding: 12px 14px !important;
  }
  .fw-modal .fw-filter-hint {
    font-size: 13px !important;
    line-height: 1.45;
    color: #c5d4e6 !important;
  }
  .fw-modal .fw-group-select,
  .fw-modal select.fw-group-select {
    min-height: 320px !important;
    height: 42vh !important;
    max-height: 420px;
    font-size: 17px !important;
    padding: 8px !important;
    border: 2px solid #3b82f6 !important;
    border-radius: 12px !important;
  }
  .fw-modal .fw-group-select option {
    padding: 14px 10px !important;
    min-height: 48px !important;
    font-size: 17px !important;
    line-height: 1.4;
  }
  .fw-modal .fw-select-row {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .fw-modal .fw-select-row .btn {
    width: 100% !important;
    min-height: 48px !important;
    font-size: 16px !important;
  }
  .fw-modal .modal-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 94vh !important;
  }
  .fw-modal input, .fw-modal select, .fw-modal textarea {
    font-size: 16px !important;
    min-height: 46px !important;
  }
}


/* ===== custom group list (iOS Safari select size=N 空白修复) ===== */
.fw-group-list {
  width: 100%;
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #0a1220;
  border: 2px solid #3b82f6;
  border-radius: 12px;
  padding: 6px;
  box-sizing: border-box;
}
.fw-group-item {
  display: block;
  width: 100%;
  text-align: left;
  background: #121c2c;
  color: #e8eef6 !important;
  border: 1px solid #2a3a52;
  border-radius: 10px;
  padding: 12px 12px;
  margin: 0 0 6px;
  font-size: 15px;
  line-height: 1.4;
  cursor: pointer;
  word-break: break-word;
}
.fw-group-item:last-child { margin-bottom: 0; }
.fw-group-item:active,
.fw-group-item.on {
  background: #1d4ed8;
  border-color: #60a5fa;
  color: #fff !important;
}
.fw-group-empty {
  color: #fbbf24;
  font-size: 14px;
  padding: 18px 12px;
  line-height: 1.5;
  text-align: center;
}
.fw-group-meta {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: #93a5c8;
}
.fw-group-item.on .fw-group-meta { color: #dbeafe; }

@media (max-width: 1200px) {
  .fw-modal .fw-group-list {
    min-height: 320px !important;
    height: 42vh !important;
    max-height: 480px;
    border-width: 2px;
  }
  .fw-modal .fw-group-item {
    font-size: 16px !important;
    padding: 14px 12px !important;
    min-height: 48px;
  }
  /* 避免通用 select min-height 把列表压扁 */
  .fw-modal .fw-group-list {
    min-height: 320px !important;
  }
}
