:root {
  --bg: #0b0d14;
  --panel: #121624;
  --panel-2: #1a1f32;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f5ff;
  --muted: #9aa3c2;
  --gold: #e7c36a;
  --gold-2: #f5d98a;
  --violet: #7b6cff;
  --bot: #1e2540;
  --user: linear-gradient(135deg, #6d5efc, #8b5cf6);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.light {
  --bg: #eef1f8;
  --panel: #ffffff;
  --panel-2: #f6f8fd;
  --line: rgba(20, 24, 40, 0.08);
  --text: #161a2b;
  --muted: #5d6680;
  --bot: #eef0f8;
  --shadow: 0 12px 30px rgba(40, 50, 80, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans Devanagari", "Poppins", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(123, 108, 255, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(231, 195, 106, 0.12), transparent 26%),
    var(--bg);
  color: var(--text);
}

.app {
  width: min(1180px, calc(100% - 24px));
  height: calc(100vh - 24px);
  margin: 12px auto;
  display: grid;
  grid-template-columns: 280px 1fr;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  font-weight: 700; color: #1a1406;
  background: linear-gradient(145deg, var(--gold-2), var(--gold));
}
.brand h1 { font-size: 20px; line-height: 1; }
.brand p { color: var(--muted); font-size: 12px; }

.new-chat-btn, .chip, .suggest, .icon-btn, #sendBtn, .key-cta {
  border: 0; cursor: pointer; font-family: inherit;
}
.save-btn {
  position: relative;
}

.save-btn.saved {
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  color: #1a1406;
}

.new-chat-btn {
  width: 100%; padding: 12px; border-radius: 12px;
  color: #1a1406; font-weight: 600;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
}

.sidebar-section h3 {
  font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 10px;
}

.chip, .suggest {
  display: block; width: 100%; text-align: left;
  margin-bottom: 8px; padding: 10px 12px; border-radius: 12px;
  color: var(--text); background: transparent; border: 1px solid var(--line);
  font-size: 13px;
}
.chip:hover, .suggest:hover { background: rgba(123, 108, 255, 0.12); }
.chip.active {
  background: linear-gradient(135deg, rgba(123,108,255,.35), rgba(231,195,106,.2));
  border-color: transparent;
}

.sidebar-footer {
  margin-top: auto; display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #3ddc97; box-shadow: 0 0 10px #3ddc97;
}

.chat-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.bot-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.bot-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--violet), #49b7ff);
  font-size: 18px; flex-shrink: 0;
}
.bot-info h2 {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
}

.bot-info p { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--panel-2); color: var(--text); font-size: 16px;
  display: grid; place-items: center; flex-shrink: 0;
}
.icon-btn.tiny { width: 28px; height: 28px; border-radius: 8px; font-size: 12px; }
.icon-btn.listening { background: #ef4444; color: #fff; }
.menu-btn { display: none; }
.key-cta {
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13px;
  color: #1a1406;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  flex-shrink: 0;
  width: 40px;
  font-size: 0;
}
.key-cta::after {
  content: "🔑";
  font-size: 16px;
}

.key-cta.sidebar-key { width: 100%; height: 44px; }

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

.welcome {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.welcome h3 { margin-bottom: 6px; }
.welcome p { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.feat-list { list-style: none; display: grid; gap: 7px; }
.feat-list li {
  font-size: 13px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(123, 108, 255, 0.08);
}

.msg {
  max-width: min(90%, 640px);
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise .25s ease;
}
.msg.bot { align-self: flex-start; background: var(--bot); border-top-left-radius: 6px; white-space: normal; }
.msg.user { align-self: flex-end; color: #fff; background: var(--user); border-top-right-radius: 6px; }
.msg img.shot {
  display: block; max-width: 220px; max-height: 160px;
  border-radius: 10px; margin-top: 8px; object-fit: cover;
}
.msg .diagram {
  display: block; width: 100%; max-width: 420px; height: auto;
  margin: 10px 0; border-radius: 12px;
}
.msg p { margin: 8px 0; }
.msg .hint { color: var(--muted); font-size: 12px; }
.file-tag {
  display: inline-block; margin-top: 8px; font-size: 12px;
  padding: 6px 8px; border-radius: 8px; background: rgba(0,0,0,.2);
}
.codebox {
  display: block; margin-top: 8px; padding: 10px;
  background: #0a0f1c; color: #bbf7d0;
  border-radius: 10px; overflow-x: auto;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px;
  white-space: pre;
}

.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
  animation: bounce 1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

.preview-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-top: 1px solid var(--line);
}
.preview-bar.hidden, .backdrop.hidden, .modal.hidden { display: none; }
#previews { display: flex; gap: 8px; overflow-x: auto; flex: 1; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; }
.file-mini { font-size: 11px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); }

.composer {
  display: flex; gap: 8px; align-items: center;
  min-width: 0;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
#userInput {
  flex: 1;
  min-width: 0;
  width: 0;
  height: 46px; border: 1px solid var(--line); border-radius: 14px;
  padding: 0 14px; background: var(--panel-2); color: var(--text);
  font-family: inherit; font-size: 14px; outline: none;
}
#sendBtn {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 46px; height: 46px; border-radius: 14px;
  color: #1a1406; font-size: 18px;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
}

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: end center;
  background: rgba(0,0,0,.45);
}
.sheet {
  width: min(480px, 100%);
  background: var(--panel);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
}
.sheet h3 { margin-bottom: 8px; }
.sheet p { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.sheet input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); padding: 0 12px; font-family: inherit;
  margin-bottom: 10px;
}
.sheet .row { display: flex; gap: 8px; align-items: center; }
.sheet .row .chip, .sheet .row .new-chat-btn { width: auto; padding: 10px 14px; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-4px); opacity: 1; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    height: 100vh; width: 100%; margin: 0; border-radius: 0; border: 0;
  }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, 300px);
    z-index: 30; transform: translateX(-105%); transition: transform .25s ease;
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: grid; }
  .msg { max-width: 92%; }
}
.more-wrap { position: relative; flex-shrink: 0; }
.more-menu {
  position: absolute;
  right: 0;
  top: 46px;
  min-width: 140px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  z-index: 50;
  box-shadow: var(--shadow);
}
.more-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.more-menu button:hover { background: rgba(123, 108, 255, 0.12); }
.more-menu.hidden { display: none; }
