:root {
  --bg: #e8eee9;
  --bg-2: #f7faf7;
  --ink: #14201a;
  --muted: #5a6b61;
  --line: #c5d2c8;
  --accent: #0f6e56;
  --accent-2: #14856a;
  --danger: #9b2c2c;
  --warn-bg: #fff4e0;
  --warn-ink: #7a4b00;
  --shadow: 0 12px 32px rgba(20, 32, 26, 0.07);
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --fs: 13px;
  --fs-sm: 12px;
  --fs-xs: 11px;
  --fs-h1: 1.45rem;
  --fs-h2: 1.15rem;
  --fs-brand: 1.35rem;
  --pad: 16px;
  --rail-w: 200px;
  --main-max: 1180px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  background:
    radial-gradient(900px 480px at 10% -10%, #d7ebe1 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 0%, #dfe8e2 0%, transparent 50%),
    var(--bg);
}

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  height: 100dvh;
  padding: 18px 14px;
  padding-top: calc(18px + var(--safe-t));
  padding-left: calc(14px + var(--safe-l));
  border-right: 1px solid var(--line);
  background: rgba(247, 250, 247, 0.92);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
}

.brand-mark {
  margin: 0;
  font-family: var(--display);
  font-size: var(--fs-brand);
  letter-spacing: -0.03em;
  line-height: 1;
}
.brand-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  font: inherit;
  font-size: var(--fs-sm);
  color: var(--muted);
  cursor: pointer;
}
.nav button:hover { background: rgba(15, 110, 86, 0.08); color: var(--ink); }
.nav button.active {
  background: var(--ink);
  color: #f4faf6;
}

.rail-foot {
  margin-top: auto;
  font-size: var(--fs-xs);
  color: var(--muted);
  line-height: 1.4;
}

.main {
  padding: 18px 22px calc(36px + var(--safe-b));
  padding-right: calc(22px + var(--safe-r));
  min-width: 0;
  width: 100%;
  max-width: calc(var(--main-max) + 44px);
}
.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.top-title { min-width: 0; flex: 1; }
.top-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.top h1 {
  margin: 0;
  font-family: var(--display);
  font-size: var(--fs-h1);
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.lede {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.token-status {
  margin: 0;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  white-space: nowrap;
  font-size: var(--fs-xs);
  line-height: 1.4;
}
.warn-text { color: var(--danger); }
.token-status.warn-text {
  color: var(--warn-ink);
  border-color: #e8c98a;
  background: var(--warn-bg);
}
.token-row { display: flex; gap: 6px; margin-top: 6px; }
.token-row input { flex: 1; min-width: 0; }
#panel-login label[for="apiToken"] {
  display: block;
  font-size: var(--fs-xs);
  color: var(--muted);
}

.panel { display: none; }
.panel.active { display: block; }
#panel-chats.active {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 120px);
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.stack-blocks {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#panel-overview .check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: var(--fs-sm);
}
#panel-overview .check input { accent-color: var(--accent); }

.block {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.block-head .row.tight {
  margin: 0;
  flex-wrap: nowrap;
}
.block h2, .block h3 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: var(--fs-h2);
  letter-spacing: -0.02em;
}
.block h3 { margin-top: 14px; font-size: 1rem; }
.block-head h2,
.block-head h3 {
  margin: 0;
}
.block-head + .hint,
.block-head + .mono,
.block-head + .tabs,
.block-head + .row,
.block-head + .list,
.block-head + .presets-list {
  margin-top: 0;
}

.hint {
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.4;
  margin: 0 0 8px;
}
.hint.warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
  padding: 8px 10px;
  border-radius: 10px;
}
.meta { color: var(--muted); font-size: var(--fs-xs); }

.mono {
  white-space: pre-wrap;
  word-break: break-word;
  background: #eef4f0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: var(--fs-xs);
  line-height: 1.4;
  max-height: 280px;
  overflow: auto;
}
#adStatus.mono { max-height: 120px; }
#adBox.mono { max-height: 320px; }
#authStatus.mono { max-height: 160px; }

.row, .stack, label { display: flex; gap: 6px; }
.row { align-items: center; margin: 8px 0; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.stack { flex-direction: column; align-items: stretch; }
.actions-stack { gap: 8px; }
.actions-stack .row.tight { margin: 0; }
label {
  flex-direction: column;
  font-size: var(--fs-xs);
  color: var(--muted);
  margin: 4px 0;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: var(--fs);
  color: var(--ink);
  background: #fff;
  min-height: 36px;
}
input.grow, .grow { flex: 1; min-width: 120px; }
input.input-narrow {
  width: 88px;
  min-width: 72px;
  flex: 0 0 auto;
}
textarea { resize: vertical; min-height: 64px; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f4fffa;
}
.btn.primary:hover { background: var(--accent-2); }
.btn.danger {
  background: transparent;
  border-color: #e2b4b4;
  color: var(--danger);
}
.btn.chat-back {
  padding: 5px 10px;
  font-size: var(--fs-xs);
}

.list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.list.compact { max-height: none; overflow: auto; -webkit-overflow-scrolling: touch; }
.list .item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: var(--fs-sm);
}
.list .item.selectable { cursor: pointer; }
.list .item.selectable:hover,
.list .item.active {
  border-color: var(--accent);
  background: #eef8f3;
}
.list .item small { color: var(--muted); font-size: var(--fs-xs); }
.hit-item {
  align-items: flex-start;
}
.hit-item .hit-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  width: 100%;
}
.hit-item .hit-title {
  font-weight: 700;
  font-size: var(--fs-sm);
  line-height: 1.3;
}
.hit-item .hit-meta {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.35;
}
.hit-item .hit-preview {
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.list-empty {
  margin: 8px 0;
  padding: 16px 12px;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-sm);
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #f3f7f4;
}

.pager {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  flex-wrap: wrap;
}
.pager .meta { margin: 0; }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.tabs button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: var(--fs-xs);
  cursor: pointer;
  color: var(--muted);
}
.tabs button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #f4faf6;
}
.search-row { margin-top: 0; }

.chat-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) 1fr;
  gap: 12px;
  flex: 1;
  min-height: calc(100dvh - 130px);
  align-items: stretch;
}
.chat-sidebar,
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  height: calc(100dvh - 130px);
  max-height: calc(100dvh - 130px);
}
.chat-sidebar .list.compact {
  flex: 1;
  min-height: 0;
  margin-top: 8px;
}
.chat-sidebar .pager { flex-shrink: 0; }
.chat-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.chat-head-left {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}
.chat-head h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
  word-break: break-word;
}
.chat-head-actions { flex-shrink: 0; margin: 0; }
.listen-bar {
  margin-bottom: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  max-height: none;
  overflow: visible;
}
.listen-bar-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  min-height: 32px;
}
.listen-bar-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  font-size: var(--fs-sm);
}
.listen-bar-status strong {
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.listen-rule-brief {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.listen-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa59e;
  flex-shrink: 0;
}
.listen-bar.on .listen-dot {
  background: var(--accent);
}
.listen-bar-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}
.btn-sm {
  padding: 5px 10px;
  min-height: 30px;
  font-size: var(--fs-xs);
  font-weight: 600;
}
.listen-bar.on {
  border-color: #b7dccb;
  background: #f0faf5;
}
.listen-more {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  max-height: min(36vh, 220px);
  overflow: auto;
}
.listen-more[hidden] { display: none !important; }
.listen-bar.expanded .listen-more:not([hidden]) {
  display: flex;
}
.listen-more-hint { margin: 0; }
.listen-kw-row,
.listen-adv-actions {
  margin: 0;
}
.listen-adv-actions:empty { display: none; }
.listen-nick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  cursor: pointer;
  user-select: none;
  width: fit-content;
}
.listen-nick input { accent-color: var(--accent); }
.kw-chips,
.listen-word-panels {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}
.listen-word-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.listen-word-row .listen-word-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  min-width: 3.2em;
}
.kw-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e7f3ec;
  border: 1px solid #b7dccb;
  font-size: var(--fs-xs);
}
.kw-chip.kind-require {
  background: #eef2ff;
  border-color: #c7d2fe;
}
.kw-chip.kind-exclude {
  background: #fef2f2;
  border-color: #fecaca;
}
.kw-chip button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
  font: inherit;
  line-height: 1;
}
.listen-word-kind {
  flex: 0 0 auto;
  width: auto;
  min-width: 5.5rem;
  padding: 6px 8px;
  min-height: 32px;
  font-size: var(--fs-xs);
}
.watch-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 10px;
  background: #d9f0e6;
  color: var(--accent);
  vertical-align: middle;
}
.item.selectable.watching {
  border-color: #b7dccb;
}
.presets-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}
.preset-word-section {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.preset-word-section h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}
.preset-word-section .hint {
  margin-bottom: 6px;
}
.preset-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}
.preset-card.open { border-color: #b7dccb; }
.preset-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  background: #f7faf7;
}
.preset-head:hover { background: #eef6f1; }
.preset-head h3 {
  margin: 0;
  font-size: 0.95rem;
}
.preset-body {
  display: none;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
}
.preset-card.open .preset-body { display: block; }
.preset-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.preset-toggles .check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-sm);
  cursor: pointer;
  user-select: none;
}
.preset-kw-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  margin: 6px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f7faf7;
  -webkit-overflow-scrolling: touch;
}
.preset-kw-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 8px;
}
.preset-kw-item:hover { background: #eef6f1; }
.preset-kw-item input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  padding: 4px 6px;
  border-radius: 8px;
  min-height: 32px;
}
.preset-kw-item input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}
.rules-empty {
  margin: 8px;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.listen-preset-row {
  align-items: center;
  margin: 0;
  flex-wrap: nowrap;
  gap: 6px;
}
.listen-preset-row select {
  min-width: 0;
  flex: 1;
  font-size: var(--fs-sm);
  padding: 6px 8px;
  min-height: 32px;
}
.listen-preset-row .listen-nick {
  flex-shrink: 0;
  white-space: nowrap;
  margin: 0;
}

.thread {
  flex: 1;
  overflow: auto;
  background: #eef4f0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.bubble {
  max-width: min(88%, 520px);
  padding: 7px 10px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  align-self: flex-start;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.bubble.out {
  align-self: flex-end;
  background: #d9f0e6;
  border-color: #b7dccb;
}
.bubble .who {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 3px;
}
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.bubble.replying {
  outline: 2px solid var(--accent);
}
.compose-wrap {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}
.compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: end;
}
.compose-tools {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  font-size: var(--fs-xs);
}
.compose-hint { margin-left: auto; }
.file-btn {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
}
.file-btn input { display: none; }
.reply-bar {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 10px;
  background: #e7f3ec;
  border: 1px solid #b7dccb;
  font-size: var(--fs-sm);
}
.attach-preview {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fff;
}
.attach-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.emoji-panel {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.75rem, 1fr));
  gap: 2px;
  max-height: 140px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}
.emoji-panel button {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 6px;
  padding: 3px;
}
.emoji-panel button:hover { background: #eef4f0; }

.toast {
  position: sticky;
  top: 8px;
  z-index: 20;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--ink);
  color: #f4faf6;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow);
}

/* admin gate */
.admin-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(45, 106, 79, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 80%, rgba(180, 120, 60, 0.12), transparent 50%),
    var(--bg);
}
.admin-gate[hidden] { display: none !important; }
.admin-gate-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 28px 24px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  box-shadow: var(--shadow);
}
.admin-gate-card .brand-mark {
  margin: 0;
  font-family: var(--display);
  font-size: 1.75rem;
}
.admin-gate-card .lede { margin: 0 0 8px; color: var(--muted); }
.admin-gate-card input {
  width: 100%;
  padding: 10px 12px;
}
.admin-gate-card .btn { width: 100%; margin-top: 4px; }
#appShell[hidden] { display: none !important; }
.rail-foot .btn {
  margin-top: 10px;
  width: 100%;
}

/* env settings */
.env-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 10px;
}
.env-cat h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.env-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 10px;
  align-items: stretch;
}
.env-label strong { font-size: var(--fs-sm); }
.env-row input {
  width: 100%;
}
.bool-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  overflow: hidden;
  width: fit-content;
}
.bool-toggle .bool-opt {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.bool-toggle .bool-opt.active {
  background: var(--accent);
  color: #fff;
}
.bool-toggle .bool-opt.off.active {
  background: #5c6570;
}
.cfg-file-tabs {
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.cfg-file-tabs .btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.cfg-editor {
  width: 100%;
  min-height: 280px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 12px;
  resize: vertical;
  white-space: pre;
  tab-size: 2;
}

/* ads panel */
.ads-panel .ads-advanced {
  margin-top: 8px;
}
.ads-panel .ads-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: var(--fs-sm);
  margin-bottom: 6px;
}
.ads-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.ads-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.ads-card.on {
  border-color: #b7dccb;
  background: #f0faf5;
}
.ads-card-main {
  min-width: 0;
  flex: 1;
}
.ads-card-preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--fs-sm);
  word-break: break-word;
}
.ads-card .row.tight {
  margin: 0;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.ads-form {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.ads-form label {
  flex: 1;
  min-width: 120px;
}
.ads-check {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px;
  margin: 4px 8px 4px 0;
  color: var(--ink);
  font-size: var(--fs-sm);
  cursor: pointer;
  user-select: none;
}
.ads-check input { accent-color: var(--accent); width: auto; min-height: 0; }
.ads-members {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  max-height: 180px;
  overflow: auto;
}
.ads-member {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  margin: 0;
  flex-direction: row;
  color: var(--ink);
}
.ads-member input { width: auto; min-height: 0; accent-color: var(--accent); }
.ads-import {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3f7f4;
}
.ads-import h3 {
  margin: 0;
  font-size: 1rem;
}
.ads-pick-list {
  max-height: 280px;
  margin-top: 8px;
}
.ads-pick-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin: 0;
  color: var(--ink);
}
.ads-pick-item input { width: auto; min-height: 0; accent-color: var(--accent); flex-shrink: 0; }
.ads-msg-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.ads-gaps label {
  flex: 0 1 140px;
  min-width: 110px;
}
.ads-hours {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 6px 0 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.ads-hour {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--ink);
  cursor: pointer;
}
.ads-hour input { width: auto; min-height: 0; accent-color: var(--accent); }

/* tablet / narrow desktop */
@media (max-width: 1100px) {
  .main {
    max-width: none;
  }
}

@media (max-width: 960px) {
  :root {
    --fs: 12.5px;
    --rail-w: 100%;
  }
  .shell {
    grid-template-columns: 1fr;
  }
  .rail {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px 8px;
    padding-top: calc(10px + var(--safe-t));
    padding-left: calc(12px + var(--safe-l));
    padding-right: calc(12px + var(--safe-r));
    gap: 8px;
    overflow: visible;
  }
  .brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
  }
  .brand-sub { margin: 0; }
  .rail-foot { display: none; }
  .nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav button {
    flex: 0 0 auto;
    padding: 6px 10px;
    white-space: nowrap;
  }
  .main {
    padding: 12px 12px calc(28px + var(--safe-b));
    max-width: none;
  }
  .top { flex-direction: column; gap: 6px; margin-bottom: 10px; }
  .grid.two { grid-template-columns: 1fr; }
  #panel-chats.active { min-height: auto; }
  .chat-layout {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 10px;
  }
  .chat-sidebar,
  .chat-main {
    height: auto;
    max-height: none;
  }
  .chat-sidebar .list.compact { max-height: 42vh; }
  .thread { min-height: 42vh; max-height: 52vh; }
  .bubble { max-width: 92%; }
  .toast { top: 56px; }
  .compose-hint { margin-left: 0; width: 100%; }
}

/* phone: list / thread toggle */
@media (max-width: 640px) {
  :root {
    --fs: 12px;
    --fs-sm: 11.5px;
    --fs-xs: 10.5px;
    --fs-h1: 1.25rem;
    --fs-h2: 1.05rem;
    --fs-brand: 1.15rem;
    --radius: 12px;
  }
  .main { padding: 10px 10px calc(24px + var(--safe-b)); }
  .block { padding: 12px; }
  .block-head .row.tight {
    width: 100%;
    flex-wrap: wrap;
  }
  .btn {
    padding: 8px 11px;
    min-height: 34px;
  }
  .row .btn,
  .search-row .btn {
    flex: 1 1 auto;
  }
  .token-row,
  .search-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    grid-template-columns: 1fr;
  }
  .token-row .btn,
  .search-row .btn {
    width: 100%;
  }
  /* 手机会话：发送区保持横排，少占纵向空间 */
  .compose {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
  }
  .compose .btn {
    width: auto;
    min-width: 64px;
  }
  .listen-bar {
    padding: 6px 8px;
  }
  .listen-bar-main {
    gap: 6px;
  }
  .listen-bar-actions .btn-sm {
    min-height: 34px;
    padding: 6px 12px;
  }
  .listen-more {
    max-height: min(40vh, 240px);
  }
  .listen-preset-row {
    flex-wrap: wrap;
  }
  .listen-preset-row select {
    flex: 1 1 140px;
    width: auto;
    min-width: 120px;
  }
  .listen-preset-row .btn,
  .listen-kw-row .btn {
    flex: 0 0 auto;
    width: auto;
  }
  .listen-preset-row .listen-nick {
    flex: 0 0 auto;
  }
  .listen-kw-row {
    flex-wrap: nowrap;
  }
  .emoji-panel {
    max-height: 96px;
  }
  .compose textarea {
    min-height: 44px;
    max-height: 88px;
  }
  .compose-hint { display: none; }
  .preset-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .preset-toggles {
    flex-direction: column;
    align-items: stretch;
  }
  .preset-toggles input,
  .preset-toggles select,
  .preset-toggles .btn {
    width: 100%;
  }
  .list .item {
    flex-direction: column;
    align-items: stretch;
  }
  .list .item .row.tight {
    width: 100%;
  }
  .list .item .row.tight .btn {
    flex: 1;
  }
  .pager {
    flex-direction: column;
    align-items: stretch;
  }
  .pager .row.tight {
    width: 100%;
  }
  .pager .btn {
    flex: 1;
  }
  .chat-head {
    flex-direction: column;
  }
  .chat-head-actions,
  .chat-head-actions .btn {
    width: 100%;
  }
  input.grow, .grow { min-width: 0; }

  .chat-layout[data-view="list"] .chat-main { display: none; }
  .chat-layout[data-view="thread"] .chat-sidebar { display: none; }
  .chat-layout[data-view="thread"] .chat-main {
    height: calc(100dvh - 118px);
    max-height: calc(100dvh - 118px);
  }
  .chat-layout[data-view="thread"] .thread {
    min-height: 0;
    max-height: none;
    flex: 1;
  }
  .chat-layout[data-view="list"] .chat-sidebar {
    height: auto;
    max-height: none;
  }
  .chat-layout[data-view="list"] .chat-sidebar .list.compact {
    max-height: min(62vh, calc(100dvh - 220px));
  }
  .ads-card {
    flex-direction: column;
  }
  .ads-card .row.tight,
  .ads-form .row.tight {
    width: 100%;
  }
  .ads-card .row.tight .btn,
  .ads-form .row.tight .btn {
    flex: 1;
  }
  .ads-gaps label {
    flex: 1 1 45%;
  }
}
