/* ══ KEYTUBE AI — dark chat theme ══════════════════════════════ */
:root {
  --k-bg: #0b0d12;
  --k-top: #10131a;
  --k-card: #131720;
  --k-card2: #171c26;
  --k-line: #1f2531;
  --k-text: #f1f4f9;
  --k-mut: #8b94a6;
  --k-blue: #2f7bff;
  --k-link: #7db3ff;
  --k-user: #1c2433;
  --k-red: #ff5a5a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--k-bg);
  color: var(--k-text);
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}
button { font-family: inherit; color: inherit; }
a { color: var(--k-link); }

/* layout */
.ai-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top, 0px);
}

/* header */
.ai-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--k-top);
  border-bottom: 1px solid var(--k-line);
  flex-shrink: 0;
}
.ai-top-home { display: grid; place-items: center; border-radius: 50%; overflow: hidden; }
.ai-top-home img { display: block; border-radius: 50%; object-fit: cover; }
.ai-top-info { flex: 1; min-width: 0; }
.ai-top-name { font-size: 1.18rem; font-weight: 700; letter-spacing: .2px; }
.ai-top-status { font-size: .8rem; color: var(--k-mut); }
.ai-top-btn {
  background: none; border: 0; padding: 8px; border-radius: 12px; cursor: pointer; color: var(--k-text);
  display: grid; place-items: center;
}
.ai-top-btn:active { background: var(--k-card2); }

/* chat window */
.ai-chat-window {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--k-line) transparent;
}

/* hero */
.ai-hero { text-align: center; padding: 6px 0 22px; }
.ai-hero-logo {
  width: 80px; height: 80px; margin: 0 auto 14px;
  border-radius: 50%; background: var(--k-card); border: 1px solid var(--k-line);
  display: grid; place-items: center; overflow: hidden;
}
.ai-hero-logo img { width: 52px; height: 52px; object-fit: contain; border-radius: 50%; }
.ai-hero h1 { margin: 0 0 6px; font-size: 1.7rem; font-weight: 700; }
.ai-hero p { margin: 0 auto 20px; max-width: 30ch; color: var(--k-mut); font-size: 1.02rem; line-height: 1.5; }

.ai-cards { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.ai-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 13px 16px;
  background: var(--k-card); border: 1px solid var(--k-line); border-radius: 18px;
  cursor: pointer; text-align: left;
}
.ai-card:active { background: var(--k-card2); }
.ai-card-ic { display: grid; place-items: center; width: 30px; flex-shrink: 0; }
.ai-card-tx { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ai-card-t { font-size: .98rem; font-weight: 500; }
.ai-card-s { font-size: .8rem; color: var(--k-mut); margin-top: 1px; }
.ai-card-ch { color: var(--k-mut); display: grid; }

/* messages */
.ai-msgs { display: flex; flex-direction: column; gap: 14px; padding-bottom: 6px; }
.ai-msg { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
.ai-msg-user { justify-content: flex-end; }
.ai-msg-ai { justify-content: flex-start; }

.ai-av {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--k-card); border: 1px solid var(--k-line);
  display: grid; place-items: center; overflow: hidden; align-self: flex-start;
}
.ai-av-user { background: #1d2a44; border-color: #2a3d63; align-self: flex-end; }
.ai-av-user img { width: 100% !important; height: 100% !important; border-radius: 50%; object-fit: cover; }
.ai-av-init { font-weight: 700; font-size: .95rem; color: #a8cbff; }
.ai-msg-user .user-bubble { max-width: calc(100% - 52px); }
.ai-av img { width: 24px; height: 24px; object-fit: contain; border-radius: 50%; }

.ai-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: calc(100% - 50px); }
.ai-time { font-size: .72rem; color: var(--k-mut); padding-left: 4px; }

.ai-bubble {
  padding: 11px 14px; border-radius: 18px;
  overflow-wrap: anywhere; word-break: break-word;
}
.bot-bubble { background: var(--k-card); border: 1px solid var(--k-line); border-bottom-left-radius: 8px; }
.user-bubble {
  max-width: 82%; background: var(--k-user); border: 1px solid #263046; border-bottom-right-radius: 8px;
}
.ai-utext { white-space: pre-wrap; }
.ai-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  margin-top: 3px; font-size: .72rem; color: var(--k-mut);
}
.ai-meta svg { color: #4a9bff; }

/* rich text */
.ai-link, .ai-bubble a:not(.ai-chip):not(.ai-src):not(.ai-gimg):not(.ai-inline-img) { color: var(--k-link); text-decoration: underline; text-underline-offset: 2px; }
.ai-movie-link, .ai-movie-search { color: var(--k-link); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.ai-bullet { color: var(--k-blue); }
.ai-tag { font-size: .76rem; color: var(--k-mut); margin-bottom: 6px; }
.ai-deep-text strong { font-weight: 600; }
.ai-points { margin: 10px 0 0; padding-left: 18px; color: #d3d9e4; }
.ai-points li { margin-bottom: 5px; }
.ai-inline-img { display: block; margin: 8px 0; }
.ai-inline-img img { display: block; max-width: 100%; max-height: 260px; border-radius: 12px; border: 1px solid var(--k-line); }

/* image gallery */
.ai-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 6px; margin-top: 12px; }
.ai-gimg { display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--k-card2); border: 1px solid var(--k-line); }
.ai-gimg img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* sources */
.ai-sources { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.ai-sources-t { font-size: .76rem; color: var(--k-mut); }
.ai-src {
  display: flex; flex-direction: column; gap: 1px; text-decoration: none;
  padding: 9px 11px; border-radius: 12px; background: var(--k-card2); border: 1px solid var(--k-line);
}
.ai-src:active { border-color: #2c3548; }
.ai-src-t { color: var(--k-link); font-size: .9rem; font-weight: 500; }
.ai-src-d { color: #5fd1a0; font-size: .74rem; }
.ai-src-s {
  color: var(--k-mut); font-size: .8rem; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* chips */
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ai-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 11px; border-radius: 999px; font-size: .8rem; text-decoration: none; cursor: pointer;
  background: var(--k-card2); border: 1px solid var(--k-line); color: var(--k-text);
}
.ai-chip:active { background: #1f2635; }
.ai-chip-link { color: var(--k-link) !important; }

/* submit to team */
.ai-submit-row { padding-left: 4px; }
.ai-submit-q-btn {
  padding: 7px 12px; font-size: .8rem; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid #2c3548; color: var(--k-link);
}

/* typing */
.ai-typing-dots { display: inline-flex; gap: 4px; align-items: center; vertical-align: middle; }
.ai-typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--k-mut); animation: aiDot 1.1s infinite ease-in-out; }
.ai-typing-dots span:nth-child(2) { animation-delay: .15s; }
.ai-typing-dots span:nth-child(3) { animation-delay: .3s; }
.ai-typing-label { margin-left: 10px; color: var(--k-mut); font-size: .85rem; }
@keyframes aiDot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* bottom bar */
.ai-bottom {
  position: relative; flex-shrink: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--k-bg);
}
.ai-mode-chip {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 8px 4px;
  padding: 5px 6px 5px 12px; border-radius: 999px; font-size: .82rem;
  background: #14223a; border: 1px solid #25406b; color: #a8cbff;
}
.ai-mode-chip[hidden] { display: none; }
.ai-chip-x { background: none; border: 0; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; color: inherit; }

.ai-input-row { display: flex; align-items: flex-end; gap: 8px; }
.ai-round-btn, .ai-send-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
}
.ai-round-btn { background: var(--k-card2); color: var(--k-text); border: 1px solid var(--k-line); }
.ai-send-btn { background: var(--k-blue); color: #fff; box-shadow: 0 4px 14px rgba(47, 123, 255, .35); }
.ai-send-btn.busy { opacity: .45; }
.ai-input-pill {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 6px;
  background: var(--k-card); border: 1px solid var(--k-line); border-radius: 24px; padding: 4px 8px 4px 16px;
}
.ai-input-pill:focus-within { border-color: #2d4f8c; }
.ai-textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  color: var(--k-text); font: inherit; line-height: 1.4; padding: 10px 0; max-height: 120px;
}
.ai-textarea::placeholder { color: var(--k-mut); }
.ai-emoji-btn { background: none; border: 0; cursor: pointer; color: var(--k-mut); width: 36px; height: 38px; display: grid; place-items: center; }
.ai-footer-note { text-align: center; font-size: .68rem; color: #5d6577; margin-top: 7px; }

/* popovers */
.ai-pop {
  position: absolute; bottom: calc(100% - 4px); left: 12px; z-index: 20;
  background: var(--k-card2); border: 1px solid #2a3243; border-radius: 16px; padding: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}
.ai-pop[hidden] { display: none; }
.ai-pop-item {
  display: block; width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 11px 14px; border-radius: 12px; font-size: .95rem;
}
.ai-pop-item:active { background: #222a3a; }
.ai-emoji-pop { left: auto; right: 70px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; width: min(320px, calc(100vw - 100px)); }
.ai-emoji-pop[hidden] { display: none; }
.ai-emoji { background: none; border: 0; font-size: 1.3rem; padding: 5px; border-radius: 10px; cursor: pointer; }
.ai-emoji:active { background: #222a3a; }

/* lightbox */
.ai-lb {
  position: fixed; inset: 0; z-index: 200; background: rgba(4, 6, 10, .94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 56px 14px 24px;
}
.ai-lb[hidden] { display: none; }
.ai-lb-x {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 14px;
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--k-card2); color: var(--k-text); font-size: 1rem;
}
.ai-lb-img { max-width: 100%; max-height: 68vh; object-fit: contain; border-radius: 14px; }
.ai-lb-cap { color: #cfd6e3; font-size: .88rem; text-align: center; max-width: 90%; }
.ai-lb-links { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* submit modal */
.ai-modal {
  position: fixed; inset: 0; z-index: 150; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .65); padding: 16px;
}
.ai-modal.open { display: flex; }
.ai-modal-content {
  width: 100%; max-width: 400px; padding: 20px;
  background: var(--k-card); border: 1px solid var(--k-line); border-radius: 20px;
}
.ai-modal-content h3 { margin: 0 0 6px; font-size: 1.1rem; }
.ai-modal-content p { margin: 0 0 8px; color: var(--k-mut); font-size: .85rem; }
.ai-modal-content label { display: block; margin-top: 12px; font-size: .78rem; color: var(--k-mut); }
.ai-modal-content textarea, .ai-modal-content input {
  width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit; color: var(--k-text);
  background: var(--k-bg); border: 1px solid var(--k-line); border-radius: 12px; outline: 0;
}
.ai-modal-content textarea:focus, .ai-modal-content input:focus { border-color: #2d4f8c; }
.ai-modal-err { min-height: 18px; margin-top: 6px; color: var(--k-red); font-size: .8rem; }
.ai-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.ai-modal-cancel, .ai-modal-ok { padding: 9px 16px; border-radius: 999px; border: 0; cursor: pointer; font-size: .88rem; }
.ai-modal-cancel { background: var(--k-card2); }
.ai-modal-ok { background: var(--k-blue); color: #fff; }
.ai-modal-ok:disabled { opacity: .5; }

@media (prefers-reduced-motion: reduce) {
  .ai-typing-dots span { animation: none; opacity: .6; }
}
