/* ============================================================
   Redddy Support Official — customer chat
   WhatsApp-inspired, mobile first
   ============================================================ */

:root {
  --teal-900: #075e54;
  --teal-700: #128c7e;
  --green: #25d366;
  --green-deep: #1da851;

  --bg-chat: #efeae2;
  --bg-panel: #ffffff;
  --bg-bar: #f0f2f5;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;

  --text: #111b21;
  --text-dim: #667781;
  --line: #e5e8ea;
  --shadow: 0 1px 1px rgba(11, 20, 26, 0.13);
  --shadow-lg: 0 10px 40px rgba(11, 20, 26, 0.22);

  --header-h: 56px;
  --radius: 14px;
  --app-h: 100dvh;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="dark"] {
  --teal-900: #1f2c33;
  --bg-chat: #0b141a;
  --bg-panel: #111b21;
  --bg-bar: #202c33;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --text: #e9edef;
  --text-dim: #8696a0;
  --line: #222d34;
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.5);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-chat);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

.app {
  display: flex;
  height: var(--app-h);
  overflow: hidden;
}

/* ---------- sidebar: desktop only ---------- */
.sidebar { display: none; }

/* ---------- conversation ---------- */
.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg-chat);
}

.conv-header {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  height: calc(var(--header-h) + var(--safe-t));
  padding: 0 6px 0 12px;
  padding-top: var(--safe-t);
  background: var(--teal-900);
  color: #fff;
}

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--teal-700); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px; flex-shrink: 0;
}
.avatar-header { width: 38px; height: 38px; font-size: 15px; background: rgba(255,255,255,.18); }

.conv-heading { flex: 1; min-width: 0; }
.conv-title {
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-status { font-size: 12px; color: rgba(255,255,255,.72); margin-top: 1px; }
.conv-status.online { color: #b8f5c8; }
.conv-status.typing { color: #b8f5c8; font-style: italic; }

.hdr-btn {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; position: relative;
}
.hdr-btn svg { width: 22px; height: 22px; }
.hdr-btn:active { background: rgba(255,255,255,.14); }
.hdr-badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--green); color: #05231b;
  font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center;
  box-shadow: 0 0 0 2px var(--teal-900);
}

/* header dropdown */
.menu {
  position: absolute; top: calc(100% - 6px); right: 8px;
  background: var(--bg-panel); color: var(--text);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  min-width: 220px; padding: 6px; z-index: 40;
  display: none; flex-direction: column;
  transform-origin: top right;
  animation: pop .12s ease-out;
}
.menu.open { display: flex; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
.menu-item { text-align: left; padding: 12px 14px; border-radius: 8px; font-size: 14.5px; }
.menu-item:active { background: var(--bg-bar); }
.menu-item.danger { color: #e0555a; }

/* ---------- sticky notification notice ---------- */
.notice {
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0; position: relative; z-index: 20;
  padding: 10px 10px 10px 14px;
  background: #fff8e1; color: #6b5518;
  border-bottom: 1px solid rgba(0,0,0,.06);
  font-size: 13px;
}
html[data-theme="dark"] .notice { background: #182229; color: #e5c980; border-bottom-color: var(--line); }
.notice-icon { display: flex; flex-shrink: 0; }
.notice-icon svg { width: 19px; height: 19px; }
.notice-text { flex: 1; line-height: 1.35; }
.notice-cta {
  flex-shrink: 0; background: var(--green-deep); color: #fff;
  padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
}
.notice-cta:active { transform: scale(.96); }
.notice-x { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; opacity: .6; }
.notice-x svg { width: 16px; height: 16px; }

.conn-bar {
  flex-shrink: 0; text-align: center; font-size: 12.5px; font-weight: 500;
  padding: 7px; background: #ffe0b2; color: #7a4f10;
}
html[data-theme="dark"] .conn-bar { background: #2a2114; color: #f0c078; }

/* ---------- messages ---------- */
.conv-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 4% 14px;
  background-color: var(--bg-chat);
  background-image: url('whatsapp-bg.svg');
  background-repeat: repeat;
  background-size: 260px 260px;
}
html[data-theme="dark"] .conv-body { background-blend-mode: luminosity; opacity: 1; }

.empty-state {
  margin: auto; text-align: center; max-width: 320px; padding: 24px 18px;
  background: var(--bg-panel); border-radius: 18px; box-shadow: var(--shadow);
}
.empty-badge {
  width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%;
  background: rgba(37,211,102,.14); color: var(--teal-700);
  display: flex; align-items: center; justify-content: center;
}
.empty-badge svg { width: 27px; height: 27px; }
.empty-title { margin: 0 0 6px; font-size: 16.5px; font-weight: 600; }
.empty-sub { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); }

.day-divider {
  align-self: center; margin: 12px 0 6px;
  background: var(--bg-panel); color: var(--text-dim);
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow);
}

.msg {
  position: relative;
  max-width: 85%;
  padding: 6px 9px 7px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.42;
  box-shadow: var(--shadow);
  animation: msgIn .16s ease-out;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  .msg, .menu { animation: none; }
}

.msg.agent { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.msg.visitor { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }

.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0 2px; }
.msg-text a { color: var(--teal-700); }
html[data-theme="dark"] .msg-text a { color: #7ee0c0; }

.msg-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 3px;
  font-size: 11px; color: var(--text-dim); margin-top: 1px; padding-right: 1px;
  line-height: 1;
}
.ticks { width: 15px; height: 11px; }
.ticks.read { color: #53bdeb; }

.msg-attachment { display: block; margin: -2px -5px 3px; }
.msg-attachment img, .msg-attachment video {
  display: block; max-width: min(68vw, 280px); max-height: 300px;
  border-radius: 6px; background: rgba(0,0,0,.05);
}
.msg-attachment audio { width: min(64vw, 250px); height: 38px; margin: 2px 0; }
.msg-file {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit;
  background: rgba(0,0,0,.05); border-radius: 8px; padding: 9px 11px; min-width: 170px; margin-bottom: 3px;
}
html[data-theme="dark"] .msg-file { background: rgba(255,255,255,.06); }
.msg-file-icon {
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: var(--teal-700); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.msg-file-icon svg { width: 17px; height: 17px; }
.msg-file-name { font-size: 13.5px; overflow-wrap: anywhere; }
.msg-file-size { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }

.msg.pending { opacity: .72; }

/* typing bubble */
.typing-bubble {
  align-self: flex-start; background: var(--bubble-in); box-shadow: var(--shadow);
  border-radius: 8px; border-top-left-radius: 2px; padding: 11px 13px;
  display: flex; gap: 4px; align-items: center;
}
.typing-bubble i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.3s infinite ease-in-out;
}
.typing-bubble i:nth-child(2) { animation-delay: .18s; }
.typing-bubble i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,60%,100% { opacity: .3; } 30% { opacity: 1; } }

/* jump to latest */
.scroll-down {
  position: absolute; right: 14px; bottom: 88px; z-index: 15;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg-panel); color: var(--text-dim);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
}
.scroll-down svg { width: 20px; height: 20px; }
.sd-badge {
  position: absolute; top: -5px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; background: var(--green); color: #05231b;
  font-size: 11px; font-weight: 700; line-height: 19px; text-align: center;
}

.upload-progress {
  flex-shrink: 0; font-size: 12.5px; color: var(--text-dim);
  padding: 7px 16px; background: var(--bg-bar);
}

/* ---------- composer ---------- */
.composer {
  flex-shrink: 0; position: relative; z-index: 18;
  background: var(--bg-bar);
  padding: 6px 6px calc(6px + var(--safe-b));
}
.composer-row { display: flex; align-items: flex-end; gap: 5px; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
}
.icon-btn svg { width: 23px; height: 23px; }
.icon-btn:active { background: rgba(0,0,0,.07); }
html[data-theme="dark"] .icon-btn:active { background: rgba(255,255,255,.08); }

#msgInput {
  flex: 1; min-width: 0;
  border: none; outline: none; resize: none;
  background: var(--bg-panel); color: var(--text);
  border-radius: 21px;
  padding: 11px 15px;
  font-family: inherit;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  line-height: 1.35;
  max-height: 132px;
  box-shadow: var(--shadow);
}
#msgInput::placeholder { color: var(--text-dim); }

.round-btn {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: var(--teal-700); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease;
}
.round-btn:active { transform: scale(.92); }
.round-btn svg { width: 22px; height: 22px; }
#sendBtn svg { margin-left: 1px; }

/* recording bar */
.recording {
  position: absolute; inset: 6px 6px calc(6px + var(--safe-b));
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-bar); border-radius: 21px; padding: 0 4px 0 6px;
}
.rec-cancel { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; color: var(--text-dim); }
.rec-cancel svg { width: 21px; height: 21px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e0555a; animation: pulse 1.1s infinite; flex-shrink: 0; }
@keyframes pulse { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600; min-width: 40px; }
.rec-hint { flex: 1; font-size: 12.5px; color: var(--text-dim); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- emoji tray ---------- */
.emoji-tray {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  background: var(--bg-panel); border-radius: 12px;
  padding: 6px; margin-bottom: 6px;
  max-height: 34vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.emoji-tray button { font-size: 26px; padding: 8px 0; border-radius: 8px; line-height: 1; }
.emoji-tray button:active { background: var(--bg-bar); }

/* ---------- attachment sheet ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(11,20,26,.45);
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: var(--bg-panel);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(24px + var(--safe-b));
  transform: translateY(110%);
  transition: transform .22s cubic-bezier(.32, .72, 0, 1);
  box-shadow: var(--shadow-lg);
}
.sheet.open { transform: translateY(0); }
.sheet-grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 18px; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sheet-tile {
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  font-size: 12.5px; color: var(--text-dim); padding: 6px 0; border-radius: 12px;
}
.sheet-tile:active { background: var(--bg-bar); }
.tile-icon {
  width: 54px; height: 54px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.tile-icon svg { width: 25px; height: 25px; }
.ti-media { background: linear-gradient(140deg, #0c8bff, #5a4bff); }
.ti-camera { background: linear-gradient(140deg, #ff4d6d, #d62aa0); }
.ti-doc { background: linear-gradient(140deg, #7b61ff, #5a3bd6); }
.ti-audio { background: linear-gradient(140deg, #ff8a00, #ff5a2d); }

/* ---------- notification centre ---------- */
.panel {
  position: fixed; inset: 0; z-index: 90;
  background: var(--bg-panel);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .24s cubic-bezier(.32, .72, 0, 1);
  visibility: hidden;
}
.panel.open { transform: translateX(0); visibility: visible; }

.panel-header {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
  height: calc(var(--header-h) + var(--safe-t));
  padding: 0 10px 0 4px; padding-top: var(--safe-t);
  background: var(--teal-900); color: #fff;
}
.panel-title { flex: 1; font-size: 17px; font-weight: 600; }
.panel-link { font-size: 13.5px; font-weight: 600; color: #b8f5c8; padding: 8px; }

.push-row {
  display: flex; align-items: center; gap: 14px; flex-shrink: 0;
  padding: 16px; border-bottom: 8px solid var(--bg-chat);
}
.push-row-title { font-size: 15.5px; font-weight: 600; margin-bottom: 3px; }
.push-row-sub { font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.push-row-text { flex: 1; }

.switch {
  width: 50px; height: 30px; border-radius: 15px; flex-shrink: 0;
  background: #c9d0d4; position: relative; transition: background .18s ease;
}
html[data-theme="dark"] .switch { background: #3b4a54; }
.switch[aria-checked="true"] { background: var(--green-deep); }
.knob {
  position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .18s cubic-bezier(.32,.72,0,1);
}
.switch[aria-checked="true"] .knob { transform: translateX(20px); }

.notif-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.notif-empty {
  padding: 60px 40px; text-align: center; color: var(--text-dim);
}
.notif-empty svg { width: 46px; height: 46px; opacity: .35; margin-bottom: 14px; }
.notif-empty p { margin: 0; font-size: 13.5px; line-height: 1.6; }

.notif-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  width: 100%; text-align: left;
}
.notif-item:active { background: var(--bg-bar); }
.notif-item.unread { background: rgba(37,211,102,.07); }
.notif-av {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--teal-700); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px;
}
.notif-body { flex: 1; min-width: 0; }
.notif-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.notif-title { font-size: 14.5px; font-weight: 600; }
.notif-time { font-size: 11.5px; color: var(--text-dim); flex-shrink: 0; }
.notif-text {
  font-size: 13.5px; color: var(--text-dim); margin-top: 2px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex-shrink: 0; align-self: center; }

/* ---------- name modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(11,20,26,.5);
  display: none; align-items: center; justify-content: center; padding: 22px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--bg-panel); border-radius: 16px; padding: 22px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.modal-card h2 { margin: 0 0 6px; font-size: 18px; }
.modal-card p { margin: 0 0 16px; font-size: 13.5px; color: var(--text-dim); line-height: 1.5; }
.modal-card input {
  width: 100%; padding: 12px 14px; font-size: 16px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
  background: var(--bg-chat); color: var(--text);
}
.modal-card input:focus { border-color: var(--teal-700); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-ghost { padding: 11px 18px; border-radius: 22px; font-size: 14.5px; font-weight: 600; color: var(--text-dim); }
.btn-solid { padding: 11px 22px; border-radius: 22px; font-size: 14.5px; font-weight: 600; background: var(--teal-700); color: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  z-index: 99; max-width: 88vw;
  background: rgba(17,27,33,.94); color: #fff;
  padding: 11px 18px; border-radius: 22px; font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .18s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* focus visibility for keyboard users */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ============================================================
   Tablet / desktop
   ============================================================ */
@media (min-width: 820px) {
  body { background: #d9dbd5; }
  html[data-theme="dark"] body { background: #0b141a; }

  .app {
    max-width: 1500px; margin: 0 auto;
    height: 100dvh;
    box-shadow: 0 6px 30px rgba(11,20,26,.12);
  }

  .sidebar {
    display: flex; flex-direction: column;
    width: 340px; flex-shrink: 0;
    background: var(--bg-panel); border-right: 1px solid var(--line);
  }
  .sidebar-header { padding: 14px 18px; background: var(--bg-bar); border-bottom: 1px solid var(--line); }
  .brand { display: flex; align-items: center; gap: 12px; }
  .brand-avatar {
    width: 42px; height: 42px; border-radius: 50%; background: var(--teal-700); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 17px;
  }
  .brand-name { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
  .brand-tag { font-size: 12px; color: var(--text-dim); margin-top: 1px; }

  .chat-list { flex: 1; overflow-y: auto; }
  .chat-item { display: flex; align-items: center; gap: 13px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
  .chat-item.active { background: var(--bg-bar); }
  .chat-item-text { min-width: 0; }
  .chat-item-name { font-weight: 600; font-size: 14.5px; }
  .chat-item-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }
  .chat-item-sub.online { color: var(--green-deep); font-weight: 600; }
  .sidebar-note { padding: 20px 18px; font-size: 12.5px; line-height: 1.6; color: var(--text-dim); }

  .conv-header { padding-left: 18px; padding-right: 10px; }
  .conv-body { padding: 20px 6% 20px; gap: 4px; }
  .msg { max-width: min(65%, 520px); font-size: 14.5px; }
  .msg-attachment img, .msg-attachment video { max-width: 300px; }
  .composer { padding: 8px 14px; }
  .icon-btn:hover { background: rgba(0,0,0,.06); }
  .round-btn:hover { background: var(--teal-900); }
  .menu-item:hover { background: var(--bg-bar); }
  .notif-item:hover { background: var(--bg-bar); }

  .panel {
    left: auto; width: 400px; border-left: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
  }
  .sheet { left: 50%; right: auto; width: 420px; transform: translate(-50%, 110%); }
  .sheet.open { transform: translate(-50%, 0); }
  .emoji-tray { grid-template-columns: repeat(12, 1fr); }
  .scroll-down { bottom: 92px; }
}
