/* ================================================================
   Animated iMessage — Tablet Frame + Bubble Styling
   Scoped under .imsg to avoid collisions with the onboarding app.
   ================================================================ */

/* ── Tokens ── */
.imsg {
  --im-blue: #007AFF;
  --im-gray: #E9E9EB;
  --im-meta: #8E8E93;
  --im-radius: 18px;
  --im-radius-grouped: 4px;
  --im-white: #ffffff;
  --im-black: #000000;
  --im-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

/* ── Tablet Frame ── */
.imsg__phone {
  position: relative;
  width: 580px;
  max-width: 100%;
  margin: 0 auto;
  background: var(--im-white);
  border: 3px solid #1C1917;
  border-radius: 36px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.04),
    0 8px 24px rgba(0,0,0,0.08),
    0 24px 48px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  height: 720px;
}

/* ── Status Bar ── */
.imsg__statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px 0;
  height: 54px;
  background: #f6f6f6;
  flex-shrink: 0;
}

.imsg__statusbar-time {
  font-family: var(--im-font);
  font-size: 15px;
  font-weight: 600;
  color: var(--im-black);
  width: 54px;
}

/* Dynamic Island */
.imsg__dynamic-island {
  width: 120px;
  height: 34px;
  background: var(--im-black);
  border-radius: 20px;
}

.imsg__statusbar-icons {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 54px;
  justify-content: flex-end;
}

.imsg__statusbar-icons svg {
  width: 16px;
  height: 12px;
  fill: var(--im-black);
}

/* ── Nav Bar ── */
.imsg__navbar {
  display: flex;
  align-items: center;
  padding: 8px 20px 10px;
  background: #f6f6f6;
  border-bottom: 0.5px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
  gap: 10px;
}

.imsg__back {
  display: flex;
  align-items: center;
  color: var(--im-blue);
}

.imsg__back svg {
  width: 22px;
  height: 22px;
}

.imsg__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Pixelify Sans', cursive;
  font-size: 14px;
  font-weight: 600;
  color: var(--im-white);
  letter-spacing: -0.5px;
  padding-top: 3px;
  flex-shrink: 0;
}

.imsg__contact-name {
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex: 1;
  min-width: 0;
  position: relative;
  top: 3px;
}

.imsg__brand-workup {
  font-family: 'Pixelify Sans', cursive;
  font-size: 28px;
  font-weight: 600;
  color: #F97316;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.imsg__brand-tm {
  font-family: var(--im-font);
  font-size: 11px;
  font-weight: 400;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
}

.imsg__brand-byline {
  font-family: var(--im-font);
  font-size: 12px;
  font-weight: 400;
  color: var(--im-meta);
  white-space: nowrap;
}

/* ── Conversation Area ── */
.imsg__conversation {
  flex: 1;
  min-height: 0;
  padding: 14px 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  overflow-y: auto;
  background: var(--im-white);
  text-align: left;
  /* Hide scrollbar across browsers */
  scrollbar-width: none;           /* Firefox */
  -ms-overflow-style: none;        /* IE/Edge */
}
.imsg__conversation::-webkit-scrollbar {
  display: none;                   /* Chrome/Safari */
}

/* ── Message Wrapper ── */
.imsg__msg {
  max-width: 75%;
  margin-top: 2px;
  flex-shrink: 0;
}

.imsg__msg--single,
.imsg__msg--first {
  margin-top: 10px;
}

.imsg__msg:first-child,
.imsg__msg--single:first-child,
.imsg__msg--first:first-child {
  margin-top: 0;
}

.imsg__msg--assistant {
  align-self: flex-start;
}

.imsg__msg--user {
  align-self: flex-end;
}

/* ── Bubble Base Styles ── */
.imsg__bubble--assistant {
  font-family: var(--im-font);
  font-size: 16px;
  line-height: 1.35;
  color: var(--im-black);
  background: var(--im-gray);
  padding: 8px 14px;
  position: relative;
  border-radius: var(--im-radius);
}

.imsg__bubble--assistant strong {
  font-weight: 700;
}

.imsg__bubble--user {
  font-family: var(--im-font);
  font-size: 16px;
  line-height: 1.35;
  color: #fff;
  background: var(--im-blue);
  padding: 8px 14px;
  position: relative;
  border-radius: var(--im-radius);
}

/* ── Border-radius per position — User (tail right) ── */
.imsg__msg--single.imsg__msg--user .imsg__bubble--user {
  border-radius: var(--im-radius) var(--im-radius) var(--im-radius-grouped) var(--im-radius);
}
.imsg__msg--first.imsg__msg--user .imsg__bubble--user {
  border-radius: var(--im-radius) var(--im-radius) var(--im-radius-grouped) var(--im-radius);
}
.imsg__msg--middle.imsg__msg--user .imsg__bubble--user {
  border-radius: var(--im-radius-grouped) var(--im-radius) var(--im-radius-grouped) var(--im-radius);
}
.imsg__msg--last.imsg__msg--user .imsg__bubble--user {
  border-radius: var(--im-radius-grouped) var(--im-radius) var(--im-radius) var(--im-radius);
}

/* ── Border-radius per position — Assistant (tail left) ── */
.imsg__msg--single.imsg__msg--assistant .imsg__bubble--assistant {
  border-radius: var(--im-radius) var(--im-radius) var(--im-radius) var(--im-radius-grouped);
}
.imsg__msg--first.imsg__msg--assistant .imsg__bubble--assistant {
  border-radius: var(--im-radius) var(--im-radius) var(--im-radius) var(--im-radius-grouped);
}
.imsg__msg--middle.imsg__msg--assistant .imsg__bubble--assistant {
  border-radius: var(--im-radius) var(--im-radius-grouped) var(--im-radius) var(--im-radius-grouped);
}
.imsg__msg--last.imsg__msg--assistant .imsg__bubble--assistant {
  border-radius: var(--im-radius) var(--im-radius-grouped) var(--im-radius) var(--im-radius);
}

/* ── Bubble Tail — User (right side, single + last) ── */
.imsg__msg--single.imsg__msg--user .imsg__bubble--user::before,
.imsg__msg--last.imsg__msg--user .imsg__bubble--user::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: -7px;
  width: 20px;
  height: 25px;
  background: var(--im-blue);
  border-radius: 0 0 0 16px / 0 0 0 14px;
}

.imsg__msg--single.imsg__msg--user .imsg__bubble--user::after,
.imsg__msg--last.imsg__msg--user .imsg__bubble--user::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: -26px;
  width: 26px;
  height: 25px;
  background: var(--im-white);
  border-bottom-left-radius: 10px;
}

/* ── Bubble Tail — Assistant (left side, single + last) ── */
.imsg__msg--single.imsg__msg--assistant .imsg__bubble--assistant::before,
.imsg__msg--last.imsg__msg--assistant .imsg__bubble--assistant::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: -7px;
  width: 20px;
  height: 25px;
  background: var(--im-gray);
  border-radius: 0 0 16px 0 / 0 0 14px 0;
}

.imsg__msg--single.imsg__msg--assistant .imsg__bubble--assistant::after,
.imsg__msg--last.imsg__msg--assistant .imsg__bubble--assistant::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -26px;
  width: 26px;
  height: 25px;
  background: var(--im-white);
  border-bottom-right-radius: 10px;
}

/* ── Typing Indicator ── */
.imsg__typing {
  display: none;
  gap: 8px;
  padding: 8px 14px;
  align-items: center;
  background: var(--im-gray);
  border-radius: var(--im-radius) var(--im-radius) var(--im-radius) var(--im-radius-grouped);
  width: fit-content;
  max-width: 75%;
  align-self: flex-start;
  margin-top: 10px;
  flex-shrink: 0;
}

.imsg__typing--visible {
  display: flex;
}

.imsg__typing-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.imsg__typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--im-meta);
  animation: imsg-typing-bounce 1.4s infinite;
}

.imsg__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.imsg__typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

.imsg__typing-status {
  font-family: var(--im-font);
  font-size: 14px;
  font-style: italic;
  color: rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: imsg-status-fade-in 0.3s ease both;
}

.imsg__typing-status:empty {
  display: none;
}

@keyframes imsg-status-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Delivered Text ── */
.imsg__delivered {
  text-align: right;
  font-family: var(--im-font);
  font-size: 12px;
  font-weight: 400;
  color: var(--im-meta);
  margin: 2px 0 0;
  max-width: 75%;
  align-self: flex-end;
  flex-shrink: 0;
}

/* ── Quick-Reply Chips ── */
.imsg__chips-wrap {
  align-self: flex-end;
  max-width: 85%;
  margin-top: 10px;
  flex-shrink: 0;
}

.imsg__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.imsg__chip {
  font-family: var(--im-font);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1.5px solid var(--im-blue);
  background: var(--im-white);
  color: var(--im-blue);
  cursor: default;
  transition: all 0.25s ease;
}

.imsg__chip--selected {
  background: var(--im-blue);
  color: var(--im-white);
}

/* Dim non-selected chips when one is chosen */
.imsg__chips--decided .imsg__chip:not(.imsg__chip--selected) {
  opacity: 0.4;
  transition: opacity 0.3s ease;
}

/* ── Animation States ──
   Hidden messages use display:none so they take zero space.
   The JS adds --hidden to every item on reset, removes it on reveal. */
.imsg__msg--hidden,
.imsg__chips-wrap--hidden,
.imsg__delivered--hidden {
  display: none !important;
}

/* Fade-in when revealed */
@keyframes imsg-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.imsg__msg--revealed {
  animation: imsg-fade-in 0.3s ease both;
}

.imsg__chips-wrap--revealed {
  animation: imsg-fade-in 0.3s ease both;
}

.imsg__delivered--revealed {
  animation: imsg-fade-in 0.2s ease both;
}

/* ── Input Bar ── */
.imsg__inputbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f6f6f6;
  border-top: 0.5px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}

.imsg__inputbar-field {
  flex: 1;
  min-height: 34px;
  padding: 6px 14px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 18px;
  background: var(--im-white);
  font-family: var(--im-font);
  font-size: 16px;
  line-height: 1.3;
  color: var(--im-black);
  text-align: left;
}

.imsg__inputbar-text {
  color: rgba(0,0,0,0.35);
}

.imsg__inputbar-text--typing {
  color: var(--im-black);
}

.imsg__inputbar-text:empty::before {
  content: 'iMessage';
  color: rgba(0,0,0,0.35);
}

/* Blinking cursor when typing */
.imsg__inputbar-text--typing::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--im-blue);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: imsg-cursor-blink 0.6s step-end infinite;
}

@keyframes imsg-cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.imsg__inputbar-send {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--im-blue);
  color: var(--im-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.3;
  transition: opacity 0.2s;
}

.imsg__inputbar-text--typing ~ .imsg__inputbar-send,
.imsg__inputbar-field:has(.imsg__inputbar-text--typing) + .imsg__inputbar-send {
  opacity: 1;
}

.imsg__inputbar-send svg {
  width: 16px;
  height: 16px;
}

/* ── Replay Button ── */
.imsg__replay {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 16px auto 0;
  padding: 8px 20px;
  border: 1.5px solid var(--im-meta);
  border-radius: 20px;
  background: transparent;
  font-family: var(--im-font);
  font-size: 13px;
  font-weight: 500;
  color: var(--im-meta);
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: center;
  flex-shrink: 0;
}

.imsg__replay:hover {
  border-color: var(--im-blue);
  color: var(--im-blue);
}

.imsg__replay--visible {
  display: flex;
}

.imsg__replay svg {
  width: 14px;
  height: 14px;
}

/* ── Home Indicator ── */
.imsg__home-indicator {
  display: flex;
  justify-content: center;
  padding: 8px 0 10px;
  background: var(--im-white);
  flex-shrink: 0;
}

.imsg__home-indicator-bar {
  width: 134px;
  height: 5px;
  background: var(--im-black);
  border-radius: 3px;
  opacity: 0.2;
}

/* ── Responsive ── */
@media (max-width: 620px) {
  .imsg__phone {
    width: 100%;
    border-width: 2px;
    border-radius: 24px;
  }

  .imsg__phone {
    height: 640px;
  }

  .imsg__conversation {
    padding: 12px 16px 14px;
  }
}

@media (max-width: 480px) {
  .imsg__phone {
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .imsg__statusbar {
    padding: 14px 20px 0;
  }
}
