/* ============================================================
   MyroPay Chat — layered on the existing app.myropay.com theme.
   Depends on css/styles.css being loaded first for --accent,
   --bg-primary, --font-display etc.
   ============================================================ */

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body.chat-body {
  margin: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: calc(var(--app-vh, 1vh) * 100);
}

/* ── Header ─────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.chat-back {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card); color: var(--text-primary);
  border: none; cursor: pointer; flex-shrink: 0;
  text-decoration: none; font-size: 15px;
}
.chat-back:active { background: var(--bg-card-hover); }

.chat-avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; flex-shrink: 0;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-title {
  font-family: var(--font-display); font-weight: 700; font-size: 15.5px;
  display: flex; align-items: center; gap: 6px;
}
.chat-header-sub {
  font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 5px;
}
.chat-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.chat-dot.locked { background: var(--amber); }

.chat-header-actions { display: flex; gap: 8px; }
.chat-icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: none;
  background: var(--bg-card); color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; font-size: 14px;
}
.chat-icon-btn:active { background: var(--bg-card-hover); }
.chat-badge {
  position: absolute; top: -3px; right: -3px; min-width: 15px; height: 15px;
  border-radius: 8px; background: var(--red); color: #fff; font-size: 9.5px;
  font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

/* ── Message stream ─────────────────────────────────────── */
.chat-stream {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg-row { display: flex; gap: 8px; max-width: 100%; }
.msg-row.from-bot { justify-content: flex-start; }
.msg-row.from-user { justify-content: flex-end; }

.msg-bot-avatar {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0; margin-top: 2px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px;
}

.bubble {
  max-width: 78%; padding: 10px 13px; border-radius: 16px;
  font-size: 14.5px; line-height: 1.42; white-space: pre-wrap; word-break: break-word;
  animation: bubbleIn .28s var(--spring);
}
@keyframes bubbleIn { from { opacity:0; transform: translateY(6px) scale(.98);} to {opacity:1; transform:none;} }

.from-bot .bubble {
  background: var(--bg-card); border: 1px solid var(--border);
  border-top-left-radius: 4px; color: var(--text-primary);
}
.from-user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; border-top-right-radius: 4px;
}

.bubble b { font-weight: 700; }
.bubble .mono { font-family: var(--font-mono); }

/* Card-style bot messages (balance, receipt, tx list) */
.bubble.card-bubble {
  max-width: 86%; padding: 0; overflow: hidden; background: var(--bg-card);
  border: 1px solid var(--card-border);
}
.card-inner { padding: 14px; }
.card-header-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:2px;}
.card-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-tertiary); font-weight:700; }
.card-amount { font-family: var(--font-display); font-size: 26px; font-weight: 800; margin: 4px 0; }
.card-amount.positive { color: var(--green); }
.card-amount.negative { color: var(--red); }
.card-sub { font-size: 12.5px; color: var(--text-secondary); }

.receipt-card { background: var(--card-gradient); }
.receipt-row { display:flex; justify-content:space-between; padding:7px 0; border-bottom:1px dashed var(--border); font-size:13px;}
.receipt-row:last-child { border-bottom: none; }
.receipt-row span:first-child { color: var(--text-secondary); }
.receipt-status { display:inline-flex; align-items:center; gap:5px; font-weight:700; }
.receipt-status.completed { color: var(--green); }
.receipt-status.pending { color: var(--amber); }
.receipt-status.failed { color: var(--red); }

.tx-mini-row {
  display:flex; align-items:center; gap:10px; padding:9px 0; border-bottom:1px solid var(--border);
}
.tx-mini-row:last-child { border-bottom:none; }
.tx-mini-icon {
  width:32px;height:32px;border-radius:10px;display:flex;align-items:center;justify-content:center;
  background:var(--bg-input); font-size:13px; flex-shrink:0;
}
.tx-mini-body { flex:1; min-width:0; }
.tx-mini-title { font-size:13.5px; font-weight:600; }
.tx-mini-date { font-size:11px; color:var(--text-tertiary); }
.tx-mini-amount { font-size:13.5px; font-weight:700; white-space:nowrap; }
.tx-mini-amount.positive { color: var(--green); }
.tx-mini-amount.negative { color: var(--red); }

.card-actions { display:flex; gap:8px; padding: 0 14px 14px; }
.card-actions button {
  flex:1; padding:9px; border-radius:10px; border:none; font-size:12.5px; font-weight:700;
  background: var(--bg-input); color: var(--text-primary); cursor:pointer;
}
.card-actions button.primary { background: var(--accent); color:#fff; }

/* Suggestion / quick-reply chips */
.chip-row { display:flex; flex-wrap:wrap; gap:8px; padding: 2px 2px 6px; }
.chip {
  padding: 8px 13px; border-radius: 20px; background: var(--bg-card);
  border: 1px solid var(--border); font-size: 13px; color: var(--text-primary);
  cursor: pointer; white-space: nowrap; display:flex; align-items:center; gap:5px;
}
.chip:active { background: var(--bg-card-hover); }
.chip.suggested { border-color: var(--card-border); background: var(--card-gradient); }

.typing-row .bubble { display:flex; align-items:center; gap:4px; padding: 12px 15px; }
.typing-dot { width:6px;height:6px;border-radius:50%;background:var(--text-tertiary); animation: typingBounce 1.1s infinite; }
.typing-dot:nth-child(2){animation-delay:.15s;} .typing-dot:nth-child(3){animation-delay:.3s;}
@keyframes typingBounce { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-4px);opacity:1} }

.chat-date-divider { text-align:center; font-size:11px; color:var(--text-tertiary); margin: 10px 0 2px; }

/* ── Shortcut rail (above input) ───────────────────────────*/
.shortcut-rail {
  display:flex; gap:8px; padding: 8px 14px; overflow-x:auto; flex-shrink:0;
  border-top: 1px solid var(--glass-border);
}
.shortcut-rail::-webkit-scrollbar { display:none; }
.shortcut-pill {
  flex-shrink:0; display:flex; align-items:center; gap:6px; padding:8px 12px;
  border-radius: 14px; background: var(--bg-card); border:1px solid var(--border);
  font-size:12.5px; font-weight:600; cursor:pointer; color: var(--text-primary);
}
.shortcut-pill iconify-icon, .shortcut-pill .fa { color: var(--accent); font-size: 14px; }
.shortcut-pill:active { background: var(--bg-card-hover); }

/* ── Composer ───────────────────────────────────────────── */
.chat-composer {
  display:flex; align-items:flex-end; gap:8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--glass-bg); backdrop-filter: blur(20px);
  border-top: 1px solid var(--glass-border); flex-shrink:0;
}
.composer-plus {
  width:40px;height:40px;border-radius:50%;border:none;flex-shrink:0;
  background: var(--bg-card); color: var(--text-secondary); font-size:16px; cursor:pointer;
}
.composer-input-wrap {
  flex:1; background: var(--bg-input); border:1px solid var(--border); border-radius:22px;
  display:flex; align-items:center; padding: 4px 6px 4px 15px; min-height:40px;
}
#chat-input {
  flex:1; border:none; background:transparent; color:var(--text-primary); font-size:14.5px;
  font-family: var(--font-body); resize:none; max-height:100px; padding:8px 0; outline:none;
}
#chat-input::placeholder { color: var(--text-tertiary); }
.composer-send {
  width:34px;height:34px;border-radius:50%;border:none;flex-shrink:0;
  background: var(--accent); color:#fff; display:flex;align-items:center;justify-content:center; cursor:pointer;
  transition: opacity .15s, transform .15s;
}
.composer-send:disabled { opacity:.4; }
.composer-send:active:not(:disabled) { transform: scale(.92); }

/* PIN dots inside composer when masking is active */
.pin-mask-wrap { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px; padding:6px 0; }
.pin-box-row { display:flex; gap:9px; }
.pin-dot-input {
  width:38px; height:42px; text-align:center; font-size:19px; font-family: var(--font-mono);
  border-radius:10px; border:1px solid var(--border); background: var(--bg-input); color: var(--text-primary);
}
.pin-dot-input:focus { border-color: var(--accent); outline:none; }
.pin-cancel-btn {
  border:none; background:none; color: var(--text-tertiary); font-size:11.5px; padding:2px 6px; cursor:pointer;
}
.pin-cancel-btn:active { color: var(--text-secondary); }

/* ── Idle-lock overlay ──────────────────────────────────────*/
.idle-overlay {
  position: fixed; inset: 0; z-index: 500; background: rgba(8,9,15,0.72);
  backdrop-filter: blur(6px); display:flex; align-items:center; justify-content:center;
  opacity:0; pointer-events:none; transition: opacity .25s;
}
.idle-overlay.show { opacity:1; pointer-events:auto; }
.idle-card {
  width: min(340px, 88vw); background: var(--bg-secondary); border:1px solid var(--border);
  border-radius: 20px; padding: 26px 22px; text-align:center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.idle-lock-icon {
  width:56px;height:56px;border-radius:16px;margin:0 auto 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display:flex;align-items:center;justify-content:center;color:#fff;font-size:22px;
}
.idle-title { font-family: var(--font-display); font-weight:700; font-size:17px; margin-bottom:4px; }
.idle-sub { font-size:13px; color:var(--text-secondary); margin-bottom:18px; }
.idle-code-inputs { display:flex; gap:8px; justify-content:center; margin-bottom:16px; }
.idle-code-inputs input {
  width:38px; height:46px; text-align:center; font-size:19px; font-family:var(--font-mono);
  border-radius:10px; border:1px solid var(--border); background: var(--bg-input); color:var(--text-primary);
}
.idle-code-inputs input:focus { border-color: var(--accent); outline:none; }
.idle-error { color: var(--red); font-size:12.5px; min-height:16px; margin-bottom:8px; }
.idle-verify-btn {
  width:100%; padding:12px; border-radius:12px; border:none; background:var(--accent); color:#fff;
  font-weight:700; font-size:14px; cursor:pointer;
}
.idle-verify-btn:disabled { opacity:.5; }

/* ── Onboarding / setup guard ───────────────────────────────*/
.setup-guard {
  position: fixed; inset:0; background: var(--bg-primary); z-index: 600;
  display:flex; flex-direction:column; align-items:center; justify-content:center; padding: 30px; text-align:center;
}
.setup-guard i, .setup-guard iconify-icon { font-size: 40px; color: var(--accent); margin-bottom: 16px; }
.setup-guard h2 { font-family: var(--font-display); margin: 0 0 8px; }
.setup-guard p { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; max-width: 320px; }
.setup-guard a.btn {
  padding: 12px 22px; background: var(--accent); color:#fff; border-radius: 12px;
  text-decoration:none; font-weight:700; font-size:14px;
}

/* Toast (mirrors app.myropay.com's, kept local so chat.html has no dependency) */
.toast-el {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--bg-secondary); color: var(--text-primary); border:1px solid var(--border);
  padding: 10px 18px; border-radius: 12px; font-size: 13px; z-index: 700; opacity:0;
  transition: all .25s; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.toast-el.show { opacity:1; transform: translateX(-50%) translateY(0); }
.toast-el.error { border-color: var(--red); }
.toast-el.success { border-color: var(--green); }

/* Floating entry-point bubble used on index.html */
.chat-fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40;
  width: 52px; height: 52px; border-radius: 50%; text-decoration:none;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display:flex; align-items:center; justify-content:center; color:#fff; font-size:20px;
  box-shadow: 0 10px 26px var(--accent-glow); border: none;
}
.chat-fab .fa { position: relative; }
.chat-fab-badge {
  position:absolute; top:-2px; right:-2px; min-width:16px; height:16px; border-radius:8px;
  background: var(--red); font-size:9.5px; font-weight:800; color:#fff;
  display:flex; align-items:center; justify-content:center; padding:0 3px;
}

@media (min-width: 860px) {
  .chat-stream, .chat-composer, .chat-header, .shortcut-rail { max-width: 640px; margin-left:auto; margin-right:auto; }
}
