/* ── Mechamey Dental AI Chat ───────────────────────────────────────────── */

.dental-chat-root {
  --chat-accent: #6f9cff;
  --chat-accent-soft: rgba(91, 140, 255, 0.14);
  --chat-glass: rgba(12, 13, 17, 0.82);
  --chat-border: rgba(255, 255, 255, 0.1);
  --chat-shadow: 0 28px 90px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --chat-ease: cubic-bezier(0.22, 1, 0.36, 1);
  position: fixed;
  inset: auto 0 0 auto;
  z-index: 220;
  pointer-events: none;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.dental-chat-root *,
.dental-chat-root *::before,
.dental-chat-root *::after {
  box-sizing: border-box;
}

.dental-chat-root.is-open {
  pointer-events: auto;
}

/* ── Notification peek ── */

.dental-chat-notify {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 68px);
  width: min(360px, calc(100vw - 36px));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  background:
    radial-gradient(circle at 0% 0%, rgba(91, 140, 255, 0.18), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04)),
    rgba(10, 11, 14, 0.92);
  box-shadow: var(--chat-shadow);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  visibility: hidden;
  transition:
    opacity 420ms var(--chat-ease),
    transform 420ms var(--chat-ease),
    visibility 420ms var(--chat-ease);
}

.dental-chat-notify.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.dental-chat-notify.is-hidden {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  visibility: hidden;
  pointer-events: none;
}

.dental-chat-notify__avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 800;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  box-shadow: 0 12px 28px rgba(91, 140, 255, 0.28);
}

.dental-chat-notify__avatar::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 17px;
  border: 2px solid rgba(138, 180, 255, 0.35);
  animation: dental-chat-pulse 2.4s var(--chat-ease) infinite;
}

.dental-chat-notify__copy strong {
  display: block;
  color: rgba(248, 250, 252, 0.96);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
}

.dental-chat-notify__copy span {
  display: block;
  margin-top: 3px;
  color: rgba(161, 168, 181, 0.92);
  font-size: 0.82rem;
  line-height: 1.35;
}

.dental-chat-notify__close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  color: rgba(248, 250, 252, 0.72);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: background 180ms var(--chat-ease), color 180ms var(--chat-ease);
}

.dental-chat-notify__close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

/* ── FAB launcher ── */

.dental-chat-fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border: 1px solid rgba(138, 180, 255, 0.28);
  border-radius: 20px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  box-shadow:
    0 18px 44px rgba(91, 140, 255, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(16px) scale(0.9);
  visibility: hidden;
  transition:
    opacity 320ms var(--chat-ease),
    transform 320ms var(--chat-ease),
    visibility 320ms var(--chat-ease),
    box-shadow 220ms var(--chat-ease);
}

.dental-chat-fab.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
}

.dental-chat-fab:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow:
    0 22px 52px rgba(91, 140, 255, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.dental-chat-fab svg {
  width: 26px;
  height: 26px;
}

.dental-chat-fab__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
  background: #55d38a;
  box-shadow: 0 0 0 2px rgba(10, 11, 14, 0.9);
}

/* ── Chat window (macOS frame) ── */

.dental-chat-panel {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(420px, calc(100vw - 24px));
  height: min(680px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 24px;
  background:
    radial-gradient(circle at 18% 0%, rgba(91, 140, 255, 0.12), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02)),
    rgba(8, 9, 11, 0.94);
  box-shadow: var(--chat-shadow);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
  opacity: 0;
  transform: translateY(24px) scale(0.94);
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 380ms var(--chat-ease),
    transform 380ms var(--chat-ease),
    visibility 380ms var(--chat-ease);
}

.dental-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  pointer-events: auto;
}

.dental-chat-panel__chrome {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.025);
}

.dental-chat-traffic {
  display: flex;
  gap: 7px;
}

.dental-chat-traffic__btn {
  width: 11px;
  height: 11px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms var(--chat-ease), filter 160ms var(--chat-ease);
}

.dental-chat-traffic__btn:hover {
  transform: scale(1.12);
  filter: brightness(1.08);
}

.dental-chat-traffic__btn:active {
  transform: scale(0.94);
}

.dental-chat-traffic__btn--close { background: rgba(255, 95, 86, 0.82); }
.dental-chat-traffic__btn--min { background: rgba(255, 189, 46, 0.82); }
.dental-chat-traffic__btn--max { background: rgba(39, 201, 63, 0.82); }

.dental-chat-panel__title {
  flex: 1;
  min-width: 0;
}

.dental-chat-panel__title strong {
  display: block;
  color: rgba(248, 250, 252, 0.96);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dental-chat-panel__title small {
  display: block;
  margin-top: 2px;
  color: rgba(161, 168, 181, 0.88);
  font-size: 0.72rem;
  font-weight: 500;
}

.dental-chat-panel__minimize {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 10px;
  color: rgba(248, 250, 252, 0.72);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 180ms var(--chat-ease), color 180ms var(--chat-ease);
}

.dental-chat-panel__minimize:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* ── Messages ── */

.dental-chat-messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
}

.dental-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.dental-chat-messages::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
}

.dental-chat-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  animation: dental-chat-msg-in 420ms var(--chat-ease) both;
}

.dental-chat-msg.is-user {
  flex-direction: row-reverse;
}

.dental-chat-msg__avatar {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: rgba(248, 250, 252, 0.92);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.dental-chat-msg.is-bot .dental-chat-msg__avatar {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  border-color: rgba(138, 180, 255, 0.24);
}

.dental-chat-msg__bubble {
  max-width: min(82%, 300px);
  padding: 12px 14px;
  border-radius: 18px;
  color: rgba(248, 250, 252, 0.94);
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.dental-chat-msg.is-bot .dental-chat-msg__bubble {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom-left-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.dental-chat-msg.is-user .dental-chat-msg__bubble {
  border-bottom-right-radius: 8px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  box-shadow: 0 10px 28px rgba(91, 140, 255, 0.22);
}

.dental-chat-msg__bubble p {
  margin: 0;
}

.dental-chat-msg__bubble p + p {
  margin-top: 8px;
}

.dental-chat-msg__bubble ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.dental-chat-msg__bubble li {
  margin: 4px 0;
}

/* ── Thinking / streaming ── */

.dental-chat-thinking {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  animation: dental-chat-msg-in 320ms var(--chat-ease) both;
}

.dental-chat-thinking__card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid rgba(138, 180, 255, 0.16);
  border-radius: 16px;
  background: rgba(91, 140, 255, 0.08);
}

.dental-chat-thinking__icon {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(91, 140, 255, 0.16);
}

.dental-chat-thinking__icon svg {
  width: 16px;
  height: 16px;
  animation: dental-chat-spin 1.2s linear infinite;
}

.dental-chat-thinking__steps {
  flex: 1;
  min-width: 0;
}

.dental-chat-thinking__label {
  color: rgba(248, 250, 252, 0.92);
  font-size: 0.82rem;
  font-weight: 600;
}

.dental-chat-thinking__detail {
  margin-top: 3px;
  color: rgba(161, 168, 181, 0.9);
  font-size: 0.75rem;
  line-height: 1.4;
  transition: opacity 220ms var(--chat-ease);
}

.dental-chat-thinking__dots {
  display: inline-flex;
  gap: 4px;
  margin-top: 8px;
}

.dental-chat-thinking__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(138, 180, 255, 0.75);
  animation: dental-chat-dot 1.2s var(--chat-ease) infinite;
}

.dental-chat-thinking__dots span:nth-child(2) { animation-delay: 0.15s; }
.dental-chat-thinking__dots span:nth-child(3) { animation-delay: 0.3s; }

.dental-chat-stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--chat-accent);
  animation: dental-chat-blink 0.9s step-end infinite;
}

/* ── Quick replies ── */

.dental-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 14px 42px;
  animation: dental-chat-msg-in 420ms var(--chat-ease) both;
}

.dental-chat-quick button {
  padding: 9px 14px;
  border: 1px solid rgba(138, 180, 255, 0.22);
  border-radius: 99px;
  color: rgba(248, 250, 252, 0.92);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 650;
  background: rgba(91, 140, 255, 0.1);
  cursor: pointer;
  transition:
    transform 180ms var(--chat-ease),
    background 180ms var(--chat-ease),
    border-color 180ms var(--chat-ease);
}

.dental-chat-quick button:hover {
  transform: translateY(-1px);
  background: rgba(91, 140, 255, 0.16);
  border-color: rgba(138, 180, 255, 0.34);
}

.dental-chat-quick button:active {
  transform: translateY(0);
}

/* ── Inline consult form (iOS sheet feel) ── */

.dental-chat-form-card {
  max-width: min(92%, 320px);
  margin: 0 0 14px 42px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  animation: dental-chat-msg-in 420ms var(--chat-ease) both;
}

.dental-chat-form-card h4 {
  margin: 0 0 10px;
  color: rgba(248, 250, 252, 0.96);
  font-size: 0.86rem;
  font-weight: 700;
}

.dental-chat-form-card label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  color: rgba(161, 168, 181, 0.92);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dental-chat-form-card input,
.dental-chat-form-card select,
.dental-chat-form-card textarea {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #fff;
  font: inherit;
  font-size: 0.86rem;
  background: rgba(255, 255, 255, 0.045);
  outline: none;
  transition: border-color 180ms var(--chat-ease), box-shadow 180ms var(--chat-ease);
}

.dental-chat-form-card textarea {
  min-height: 72px;
  padding-top: 10px;
  resize: vertical;
}

.dental-chat-form-card input:focus,
.dental-chat-form-card select:focus,
.dental-chat-form-card textarea:focus {
  border-color: rgba(138, 180, 255, 0.42);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.12);
}

.dental-chat-form-card button[type="submit"] {
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  box-shadow: 0 14px 32px rgba(91, 140, 255, 0.24);
  transition: transform 180ms var(--chat-ease), opacity 180ms var(--chat-ease);
}

.dental-chat-form-card button[type="submit"]:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.dental-chat-form-card__status {
  margin: 8px 0 0;
  color: rgba(161, 168, 181, 0.92);
  font-size: 0.78rem;
  line-height: 1.4;
}

.dental-chat-form-card__hint {
  margin: 8px 0 0;
  color: rgba(161, 168, 181, 0.72);
  font-size: 0.72rem;
  line-height: 1.4;
}

.dental-chat-summary-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.dental-chat-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.dental-chat-summary-row span {
  color: rgba(161, 168, 181, 0.88);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dental-chat-summary-row strong {
  color: rgba(248, 250, 252, 0.94);
  font-size: 0.84rem;
  font-weight: 650;
  text-align: right;
  word-break: break-word;
}

.dental-chat-consult-submit {
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  box-shadow: 0 14px 32px rgba(91, 140, 255, 0.24);
  transition: transform 180ms var(--chat-ease), opacity 180ms var(--chat-ease);
}

.dental-chat-consult-submit:hover:not(:disabled) {
  transform: translateY(-1px);
}

.dental-chat-consult-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Composer ── */

.dental-chat-composer {
  padding: 12px 14px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.02);
}

.dental-chat-composer__wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  transition: border-color 180ms var(--chat-ease), box-shadow 180ms var(--chat-ease);
}

.dental-chat-composer__wrap:focus-within {
  border-color: rgba(138, 180, 255, 0.34);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.1);
}

.dental-chat-composer textarea {
  width: 100%;
  max-height: 120px;
  min-height: 24px;
  padding: 6px 8px;
  border: 0;
  resize: none;
  color: rgba(248, 250, 252, 0.96);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  background: transparent;
  outline: none;
}

.dental-chat-composer textarea::placeholder {
  color: rgba(161, 168, 181, 0.72);
}

.dental-chat-send {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0)),
    linear-gradient(135deg, #3e72f4, #6f9cff);
  cursor: pointer;
  transition: transform 180ms var(--chat-ease), opacity 180ms var(--chat-ease);
}

.dental-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dental-chat-send:not(:disabled):hover {
  transform: translateY(-1px);
}

.dental-chat-composer__hint {
  margin: 8px 4px 0;
  color: rgba(161, 168, 181, 0.72);
  font-size: 0.68rem;
  text-align: center;
}

/* ── Body states ── */

body.dental-chat-open {
  overflow: hidden;
}

body.dental-chat-open .sticky-consult {
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile: full-height sheet ── */

@media (max-width: 640px) {
  .dental-chat-panel {
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(100dvh, 100vh);
    max-height: none;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
  }

  .dental-chat-panel.is-open {
    transform: translateY(0);
  }

  .dental-chat-notify {
    right: max(14px, env(safe-area-inset-right));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 68px);
    width: min(calc(100vw - 28px), 360px);
  }

  .dental-chat-fab {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .dental-chat-quick,
  .dental-chat-form-card {
    margin-left: 0;
  }
}

body.dental-chat-open .dental-chat-fab {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Animations ── */

@keyframes dental-chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dental-chat-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.92); }
}

@keyframes dental-chat-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

@keyframes dental-chat-spin {
  to { transform: rotate(360deg); }
}

@keyframes dental-chat-blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .dental-chat-notify,
  .dental-chat-fab,
  .dental-chat-panel,
  .dental-chat-msg,
  .dental-chat-thinking,
  .dental-chat-quick,
  .dental-chat-form-card {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .dental-chat-thinking__icon svg,
  .dental-chat-notify__avatar::after,
  .dental-chat-thinking__dots span {
    animation: none !important;
  }
}
