/* The help chat. Loaded by every public page, after the page's own styles and a11y.css. */

/* --- the button that opens it --- */

.chat-open {
  position: relative;
  cursor: pointer;
}

/* Where the page has no place for the button, it floats in the corner. */
.chat-float {
  position: fixed;
  z-index: 40;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 18px 10px 16px;
  font: 800 1rem/1 var(--body, Arial, sans-serif);
  color: #ffffff;
  background: #0b6357;
  border: 2px solid #fff6e2;
  border-radius: 999px;
  box-shadow: 0 10px 26px #0d2a3655;
  animation: chat-in 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) 0.6s both;
}

.chat-icon {
  width: 24px;
  height: 24px;
  background: currentColor;
  -webkit-mask: url('brand/chat.svg') center / contain no-repeat;
  mask: url('brand/chat.svg') center / contain no-repeat;
}

/* In the form's header the button is a round icon, like the accessibility one beside it. */
.chat-round {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff6e2;
  background: #0b6357;
  border: 2px solid #fff6e2;
  border-radius: 50%;
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: #f2a93b;
  border: 2px solid #ffffff;
  border-radius: 50%;
}

.chat-open:focus-visible,
.chat-panel :focus-visible {
  outline: 3px solid #f2a93b;
  outline-offset: 2px;
  box-shadow: none;
}

/* --- the window --- */

.chat-panel {
  position: fixed;
  z-index: 45;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 32px));
  height: min(600px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  color: var(--text, #1c2a2d);
  background: var(--surface, #fffdf8);
  border: 1.5px solid var(--line, #e2d8c4);
  border-radius: 22px;
  box-shadow: 0 24px 60px #0d2a3666;
  overflow: hidden;
  font: 500 1rem/1.5 var(--body, Arial, sans-serif);
  text-align: start;
  animation: chat-up 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-panel[hidden] {
  display: none;
}

/* On a phone the window takes the screen, so the keyboard does not hide it. */
@media (max-width: 520px) {
  .chat-panel {
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
  }
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  color: #fff6e2;
  background: #0d2a36;
}

.chat-head h2 {
  margin: 0;
  font: 1.15rem/1.2 var(--display, Arial, sans-serif);
  color: inherit;
}

.chat-close {
  width: 40px;
  height: 40px;
  padding: 0;
  font: 1.6rem/1 Arial, sans-serif;
  color: inherit;
  background: #fff6e21f;
  border: 1px solid #fff6e255;
  border-radius: 50%;
  cursor: pointer;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--page, #faf4e8);
}

.chat-line {
  max-width: 86%;
  margin: 0;
  padding: 9px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: chat-line 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.chat-line a {
  color: inherit;
  font-weight: 700;
}

.from-customer {
  align-self: flex-end;
  color: #ffffff;
  background: #0b6357;
  border-end-end-radius: 4px;
}

.from-assistant,
.from-agent {
  align-self: flex-start;
  background: var(--surface, #fffdf8);
  border: 1px solid var(--line, #e2d8c4);
  border-end-start-radius: 4px;
}

/* A person's answer is marked as one. */
.from-agent {
  border-color: var(--accent, #0f7b6c);
  border-width: 2px;
}

.from-agent::before {
  content: 'נציג';
  display: block;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-strong, #0a5c51);
}

.from-note {
  align-self: center;
  max-width: 100%;
  font-size: 0.875rem;
  text-align: center;
  color: var(--muted, #55615f);
  background: none;
}

.chat-typing {
  display: flex;
  gap: 5px;
  margin: 0;
  padding: 0 18px 10px;
  background: var(--page, #faf4e8);
}

.chat-typing[hidden] {
  display: none;
}

.chat-typing i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted, #55615f);
  animation: chat-dot 1s ease-in-out infinite;
}

.chat-typing i:nth-of-type(2) {
  animation-delay: 0.15s;
}

.chat-typing i:nth-of-type(3) {
  animation-delay: 0.3s;
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 6px;
  border-top: 1px solid var(--line, #e2d8c4);
}

.chat-composer[hidden],
.chat-ticket[hidden] {
  display: none;
}

.chat-panel textarea,
.chat-panel input {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: var(--surface, #fffdf8);
  border: 1.5px solid var(--muted, #55615f);
  border-radius: 14px;
}

.chat-panel textarea {
  flex: 1;
  max-height: 120px;
  resize: none;
}

.chat-send {
  flex: none;
  min-height: 46px;
  padding: 10px 16px;
  font: 800 1rem/1 var(--body, Arial, sans-serif);
  color: #ffffff;
  background: #0b6357;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
}

.chat-send:disabled {
  opacity: 0.6;
  cursor: progress;
}

.chat-status,
.chat-error {
  margin: 0;
  padding: 0 14px;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--danger, #b3261e);
}

.chat-status:empty,
.chat-error:empty {
  display: none;
}

.chat-ticket {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-top: 1px solid var(--line, #e2d8c4);
}

.chat-ticket-title {
  margin: 0;
  font-weight: 800;
}

.chat-ticket label {
  margin: 4px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.chat-ticket .chat-error {
  padding: 0;
}

.chat-ticket-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.chat-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 12px 0;
}

.chat-plain {
  min-height: 40px;
  padding: 6px 8px;
  font: 700 0.9rem/1.2 var(--body, Arial, sans-serif);
  color: var(--accent-strong, #0a5c51);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.chat-plain[hidden] {
  display: none;
}

.chat-fine {
  margin: 0;
  padding: 2px 14px calc(10px + env(safe-area-inset-bottom));
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted, #55615f);
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.8);
  }
}

@keyframes chat-up {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
}

@keyframes chat-line {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes chat-dot {
  50% {
    transform: translateY(-4px);
    opacity: 0.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-float,
  .chat-panel,
  .chat-line,
  .chat-typing i {
    animation: none;
  }
}
