html, body { height: 100%; }
body { overflow: hidden; background: var(--bg); }

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  height: var(--app-h, 100dvh);
  margin: 0 auto;
  background: var(--surface-2);
}
@media (min-width: 680px) {
  body { background: var(--surface-3); }
  .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); box-shadow: var(--shadow); }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border);
}
.mini-avatar {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--border);
}
.brand-text { min-width: 0; }
.title { font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-xs); }
.dot { width: 8px; height: 8px; border-radius: var(--r-full); background: var(--border-strong); }
.status.on .dot { background: var(--ok); }
.status.on { color: var(--ok); }
.head-btn { flex: none; }

.log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.day {
  display: flex;
  justify-content: center;
  margin: 8px 0 14px;
}
.day span {
  padding: 3px 12px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-xs);
}

.row { display: flex; margin-bottom: 8px; }
.row.me { flex-direction: column; align-items: flex-end; }
.row.them { align-items: flex-start; gap: 8px; }
.row.them.first { margin-top: 4px; }
.face { width: 36px; flex: none; }
.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; max-width: calc(100% - 44px); }
.who { margin: 0 0 -2px 2px; color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; }
.line { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.row.me .line { flex-direction: row-reverse; max-width: 86%; }
.bubble {
  min-width: 0;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: var(--fs-md);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.row.them .bubble { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-top-left-radius: 6px; }
.row.me .bubble { background: var(--accent); color: var(--accent-ink); border-top-right-radius: 6px; }
.time { flex: none; color: var(--muted); font-size: 11px; white-space: nowrap; }

.ask { display: flex; flex-direction: column; width: 100%; max-width: 330px; }
.ask-open { align-self: flex-start; min-height: 40px; padding: 0 16px; border-radius: var(--r-full); font-size: var(--fs-sm); }
.ask.locked .ask-open { background: var(--ok-soft); border-color: var(--ok-soft); color: var(--ok); opacity: 1; }

.lead-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 12px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  border-top-left-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.lc-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-md);
  font-weight: 700;
}
.lc-row { display: grid; grid-template-columns: 118px minmax(0, 1fr); align-items: center; gap: 6px; }
.lc-row span { color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.lc-row input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 16px;
  outline: none;
}
.lc-row input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.lc-row input:disabled { color: var(--text); opacity: 1; background: var(--surface-3); -webkit-text-fill-color: var(--text); }
.lead-card .btn-block { min-height: 44px; margin-top: 2px; }
.lead-card .btn-block:disabled { background: var(--ok); border-color: var(--ok); color: #fff; opacity: 1; }
.lc-err { margin: 0; color: var(--danger); font-size: var(--fs-sm); }
.lc-err:empty { display: none; }
.lc-agree { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.agree-more {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.agree-more .i { width: 12px; height: 12px; }
.agree-more[aria-expanded="true"] .i { transform: rotate(180deg); }
.agree-text {
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--fs-xs);
  white-space: pre-wrap;
}
@media (max-width: 360px) {
  .lc-row { grid-template-columns: 1fr; gap: 4px; }
}

.notice { display: flex; justify-content: center; margin: 10px 0 14px; }
.notice span {
  max-width: 90%;
  padding: 6px 14px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-sm);
  text-align: center;
  white-space: pre-wrap;
}
.done {
  display: flex;
  gap: 10px;
  max-width: 92%;
  margin: 10px auto 14px;
  padding: 12px 14px;
  border: 1px solid var(--ok);
  border-radius: var(--r-lg);
  background: var(--ok-soft);
  color: var(--text);
  font-size: var(--fs-sm);
  white-space: pre-wrap;
  word-break: break-word;
}
.done .i { color: var(--ok); margin-top: 1px; }

.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
  color: var(--muted);
  font-size: var(--fs-xs);
}
.typing .mini-avatar { width: 28px; height: 28px; }
.typing-dots { display: inline-flex; gap: 3px; padding: 8px 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.typing-dots i { width: 5px; height: 5px; border-radius: var(--r-full); background: var(--muted); animation: blink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing-dots i { animation: none; opacity: .7; } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 128px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--surface-2);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); background: var(--surface); }
.send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-ink);
}
.send:hover:not(:disabled) { background: var(--accent-hover); }

.gate-note {
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  word-break: keep-all;
}
.gated .ask { max-width: 360px; }
