:root {
  --phone-w: 390px;
  --phone-h: 780px;
  --frame-radius: 52px;
  --screen-radius: 40px;
  --ink: #0b0c10;
  --bg-stage: #14161c;
  --bubble-me: #2f6bff;
  --bubble-bot: #ffffff;
  --bubble-bot-text: #1b1d24;
  --accent: #2f6bff;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 50% 20%, #1e212b 0%, var(--bg-stage) 60%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow-x: hidden;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px 16px;
  width: 100%;
}

/* Operator controls — deliberately outside the phone frame */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  order: 2;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #1f2937;
  border: 1px solid #333a47;
  color: #e7e9ee;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.control-btn:hover {
  background: #2a3242;
}

.control-btn:active {
  transform: scale(0.97);
}

.control-icon {
  font-size: 16px;
  display: inline-block;
  transition: transform 0.4s ease;
}

.control-btn.spinning .control-icon {
  transform: rotate(360deg);
}

.status-pill {
  font-size: 12px;
  color: #9aa3b2;
  background: #1a1e27;
  border: 1px solid #2a3242;
  padding: 6px 12px;
  border-radius: 999px;
}

/* Phone frame */
.phone {
  order: 1;
  filter: drop-shadow(0 30px 60px rgba(0, 0, 0, 0.55));
}

.phone-frame {
  position: relative;
  width: var(--phone-w);
  height: var(--phone-h);
  max-height: 82vh;
  background: linear-gradient(155deg, #3a3d45, #101114 40%, #101114 60%, #3a3d45);
  border-radius: var(--frame-radius);
  padding: 14px;
  aspect-ratio: 390 / 780;
}

.notch {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 34%;
  height: 26px;
  background: #101114;
  border-radius: 0 0 18px 18px;
  z-index: 5;
}

.screen {
  position: relative;
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: var(--screen-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 26px 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  flex-shrink: 0;
}

.status-icons {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
}

.chat-app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #eef1f6;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 12px;
  background: #fff;
  border-bottom: 1px solid #e7e9ee;
  flex-shrink: 0;
}

.back-arrow {
  font-size: 26px;
  color: var(--accent);
  font-weight: 700;
  margin-right: 2px;
}

.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.chat-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.chat-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.chat-sub {
  font-size: 12px;
  color: #8a8f9c;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 4px 0;
  animation: bubble-in 0.22s ease-out;
}

.bubble-row.me {
  justify-content: flex-end;
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.bubble {
  max-width: 74%;
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

.bubble.bot {
  background: var(--bubble-bot);
  color: var(--bubble-bot-text);
  border-bottom-left-radius: 4px;
}

.bubble.me {
  background: var(--bubble-me);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.error {
  background: #fdecec;
  color: #9a2f2f;
  border: 1px solid #f3c6c6;
}

.msg-time {
  font-size: 10.5px;
  color: #a3a9b7;
  margin: 2px 4px 8px;
}

.bubble-row.me + .msg-time-row {
  text-align: right;
}

.time-row {
  display: flex;
  font-size: 10.5px;
  color: #a3a9b7;
  padding: 0 4px 8px;
}

.time-row.me {
  justify-content: flex-end;
}

.quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 4px 10px;
}

.quick-option {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.quick-option:hover {
  background: #eef2ff;
}

.quick-option:disabled {
  opacity: 0.5;
  cursor: default;
}

.system-banner-row {
  display: flex;
  justify-content: center;
  margin: 10px 0;
  animation: bubble-in 0.22s ease-out;
}

.system-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 88%;
  background: #eef2ff;
  color: #3a3fa0;
  border: 1px solid #d7dcf9;
  border-radius: 14px;
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}

.system-banner-icon {
  font-size: 15px;
  flex-shrink: 0;
}

.attachment-bubble {
  padding: 4px;
  background: var(--bubble-bot);
}

.attachment-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  width: 100%;
  border-radius: 14px;
  object-fit: cover;
}

.attachment-file {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.attachment-file-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.attachment-file-name {
  font-size: 13.5px;
  color: var(--bubble-bot-text);
  word-break: break-word;
}

.typing-row {
  display: flex;
  align-items: center;
  margin: 4px 0;
}

.typing-bubble {
  background: var(--bubble-bot);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 11px 16px;
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #b4b8c4;
  animation: typing-bounce 1.1s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid #e7e9ee;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  border: 1px solid #dde1e9;
  background: #f5f6fa;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14.5px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.3;
  outline: none;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.chat-send:disabled {
  opacity: 0.45;
  cursor: default;
}

.chat-send:active:not(:disabled) {
  transform: scale(0.94);
}

.home-indicator {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 34%;
  height: 5px;
  background: #101114;
  border-radius: 3px;
}

@media (max-width: 460px) {
  :root {
    --phone-w: 100vw;
    --phone-h: 100vh;
  }
  .phone-frame {
    border-radius: 0;
    padding: 0;
    max-height: 100vh;
  }
  .screen {
    border-radius: 0;
  }
  .notch {
    display: none;
  }
  .home-indicator {
    display: none;
  }
}

@media (max-height: 760px) {
  :root {
    --phone-h: 640px;
    --phone-w: 320px;
  }
}

/* Links inside chat bubbles. Underlined (never colour-only, so they read as
   links on both bubble backgrounds) and allowed to break mid-URL: product
   links are long and must not push the bubble past the phone frame. */
.msg-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.bubble.bot .msg-link {
  color: var(--accent);
}

.msg-link:hover {
  opacity: 0.75;
}
