/* ============================================================
   LeTools AI Chat Dialog — Dark Cyberpunk Theme
   Matches the LeTools homepage aesthetic: cyan accents, dark
   backgrounds, noise grain overlays.
   ============================================================ */

/* ---- Backdrop ---- */
.chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.chat-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ---- Dialog Container — pops out from robot mascot ---- */
.chat-dialog {
  position: fixed;
  top: 92px;
  right: 16px;
  z-index: 9999;
  width: 420px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: rgba(10, 11, 16, 0.97);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(0, 240, 255, 0.06),
    0 24px 80px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(0, 240, 255, 0.04);
  opacity: 0;
  transform: scale(0.4) translateY(-16px);
  transform-origin: top right;
  transition: opacity 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.chat-dialog.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Speech-bubble arrow pointing up at robot */
.chat-dialog::after {
  content: '';
  position: absolute;
  top: -10px;
  right: 56px;
  width: 20px;
  height: 20px;
  background: rgba(10, 11, 16, 0.97);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-right: none;
  border-bottom: none;
  transform: rotate(45deg);
  z-index: 2;
  pointer-events: none;
}

/* Noise grain overlay — matches homepage hero noise */
.chat-dialog::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: screen;
  pointer-events: none;
  border-radius: 20px;
}

/* ---- Header ---- */
.chat-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0, 240, 255, 0.1);
  background: rgba(0, 240, 255, 0.02);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.15), rgba(0, 240, 255, 0.05));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.chat-header-title {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.chat-header-subtitle {
  font-size: 10px;
  color: rgba(0, 240, 255, 0.5);
  letter-spacing: 0.05em;
}

.chat-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 16px;
  line-height: 1;
}
.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
}

/* ---- Messages Area ---- */
.chat-messages {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 240, 255, 0.15);
  border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 240, 255, 0.3);
}

/* ---- Welcome State ---- */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 12px;
  text-align: center;
  flex: 1;
  gap: 20px;
}

.chat-welcome-icon {
  font-size: 48px;
  opacity: 0.8;
}

.chat-welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

.chat-welcome-desc {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  line-height: 1.5;
  max-width: 300px;
}

.chat-welcome-questions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}

.chat-suggestion-btn {
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s ease;
  line-height: 1.4;
}
.chat-suggestion-btn:hover {
  background: rgba(0, 240, 255, 0.06);
  border-color: rgba(0, 240, 255, 0.25);
  color: #fff;
  transform: translateX(4px);
}

/* ---- Message Bubbles ---- */
.chat-message {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: chat-msg-in 0.3s ease-out;
}

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

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.assistant {
  align-self: flex-start;
}

.chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.chat-message.user .chat-avatar {
  background: rgba(0, 240, 255, 0.12);
}

.chat-message.assistant .chat-avatar {
  background: rgba(255, 255, 255, 0.06);
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-message.user .chat-bubble {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.15);
  color: #e0f7fa;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.85);
  border-bottom-left-radius: 4px;
}

/* Markdown styles inside messages */
.chat-bubble p {
  margin: 0 0 8px;
}
.chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-bubble a {
  color: #00f0ff;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.chat-bubble a:hover {
  color: #80f8ff;
}
.chat-bubble code {
  font-family: "SF Mono", "JetBrains Mono", "Menlo", monospace;
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
}
.chat-bubble pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.45;
}
.chat-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
}
.chat-bubble strong {
  color: #fff;
  font-weight: 600;
}
.chat-bubble em {
  color: rgba(0, 240, 255, 0.8);
}

/* List styles — ensure markers are visible */
.chat-bubble ul, .chat-bubble ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}
.chat-bubble ul {
  list-style-type: disc;
}
.chat-bubble ol {
  list-style-type: decimal;
}
.chat-bubble li {
  margin-bottom: 3px;
  display: list-item;
}
.chat-bubble li::marker {
  color: rgba(0, 240, 255, 0.5);
}

/* Header styles inside messages */
.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3,
.chat-bubble h4,
.chat-bubble h5,
.chat-bubble h6 {
  color: #fff;
  font-weight: 700;
  margin: 12px 0 6px;
  line-height: 1.3;
}
.chat-bubble h1:first-child,
.chat-bubble h2:first-child,
.chat-bubble h3:first-child,
.chat-bubble h4:first-child,
.chat-bubble h5:first-child,
.chat-bubble h6:first-child {
  margin-top: 0;
}
.chat-bubble h1 { font-size: 1.3em; }
.chat-bubble h2 { font-size: 1.15em; }
.chat-bubble h3 { font-size: 1.05em; }
.chat-bubble h4 { font-size: 1em; }
.chat-bubble h5 { font-size: 0.95em; }
.chat-bubble h6 { font-size: 0.9em; }

/* ---- Streaming Cursor ---- */
.chat-streaming-cursor::after {
  content: '▊';
  display: inline;
  color: rgba(0, 240, 255, 0.7);
  animation: chat-cursor-blink 0.8s step-end infinite;
  font-size: 0.9em;
  margin-left: 1px;
  vertical-align: baseline;
}
@keyframes chat-cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ---- Typing Indicator ---- */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  min-height: 36px;
}
.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(0, 240, 255, 0.5);
  animation: chat-dot-bounce 1.4s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}
.chat-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes chat-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- Input Area ---- */
.chat-input-area {
  position: relative;
  z-index: 1;
  padding: 12px 16px;
  border-top: 1px solid rgba(0, 240, 255, 0.1);
  background: rgba(0, 240, 255, 0.015);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input-area.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 14px;
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 120px;
  transition: border-color 0.25s ease;
}
.chat-input:focus {
  border-color: rgba(0, 240, 255, 0.35);
}
.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
}

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.3), rgba(0, 240, 255, 0.12));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  flex-shrink: 0;
  font-size: 16px;
}
.chat-send-btn:hover {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.5), rgba(0, 240, 255, 0.2));
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
  transform: scale(1.05);
}
.chat-send-btn:active {
  transform: scale(0.95);
}

/* ---- Rate Limit Bar ---- */
.chat-rate-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.25);
  border-top: 1px solid rgba(255, 255, 255, 0.03);
  background: rgba(0, 0, 0, 0.2);
  letter-spacing: 0.02em;
}
.chat-rate-bar.exhausted {
  color: rgba(0, 240, 255, 0.4);
}

/* ---- Clear History Button ---- */
.chat-clear-btn {
  color: rgba(255, 255, 255, 0.25);
  font-size: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease;
  letter-spacing: 0.02em;
  border: none;
  background: none;
  padding: 0;
}
.chat-clear-btn:hover {
  color: rgba(0, 240, 255, 0.6);
  text-decoration: underline;
}

/* ---- Mobile: Fullscreen ---- */
@media (max-width: 500px) {
  .chat-dialog {
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .chat-dialog::before {
    border-radius: 0;
  }
  .chat-dialog.open {
    transform: none;
  }
  .chat-header {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }
  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---- Apple-inspired light theme and expanded reading layout ---- */
.chat-backdrop {
  background: rgba(29, 29, 31, 0.22);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-dialog {
  width: min(680px, calc(100vw - 48px));
  height: min(760px, calc(100vh - 116px));
  max-width: calc(100vw - 32px);
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(0, 0, 0, 0.08);
  border-radius: 24px;
  box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, 0 28px 90px rgba(0,0,0,.18);
}
.chat-dialog::after { background: rgba(255,255,255,.96); border-color: rgba(0,0,0,.08); }
.chat-dialog::before { opacity: 0; }
.chat-header { padding: 20px 24px; border-bottom-color: rgba(0,0,0,.07); background: rgba(245,245,247,.78); }
.chat-header-left { gap: 12px; }
.chat-header-icon { width: 40px; height: 40px; border-radius: 10px; background: #eaf3ff; font-size: 20px; }
.chat-header-title { font-size: 17px; color: #1d1d1f; }
.chat-header-subtitle { font-size: 12px; color: #6e6e73; }
.chat-close-btn { border-color: rgba(0,0,0,.08); background: rgba(0,0,0,.03); color: #6e6e73; }
.chat-close-btn:hover { background: rgba(0,0,0,.07); color: #1d1d1f; border-color: rgba(0,0,0,.12); }
.chat-messages { padding: 22px 24px; gap: 18px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,113,227,.18); }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(0,113,227,.35); }
.chat-welcome-title { font-size: 22px; color: #1d1d1f; }
.chat-welcome-desc { max-width: 420px; font-size: 15px; line-height: 1.6; color: #6e6e73; }
.chat-welcome-questions { max-width: 460px; }
.chat-suggestion-btn { padding: 13px 16px; background: #f5f5f7; border-color: rgba(0,0,0,.07); color: #424245; font-size: 14px; }
.chat-suggestion-btn:hover { background: #edf5ff; border-color: rgba(0,113,227,.22); color: #0066cc; }
.chat-message { gap: 10px; max-width: 92%; }
.chat-avatar { width: 34px; height: 34px; font-size: 16px; }
.chat-message.user .chat-avatar { background: #dceeff; }
.chat-message.assistant .chat-avatar { background: #f0f0f2; }
.chat-bubble { padding: 14px 17px; border-radius: 18px; font-size: 16px; line-height: 1.65; }
.chat-message.user .chat-bubble { background: #0071e3; border-color: #0071e3; color: #fff; }
.chat-message.assistant .chat-bubble { background: #f5f5f7; border-color: rgba(0,0,0,.06); color: #1d1d1f; }
.chat-bubble a { color: #0066cc; }
.chat-bubble a:hover { color: #0071e3; }
.chat-bubble code { background: rgba(0,0,0,.07); }
.chat-bubble pre { background: #1d1d1f; color: #f5f5f7; border-color: rgba(0,0,0,.12); font-size: 14px; }
.chat-bubble strong, .chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4, .chat-bubble h5, .chat-bubble h6 { color: #1d1d1f; }
.chat-message.user .chat-bubble strong { color: #fff; }
.chat-bubble em { color: #0066cc; }
.chat-bubble li::marker, .chat-streaming-cursor::after { color: rgba(0,113,227,.7); }
.chat-typing-dot { background: rgba(0,113,227,.55); }
.chat-input-area { padding: 16px 20px; gap: 10px; border-top-color: rgba(0,0,0,.07); background: rgba(245,245,247,.72); }
.chat-input { background: #fff; border-color: rgba(0,0,0,.12); border-radius: 14px; padding: 12px 15px; color: #1d1d1f; font-size: 16px; }
.chat-input:focus { border-color: rgba(0,113,227,.65); box-shadow: 0 0 0 3px rgba(0,113,227,.1); }
.chat-input::placeholder { color: #86868b; }
.chat-send-btn { width: 44px; height: 44px; background: #0071e3; }
.chat-send-btn:hover { background: #0077ed; box-shadow: 0 8px 20px rgba(0,113,227,.2); }
.chat-rate-bar { font-size: 11px; color: #86868b; border-top-color: rgba(0,0,0,.04); background: #f5f5f7; }
.chat-rate-bar.exhausted { color: rgba(0,113,227,.65); }
.chat-clear-btn { color: #86868b; }
.chat-clear-btn:hover { color: #0066cc; }

@media (max-width: 500px) {
  .chat-dialog { width: 100%; max-width: 100%; height: 100%; border-radius: 0; }
  .chat-messages { padding: 18px 16px; }
  .chat-bubble { font-size: 15px; }
}
@media (min-width: 501px) and (max-width: 760px) {
  .chat-dialog { width: calc(100vw - 32px); right: 16px; }
}
