:root {
  --bg: #0f172a;
  --panel: #111827;
  --card: #1f2937;
  --accent: #22c55e;
  --accent-2: #16a34a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --user: #2563eb;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(160deg, #0b1220, #0f172a);
  color: var(--text);
}

/* ---- Chat ---- */
.chat-wrap {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: none;
  border-radius: 0;
  overflow: hidden;
}
/* Page itself never scrolls; only the message list does. Beige backdrop (no blue). */
body:has(.chat-wrap) { overflow: hidden; background: #d8d2c7; }

@media (min-width: 760px) {
  .chat-wrap {
    height: calc(100dvh - 32px);
    margin: 16px auto;
    border: 1px solid #1f2937;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  }
}

.chat-header, .inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #0b1324;
  border-bottom: 1px solid #1f2937;
}

/* WhatsApp-style green header for the chat page only */
.chat-header { background: #008069; border-bottom-color: #017561; }
.chat-header .title { color: #fff; }
.chat-header .subtitle { color: rgba(255,255,255,0.85); }
.chat-header .link { color: #fff; }
.chat-header .dot { background: #b6f5c8; box-shadow: 0 0 12px #b6f5c8; }

.brand { display: flex; align-items: center; gap: 12px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.title { font-weight: 700; }
.subtitle { font-size: 12px; color: var(--muted); }
.link { color: var(--accent); text-decoration: none; font-size: 14px; }
.link:hover { text-decoration: underline; }

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* WhatsApp-style beige chat background */
  background: #efeae2;
}

.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  color: #111b21;
}
.msg.assistant .bubble { background: #ffffff; border-top-left-radius: 4px; }
.msg.user .bubble { background: #d9fdd3; color: #111b21; border-top-right-radius: 4px; }

.qr { margin-top: 8px; width: 200px; max-width: 70vw; height: auto; background: white; border-radius: 10px; padding: 6px; }

.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #d9d3c9;
  /* Same beige family as the message area */
  background: #efeae2;
}
.composer input {
  flex: 1;
  padding: 11px 16px;
  border-radius: 22px;
  border: 1px solid #d1d7db;
  background: #ffffff;
  color: #111b21;
  font-size: 15px;
}
.composer input::placeholder { color: #8696a0; }
.composer input:focus { outline: none; border-color: #25d366; }

/* Emoji picker */
.emoji-panel {
  position: absolute;
  left: 8px; right: 8px;
  bottom: 70px;
  max-width: 704px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 -8px 28px rgba(0,0,0,0.25);
  z-index: 30;
}
.emoji-panel .emoji {
  font-size: 22px;
  line-height: 1;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.emoji-panel .emoji:hover { background: #f0f0f0; }
.composer button:not(.icon-btn) {
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--accent-2);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
[hidden] { display: none !important; }

/* Round icon buttons (emoji / attach / mic / send / cancel) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn.mic { background: #008069; }
.icon-btn.mic:hover { background: #017561; }
.icon-btn.send { background: #008069; }
.icon-btn.send:hover { background: #017561; }
.icon-btn.cancel { background: #e0dcd3; color: #54656f; }
.icon-btn.cancel:hover { background: #d1ccc2; }
/* Ghost buttons (emoji / attach) sit on the beige composer */
.icon-btn.ghost { background: transparent; color: #54656f; }
.icon-btn.ghost:hover { background: rgba(0,0,0,0.06); }

/* Recording bar (WhatsApp style) */
.rec-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid #d9d3c9;
  background: #efeae2;
}
.rec-bar .rec-time { color: #111b21; }
.rec-bar .rec-hint { color: #54656f; }
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 10px #ef4444;
  animation: recpulse 1.2s infinite ease-in-out;
  flex: 0 0 auto;
}
@keyframes recpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); min-width: 42px; }
.rec-hint { flex: 1; color: var(--muted); font-size: 13px; }

/* ---- Inbox ---- */
.inbox-wrap { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.inbox-actions { display: flex; gap: 16px; align-items: center; }
.inbox-actions select { background: #0f172a; color: var(--text); border: 1px solid #374151; border-radius: 8px; padding: 6px; }
.inbox-body { display: grid; grid-template-columns: 320px 1fr; gap: 16px; margin-top: 16px; }
.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket-card { background: var(--card); border: 1px solid #374151; border-radius: 12px; padding: 12px; cursor: pointer; }
.ticket-card:hover { border-color: var(--accent); }
.ticket-top { display: flex; gap: 8px; margin-bottom: 6px; }
.ticket-subject { font-weight: 600; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #374151; text-transform: uppercase; }
.badge.escalation { background: #b45309; }
.badge.refund { background: #7c3aed; }
.badge.status-open { background: #dc2626; }
.badge.status-resolved { background: #16a34a; }
.ticket-detail { background: var(--card); border: 1px solid #374151; border-radius: 12px; padding: 16px; min-height: 400px; }
.detail-header { border-bottom: 1px solid #374151; padding-bottom: 12px; margin-bottom: 12px; }
.detail-header button { margin-top: 8px; padding: 6px 12px; border: none; border-radius: 8px; background: var(--accent-2); color: white; cursor: pointer; }
.transcript { display: flex; flex-direction: column; gap: 10px; }
.transcript .msg { max-width: 100%; }
.transcript .role { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.transcript .text { white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
