/* ============================================================
   BANDOCHAP CUSTOMER CHAT — white & green, WhatsApp-style
   ============================================================ */
:root {
  --green: #00a884;
  --green-dark: #008069;
  --green-soft: #e7f8f2;
  --green-online: #25d366;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --text: #111b21;
  --text-2: #54656f;
  --text-3: #8696a0;
  --border: #e9edef;
  --hover: #f5f6f6;
  --tick-blue: #53bdeb;
  --shadow-sm: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;

  --vodacom: #e60000;
  --airtel: #ed1c24;
  --yas: #6d28d9;
  --halotel: #f97316;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Icons */
.i {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app {
  height: 100vh;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  background: var(--surface);
}

@media (min-width: 1440px) {
  body { padding: 19px; background: linear-gradient(var(--green) 0 127px, var(--bg) 127px); }
  .app { height: calc(100vh - 38px); box-shadow: 0 6px 18px rgba(11, 20, 26, 0.08); }
}

.pane-header {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.pane-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane-title h2, .pane-title h3 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
}
.pane-title h2 span { overflow: hidden; text-overflow: ellipsis; }
.verified { width: 17px; height: 17px; color: var(--green); }

.status-online, .chat-status {
  font-size: 0.8rem;
  color: var(--text-2);
}
.status-online { color: var(--green-dark); }
.chat-status.typing { color: var(--green-dark); font-weight: 600; }

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--green-soft);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  border-radius: 50%;
  color: var(--text-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background-color 0.15s;
}
.icon-btn:hover { background: rgba(11, 20, 26, 0.06); }
.icon-btn:focus-visible, .btn:focus-visible, .lipa-copy:focus-visible, .lipa-receipt:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* ============================================================
   CHAT PANE
   ============================================================ */
.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 7% 12px;
  display: flex;
  flex-direction: column;
  background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 0);
  background-size: 22px 22px;
}

.system-note {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-bottom: 12px;
  border-radius: 7.5px;
  background: #fff5c4;
  color: #54656f;
  font-size: 0.78rem;
  box-shadow: var(--shadow-sm);
}
.system-note .i { width: 13px; height: 13px; }

.date-divider { align-self: center; margin-bottom: 12px; }
.date-divider span {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 7.5px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}

.messages-flow { display: flex; flex-direction: column; gap: 2px; }

/* ============================================================
   BUBBLES
   ============================================================ */
.msg-row { display: flex; margin-bottom: 2px; animation: msgIn 0.18s ease-out; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.msg-row.in + .msg-row.out, .msg-row.out + .msg-row.in { margin-top: 8px; }

.msg-bubble {
  position: relative;
  max-width: min(65%, 560px);
  padding: 6px 8px 8px 9px;
  border-radius: 7.5px;
  box-shadow: var(--shadow-sm);
  font-size: 0.93rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.msg-row.in .msg-bubble { background: var(--bubble-in); border-top-left-radius: 0; }
.msg-row.out .msg-bubble { background: var(--bubble-out); border-top-right-radius: 0; }

.msg-row.in .msg-bubble::before,
.msg-row.out .msg-bubble::after {
  content: "";
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-bottom: 10px solid transparent;
}
.msg-row.in .msg-bubble::before { left: -8px; border-right: 8px solid var(--bubble-in); }
.msg-row.out .msg-bubble::after { right: -8px; border-left: 8px solid var(--bubble-out); }

.msg-text { white-space: pre-wrap; }
.msg-text strong { font-weight: 600; }

.msg-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 6px 0 -4px 12px;
  font-size: 0.68rem;
  color: var(--text-3);
  user-select: none;
}

.tick { width: 16px; height: 16px; color: var(--text-3); }
.tick.read { color: var(--tick-blue); }

.msg-image {
  display: block;
  margin: -2px -4px 6px -5px;
  border-radius: 6px;
  overflow: hidden;
  max-width: 280px;
  cursor: zoom-in;
}
.msg-image img { width: 100%; display: block; }

.msg-order {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--green-soft);
  border-left: 3px solid var(--green);
  font-size: 0.82rem;
  color: var(--green-dark);
}
.msg-order .i { width: 16px; height: 16px; }

.msg-row.no-anim { animation: none; }

/* Lipa Namba card */
.lipa-card {
  width: 300px;
  max-width: 85%;
  padding: 12px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lipa-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--green-dark);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lipa-head .i { width: 16px; height: 16px; }
.lipa-head small {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-2);
  text-transform: none;
  letter-spacing: 0;
}
.lipa-number-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  border-radius: 10px;
  background: var(--green-soft);
}
.lipa-number {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.lipa-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: none;
  border-radius: 17px;
  background: var(--green);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s;
}
.lipa-copy .i { width: 15px; height: 15px; }
.lipa-copy:hover { background: var(--green-dark); }
.lipa-copy.copied { background: var(--green-dark); }
.lipa-name { margin-top: -4px; font-size: 0.88rem; color: var(--text-2); }
.lipa-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.lipa-details div { display: flex; justify-content: space-between; gap: 12px; }
.lipa-details span { color: var(--text-2); }
.lipa-amount { color: var(--green-dark); }
.lipa-receipt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 19px;
  background: var(--surface);
  color: var(--green-dark);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.lipa-receipt .i { width: 16px; height: 16px; }
.lipa-receipt:hover { background: var(--green-soft); border-color: var(--green); }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Typing indicator */
.typing-bubble {
  display: inline-flex;
  align-self: flex-start;
  gap: 4px;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 7.5px;
  border-top-left-radius: 0;
  background: var(--bubble-in);
  box-shadow: var(--shadow-sm);
}
.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: typing 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

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

/* ============================================================
   COMPOSER
   ============================================================ */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 12px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer .icon-btn { margin-bottom: 2px; }

.composer-input {
  flex: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 22px;
  background: var(--surface);
}
.composer-input textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.35;
  max-height: 120px;
  color: var(--text);
}
.composer-input textarea::placeholder { color: var(--text-3); }

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--green-dark); }
.send-btn:active { transform: scale(0.94); }
.send-btn .i { width: 22px; height: 22px; margin-left: 2px; }

/* ============================================================
   MODALS
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(11, 20, 26, 0.5);
  animation: fade 0.15s ease-out;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(11, 20, 26, 0.2);
  overflow: hidden;
  animation: rise 0.2s ease-out;
}
.modal-card.modal-sm { max-width: 360px; }
.modal-card.modal-lg { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 12px 20px;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }

.modal-body { padding: 4px 20px 20px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 20px 20px;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.15); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border: none;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}
.btn .i { width: 18px; height: 18px; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: none; color: var(--green-dark); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--hover); }
.btn-block { width: 100%; }

.receipt-preview {
  display: grid;
  place-items: center;
  max-height: 300px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}
.receipt-preview img { max-width: 100%; max-height: 300px; object-fit: contain; }

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
  .messages { padding: 12px 12px 8px; }
  .msg-bubble { max-width: 85%; }
  .composer-input textarea, .input { font-size: 16px; } /* prevents iOS zoom */

  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none;
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
