/**
 * KLKBAT AI — chat interface
 */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: rgba(16, 185, 129, 0.2);
}

:root {
  --header-h: clamp(72px, 10vw, 88px);
  --input-h: 7.75rem;
}

body {
  height: 100dvh;
  min-height: 100dvh;
  background: transparent;
  color: var(--text-primary);
  font-family: 'Cairo', 'Tajawal', sans-serif;
  overflow: hidden;
}

/* ——— Header (logo only, physical top-left) ——— */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  z-index: 100;
  padding: 1rem 1.25rem;
  direction: ltr;
}

.site-logo {
  display: inline-flex;
  text-decoration: none;
  line-height: 0;
  transition: transform 0.25s ease, filter 0.25s ease;
}

.site-logo img {
  width: clamp(56px, 8vw, 72px);
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 16px var(--ai-glow));
}

.site-logo:hover {
  transform: scale(1.03);
  filter: brightness(1.05);
}

/* ——— Layout ——— */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--input-h) - env(safe-area-inset-bottom, 0px));
  padding-top: var(--header-h);
  overflow: hidden;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
  overflow: hidden;
}

/* ——— Welcome ——— */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 0;
  gap: 1rem;
  animation: fadeUp 0.5s ease;
}

.welcome.is-hidden {
  display: none;
}

.welcome h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  background: linear-gradient(135deg, #fff 20%, var(--ai) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 420px;
  line-height: 1.6;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.5rem;
  max-width: 560px;
}

.suggestion-chip {
  padding: 0.6rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.85);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.suggestion-chip:hover {
  border-color: var(--ai-border);
  background: var(--ai-light);
  color: #fff;
}

/* ——— Messages ——— */
.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(16, 185, 129, 0.35) transparent;
}

.messages:not(:empty) {
  flex: 1 1 0;
}

.messages:empty {
  display: none;
}

.message {
  display: flex;
  gap: 0.75rem;
  max-width: 100%;
  animation: fadeUp 0.3s ease;
}

.message--user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.message--assistant .message-avatar {
  width: 36px;
  height: 36px;
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid var(--ai-border-soft);
  padding: 2px;
  overflow: hidden;
}

.message--assistant .message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  image-rendering: auto;
}

.message--user .message-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.75);
}

.message--user .user-avatar-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.message-bubble {
  padding: 0.85rem 1.1rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.65;
  max-width: min(85%, 640px);
}

.message--assistant .message-bubble {
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid var(--ai-border-soft);
  border-top-right-radius: 4px;
}

.message--user .message-bubble {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(16, 185, 129, 0.08));
  border: 1px solid var(--ai-border);
  border-top-left-radius: 4px;
}

.message--typing .message-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 1rem 1.25rem;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ai);
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ——— Input (fixed bottom) ——— */
.chat-input-area {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  height: calc(var(--input-h) + env(safe-area-inset-bottom, 0px));
  padding: 0.75rem clamp(1rem, 4vw, 2rem) calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(8, 8, 8, 0.98) 65%, transparent);
  pointer-events: none;
}

.chat-input-area .chat-input-wrap,
.chat-input-area .input-hint {
  pointer-events: auto;
}

.chat-input-area .chat-input-wrap {
  max-width: 720px;
  margin: 0 auto;
}

.chat-input-area .input-hint {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.45rem 0.45rem 0.45rem 1.15rem;
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(12, 18, 15, 0.95), rgba(8, 10, 9, 0.98));
  border: 1px solid var(--ai-border-soft);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.chat-input-wrap:focus-within {
  border-color: var(--ai);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 0 3px rgba(16, 185, 129, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  min-height: 28px;
  padding: 0.55rem 0;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.38);
}

.btn-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #12c98e, var(--ai) 45%, var(--ai-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
  box-shadow: 0 6px 20px var(--ai-glow);
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.06);
  filter: brightness(1.06);
  box-shadow: 0 8px 26px rgba(16, 185, 129, 0.5);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-send svg {
  width: 19px;
  height: 19px;
  margin-inline-start: -1px;
}

.input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: rgba(16, 185, 129, 0.45);
  margin-top: 0.65rem;
}

/* ——— Responsive ——— */
@media (max-width: 640px) {
  .site-header {
    padding: 0.85rem 1rem;
  }

  .site-logo img {
    width: 52px;
  }

  .suggestions {
    flex-direction: column;
    align-items: stretch;
  }
}
