/* AI Assistant — Centered full-width chat */

html:has(.ai-page) {
  overflow-x: hidden;
  max-width: 100%;
}

.ai-page {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.ai-page .bg-glow {
  max-width: 100vw;
  overflow: hidden;
}

.ai-page .bg-glow,
.ai-page .bg-grid {
  z-index: 0;
}

/* Header */
.ai-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: 16px 24px;
  background: rgba(5, 8, 22, 0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.ai-header__inner {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.ai-header__title {
  flex: 1;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.ai-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ai-header__btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--gray);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.ai-header__btn:hover {
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: var(--glow-blue);
}

.ai-header .brand { flex-shrink: 0; }

/* Main shell — centered */
.ai-main {
  position: relative;
  z-index: 1;
  padding: 96px 24px 24px;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100vw;
  display: flex;
  justify-content: center;
  box-sizing: border-box;
}

.ai-shell {
  width: 100%;
  max-width: 960px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100vh - 120px);
  box-sizing: border-box;
}

.glass-panel {
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--glow-blue), 0 8px 40px rgba(0, 0, 0, 0.45);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Intro bar */
.ai-intro {
  padding: 20px 24px;
  flex-shrink: 0;
  transition: opacity 0.3s, max-height 0.4s, margin 0.4s, padding 0.4s;
}

.ai-intro.is-collapsed {
  display: none;
}

.ai-intro__head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.ai-avatar {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(0, 207, 255, 0.4);
  background: rgba(0, 207, 255, 0.08);
}

.ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.ai-avatar__pulse {
  position: absolute;
  inset: -4px;
  border-radius: 16px;
  border: 1px solid rgba(139, 92, 246, 0.5);
  animation: avatar-pulse 2.5s ease-out infinite;
}

.ai-intro h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.ai-intro__text {
  font-size: 0.88rem;
  color: var(--gray);
  line-height: 1.55;
}

.ai-intro__hint {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 10px;
}

/* Suggestions */
.ai-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-suggestions--row {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-suggestions--grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: min(640px, 100%);
  min-width: 0;
}

.suggestion-card {
  text-align: left;
  padding: 12px 16px;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--gray);
  background: rgba(0, 207, 255, 0.05);
  border: 1px solid rgba(0, 207, 255, 0.2);
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.3s var(--ease);
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.ai-suggestions--row .suggestion-card {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}

.suggestion-card:hover {
  color: var(--white);
  border-color: var(--purple);
  background: rgba(139, 92, 246, 0.1);
  box-shadow: var(--glow-purple);
}

/* Chat panel — fills remaining space */
.ai-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 520px;
  max-height: calc(100vh - 280px);
  overflow: hidden;
  width: 100%;
  min-width: 0;
}

.ai-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  width: 100%;
}

.ai-chat__messages::-webkit-scrollbar { width: 6px; }
.ai-chat__messages::-webkit-scrollbar-thumb {
  background: rgba(0, 207, 255, 0.25);
  border-radius: 3px;
}

/* Empty state */
.ai-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 28px;
  width: 100%;
}

.ai-empty.is-hidden { display: none; }

.ai-empty__icon {
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  background: rgba(0, 207, 255, 0.1);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--glow-blue);
}

.ai-empty__icon svg { width: 36px; height: 36px; }

.ai-empty h3 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
}

/* Messages */
.msg {
  display: flex;
  gap: 12px;
  max-width: 78%;
  animation: msg-in 0.4s var(--ease) forwards;
  opacity: 0;
}

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

.msg--bot {
  align-self: flex-start;
}

.msg__avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(139, 92, 246, 0.15);
}

.msg--user .msg__avatar { display: none; }

.msg__avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.msg__bubble {
  padding: 16px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
  border-radius: 20px;
}

.msg--bot .msg__bubble {
  background: rgba(8, 12, 28, 0.95);
  border: 1px solid rgba(139, 92, 246, 0.3);
  color: var(--gray);
  border-bottom-left-radius: 6px;
  box-shadow: var(--glow-purple);
}

.msg--user .msg__bubble {
  background: linear-gradient(135deg, rgba(0, 207, 255, 0.22), rgba(139, 92, 246, 0.28));
  border: 1px solid rgba(0, 207, 255, 0.4);
  color: var(--white);
  border-bottom-right-radius: 6px;
  box-shadow: var(--glow-blue);
}

.msg.msg--highlight .msg__bubble {
  outline: 2px solid var(--blue);
}

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

@keyframes avatar-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.15); opacity: 0; }
}

/* Typing */
.ai-typing {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 0 32px 12px;
  width: 100%;
}

.ai-typing.active { display: flex; }

.ai-typing__avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.ai-typing__avatar img { width: 100%; height: 100%; object-fit: contain; }

.ai-typing__dots {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: rgba(8, 12, 28, 0.95);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 20px;
}

.ai-typing__dots span {
  width: 7px;
  height: 7px;
  background: var(--blue);
  border-radius: 50%;
  animation: typing-dot 1.2s ease-in-out infinite;
}

.ai-typing__dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing__dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); }
  30% { opacity: 1; transform: scale(1); }
}

/* Voice status */
.voice-status {
  padding: 8px 24px 0;
  font-size: 0.82rem;
  color: var(--blue);
  text-align: center;
}

.voice-status:not([hidden]) {
  animation: pulse-voice 1.5s ease-in-out infinite;
}

@keyframes pulse-voice {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Input */
.ai-input {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  background: rgba(5, 8, 22, 0.7);
  border-radius: 0 0 24px 24px;
  width: 100%;
  flex-shrink: 0;
}

.ai-input input {
  flex: 1;
  min-width: 0;
  padding: 16px 20px;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--white);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-input input:focus {
  border-color: var(--blue);
  box-shadow: var(--glow-blue);
}

.ai-input input::placeholder { color: var(--gray-dim); }

.ai-input__icon {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.25s;
}

.ai-input__icon:hover {
  color: var(--blue);
  border-color: var(--blue);
}

.ai-input__icon.is-listening {
  color: var(--purple);
  border-color: var(--purple);
  box-shadow: var(--glow-purple);
}

.ai-input__send {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grad);
  border: none;
  border-radius: 14px;
  color: var(--white);
  cursor: pointer;
  box-shadow: var(--glow-blue);
  transition: transform 0.25s, box-shadow 0.25s;
}

.ai-input__send:hover {
  transform: scale(1.05);
  box-shadow: var(--glow-blue), var(--glow-purple);
}

/* Search overlay */
.ai-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(5, 8, 22, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 100px 24px 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.ai-search-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.ai-search-modal {
  position: relative;
  width: 100%;
  max-width: 520px;
  padding: 20px;
  border-radius: 20px;
}

.ai-search-modal input {
  width: 100%;
  padding: 14px 40px 14px 16px;
  font-size: 1rem;
  color: var(--white);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
}

.ai-search-close {
  position: absolute;
  top: 28px;
  right: 28px;
  background: none;
  border: none;
  color: var(--gray);
  font-size: 1.5rem;
  cursor: pointer;
}

.ai-search-results {
  list-style: none;
  margin-top: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.ai-search-results li {
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--gray);
  border-radius: 10px;
  cursor: pointer;
}

.ai-search-results li:hover {
  background: rgba(0, 207, 255, 0.1);
  color: var(--white);
}

/* Responsive — tablet */
@media (max-width: 1024px) {
  .ai-main { padding: 88px 16px 16px; }
  .ai-shell { max-width: 100%; }
  .ai-suggestions--row { flex-direction: column; }
  .ai-suggestions--row .suggestion-card { width: 100%; }
}

/* Responsive — mobile: single full-width chat */
@media (max-width: 768px) {
  .ai-header {
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
  }

  .ai-header__inner {
    padding: 8px 10px;
    gap: 6px;
    max-width: 100%;
  }

  .ai-header .brand {
    min-width: 0;
    flex-shrink: 1;
  }

  .ai-header__title {
    font-size: 0.9rem;
    text-align: center;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ai-header__actions {
    gap: 4px;
    flex-shrink: 0;
  }

  .ai-header__btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .ai-header .btn--ghost.btn--sm {
    font-size: 0;
    padding: 8px;
    min-width: 40px;
    width: 40px;
    overflow: hidden;
  }

  .ai-header .btn--ghost.btn--sm::after {
    content: '←';
    font-size: 1.1rem;
    color: var(--gray);
  }

  .ai-main {
    padding: calc(60px + env(safe-area-inset-top, 0px)) 8px calc(8px + env(safe-area-inset-bottom, 0px));
    min-height: 100dvh;
    align-items: stretch;
  }

  .ai-shell {
    width: 100%;
    max-width: 100%;
    min-height: calc(100dvh - 60px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    gap: 0;
    flex: 1;
  }

  /* Hide top intro panel on mobile — suggestions live in chat empty state */
  .ai-intro {
    display: none !important;
  }

  .ai-chat {
    flex: 1;
    min-height: calc(100dvh - 68px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: none;
    border-radius: 16px;
    box-shadow: var(--glow-blue);
  }

  .ai-chat__messages {
    padding: 12px 10px;
    min-height: 0;
    overflow-x: hidden;
  }

  .ai-empty {
    padding: 24px 12px;
    gap: 20px;
    width: 100%;
    box-sizing: border-box;
  }

  .ai-suggestions,
  .ai-suggestions--grid,
  .ai-suggestions--row {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .suggestion-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .msg {
    max-width: 88%;
  }

  .msg__bubble {
    font-size: 0.88rem;
    padding: 10px 14px;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .msg__avatar {
    width: 32px;
    height: 32px;
  }

  .ai-typing {
    padding: 0 10px 8px;
  }

  .ai-input {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
    border-radius: 0 0 16px 16px;
    width: 100%;
    box-sizing: border-box;
  }

  .ai-input input {
    flex: 1;
    min-width: 0;
    width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  .ai-input__icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    flex-shrink: 0;
  }

  .ai-input__send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    flex-shrink: 0;
  }

  .ai-input__icon#attachBtn { display: none; }

  .voice-status {
    padding: 6px 10px 0;
    font-size: 0.75rem;
  }

  .ai-search-overlay {
    padding: calc(64px + env(safe-area-inset-top, 0px)) 10px 10px;
  }

  .ai-search-modal {
    max-width: 100%;
  }

  .glass-panel {
    border-radius: 16px;
  }
}

@media (max-width: 480px) {
  .ai-header .brand__name { display: none; }

  .ai-empty h3 { font-size: 1.1rem; }

  .ai-empty__icon {
    width: 56px;
    height: 56px;
  }

  .ai-chat {
    border-radius: 12px;
  }
}

@media (hover: none) {
  .suggestion-card:hover {
    transform: none;
  }
}
