/* Luna, the chat assistant. Uses only the tokens of tokens.css.
   Desktop: a panel above the site's moon launcher (#lunaLauncher, 64px, right 20px, bottom 20px).
   Phone (<=640px): a full-screen sheet that follows the visual viewport, so the keyboard never hides the composer.
   Only opacity and transform are animated. */

.luna-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.luna-panel,
.luna-panel *,
.luna-panel *::before,
.luna-panel *::after,
.luna-launcher-fallback {
  box-sizing: border-box;
}

.luna-panel {
  position: fixed;
  right: 20px;
  bottom: 96px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 40px));
  height: min(600px, calc(100vh - 116px));
  height: min(600px, calc(100dvh - 116px));
  background: var(--canvas-2);
  color: var(--text-primary);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  transform-origin: 100% 100%;
  transition: opacity var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
  contain: layout paint;
}

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

.luna.is-in .luna-panel {
  opacity: 1;
  transform: none;
}

.luna-panel:focus {
  outline: none;
}

.luna-panel :focus-visible,
.luna-launcher-fallback:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.luna-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
  flex: 0 0 auto;
}

.luna-id {
  flex: 1 1 auto;
  min-width: 0;
}

.luna-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 17px;
  line-height: 1.25;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.luna-subtitle {
  margin: 2px 0 0;
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.luna-ava {
  display: inline-flex;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
}

.luna-ava img {
  width: 100%;
  height: 100%;
  display: block;
}

.luna-ava--head {
  width: 40px;
  height: 40px;
}

.luna-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--t-fast) var(--ease-out), background-color var(--t-fast) var(--ease-out);
}

.luna-close:hover {
  color: var(--text-primary);
  background: var(--panel);
}

.luna-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
}

.luna-icon svg {
  width: 100%;
  height: 100%;
}

/* ---------- Transcript ---------- */

.luna-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.luna-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.luna-log[data-empty]::before {
  content: attr(data-empty);
  color: var(--text-secondary);
  font-size: 14px;
}

.luna-msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.luna-bubble {
  margin: 0;
  padding: 10px 14px;
  border-radius: 16px;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: normal;
}

.luna-msg--visitor {
  align-self: flex-end;
  align-items: flex-end;
  max-width: 86%;
}

.luna-msg--visitor .luna-bubble {
  background: var(--mantel);
  color: var(--ink);
  border-bottom-right-radius: 6px;
}

.luna-msg--visitor .luna-bubble a {
  color: var(--ink);
}

.luna-msg--bot {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  align-self: flex-start;
  max-width: 94%;
}

.luna-msg-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.luna-msg--bot .luna-bubble {
  background: var(--panel);
  color: var(--text-primary);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.luna-bubble a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--line-strong);
}

.luna-bubble a:hover {
  text-decoration-color: currentColor;
}

.luna-state {
  margin: 4px 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.luna-msg--visitor.is-error .luna-bubble {
  box-shadow: 0 0 0 1px var(--red-soft);
}

.luna-msg--visitor.is-error .luna-state::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--red-soft);
  vertical-align: 1px;
}

.luna-why,
.luna-wait {
  margin: 4px 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
  max-width: 100%;
}

.luna-retry {
  margin-top: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.luna-retry:hover:not([disabled]) {
  background: var(--panel);
}

.luna-retry[disabled] {
  opacity: .5;
  cursor: default;
}

.luna-msg--notice {
  align-self: center;
  max-width: 92%;
}

.luna-notice-text {
  margin: 0;
  padding: 6px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* ---------- Unavailable notice ---------- */

.luna-notice {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.luna-notice-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 16px;
}

.luna-notice-body {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---------- Chips ---------- */

.luna-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 36px;
}

.luna-chip {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}

.luna-chip:hover:not([disabled]) {
  background: var(--panel);
  border-color: var(--text-secondary);
}

.luna-chip[disabled] {
  opacity: .5;
  cursor: default;
}

/* ---------- Cards: review, confirmation, failure, cancellation ---------- */

.luna-blocks {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.luna-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.luna-card--confirmed {
  box-shadow: inset 3px 0 0 var(--success);
}

.luna-card--failed {
  box-shadow: inset 3px 0 0 var(--red);
}

.luna-card-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.3;
}

.luna-data {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
}

.luna-data dt {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding-top: 2px;
}

.luna-data dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.luna-note {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.luna-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.luna-btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}

.luna-btn:hover:not([disabled]) {
  background: var(--panel-2);
}

.luna-btn--strong {
  background: var(--mantel);
  border-color: var(--mantel);
  color: var(--ink);
}

.luna-btn--strong:hover:not([disabled]) {
  background: var(--mantel-2);
}

.luna-btn[disabled] {
  opacity: .5;
  cursor: default;
}

.luna-confirm {
  align-self: stretch;
}

/* ---------- Ways out: phone, WhatsApp, tickets, engine ---------- */

.luna-actions,
.luna-contact-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.luna-action {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-self: flex-start;
  min-height: var(--tap);
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-decoration: none;
  transition: background-color var(--t-fast) var(--ease-out);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.luna-action:hover {
  background: var(--panel);
}

.luna-action-label {
  font-weight: 600;
  font-size: 14px;
}

.luna-action-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

.luna-mini {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.luna-contact {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--canvas);
  border: 1px solid var(--line);
}

.luna-contact .luna-action {
  align-self: stretch;
}

.luna-contact-lead {
  margin: 0;
  font-size: 14px;
  color: var(--text-primary);
}

/* ---------- Thinking ---------- */

.luna-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-left: 36px;
  font-size: 13px;
  color: var(--text-secondary);
}

.luna-thinking[hidden] {
  display: none;
}

.luna-dots {
  display: inline-flex;
  gap: 4px;
}

.luna-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: luna-blink 1.2s var(--ease-soft) infinite;
}

.luna-dots i:nth-child(2) {
  animation-delay: .2s;
}

.luna-dots i:nth-child(3) {
  animation-delay: .4s;
}

@keyframes luna-blink {
  0%, 80%, 100% { opacity: .25; }
  40% { opacity: 1; }
}

/* ---------- Composer ---------- */

.luna-form {
  flex: 0 0 auto;
  padding: 10px 12px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--canvas-2);
}

.luna-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.luna-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  max-height: 120px;
  padding: 11px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--canvas);
  color: var(--text-primary);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  overflow-y: auto;
}

.luna-input::placeholder {
  color: var(--text-secondary);
  opacity: 1;
}

.luna-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.luna-input[disabled] {
  opacity: .55;
}

.luna-send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease-out), opacity var(--t-fast) var(--ease-out);
}

.luna-send:hover:not([disabled]) {
  background: var(--accent-hover);
}

.luna-send[disabled] {
  opacity: .4;
  cursor: default;
}

.luna-reason {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.luna-reason[hidden],
.luna-turns[hidden],
.luna-chips[hidden],
.luna-contact[hidden],
.luna-notice[hidden],
.luna-blocks[hidden] {
  display: none;
}

.luna-reason-text,
.luna-turns {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.luna-turns {
  margin-top: 6px;
}

/* ---------- Fallback launcher (only when the page has no #lunaLauncher) ---------- */

.luna-launcher-fallback {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--canvas-2);
  box-shadow: var(--shadow-1);
  cursor: pointer;
}

.luna-launcher-fallback .luna-ava {
  width: 100%;
  height: 100%;
}

/* ---------- Phone: full-screen sheet on top of everything, following the visual viewport ---------- */

@media (max-width: 640px) {
  .luna-panel {
    top: var(--luna-vvt, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: 100vh;
    height: var(--luna-vvh, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: translateY(24px);
    transform-origin: 50% 100%;
  }

  .luna-head {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  html.luna-lock,
  html.luna-lock body {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .luna-panel,
  .luna-panel * {
    transition: none !important;
    animation: none !important;
  }

  .luna-panel {
    transform: none;
  }
}
