/* ═══════════════════════════════════════════
   KD GPT — ChatGPT-style Layout
   Colors from landing page: #020202 bg, gold #FFD700→#FFA500
   ═══════════════════════════════════════════ */

/* ─── Variables ─── */
:root {
  --bg:          #111111;
  --sidebar-bg:  #171717;
  --input-bg:    #1e1e1e;
  --surface:     #1e1e1e;
  --border:      rgba(255,255,255,0.08);
  --text:        #ececec;
  --text-muted:  rgba(255,255,255,0.45);
  --gold:        #FFD700;
  --gold-end:    #FFA500;
  --gold-glow:   rgba(255, 215, 0, 0.25);
  --user-bubble: #2a2a2a;
  --radius-pill: 9999px;
  --radius-msg:  18px;
  --topbar-h:    52px;
  --sidebar-w:   260px;
  --icon-rail-w: 56px;
}

/* Light mode overrides */
body.light {
  --bg:          #f9f9f9;
  --sidebar-bg:  #f1f1f1;
  --input-bg:    #ffffff;
  --surface:     #ffffff;
  --border:      rgba(0,0,0,0.08);
  --text:        #111111;
  --text-muted:  rgba(0,0,0,0.4);
  --user-bubble: #eeeeee;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* ─── App Shell ─── */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ════════════════════════════════════════
   SIDEBAR (icon rail + panel)
   ════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  transition: width 0.25s ease;
  overflow: hidden;
}

/* Sidebar top controls */
.sidebar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px 12px;
}

.sidebar-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.sidebar-icon-btn:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text);
}

body.light .sidebar-icon-btn:hover {
  background: rgba(0,0,0,0.06);
}

/* New Chat button in sidebar */
.new-chat-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.new-chat-btn:hover { background: rgba(255,255,255,0.07); }
body.light .new-chat-btn:hover { background: rgba(0,0,0,0.06); }

/* Conversation History */
.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 16px 6px;
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history::-webkit-scrollbar { width: 4px; }
.history::-webkit-scrollbar-track { background: transparent; }
.history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
body.light .history::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }

.history-item-wrapper {
  position: relative;
}

.history-item {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover { background: rgba(255,255,255,0.07); }
body.light .history-item:hover { background: rgba(0,0,0,0.06); }

.history-item.active {
  background: rgba(255,255,255,0.1);
  font-weight: 500;
}
body.light .history-item.active { background: rgba(0,0,0,0.08); }

.history-item .title {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .snippet {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-conv-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  font-size: 14px;
  padding: 4px;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.history-item-wrapper:hover .delete-conv-btn { opacity: 1; }
.delete-conv-btn:hover { background: rgba(255,80,80,0.15); color: #ff6060; }

/* Sidebar footer / ad zone */
.sidebar-ad {
  padding: 10px;
  border-top: 1px solid var(--border);
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 4px 0;
}

.sidebar-links a {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.sidebar-links a:hover {
  color: var(--gold);
}

.sidebar-copyright {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
  opacity: 0.6;
}

.clear-btn {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid rgba(255,80,80,0.3);
  border-radius: 8px;
  color: #ff7070;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.clear-btn:hover { background: rgba(255,80,80,0.1); }

/* ════════════════════════════════════════
   MAIN CONTENT AREA
   ════════════════════════════════════════ */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

/* ─── Topbar ─── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}

.topbar-brand {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.topbar-brand .crown-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.topbar-brand .gold-text {
  background: linear-gradient(135deg, var(--gold), var(--gold-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: rgba(255,215,0,0.08);
  border: 1px solid rgba(255,215,0,0.2);
  color: var(--gold);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
body.light .theme-btn { background: rgba(0,0,0,0.05); border-color: rgba(0,0,0,0.15); color: #888; }
.theme-btn:hover { background: rgba(255,215,0,0.15); transform: scale(1.05); }

/* ────────────────────────────────────────
   CHAT COLUMN (messages + input)
   ────────────────────────────────────────*/
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

/* ─── Messages ─── */
.messages {
  flex: 1;
  width: 100%;
  max-width: 720px;
  padding: 28px 24px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }
body.light .messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }

/* ─── Empty State (ChatGPT style) ─── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding-bottom: 80px;
  animation: fadeUp 0.5s ease both;
}

.empty-state .crown-badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-end));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  box-shadow: 0 0 32px var(--gold-glow);
}

.empty-state h2 {
  font-size: 26px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.3px;
}

body.light .empty-state h2 { color: #111; }

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

/* ─── Bubbles ─── */
.bubble {
  display: flex;
  gap: 14px;
  max-width: 100%;
  animation: bubbleIn 0.28s ease both;
  position: relative;
}

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

/* Bot bubble: icon + content */
.bubble-bot {
  align-items: flex-start;
}

.bot-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-end));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 3px;
  box-shadow: 0 2px 8px var(--gold-glow);
}

.bubble-content {
  flex: 1;
  min-width: 0;
  position: relative;
}

.bubble-inner {
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble-bot .bubble-inner {
  background: transparent;
  padding: 2px 0;
}

/* User bubble: pill on the right */
.bubble-user {
  justify-content: flex-end;
}

.bubble-user .bubble-content {
  max-width: 70%;
}

.bubble-user .bubble-inner {
  background: var(--user-bubble);
  border-radius: var(--radius-msg);
  padding: 12px 18px;
  color: var(--text);
}

body.light .bubble-user .bubble-inner { background: #e8e8e8; color: #111; }
body.light .bubble-bot .bubble-inner  { color: #111; }

/* Copy button */
.copy-btn {
  position: absolute;
  bottom: -22px;
  right: 0;
  font-size: 11px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  opacity: 0;
  padding: 3px 6px;
  border-radius: 4px;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}
.bubble-content:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,0.07); color: var(--gold); }
body.light .copy-btn:hover { background: rgba(0,0,0,0.05); color: #888; }

/* Typing indicator */
.thinking {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

.dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
@keyframes bounce {
  0%,80%,100% { transform: scale(0.6); opacity: 0.4; }
  40%          { transform: scale(1);   opacity: 1;   }
}

/* ─── Input Bar ─── */
.input-area {
  width: 100%;
  max-width: 720px;
  padding: 12px 24px calc(32px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 10px 8px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
  border-color: rgba(255,215,0,0.4);
  box-shadow: 0 0 0 3px rgba(255,215,0,0.08);
}

body.light .input-wrapper { background: #fff; border-color: rgba(0,0,0,0.13); }
body.light .input-wrapper:focus-within { border-color: rgba(255,165,0,0.5); box-shadow: 0 0 0 3px rgba(255,165,0,0.08); }

/* attach/plus btn */
.attach-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
}
.attach-btn:hover { background: rgba(255,255,255,0.07); color: var(--text); }
body.light .attach-btn:hover { background: rgba(0,0,0,0.06); }
.attach-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.55;
  padding: 6px 10px;
  max-height: 180px;
  overflow-y: auto;
}
.input-wrapper textarea::placeholder { color: var(--text-muted); }
body.light .input-wrapper textarea { color: #111; }
body.light .input-wrapper textarea::placeholder { color: rgba(0,0,0,0.35); }

/* send button */
.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold), var(--gold-end));
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 2px;
}
.send-btn:hover { transform: scale(1.06); box-shadow: 0 4px 12px var(--gold-glow); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* input footer note */
.input-note {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 8px;
  padding: 0 4px;
}

/* ── Image preview ── */
#imagePreview {
  padding: 6px 14px 4px;
  display: none;
}
#imagePreview img {
  max-width: 120px;
  max-height: 120px;
  border-radius: 10px;
  border: 2px solid rgba(255,215,0,0.25);
}
#removeImageBtn {
  background: rgba(255,60,60,0.8);
  color: #fff;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Image menu ── */
#imageMenu {
  background: var(--surface);
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
  position: absolute;
  z-index: 1000;
}
#imageMenu button {
  display: block;
  width: 100%;
  padding: 11px 18px;
  background: transparent;
  color: var(--text);
  border: none;
  text-align: left;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: background 0.15s;
}
#imageMenu button:hover { background: rgba(255,215,0,0.1); }
#photoLibraryBtn { border-top: 1px solid var(--border); }

/* Limit bubble */
.limit-bubble .bubble-inner {
  background: rgba(255,60,60,0.15) !important;
  border: 1px solid rgba(255,80,80,0.3);
  border-radius: var(--radius-msg) !important;
  padding: 12px 16px !important;
  color: #ff8080 !important;
}

/* Reveal animation for bot tokens */
.reveal {
  animation: revealText 500ms ease both;
}
@keyframes revealText {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════ */
@media (max-width: 780px) {
  .sidebar { display: none; }
  .messages, .input-area { max-width: 100%; padding-left: 14px; padding-right: 14px; }
  .topbar { padding: 0 14px; }
}
