:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --line: #e3e5e8;
  --text: #1f2329;
  --muted: #8a9099;
  --brand: #3a7afe;
  --brand-soft: #e8f0ff;
  --bubble-in: #ffffff;
  --bubble-out: #3a7afe;
  --danger: #e5484d;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  /* dvh follows the phone's shrinking viewport (URL bar, on-screen keyboard),
     which 100% does not — without it the composer sits under the keyboard. */
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: none;
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
}
button:active { opacity: .85; }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--brand); padding: 6px 10px; }
button.danger { background: var(--danger); }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* --- message bubbles, shared by both pages ------------------------------- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg { display: flex; max-width: 78%; }
.msg .bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
.msg .time {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  text-align: right;
}

.msg.them { align-self: flex-start; }
.msg.them .bubble { background: var(--bubble-in); border-top-left-radius: 3px; }

.msg.me { align-self: flex-end; }
.msg.me .bubble { background: var(--bubble-out); color: #fff; border-top-right-radius: 3px; }
.msg.me .time { color: rgba(255, 255, 255, .75); }

.msg.system {
  align-self: center;
  max-width: 90%;
}
.msg.system .bubble {
  background: rgba(0, 0, 0, .05);
  color: var(--muted);
  font-size: 13px;
  box-shadow: none;
}

/* --- Recovery-code card ----------------------------------------------------
 * The customer's recovery code, sent as a message. Its whole job is to survive
 * being screenshotted and retyped weeks later, so it is set large, spaced, and
 * in a face where 0 and O can't be confused — on a plate that reads as
 * something to capture rather than something to skim past.
 */

.msg .bubble.code-card { padding: 10px 12px 8px; }

.code-block {
  display: block;
  margin: 8px 0 2px;
  padding: 12px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  color: #111;
  font-family: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .12em;
  text-align: center;
  /* The code is the one thing on the page worth selecting. */
  user-select: all;
  -webkit-user-select: all;
}

.code-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.code-hint {
  font-size: 12px;
  opacity: .75;
  flex: 1;
}

.code-copy {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  opacity: .85;
  cursor: pointer;
}

/* Photos. The picture is the message, so the bubble shrinks to it — the
 * placeholder caption ("[图片]") is hidden rather than printed under every
 * image, while a real caption stays visible beneath it. */
.msg .bubble.photo { padding: 6px 6px 4px; max-width: min(72vw, 320px); }
.msg .bubble.photo.caption-only { font-size: 0; }

.photo-img {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  border-radius: 8px;
  cursor: zoom-in;
  background: rgba(127, 127, 127, .12);
}

.msg .bubble.photo .time { font-size: 11px; margin-top: 4px; }

/* --- Lightbox --------------------------------------------------------------
 * Tapping a picture opens it here instead of in a new tab; tapping again puts
 * it away. Sits above everything and swallows the tap, so nothing behind it
 * reacts. See lightbox.js.
 */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .92);
  cursor: zoom-out;
  opacity: 0;
  transition: opacity .18s ease;
  -webkit-tap-highlight-color: transparent;
}

.lightbox.open { opacity: 1; }
.lightbox[hidden] { display: none; }

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  transform: scale(.96);
  transition: transform .18s ease;
  /* A photo still has to be saveable from here — long-press must hit the image. */
  -webkit-touch-callout: default;
}

.lightbox.open .lightbox-img { transform: scale(1); }

/* Keep the page behind from scrolling under the viewer on touch. */
body.lightbox-open { overflow: hidden; }

/* Drop target for drag-and-drop uploads in the console. */
.messages.drop-target {
  outline: 2px dashed var(--accent, #3b82f6);
  outline-offset: -6px;
}

.day-sep {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 10px;
}

.typing { align-self: flex-start; color: var(--muted); font-size: 13px; padding-left: 4px; }

/* --- composer ------------------------------------------------------------ */

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  background: var(--bg);
}
.composer textarea:focus { border-color: var(--brand); }

/* --- phones ----------------------------------------------------------------
 * Both pages are used on a phone — the customer always, the agent console
 * whenever staff answer away from a desk.
 */

@media (max-width: 760px) {
  /* iOS Safari zooms the whole page when a focused field is under 16px, and
     never zooms back out. Every typable control gets 16px on a phone. */
  input, textarea, select, .composer textarea { font-size: 16px; }
  .messages { padding: 12px; }
  .msg { max-width: 86%; }
}

