/* Chat Page (mobile full-page chat) */
html:has(.chat-page), body.chat-body {
  height: 100%;
  overflow: hidden;
}

body.chat-body {
  display: block;
  align-items: initial;
  min-height: initial;
}

.chat-page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--background-color);
  font-family: var(--font-family);
  max-width: 100%;
  overflow: hidden;
}

.chat-page .chat-header {
  background: var(--accent-color);
  color: #fff;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-page .chat-header-titlegroup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.chat-page .chat-header-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Beta badge - amber #f5a524, sole use of this color across the site.
   Slight rotation gives a 'sticker slapped on' WIP feel; straightens on hover. */
.chat-page .chat-beta-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f5a524;
  color: #1a1a1a;
  font-family: var(--font-family);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 7px 3px 6px;
  border: 1px solid #b8770f;
  cursor: help;
  user-select: none;
  flex-shrink: 0;
  outline-offset: 2px;
  transform: rotate(-3.5deg);
  transform-origin: center center;
  transition: transform 0.15s ease-out;
  box-shadow: 1px 1px 0 0 rgba(0, 0, 0, 0.25);
}

.chat-page .chat-beta-badge:hover,
.chat-page .chat-beta-badge:focus,
.chat-page .chat-beta-badge:focus-within {
  transform: rotate(0deg);
}

.chat-page .chat-beta-badge-dot {
  width: 6px;
  height: 6px;
  background: #1a1a1a;
  border-radius: 50%;
  animation: chat-beta-pulse 2s ease-in-out infinite;
}

.chat-page .chat-beta-badge-sep {
  opacity: 0.55;
  padding: 0 1px;
}

@keyframes chat-beta-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.chat-page .chat-beta-tooltip {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--background-color);
  color: var(--primary-color);
  border: 1px solid #f5a524;
  border-left: 3px solid #f5a524;
  padding: 8px 10px;
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.45;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0s linear 0.15s;
  z-index: 1002;
}

/* Transparent bridge - cursor travels from badge to tooltip without
   losing hover. Mirror of the rule in chat-styles.css. */
.chat-page .chat-beta-tooltip::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -12px;
  height: 12px;
  background: transparent;
}

.chat-page .chat-beta-tooltip a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-page .chat-beta-tooltip a:hover {
  color: var(--link-hover);
}

.chat-page .chat-beta-badge:hover .chat-beta-tooltip,
.chat-page .chat-beta-badge:focus .chat-beta-tooltip,
.chat-page .chat-beta-badge:focus-within .chat-beta-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.15s, transform 0.15s, visibility 0s linear 0s;
}

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

.chat-page .chat-clear {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-family);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.chat-page .chat-clear:hover {
  color: #fff;
  border-color: #fff;
}

.chat-page .chat-back {
  background: none;
  border: none;
  color: #fff;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-page .chat-back:hover {
  opacity: 0.7;
}

.chat-page .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-page .chat-message {
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-color);
  padding: 8px 10px;
  border-left: 3px solid var(--border-color);
  max-width: 90%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.chat-page .chat-message.user {
  border-left: none;
  border-right: 3px solid var(--accent-color);
  align-self: flex-end;
  text-align: right;
}

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

.chat-page .chat-message a {
  color: var(--link-color);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Thinking indicator */
.chat-page .chat-thinking {
  font-size: 0.75rem;
  color: var(--secondary-color);
  font-style: italic;
}

.chat-page .chat-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  background: var(--accent-color);
  vertical-align: text-bottom;
  animation: chat-page-blink 0.7s step-end infinite;
}

@keyframes chat-page-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.chat-page .chat-status {
  font-size: 0.75rem;
  color: var(--secondary-color);
  padding: 6px 14px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  display: none;
}

.chat-page .chat-status.visible {
  display: block;
}

.chat-page .chat-input-area {
  display: flex;
  flex-shrink: 0;
  box-sizing: border-box;
}

.chat-page .chat-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid var(--primary-color);
  border-right: none;
  background: var(--input-bg);
  font-family: var(--font-family);
  font-size: 0.85rem;
  color: var(--primary-color);
  outline: none;
}

.chat-page .chat-input::placeholder {
  color: var(--secondary-color);
}

.chat-page .chat-send {
  background: var(--accent-color);
  color: #fff;
  border: 2px solid var(--primary-color);
  border-left: none;
  padding: 10px 14px;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
}

.chat-page .chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Suggestion chips */
.chat-page .chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
  align-self: flex-start;
}

.chat-page .chat-chip {
  background: none;
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  font-family: var(--font-family);
  font-size: 0.75rem;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-page .chat-chip:hover {
  background: var(--accent-color);
  color: #fff;
}

/* Wordmark is mobile-hidden; it only appears in the desktop card layout. */
.chat-wordmark {
  display: none;
}

/* ---- Desktop: centered brutalist console card ----
   Mobile is fullscreen (intentional - mobile users are routed here).
   On desktop the /chat/ direct link becomes a contained card framed
   against the page background, in the site's brutalist vocabulary, with
   a wordmark above it so the page stays tied to ostaps.net. */
@media (min-width: 768px) {
  /* Stack wordmark above the card and center the whole group. */
  body.chat-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    overflow: auto;
    padding: 32px 16px;
  }

  html:has(.chat-page) {
    height: auto;
    overflow: auto;
  }

  /* Wordmark: small mono link back to the site, aligned to the card edge. */
  .chat-wordmark {
    display: block;
    width: 100%;
    max-width: 760px;
    font-family: var(--font-family);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--secondary-color);
    text-decoration: none;
  }

  .chat-wordmark:hover {
    color: var(--accent-color);
  }

  /* Card, not fullscreen. Overrides the mobile fixed/100dvh rules.
     Sizes to content with a modest floor so the empty initial state
     stays compact and balanced, then grows with the conversation up
     to the cap (messages scroll internally past that). */
  .chat-page {
    position: static;
    inset: auto;
    width: 100%;
    max-width: 760px;
    height: auto;
    min-height: 360px;
    max-height: 80vh;
    border: 2px solid var(--primary-color);
    box-shadow: 6px 6px 0 0 var(--accent-color);
  }

  /* Breathing room so first messages aren't flush to the header
     and the input isn't glued to the card's bottom edge. */
  .chat-page .chat-messages {
    padding: 22px 24px;
    gap: 12px;
  }

  /* Input flush to the card's inner edges: a single 2px top rule divides
     it from the messages, and the input/send shed their own outer borders
     so there's no doubled-border seam against the card. */
  .chat-page .chat-input-area {
    border-top: 2px solid var(--primary-color);
  }

  .chat-page .chat-input {
    border: none;
    padding: 14px 18px;
  }

  .chat-page .chat-send {
    border: none;
    border-left: 2px solid var(--primary-color);
    padding: 14px 20px;
  }

  .chat-page .chat-header {
    padding: 12px 18px;
  }
}
