/* Live chat bubble — app/views/shared/_support_chat.html.erb + app/javascript/support_chat.js
   Plain CSS (not Sass) so the home page layout, which does not load the app stylesheet, can link it directly. */

.sc {
  --sc-pine: #2d5b4c;
  --sc-pine-dark: #1f4337;
  --sc-birch: #f6f4ef;
  --sc-mint: #e3ece7;
  --sc-ink: #1c2421;
  --sc-muted: #4f5a55;
  --sc-line: #dcd8cf;
  --sc-gold: #e2b866;
  --sc-focus: #b9740f;
  --sc-danger: #8a3b0a;
  --sc-lift: 0px;
  --sc-gap: 20px;

  position: fixed;
  right: calc(var(--sc-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--sc-gap) + var(--sc-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--sc-ink);
  transition: bottom 0.2s ease;
}
.sc--open { z-index: 65; }
.sc *, .sc *::before, .sc *::after { box-sizing: border-box; }
.sc [hidden] { display: none !important; }
.sc :focus-visible { outline: 3px solid var(--sc-focus); outline-offset: 2px; }

/* ---- launcher ---- */
.sc-launcher {
  order: 3;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 0 24px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--sc-pine);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(31, 67, 55, 0.32), 0 2px 6px rgba(31, 67, 55, 0.2);
  transition: background 0.15s ease, transform 0.15s ease;
}
.sc-launcher:hover { background: var(--sc-pine-dark); transform: translateY(-1px); }
.sc-launcher-close { display: none; }
.sc--open .sc-launcher-icon { display: none; }
.sc--open .sc-launcher-close { display: block; }
.sc--open .sc-launcher { padding: 0; width: 60px; justify-content: center; }
.sc--open .sc-launcher-label { display: none; }

.sc-badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--sc-gold);
  color: var(--sc-ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

/* ---- new-reply teaser ---- */
.sc-teaser {
  order: 2;
  position: relative;
  max-width: 300px;
  background: #fff;
  border: 1px solid var(--sc-line);
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 12px 30px rgba(28, 36, 33, 0.16);
  animation: sc-rise 0.25s ease-out;
}
.sc-teaser-open {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 14px 40px 14px 16px;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  color: var(--sc-ink);
  cursor: pointer;
}
.sc-teaser-open strong { font-size: 15px; color: var(--sc-pine); }
.sc-teaser-open span { font-size: 16px; }
.sc-teaser-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--sc-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

/* ---- panel ---- */
.sc-panel {
  order: 1;
  display: flex;
  flex-direction: column;
  width: 400px;
  height: 640px;
  max-height: calc(100vh - 130px - var(--sc-lift));
  background: #fff;
  border: 1px solid var(--sc-line);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(28, 36, 33, 0.22);
  overflow: hidden;
  animation: sc-rise 0.2s ease-out;
}

.sc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px 16px 18px;
  background: var(--sc-pine);
  color: #fff;
}
.sc-head-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}
.sc-head-text { flex: 1; min-width: 0; }
.sc-head h2 {
  margin: 0;
  font-family: "Manrope", "Inter", system-ui, sans-serif;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
}
.sc-head p { margin: 2px 0 0; font-size: 15px; color: rgba(255, 255, 255, 0.85); }
.sc-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.sc-close:hover { background: rgba(255, 255, 255, 0.14); }

.sc-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  background: var(--sc-birch);
}

/* ---- messages ---- */
.sc-messages {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sc-msg {
  max-width: 86%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sc-msg-body {
  padding: 11px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 17px;
}
.sc-msg--staff { align-self: flex-start; }
.sc-msg--staff .sc-msg-body {
  background: #fff;
  border: 1px solid var(--sc-line);
  border-bottom-left-radius: 6px;
}
.sc-msg--visitor { align-self: flex-end; align-items: flex-end; }
.sc-msg--visitor .sc-msg-body {
  background: var(--sc-pine);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.sc-msg--pending { opacity: 0.6; }
.sc-msg-author { font-size: 13px; font-weight: 700; color: var(--sc-muted); padding-left: 4px; }
.sc-msg-time { font-size: 12px; color: var(--sc-muted); padding: 0 4px; }

/* ---- start form ---- */
.sc-start {
  margin-top: 14px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--sc-line);
  border-radius: 16px;
  display: grid;
  gap: 12px;
}
.sc-as { margin: 0; font-weight: 700; color: var(--sc-pine); }
.sc-identity { display: grid; gap: 12px; }
.sc-field { display: grid; gap: 5px; min-width: 0; }
.sc-field > span { font-size: 15px; font-weight: 700; }
.sc-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sc-field input,
.sc-field textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--sc-line);
  border-radius: 12px;
  background: #fff;
  color: var(--sc-ink);
  font: inherit;
  font-size: 17px; /* 16px+ stops iOS zooming into the field */
}
.sc-field textarea { resize: vertical; min-height: 84px; }
.sc-field input:focus,
.sc-field textarea:focus { border-color: var(--sc-pine); outline: none; box-shadow: 0 0 0 3px rgba(45, 91, 76, 0.18); }
.sc-help { margin: -4px 0 0; font-size: 14px; color: var(--sc-muted); }

.sc-topics { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.sc-topics legend { padding: 0; margin-bottom: 6px; font-size: 15px; font-weight: 700; }
.sc-topic { position: relative; }
.sc-topic input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sc-topic span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--sc-line);
  border-radius: 999px;
  background: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.sc-topic input:checked + span { background: var(--sc-mint); border-color: var(--sc-pine); color: var(--sc-pine-dark); }
.sc-topic input:focus-visible + span { outline: 3px solid var(--sc-focus); outline-offset: 2px; }

.sc-btn {
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--sc-pine);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.sc-btn:hover { background: var(--sc-pine-dark); }
.sc-btn:disabled { opacity: 0.7; cursor: progress; }

.sc-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fbefe6;
  color: var(--sc-danger);
  font-size: 15px;
  font-weight: 600;
}
.sc-hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.sc-vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- composer ---- */
.sc-composer {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--sc-line);
  background: #fff;
  display: grid;
  gap: 8px;
}
.sc-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.sc-composer textarea {
  flex: 1;
  min-height: 48px;
  max-height: 140px;
  padding: 12px 14px;
  border: 1.5px solid var(--sc-line);
  border-radius: 14px;
  font: inherit;
  font-size: 17px;
  line-height: 1.35;
  resize: none;
  color: var(--sc-ink);
}
.sc-composer textarea:focus { border-color: var(--sc-pine); outline: none; box-shadow: 0 0 0 3px rgba(45, 91, 76, 0.18); }
.sc-send {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--sc-pine);
  color: #fff;
  cursor: pointer;
}
.sc-send:hover { background: var(--sc-pine-dark); }

/* ---- attachments ---- */
.sc-attach {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 48px;
  border-radius: 12px;
  color: var(--sc-pine);
  cursor: pointer;
}
.sc-attach:hover { background: var(--sc-mint); }
.sc-attach:focus-within { outline: 3px solid var(--sc-focus); outline-offset: 2px; }
.sc-file-chip {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--sc-mint);
  font-size: 15px;
  color: var(--sc-pine-dark);
}
.sc-file-chip span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-file-remove {
  flex: none;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--sc-pine);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}
.sc-file { display: grid; gap: 6px; max-width: 100%; }
.sc-file img {
  display: block;
  max-width: 100%;
  max-height: 240px;
  border-radius: 14px;
  border: 1px solid var(--sc-line);
  background: #fff;
  object-fit: cover;
}
.sc-file audio { width: 260px; max-width: 100%; }
.sc-file video { width: 100%; max-height: 240px; border-radius: 14px; background: #000; }
.sc-file-link {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--sc-line);
  border-radius: 12px;
  background: #fff;
  color: var(--sc-ink);
  text-decoration: none;
  font-size: 15px;
}
.sc-file--image .sc-file-link, .sc-file--audio .sc-file-link, .sc-file--video .sc-file-link {
  padding: 0 4px; border: 0; background: none; font-size: 13px; color: var(--sc-muted);
}
.sc-file-name { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-file-size { flex: none; color: var(--sc-muted); }
.sc-msg--visitor .sc-file { justify-items: end; }

.sc-foot {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--sc-line);
  background: #fff;
  font-size: 14px;
  color: var(--sc-muted);
  text-align: center;
}
.sc-foot a { color: var(--sc-pine); font-weight: 700; white-space: nowrap; }

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

/* ---- tablets & phones ---- */
@media (max-width: 900px) {
  .sc { --sc-gap: 16px; }
}

@media (max-width: 600px) {
  .sc-launcher { width: 60px; padding: 0; justify-content: center; }
  .sc-launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .sc-teaser { max-width: calc(100vw - 32px); }

  /* Full-screen chat on phones */
  .sc--open { inset: 0; gap: 0; }
  .sc--open .sc-launcher { display: none; }
  .sc--open .sc-teaser { display: none !important; }
  .sc-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .sc-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .sc-field-row { grid-template-columns: 1fr; }
  .sc-msg { max-width: 90%; }
  html.sc-locked, html.sc-locked body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .sc, .sc-launcher, .sc-panel, .sc-teaser { transition: none; animation: none; }
}

@media print {
  .sc { display: none !important; }
}


/* Round icon launcher (label kept for screen readers), and the welcome nudge. */
.sc-launcher { width: 60px; padding: 0; justify-content: center; }
.sc-launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sc-launcher--nudge { animation: sc-nudge 0.8s ease-in-out 2; }
@keyframes sc-nudge {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-6px) scale(1.06); }
  60% { transform: translateY(0) scale(0.98); }
}
.sc-teaser--welcome .sc-teaser-open strong { font-size: 16px; }
@media (prefers-reduced-motion: reduce) { .sc-launcher--nudge { animation: none; } }

/* The welcome / reply bubble pops out to the left of the chat button, so the WhatsApp
   button stacked above it stays clear. */
.sc:not(.sc--open) .sc-teaser {
  position: absolute;
  right: 72px;
  bottom: 4px;
  width: max-content;
  max-width: min(300px, calc(100vw - 110px));
}

/* Automatic reply while the visitor waits for the team. */
.sc-msg--auto .sc-msg-body { background: #fbf6e9; border: 1px dashed #e4c88a; color: #4d4428; }
.sc-msg--auto .sc-msg-author { font-style: italic; }
