/* AAIKB Web Chat UI styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* The hidden attribute must always win over explicit display rules below */
[hidden] { display: none !important; }

:root {
  --teal: #2fd4c4;
  --teal-dark: #16b3a4;
  --panel: rgba(18, 20, 24, 0.72);
  --panel-border: rgba(255, 255, 255, 0.10);
  --text: #f4f5f7;
  --text-dim: rgba(244, 245, 247, 0.62);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Porsche background image with a dark scrim for legibility */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(8,9,12,0.55) 0%, rgba(8,9,12,0.78) 45%, rgba(8,9,12,0.94) 100%),
    url("assets/porsche-bg.jpg") center 28% / cover no-repeat;
  z-index: -1;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  flex-shrink: 0;
  background: transparent;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.brand {
  display: flex;
  align-items: center;
  height: 4rem;
}

.brand img {
  width: 8rem;
  height: 4rem;
  object-fit: contain;
}

#logout-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--text);
  padding: 0.35rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.15s ease;
}
#logout-btn:hover { background: rgba(255,255,255,0.14); }

/* ── App layout ───────────────────────────────────────────────────────────── */
#app {
  flex: 1;
  width: 100%;
  max-width: 840px;
  margin: 0 auto;
  padding: 0 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#conversation {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/*
 * Push content to the bottom using auto margins instead of
 * `justify-content: flex-end`. flex-end clips overflowing content at the top of
 * a scroll container, making older messages unreachable; auto margins keep the
 * full scroll range accessible while still bottom-aligning short conversations.
 */
#welcome,
#chat-container {
  margin-top: auto;
}

/* ── Welcome / empty state ────────────────────────────────────────────────── */
#welcome {
  padding: 1rem 0.25rem 1.75rem;
}
#welcome.is-hidden { display: none; }

.welcome-title {
  display: flex;
  flex-direction: column;
  font-weight: 600;
  line-height: 1.12;
  font-size: clamp(1.9rem, 4.5vw, 3rem);
  letter-spacing: -0.01em;
  margin-bottom: 1.75rem;
}
.welcome-greeting { color: var(--text); }
.welcome-question { color: rgba(255,255,255,0.92); }

#suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
}

.suggestion-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.65rem;
  text-align: left;
  padding: 1rem 1rem 1.15rem;
  border-radius: 14px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.suggestion-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.22);
}
.suggestion-card:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.suggestion-pill {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 7px;
  color: #0c0d10;
}
.card-blue  .suggestion-pill { background: #cfe0ff; }
.card-red   .suggestion-pill { background: #ffd2cf; }
.card-green .suggestion-pill { background: #d2f0c8; }

.card-blue  { background: linear-gradient(160deg, rgba(40,60,110,0.45), var(--panel)); }
.card-red   { background: linear-gradient(160deg, rgba(110,40,50,0.45), var(--panel)); }
.card-green { background: linear-gradient(160deg, rgba(40,90,55,0.45), var(--panel)); }

.suggestion-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ── Chat messages ────────────────────────────────────────────────────────── */
#chat-container {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.5rem 0.25rem 1rem;
}

.message {
  max-width: 78%;
  padding: 0.65rem 1rem;
  border-radius: 14px;
  white-space: pre-wrap;
  line-height: 1.5;
  word-break: break-word;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: var(--teal);
  color: #06201d;
  border-bottom-right-radius: 5px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-bottom-left-radius: 5px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.message.error {
  align-self: flex-start;
  background: rgba(120, 30, 30, 0.55);
  border: 1px solid rgba(255, 120, 120, 0.4);
  color: #ffd9d6;
}

/* Blinking caret shown at the end of an assistant bubble while a
   response is still streaming in; removed once the stream completes. */
.message.assistant.streaming-cursor::after {
  content: '';
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: currentColor;
  animation: streaming-blink 1s step-start infinite;
}

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

/* Auto-linkified URLs / markdown links inside assistant answers */
.message a {
  color: var(--teal);
  text-decoration: underline;
  word-break: break-all;
}

/* Attachment indicator shown inside a sent message bubble */
.message-attachment {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: fit-content;
  max-width: 100%;
  margin-top: 0.45rem;
  padding: 0.3rem 0.6rem;
  border-radius: 10px;
  font-size: 0.82rem;
  background: rgba(0, 0, 0, 0.16);
  border: 1px solid rgba(0, 0, 0, 0.14);
}
.message.user .message-attachment {
  background: rgba(6, 32, 29, 0.16);
  border-color: rgba(6, 32, 29, 0.24);
}
.message-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#loading {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.65rem 1rem;
}
#loading span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  animation: bounce 1.2s infinite ease-in-out;
}
#loading span:nth-child(2) { animation-delay: 0.2s; }
#loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Input / composer ─────────────────────────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  padding-top: 0.25rem;
}

#validation-msg {
  font-size: 0.8rem;
  color: #ff9b94;
  min-height: 1.2em;
  margin: 0 0.25rem 0.4rem;
}

#chat-form { width: 100%; }

.composer {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 0.9rem 1rem 0.75rem;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}

.composer-spark {
  display: inline-flex;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

#prompt-input {
  width: 100%;
  min-height: 2.4rem;
  max-height: 10rem;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow-y: auto;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  padding: 0.35rem 0.15rem 0.75rem;
}
#prompt-input::placeholder { color: var(--text-dim); }

.composer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 0.7rem;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.14);
  color: var(--text-dim);
  padding: 0.4rem 0.75rem;
  border-radius: 10px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.attach-btn:hover { background: rgba(255,255,255,0.13); color: var(--text); }
.attach-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* Hide the native file input — the styled label triggers it */
#file-input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

#submit-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--teal);
  color: #06201d;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
#submit-btn:hover:not(:disabled) { background: var(--teal-dark); }
#submit-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Attachment chip ──────────────────────────────────────────────────────── */
#attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 16px;
  padding: 0.28rem 0.65rem;
  font-size: 0.82rem;
  max-width: 240px;
  color: var(--text);
}

#file-name-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#attachment-chip-remove {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 0.1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1;
}
#attachment-chip-remove:hover { color: #ff9b94; }

/* ── Auth wall ────────────────────────────────────────────────────────────── */
#auth-wall {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  position: relative;
  z-index: 0;
}

#auth-wall.is-hidden { display: none; }

.auth-wall-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  max-width: 420px;
  width: 90%;
}

.auth-wall-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.auth-wall-subtitle {
  font-size: 0.95rem;
  color: var(--text-dim);
}

.auth-wall-message {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.auth-wall-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
  margin-top: 0.5rem;
}

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

/* ── Authenticated view ───────────────────────────────────────────────────── */
#authenticated-view {
  display: none;
  flex-direction: column;
  height: 100vh;
}

#authenticated-view.is-visible {
  display: flex;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #suggestions { grid-template-columns: 1fr; }
  .message { max-width: 90%; }
  .welcome-title { font-size: clamp(1.7rem, 7vw, 2.2rem); }
}
