* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #128c7e;          /* WhatsApp teal */
  --primary-dark: #075e54;     /* darker teal */
  --accent: #25d366;           /* bright green */
  --bg: #efeae2;               /* chat background beige */
  --card: #ffffff;
  --border: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --bubble-customer: #d9fdd3;       /* sender (you) light green */
  --bubble-customer-text: #111b21;
  --bubble-admin: #ffffff;          /* receiver white */
  --bubble-admin-text: #111b21;
  --success: #25d366;
  --danger: #e53e3e;
  --shadow-bubble: 0 1px 0.5px rgba(11,20,26,.13);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.screen { display: flex; flex-direction: column; height: 100vh; }
.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
#login-screen {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255,255,255,.10) 0%, transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(255,255,255,.10) 0%, transparent 60%),
    linear-gradient(135deg, #075e54 0%, #128c7e 60%, #25d366 100%);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 38px 34px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.22);
}
.brand { text-align: center; margin-bottom: 26px; }
.logo {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
  font-size: 32px;
  box-shadow: 0 8px 22px rgba(18,140,126,.3);
  overflow: hidden;
}
.logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand h1 { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 4px; letter-spacing: -.2px; }
.subtitle { color: var(--muted); font-size: 14px; }
#login-form label { display: block; margin-bottom: 16px; }
#login-form span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #4a5568; }
#login-form input,
#login-form select {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
}
#login-form input:focus,
#login-form select:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(18,140,126,.15); }
#login-form small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.primary {
  padding: 13px; border: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: filter .15s;
}
.primary:hover { filter: brightness(1.05); }
#login-form .primary { width: 100%; }

/* ---------- CHAT ---------- */
#chat-screen { background: var(--bg); }

/* WhatsApp-style doodle background */
.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 12px 18px;
  display: flex; flex-direction: column; gap: 4px;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'><g fill='none' stroke='%23000000' stroke-opacity='.04' stroke-width='1.2'><circle cx='80' cy='80' r='38'/><path d='M250 60c10 0 20 8 20 20s-10 20-20 20-20-8-20-20 10-20 20-20z'/><path d='M340 130l24 8-8 24-24-8z'/><path d='M60 200l-15 30 30 0z'/><circle cx='200' cy='220' r='25'/><path d='M310 270c12 0 22-10 22-22s-10-22-22-22-22 10-22 22 10 22 22 22z'/><path d='M120 310l-22 22 22 22 22-22z'/><path d='M260 350h44v22h-44z'/><path d='M30 360c8-8 22-8 30 0s8 22 0 30'/></g><g fill='%23000000' fill-opacity='.025'><circle cx='80' cy='80' r='5'/><circle cx='250' cy='80' r='5'/><circle cx='200' cy='220' r='5'/><circle cx='310' cy='250' r='5'/></g></svg>");
  background-repeat: repeat;
  background-size: 420px 420px;
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--primary-dark);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
  z-index: 2;
}
.header-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex: 0 0 40px;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-logo { background: #fff; padding: 0; }
.title { font-weight: 600; font-size: 16px; line-height: 1.2; letter-spacing: -.1px; }
.status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; opacity: .85; margin-top: 2px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #fbd38d; }
.status.online .dot { background: #25d366; box-shadow: 0 0 0 2px rgba(37,211,102,.25); }
.status.offline .dot { background: #fc8181; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Store button — gradient green, eye-catching */
.store-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #25d366 0%, #1ebe5c 100%);
  color: #fff;
  border: 0;
  padding: 7px 14px;
  border-radius: 18px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .6px;
  text-decoration: none;
  box-shadow: 0 3px 10px rgba(37,211,102,.4);
  transition: transform .12s, box-shadow .12s, filter .12s;
  white-space: nowrap;
}
.store-btn:hover { transform: translateY(-1px); filter: brightness(1.08); box-shadow: 0 5px 14px rgba(37,211,102,.5); }
.store-btn:active { transform: translateY(0); }

.icon-btn {
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  padding: 8px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  width: 36px; height: 36px;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }

/* ---------- MESSAGES (bubbles WhatsApp-style) ---------- */
.msg {
  max-width: 75%;
  padding: 6px 9px 7px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.42;
  word-wrap: break-word;
  position: relative;
  animation: fadeIn .18s ease-out;
  box-shadow: var(--shadow-bubble);
  margin: 2px 0;
}
@keyframes fadeIn { from { opacity:0; transform: translateY(4px);} to { opacity:1; transform: none;} }
.msg.customer {
  background: var(--bubble-customer);
  color: var(--bubble-customer-text);
  align-self: flex-end;
  border-top-right-radius: 8px;
  border-top-left-radius: 8px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 8px;
  margin-right: 6px;
  position: relative;
}
.msg.customer::after {
  content: '';
  position: absolute;
  right: -7px;
  bottom: 0;
  width: 0; height: 0;
  border-left: 7px solid var(--bubble-customer);
  border-bottom: 7px solid transparent;
}
.msg.admin {
  background: var(--bubble-admin);
  color: var(--bubble-admin-text);
  align-self: flex-start;
  border-top-right-radius: 8px;
  border-top-left-radius: 8px;
  border-bottom-right-radius: 8px;
  border-bottom-left-radius: 0;
  margin-left: 6px;
  position: relative;
}
.msg.admin::before {
  content: '';
  position: absolute;
  left: -7px;
  bottom: 0;
  width: 0; height: 0;
  border-right: 7px solid var(--bubble-admin);
  border-bottom: 7px solid transparent;
}
.msg.system {
  align-self: center;
  background: rgba(225,245,254,.92);
  color: #334155;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 8px;
  max-width: 80%;
  text-align: center;
  box-shadow: var(--shadow-bubble);
  margin: 6px 0;
}
.msg time {
  display: inline-block;
  font-size: 10.5px;
  color: rgba(0,0,0,.45);
  margin-top: 2px;
  margin-left: 6px;
  float: right;
  line-height: 1.4;
}
.msg.system time { display: none; }
.msg::after, .msg::before { display: none; }
.msg.customer::after, .msg.admin::before { display: block; }

.msg a { color: #027eb5; text-decoration: underline; }
.msg .order-link {
  display: inline-block;
  background: rgba(0,0,0,.06);
  padding: 1px 7px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 12px;
  color: #027eb5;
}
.msg.customer .order-link { background: rgba(0,0,0,.05); }
.msg .copyable {
  cursor: pointer;
  text-decoration: underline dotted;
  color: #027eb5;
}
.msg .copyable:hover { opacity: .85; }
.msg img, .msg video {
  max-width: 280px;
  max-height: 280px;
  border-radius: 6px;
  display: block;
  margin-top: 4px;
  cursor: pointer;
}

/* ---------- COMPOSER ---------- */
.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: #f0f2f5;
  border-top: 0;
}
.composer .icon-btn {
  color: #54656f;
  font-size: 18px;
  flex: 0 0 auto;
  background: transparent;
}
.composer .icon-btn:hover { background: rgba(0,0,0,.06); color: var(--primary); }
.composer .icon-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 16px;
  flex: 0 0 44px;
  box-shadow: 0 3px 10px rgba(18,140,126,.35);
}
.composer .icon-btn.primary:hover { filter: brightness(1.08); }

#message-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: #ffffff;
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 14.5px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  outline: 0;
  box-shadow: 0 1px 1px rgba(11,20,26,.06);
}
#message-input:focus { box-shadow: 0 0 0 2px rgba(18,140,126,.18); }

/* RTL support */
body.rtl .msg.customer { align-self: flex-start; border-bottom-right-radius: 8px; border-bottom-left-radius: 0; margin-left: 6px; margin-right: 0; }
body.rtl .msg.customer::after { left: -7px; right: auto; border-right: 7px solid var(--bubble-customer); border-left: 0; }
body.rtl .msg.admin    { align-self: flex-end; border-bottom-left-radius: 8px; border-bottom-right-radius: 0; margin-right: 6px; margin-left: 0; }
body.rtl .msg.admin::before { right: -7px; left: auto; border-left: 7px solid var(--bubble-admin); border-right: 0; }
body.rtl .messages, body.rtl #message-input { direction: rtl; }

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,.85); }
#modal-img { position: relative; max-width: 90vw; max-height: 90vh; border-radius: 6px; }
#modal-close { position: absolute; top: 20px; right: 20px; font-size: 22px; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #1a202c; color: #fff;
  padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 10000;
  animation: toastIn .2s;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
@keyframes toastIn { from { opacity:0; transform: translate(-50%, 8px);} to { opacity:1; transform: translateX(-50%);} }

/* ---------- NOTIFICATION PROMPT ---------- */
.notif-prompt {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  background: linear-gradient(90deg, #d4f8d4 0%, #c6f6c6 100%);
  border-bottom: 1px solid #a7e9a7;
  color: #1f5d1f;
  font-size: 13px;
}
.notif-prompt span { flex: 1; }
.notif-prompt button {
  border: 0; padding: 7px 16px; border-radius: 16px;
  font-size: 12.5px; cursor: pointer; font-weight: 700;
}
.notif-prompt .btn-yes {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
}
.notif-prompt .btn-yes:hover { filter: brightness(1.05); }
.notif-prompt .btn-no { background: #fff; color: #4a5568; border: 1px solid #cbd5e0; }
.notif-prompt .btn-no:hover { background: #edf2f7; }

/* ---------- FILE ATTACHMENT ---------- */
.file-attachment {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.04);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  max-width: 100%;
  border: 1px solid rgba(0,0,0,.06);
}
.msg.customer .file-attachment { background: rgba(255,255,255,.6); }
.file-attachment:hover { background: rgba(0,0,0,.08); }
.msg.customer .file-attachment:hover { background: rgba(255,255,255,.8); }
.file-attachment .file-icon { font-size: 18px; }
.file-attachment .file-name { font-weight: 600; word-break: break-all; }
.file-attachment .file-action { font-size: 11.5px; opacity: .7; margin-left: 4px; color: var(--primary); }

/* ---------- BUSINESS HOURS BANNER ---------- */
.bh-banner {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 7px 14px;
  background: rgba(0,0,0,.04);
  border-bottom: 1px solid rgba(0,0,0,.07);
  color: #54656f;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .1px;
  cursor: help;
  z-index: 1;
}
.bh-banner .bh-icon { font-size: 13px; opacity: .85; }
.bh-banner .bh-sep  { opacity: .5; margin: 0 4px; }

@media (max-width: 380px) {
  .bh-banner { font-size: 11px; padding: 6px 10px; }
}

/* ---------- TRANSLATE BUTTON + POPOVER ---------- */
.msg-tools {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  clear: both;
}
.translate-btn {
  background: rgba(0,0,0,.05);
  border: 0;
  color: #54656f;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 12px;
  cursor: pointer;
  opacity: .75;
  transition: opacity .12s, background .12s;
}
.msg.customer .translate-btn { background: rgba(0,0,0,.06); }
.translate-btn:hover { opacity: 1; background: rgba(0,0,0,.1); }

.translate-more-btn {
  background: rgba(0,0,0,.05);
  border: 0;
  color: #54656f;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  cursor: pointer;
  opacity: .55;
  line-height: 1;
  transition: opacity .12s, background .12s;
}
.translate-more-btn:hover { opacity: 1; background: rgba(0,0,0,.1); }

.translation-result {
  margin-top: 6px;
  padding: 8px 12px;
  background: rgba(255,255,255,.85);
  border-left: 3px solid var(--primary);
  color: #111b21;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.45;
  clear: both;
}
.msg.customer .translation-result { background: rgba(255,255,255,.55); }
.translation-result.loading { color: #99a;  font-style: italic; }
.translation-result.error { background: #fff5f5; border-left-color: #e53e3e; color: #742a2a; }
.translation-result .tr-flag { margin-right: 6px; }

.translate-popover {
  position: fixed;
  z-index: 10000;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  padding: 4px;
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  animation: popIn .12s ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tp-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  border: 0; background: transparent;
  text-align: left;
  font-size: 13.5px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text);
}
.tp-item:hover { background: #f0f2f5; }
.tp-flag { font-size: 17px; }
.tp-name { font-weight: 500; }
.tp-item.active {
  background: #e7f9ed;
  color: var(--primary-dark);
}
.tp-item.active::after {
  content: '✓';
  margin-left: auto;
  font-weight: 700;
  color: var(--primary);
}

@media (max-width: 480px) {
  .login-card { padding: 28px 22px; }
  .msg { max-width: 88%; }
  .store-btn { padding: 5px 10px; font-size: 10.5px; }
  .icon-btn { width: 32px; height: 32px; font-size: 15px; }
}
