/* =========================
   Chat Layout
========================= */
.chat-wrapper {
  max-width: 100%;
  background: #fff;
  padding: 12px;
  box-sizing: border-box;
}

.chat-box {
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 6px;
  padding: 12px;
  height: 320px;
  overflow-y: auto;
  background: #fafafa;
  margin-bottom: 10px;

  /* Mobile/iOS scroll feel */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* =========================
   Messages & Bubbles
========================= */
.chat-message {
  display: flex;
  margin-bottom: 10px;
}

.chat-message.user { justify-content: flex-end; }
.chat-message.other { justify-content: flex-start; }
.chat-message.system { justify-content: center; }

.chat-bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.35;
  border: 1px solid rgba(0,0,0,0.10);
  background: #fff;
  word-wrap: break-word;
}

.chat-message.user .chat-bubble {
  background: rgba(74,144,226,0.10);
  border-color: rgba(74,144,226,0.25);
}

.chat-message.system .chat-bubble {
  background: #f3f4f6;
  border-color: rgba(0,0,0,0.08);
  color: #555;
  font-style: italic;
  text-align: center;
}

.chat-time {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: #777;
}

.chat-bubble i { opacity: 0.7; }

/* =========================
   Input Area
========================= */
.chat-input-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  box-sizing: border-box;
}

.chat-input:focus {
  border-color: #4a90e2;
  outline: none;
}

.chat-send,
.chat-dark-toggle {
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.12);
  cursor: pointer;
  font-size: 14px;
}

.chat-send {
  background: #4a90e2;
  color: #fff;
}

.chat-send:hover {
  background: #357abd;
}

.chat-dark-toggle {
  background: #fff;
  color: #000;
}

/* Optional online pill */
.chat-online-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

/* =========================
   Dark Mode
========================= */
body.chat-dark .chat-wrapper {
  background: #0f1115;
}

body.chat-dark .chat-box {
  background: #121621;
  border-color: rgba(255,255,255,0.12);
}

body.chat-dark .chat-input {
  background: #0f1115;
  color: #eaeaea;
  border-color: rgba(255,255,255,0.12);
}

body.chat-dark .chat-input::placeholder {
  color: rgba(255,255,255,0.55);
}

body.chat-dark .chat-bubble {
  background: #0f1115;
  color: #eaeaea;
  border-color: rgba(255,255,255,0.10);
}

body.chat-dark .chat-message.user .chat-bubble {
  background: rgba(74,144,226,0.20);
  border-color: rgba(74,144,226,0.35);
}

body.chat-dark .chat-message.system .chat-bubble {
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.78);
  border-color: rgba(255,255,255,0.10);
}

body.chat-dark .chat-dark-toggle,
body.chat-dark .chat-online-pill {
  background: #0f1115;
  color: #eaeaea;
  border-color: rgba(255,255,255,0.12);
}

/* =========================
   MOBILE-FIRST (iOS fixes)
========================= */
@media (max-width: 700px) {
  .chat-wrapper {
    padding: 10px;
  }

  /* Use more screen, leave room for sticky input */
  .chat-box {
    height: calc(100vh - 210px);
    min-height: 220px;
  }

  /* Sticky input bar + safe area */
  .chat-input-wrapper {
    position: sticky;
    bottom: 0;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: inherit;
    z-index: 10;
  }

  /* Prevent iOS zoom: input must be >=16px */
  .chat-input {
    min-height: 44px;
    font-size: 16px;
  }

  /* Larger tap targets */
  .chat-send,
  .chat-dark-toggle,
  .chat-online-pill {
    min-height: 44px;
    padding: 12px 14px;
  }

  /* Bubbles wider on small screens */
  .chat-bubble {
    max-width: 90%;
  }

  /* Optional: hide online pill on very small widths */
  @media (max-width: 380px) {
    .chat-online-pill { display: none; }
  }
}

/* Extra iOS safety */
@supports (-webkit-touch-callout: none) {
  .chat-input { font-size: 16px; }
}
