/* Feature: Support tickets — the floating help chat (public/js/support-widget.js), added by the
   server (server/support-widget.js) to the public pages and Today. Lower right, above whatever
   else sits at the bottom of the screen (cookie bar, the phone's tab bar, a listing's contact bar:
   the script measures them into --sw-lift). Its own tokens, so it looks the same on the public
   site and in the back office, light or dark. */
.sw-root {
  --sw-ink: #2f3b34;
  --sw-ink-2: #3d4c43;
  --sw-gold: #c9a227;
  --sw-bg: #fffdf8;
  --sw-soft: #f3efe5;
  --sw-line: rgba(47, 59, 52, 0.12);
  --sw-text: #1f2622;
  --sw-muted: #5b6159;
  --sw-mine: #2f3b34;
  --sw-mine-text: #ffffff;
  --sw-ok: #2e7d4f;
  --sw-warn: #a8670b;
  --sw-err: #b3261e;
  --sw-lift: 0px;
  --sw-gap: 20px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--sw-text);
}
:root[data-theme="dark"] .sw-root {
  --sw-bg: #1d2420;
  --sw-soft: #26302a;
  --sw-line: rgba(236, 230, 214, 0.12);
  --sw-text: #ece6d6;
  --sw-muted: #a9ada4;
  --sw-mine: #c9a227;
  --sw-mine-text: #1d2420;
}
.sw-root *, .sw-root *::before, .sw-root *::after { box-sizing: border-box; }
.sw-root [hidden] { display: none !important; }

/* ---------- Launcher */
.sw-launcher {
  position: fixed;
  right: calc(var(--sw-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--sw-gap) + var(--sw-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 2050;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  max-width: calc(100vw - 32px);
  padding: 0 20px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--sw-ink);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 10px 30px rgba(20, 28, 23, 0.28), 0 2px 6px rgba(20, 28, 23, 0.18);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, bottom 200ms ease;
}
.sw-launcher:hover { transform: translateY(-2px); background: var(--sw-ink-2); box-shadow: 0 14px 34px rgba(20, 28, 23, 0.32), 0 2px 6px rgba(20, 28, 23, 0.18); }
.sw-launcher:focus-visible { outline: 3px solid var(--sw-gold); outline-offset: 3px; }
.sw-launcher-icon { position: relative; display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 50%; background: var(--sw-gold); color: var(--sw-ink); flex: none; }
.sw-launcher-icon svg { width: 16px; height: 16px; }
.sw-launcher-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-badge {
  position: absolute; top: -7px; right: -9px;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; border: 2px solid var(--sw-ink);
  background: #e5484d; color: #fff;
  font-size: 0.68rem; font-weight: 700; line-height: 15px; text-align: center;
}
.sw-root.is-open .sw-launcher { transform: scale(0.94); }

/* ---------- Panel */
.sw-panel {
  position: fixed;
  right: calc(var(--sw-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--sw-gap) + 68px + var(--sw-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 2060;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(640px, calc(100vh - 140px - var(--sw-lift)));
  height: min(640px, calc(100dvh - 140px - var(--sw-lift)));
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--sw-line);
  border-radius: 20px;
  background: var(--sw-bg);
  box-shadow: 0 24px 60px rgba(20, 28, 23, 0.28), 0 4px 14px rgba(20, 28, 23, 0.12);
  animation: sw-in 180ms ease;
}
@keyframes sw-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .sw-panel, .sw-launcher { animation: none; transition: none; } }

.sw-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 12px 16px;
  background: var(--sw-ink);
  color: #fff;
  flex: none;
}
.sw-head-mark { display: inline-flex; width: 38px; height: 38px; flex: none; align-items: center; justify-content: center; border-radius: 12px; background: rgba(255, 255, 255, 0.1); color: var(--sw-gold); }
.sw-head-mark svg { width: 20px; height: 20px; }
.sw-head-text { flex: 1 1 auto; min-width: 0; }
.sw-title { margin: 0; font-size: 1rem; font-weight: 700; color: #fff; font-family: inherit; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-sub { margin: 2px 0 0; font-size: 0.78rem; color: rgba(255, 255, 255, 0.72); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-icon-btn {
  display: inline-flex; flex: none; width: 36px; height: 36px; align-items: center; justify-content: center;
  border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer;
}
.sw-icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
.sw-icon-btn:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: 1px; }
.sw-icon-btn svg { width: 18px; height: 18px; }

.sw-tabs { display: flex; gap: 4px; padding: 8px 12px 0; background: var(--sw-ink); flex: none; }
.sw-tab {
  flex: 1 1 0; min-width: 0; min-height: 40px; padding: 8px 10px;
  border: 0; border-radius: 10px 10px 0 0;
  background: transparent; color: rgba(255, 255, 255, 0.75);
  font: inherit; font-size: 0.86rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.sw-tab[aria-selected="true"] { background: var(--sw-bg); color: var(--sw-text); }
.sw-tab:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: -2px; }
.sw-tab-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #e5484d; color: #fff; font-size: 0.68rem; line-height: 18px; }

.sw-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }

/* ---------- Conversation bubbles */
.sw-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; min-width: 0; }
.sw-msg-bot { align-self: flex-start; }
.sw-msg-me { align-self: flex-end; flex-direction: row-reverse; }
.sw-avatar { display: inline-flex; flex: none; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 50%; background: var(--sw-ink); color: var(--sw-gold); }
.sw-avatar svg { width: 15px; height: 15px; }
.sw-bubble {
  min-width: 0; max-width: 82%;
  padding: 10px 13px;
  border-radius: 16px 16px 16px 4px;
  background: var(--sw-soft);
  font-size: 0.9rem; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.sw-msg-me .sw-bubble { border-radius: 16px 16px 4px 16px; background: var(--sw-mine); color: var(--sw-mine-text); }
.sw-bubble-name { display: block; margin-bottom: 2px; font-size: 0.72rem; font-weight: 700; color: var(--sw-muted); }
.sw-msg-me .sw-bubble-name { color: inherit; opacity: 0.8; }
.sw-bubble-time { display: block; margin-top: 4px; font-size: 0.68rem; opacity: 0.65; }
.sw-event { align-self: center; max-width: 92%; padding: 5px 12px; border-radius: 999px; background: var(--sw-soft); color: var(--sw-muted); font-size: 0.76rem; text-align: center; }
.sw-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.sw-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--sw-muted); opacity: 0.5; animation: sw-dot 1s infinite ease-in-out; }
.sw-typing i:nth-child(2) { animation-delay: 0.15s; }
.sw-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes sw-dot { 0%, 80%, 100% { opacity: 0.3; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Quick replies */
.sw-chips { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 36px; min-width: 0; }
.sw-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  min-height: 38px; padding: 7px 14px;
  border: 1px solid var(--sw-line); border-radius: 999px;
  background: var(--sw-bg); color: var(--sw-text);
  font: inherit; font-size: 0.85rem; font-weight: 500; text-align: left; cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}
.sw-chip:hover { border-color: var(--sw-ink); background: var(--sw-soft); }
.sw-chip:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: 1px; }
.sw-chip.is-suggested { border-color: var(--sw-gold); box-shadow: inset 0 0 0 1px var(--sw-gold); }
.sw-chip small { color: var(--sw-muted); font-weight: 400; }
.sw-chip-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.sw-chips-col { flex-direction: column; align-items: stretch; }
.sw-chips-col .sw-chip { border-radius: 12px; }

/* ---------- Cards (contact form, screenshot, summary, done) */
.sw-card { margin-left: 36px; padding: 12px; border: 1px solid var(--sw-line); border-radius: 14px; background: var(--sw-bg); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sw-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sw-field label { font-size: 0.78rem; font-weight: 600; color: var(--sw-muted); }
.sw-input {
  width: 100%; min-width: 0; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--sw-line); border-radius: 10px;
  background: var(--sw-bg); color: var(--sw-text);
  font: inherit; font-size: 16px;
}
.sw-input:focus { outline: 2px solid var(--sw-gold); outline-offset: 0; border-color: transparent; }
.sw-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--sw-ink); color: #fff;
  font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
:root[data-theme="dark"] .sw-btn { background: var(--sw-gold); color: #1d2420; }
.sw-btn:hover { filter: brightness(1.08); }
.sw-btn:disabled { opacity: 0.55; cursor: default; }
.sw-btn:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: 2px; }
.sw-btn svg { width: 16px; height: 16px; }
.sw-btn-ghost { background: transparent; color: var(--sw-text); border-color: var(--sw-line); }
:root[data-theme="dark"] .sw-btn-ghost { background: transparent; color: var(--sw-text); }
.sw-btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.sw-btn-row .sw-btn { flex: 1 1 140px; min-width: 0; }
.sw-shot { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--sw-line); background: var(--sw-soft); }
.sw-shot img { display: block; width: 100%; max-height: 180px; object-fit: contain; }
.sw-note { margin: 0; font-size: 0.78rem; color: var(--sw-muted); line-height: 1.4; }
.sw-error { margin: 0; font-size: 0.8rem; font-weight: 600; color: var(--sw-err); }
.sw-summary { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; font-size: 0.84rem; }
.sw-summary dt { color: var(--sw-muted); font-weight: 600; }
.sw-summary dd { margin: 0; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.sw-details { border-top: 1px solid var(--sw-line); padding-top: 8px; }
.sw-details summary { cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--sw-muted); list-style-position: inside; min-height: 32px; display: flex; align-items: center; gap: 6px; }
.sw-details .sw-summary { margin-top: 8px; font-size: 0.78rem; }
.sw-done { align-items: center; text-align: center; padding: 18px 14px; margin-left: 0; }
.sw-done-mark { display: inline-flex; width: 52px; height: 52px; align-items: center; justify-content: center; border-radius: 50%; background: rgba(46, 125, 79, 0.12); color: var(--sw-ok); }
.sw-done-mark svg { width: 28px; height: 28px; }
.sw-done h3 { margin: 0; font-family: inherit; font-size: 1.15rem; letter-spacing: 0; color: var(--sw-text); }
.sw-done p { margin: 0; font-size: 0.86rem; color: var(--sw-muted); }
.sw-number { font-variant-numeric: tabular-nums; }
.sw-consent .rc-consent { margin: 0; }

/* ---------- My tickets */
.sw-list { display: flex; flex-direction: column; gap: 8px; }
.sw-row {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; min-width: 0;
  padding: 12px; border: 1px solid var(--sw-line); border-radius: 14px;
  background: var(--sw-bg); color: var(--sw-text); font: inherit; text-align: left; cursor: pointer;
}
.sw-row:hover { border-color: var(--sw-ink); }
.sw-row:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: 1px; }
.sw-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.sw-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.sw-row-num { font-weight: 700; font-size: 0.85rem; }
.sw-row-subject { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-row-preview { font-size: 0.8rem; color: var(--sw-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-row-time { font-size: 0.72rem; color: var(--sw-muted); flex: none; }
.sw-unread-dot { width: 9px; height: 9px; border-radius: 50%; background: #e5484d; flex: none; margin-top: 6px; }
.sw-status { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.sw-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.sw-status-open { background: rgba(201, 162, 39, 0.16); color: #8a6d0e; }
.sw-status-answered { background: rgba(46, 125, 79, 0.13); color: var(--sw-ok); }
.sw-status-closed { background: rgba(91, 97, 89, 0.14); color: var(--sw-muted); }
:root[data-theme="dark"] .sw-status-open { color: var(--sw-gold); }
.sw-empty { margin: auto 0; padding: 24px 12px; text-align: center; color: var(--sw-muted); font-size: 0.88rem; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sw-empty svg { width: 30px; height: 30px; opacity: 0.6; }
.sw-thread-head { display: flex; align-items: center; gap: 8px; min-width: 0; padding-bottom: 10px; border-bottom: 1px solid var(--sw-line); }
.sw-thread-head .sw-icon-btn { color: var(--sw-text); }
.sw-thread-head .sw-icon-btn:hover { background: var(--sw-soft); }
.sw-thread-title { flex: 1 1 auto; min-width: 0; }
.sw-thread-title strong { display: block; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-lost { margin-top: 6px; }

/* ---------- Composer */
.sw-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--sw-line); background: var(--sw-bg); flex: none; }
.sw-compose textarea {
  flex: 1 1 auto; min-width: 0; min-height: 44px; max-height: 140px; resize: none;
  padding: 11px 13px; border: 1px solid var(--sw-line); border-radius: 14px;
  background: var(--sw-soft); color: var(--sw-text); font: inherit; font-size: 16px; line-height: 1.35;
}
.sw-compose textarea:focus { outline: 2px solid var(--sw-gold); outline-offset: 0; border-color: transparent; }
.sw-send { width: 44px; height: 44px; padding: 0; border-radius: 50%; flex: none; }
.sw-foot { margin: 0; padding: 0 14px 8px; font-size: 0.7rem; color: var(--sw-muted); text-align: center; background: var(--sw-bg); flex: none; }
.sw-skip { align-self: flex-start; margin-left: 36px; }
.sw-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Phones: a full-height sheet, the launcher shrinks to a round button. */
@media (max-width: 560px) {
  .sw-root { --sw-gap: 16px; }
  .sw-launcher { min-height: 56px; width: 56px; padding: 0; justify-content: center; }
  .sw-launcher-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .sw-launcher-icon { width: 30px; height: 30px; }
  .sw-panel {
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    background: var(--sw-ink);
  }
  .sw-panel > .sw-body, .sw-panel > .sw-compose, .sw-panel > .sw-foot { background: var(--sw-bg); }
  .sw-panel > .sw-foot { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .sw-root.is-open .sw-launcher { display: none; }
}
/* Short screens (a phone sideways): the panel takes the height there is. */
@media (max-height: 520px) and (min-width: 561px) {
  .sw-panel { bottom: 12px; right: calc(var(--sw-gap) + 72px); height: calc(100vh - 24px); height: calc(100dvh - 24px); }
}
@media print { .sw-root { display: none !important; } }

/* The visitor's phone box: the shared flag + country code picker (phone-input.js) in front of it. */
.sw-root .phone-field { display: flex; gap: 6px; min-width: 0; }
.sw-root .phone-field select {
  flex: 0 0 104px; width: 104px; min-width: 0; min-height: 42px; padding: 0 6px;
  border: 1px solid var(--sw-line); border-radius: 10px; background: var(--sw-bg); color: var(--sw-text);
  font-size: 15px;
}
.sw-root .phone-field input { flex: 1 1 auto; width: auto; min-width: 0; }

/* ---------- Answers to questions: the pages that do it, one per line. */
.sw-actions { display: flex; flex-direction: column; gap: 8px; margin-left: 36px; min-width: 0; }
.sw-actions .sw-btn { justify-content: flex-start; text-align: left; white-space: normal; }
.sw-chip-problem { border-style: dashed; }

/* ---------- Greeting bubble beside the button ("¿En qué le puedo ayudar?") */
.sw-teaser {
  position: fixed;
  right: calc(var(--sw-gap) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--sw-gap) + 70px + var(--sw-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 2055;
  display: flex;
  align-items: flex-start;
  gap: 2px;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  padding: 4px;
  border: 1px solid var(--sw-line);
  border-radius: 18px 18px 6px 18px;
  background: var(--sw-bg);
  box-shadow: 0 14px 34px rgba(20, 28, 23, 0.22), 0 2px 6px rgba(20, 28, 23, 0.12);
  animation: sw-teaser-in 260ms ease;
  transition: bottom 200ms ease;
}
@keyframes sw-teaser-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
.sw-teaser-open {
  display: flex; align-items: flex-start; gap: 10px; min-width: 0; flex: 1 1 auto;
  padding: 8px 4px 8px 8px; border: 0; border-radius: 14px; background: transparent;
  color: var(--sw-text); font: inherit; text-align: left; cursor: pointer;
}
.sw-teaser-open:hover { background: var(--sw-soft); }
.sw-teaser-open:focus-visible, .sw-teaser-x:focus-visible { outline: 2px solid var(--sw-gold); outline-offset: 1px; }
.sw-teaser-avatar { display: inline-flex; flex: none; width: 32px; height: 32px; align-items: center; justify-content: center; border-radius: 50%; background: var(--sw-ink); color: var(--sw-gold); }
.sw-teaser-avatar svg { width: 17px; height: 17px; }
.sw-teaser-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sw-teaser-title { font-size: 0.92rem; font-weight: 700; line-height: 1.3; }
.sw-teaser-sub { font-size: 0.8rem; line-height: 1.35; color: var(--sw-muted); }
.sw-teaser-x {
  display: inline-flex; flex: none; width: 32px; height: 32px; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--sw-muted); cursor: pointer;
}
.sw-teaser-x:hover { background: var(--sw-soft); color: var(--sw-text); }
.sw-teaser-x svg { width: 14px; height: 14px; }
.sw-root.is-open .sw-teaser { display: none; }
@media (prefers-reduced-motion: reduce) { .sw-teaser { animation: none; transition: none; } }
@media (max-width: 560px) {
  .sw-teaser { bottom: calc(var(--sw-gap) + 66px + var(--sw-lift) + env(safe-area-inset-bottom, 0px)); }
  .sw-teaser-sub { display: none; }
}
