:root {
  --chat-bg: #080412;
  --chat-panel: rgba(23, 13, 45, 0.8);
  --chat-border: rgba(168, 85, 247, 0.35);
  --chat-main: #f3e8ff;
  --chat-muted: #b990db;
  --chat-accent: #c084fc;
  --chat-pink: #ec4899;
  --chat-cyan: #06b6d4;
  --app-viewport-height: 100vh;
  --app-viewport-offset-top: 0px;
}

@supports (height: 100dvh) {
  :root {
    --app-viewport-height: 100dvh;
  }
}

.site-chat-body {
  overflow: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
  font-family: "Montserrat", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% -12%, rgba(147, 51, 234, 0.36), transparent 36%),
    radial-gradient(circle at 92% 16%, rgba(236, 72, 153, 0.24), transparent 34%),
    linear-gradient(180deg, #0b0618, var(--chat-bg));
  color: var(--chat-main);
}

.site-chat-body,
.site-chat-shell,
.site-chat-log,
.site-chat-composer textarea {
  scrollbar-width: none;
}

.site-chat-body::-webkit-scrollbar,
.site-chat-shell::-webkit-scrollbar,
.site-chat-log::-webkit-scrollbar,
.site-chat-composer textarea::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* The sections panel exists only on tablets and laptops (responsive.css); phones keep the full chat. */
.site-chat-nav {
  display: none !important;
}

.site-chat-shell {
  position: fixed;
  top: var(--app-viewport-offset-top);
  left: 50%;
  width: min(480px, 100%);
  height: var(--app-viewport-height);
  max-width: 480px;
  transform: translateX(-50%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.site-chat-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 42px 46px 1fr 42px;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(12, 7, 26, 0.7);
  backdrop-filter: blur(14px);
}

.site-chat-back,
.site-chat-menu,
.site-chat-plus,
.site-chat-send {
  border: 1px solid rgba(192, 132, 252, 0.34);
  color: var(--chat-main);
  background: rgba(255, 255, 255, 0.05);
}

.site-chat-back,
.site-chat-menu {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
}

.site-chat-actions {
  position: absolute;
  top: calc(100% + 10px);
  right: 16px;
  z-index: 30;
  width: min(260px, calc(100vw - 32px));
  padding: 8px;
  border: 1px solid rgba(192, 132, 252, 0.34);
  border-radius: 18px;
  background:
    radial-gradient(circle at 86% 0%, rgba(192, 132, 252, 0.18), transparent 36%),
    rgba(12, 7, 26, 0.94);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.36),
    0 0 22px rgba(168, 85, 247, 0.18);
  backdrop-filter: blur(16px);
}

.site-chat-actions button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--chat-main);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  padding: 0 12px;
}

.site-chat-actions button:active {
  background: rgba(192, 132, 252, 0.14);
}

.site-chat-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.site-chat-title {
  min-width: 0;
}

.site-chat-title strong,
.site-chat-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-chat-title strong {
  font-size: 15px;
}

.site-chat-title span {
  display: none;
  margin-top: 3px;
  color: var(--chat-muted);
  font-size: 12px;
}

.site-chat-log {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 12px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-x: hidden;
}

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

.site-chat-empty {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(28px, 9vh, 72px) 24px calc(32px + env(safe-area-inset-bottom, 0px));
  color: var(--chat-main);
  text-align: center;
}

.site-chat-empty-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  border: 1px solid var(--chat-border);
  border-radius: 50%;
  color: var(--chat-accent);
  background: var(--chat-panel);
  font-size: 27px;
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.24);
}

.site-chat-empty h1 {
  max-width: 360px;
  margin: 0;
  color: var(--chat-main);
  font-size: 28px;
  line-height: 1.18;
  letter-spacing: 0;
}

.site-chat-empty p {
  max-width: 380px;
  margin: 16px 0 26px;
  color: var(--chat-muted);
  font-size: 14px;
  line-height: 1.65;
}

.site-chat-empty-action {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-pink));
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 12px 28px rgba(168, 85, 247, 0.22);
}

.site-chat-empty-mode .site-chat-header {
  grid-template-columns: 42px 1fr;
}

.site-chat-empty-mode .site-chat-title {
  min-width: 0;
}

.site-chat-body.theme-light .site-chat-empty-mark {
  box-shadow: 0 0 24px rgba(255, 91, 168, 0.2);
}

.site-chat-body.theme-light .site-chat-empty-action {
  background: linear-gradient(135deg, #ff74b8, #d84f8f);
  box-shadow: 0 12px 28px rgba(191, 72, 126, 0.2);
}

@media (max-width: 360px) {
  .site-chat-empty {
    padding-inline: 18px;
  }

  .site-chat-empty-action {
    width: min(100%, 280px);
  }

  .site-chat-empty h1 {
    font-size: 23px;
  }
}

.site-chat-message {
  display: flex;
}

.site-chat-message.user {
  justify-content: flex-end;
}

.site-chat-bubble {
  max-width: 82%;
  padding: 14px 15px;
  border: 1px solid rgba(168, 85, 247, 0.32);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  background: rgba(23, 13, 45, 0.82);
  color: #f6edff;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
}

.site-chat-message.user .site-chat-bubble {
  border-color: rgba(236, 72, 153, 0.45);
  border-bottom-left-radius: 18px;
  border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, rgba(147, 51, 234, 0.9), rgba(236, 72, 153, 0.78));
}

/* A message and its small icon tools (copy, another reply) underneath. */
.site-chat-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 82%;
  min-width: 0;
}

.site-chat-message.user .site-chat-stack {
  align-items: flex-end;
}

.site-chat-stack .site-chat-bubble {
  max-width: 100%;
}

.site-chat-tools {
  display: flex;
  gap: 2px;
  margin-top: 3px;
  padding: 0 4px;
}

.site-chat-tool {
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #f6edff;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.site-chat-tool svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.site-chat-tool:hover,
.site-chat-tool:focus-visible {
  opacity: 0.9;
  background: rgba(168, 85, 247, 0.16);
}

.site-chat-tool:active {
  opacity: 1;
}

.site-chat-body.theme-light .site-chat-tool {
  color: #5a2a63;
}

.site-chat-composer {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-columns: 44px 1fr 50px;
  align-items: end;
  gap: 10px;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(8, 4, 18, 0), rgba(8, 4, 18, 0.96) 22%);
}

.site-chat-plus,
.site-chat-send {
  height: 44px;
  border-radius: 50%;
  font-size: 22px;
}

.site-chat-composer textarea {
  min-width: 0;
  height: 44px;
  max-height: 116px;
  border: 1px solid rgba(168, 85, 247, 0.28);
  border-radius: 18px;
  padding: 12px 16px;
  outline: none;
  color: var(--chat-main);
  background: rgba(255, 255, 255, 0.04);
  font: inherit;
  line-height: 20px;
  resize: none;
  overflow-y: auto;
}

.site-chat-send {
  border: 0;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-pink));
  color: white;
}

.site-chat-composer textarea:disabled,
.site-chat-send:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.site-chat-body.theme-light {
  --chat-bg: #fff6fb;
  --chat-panel: rgba(255, 249, 253, 0.76);
  --chat-border: rgba(255, 145, 196, 0.34);
  --chat-main: #2a1530;
  --chat-muted: #a14f72;
  --chat-accent: #ff5ba8;
  --chat-pink: #d84f8f;
  background:
    radial-gradient(circle at 50% -12%, rgba(255, 91, 168, 0.2), transparent 36%),
    radial-gradient(circle at 92% 16%, rgba(255, 145, 196, 0.18), transparent 34%),
    linear-gradient(180deg, #fff7fc, #fff0f7);
  color: var(--chat-main);
}

.site-chat-body.theme-light::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 249, 253, 0.8), rgba(255, 239, 248, 0.9)),
    url("assets/backgrounds/miti-city-bg.webp") top center / cover no-repeat;
  filter: saturate(0.74) brightness(1.28);
}

.site-chat-body.theme-light .site-chat-header {
  background: rgba(255, 249, 253, 0.76);
  border-bottom-color: rgba(255, 145, 196, 0.36);
  box-shadow: 0 12px 28px rgba(154, 79, 103, 0.08);
}

.site-chat-body.theme-light .site-chat-back,
.site-chat-body.theme-light .site-chat-menu,
.site-chat-body.theme-light .site-chat-plus {
  border-color: rgba(255, 145, 196, 0.42);
  color: #9b3d64;
  background: rgba(255, 249, 253, 0.72);
  box-shadow: 0 0 14px rgba(255, 91, 168, 0.14);
}

.site-chat-body.theme-light .site-chat-avatar {
  border-color: rgba(255, 145, 196, 0.52);
  box-shadow: 0 0 16px rgba(255, 91, 168, 0.2);
}

.site-chat-body.theme-light .site-chat-actions {
  border-color: rgba(255, 145, 196, 0.36);
  background:
    radial-gradient(circle at 86% 0%, rgba(255, 91, 168, 0.16), transparent 36%),
    rgba(255, 249, 253, 0.96);
  box-shadow:
    0 18px 48px rgba(154, 79, 103, 0.16),
    0 0 20px rgba(255, 91, 168, 0.12);
}

.site-chat-body.theme-light .site-chat-actions button {
  color: #8a3156;
}

.site-chat-body.theme-light .site-chat-actions button:active {
  background: rgba(255, 91, 168, 0.11);
}

.site-chat-body.theme-light .site-chat-bubble {
  background: rgba(255, 249, 253, 0.72);
  border-color: rgba(255, 145, 196, 0.34);
  color: #2a1530;
  box-shadow:
    0 12px 28px rgba(154, 79, 103, 0.12),
    0 0 16px rgba(255, 91, 168, 0.08);
}

.site-chat-body.theme-light .site-chat-title span {
  color: #a14f72;
}

.site-chat-body.theme-light .site-chat-title strong {
  color: #2a1530;
  text-shadow: 0 0 8px rgba(255, 91, 168, 0.14);
}

.site-chat-body.theme-light .site-chat-message.user .site-chat-bubble {
  border-color: rgba(255, 91, 168, 0.52);
  background: linear-gradient(135deg, rgba(255, 116, 184, 0.94), rgba(205, 78, 136, 0.88));
  color: #fff8fb;
  box-shadow:
    0 12px 26px rgba(191, 72, 126, 0.2),
    0 0 18px rgba(255, 91, 168, 0.24);
}

.site-chat-body.theme-light .site-chat-composer {
  background: linear-gradient(180deg, rgba(255, 246, 252, 0), rgba(255, 246, 252, 0.98) 24%);
}

/* A photo attached with «+»: a thumbnail over the composer, then in the user's message. */
.site-chat-photo-preview {
  position: relative;
  align-self: flex-start;
  margin: 0 14px -4px 68px;
}

.site-chat-photo-preview img {
  display: block;
  max-width: 120px;
  max-height: 120px;
  border: 1px solid rgba(192, 132, 252, 0.4);
  border-radius: 10px;
  object-fit: cover;
}

.site-chat-photo-preview button {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(192, 132, 252, 0.5);
  border-radius: 50%;
  background: rgba(8, 4, 18, 0.92);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.site-chat-photo {
  display: block;
  max-width: min(240px, 100%);
  max-height: 260px;
  margin-bottom: 8px;
  border-radius: 10px;
  object-fit: cover;
}

.site-chat-toast {
  position: absolute;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: min(320px, calc(100% - 40px));
  transform: translateX(-50%);
  padding: 11px 14px;
  border: 1px solid rgba(192, 132, 252, 0.34);
  border-radius: 16px;
  background: rgba(12, 7, 26, 0.94);
  color: var(--chat-main);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  box-shadow:
    0 18px 44px rgba(0, 0, 0, 0.32),
    0 0 18px rgba(168, 85, 247, 0.18);
  backdrop-filter: blur(16px);
}

.site-chat-body.theme-light .site-chat-composer textarea {
  border-color: rgba(255, 145, 196, 0.42);
  background: rgba(255, 255, 255, 0.74);
  color: #2a1530;
  box-shadow: 0 0 14px rgba(255, 91, 168, 0.1);
}

.site-chat-body.theme-light .site-chat-composer textarea::placeholder {
  color: #a87992;
}

.site-chat-body.theme-light .site-chat-toast {
  border-color: rgba(255, 145, 196, 0.42);
  background: rgba(255, 249, 253, 0.96);
  color: #8a3156;
  box-shadow:
    0 18px 42px rgba(154, 79, 103, 0.16),
    0 0 18px rgba(255, 91, 168, 0.16);
}

.site-chat-body.theme-light .site-chat-send {
  background: linear-gradient(135deg, #ff74b8, #d84f8f);
  box-shadow: 0 0 18px rgba(255, 91, 168, 0.32);
}

.site-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
}

.site-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: site-chat-typing 1.2s ease-in-out infinite;
}

.site-chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.site-chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes site-chat-typing {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 0.9; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .site-chat-typing span { animation: none; opacity: 0.6; }
}
