:root {
  --bg-deep: #070b1a;
  --navy-1: #0b1230;
  --navy-2: #0d1633;
  --glass: rgba(255,255,255,0.05);
  --glass-strong: rgba(255,255,255,0.12);
  --glass-border: rgba(255,255,255,0.15);
  --text: #eef1fb;
  --text-dim: #a4acc9;
  --text-faint: #717a9c;
  --accent-blue: #ffffff; 
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --bg-overlay-opacity: 0.96; 
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: var(--bg-deep);
  overflow: hidden;
}

/* =========================================================
   PERFECTED BACKGROUND LOGIC (DARK OVERLAY + FAINT IMAGE)
========================================================= */
.bg-layer {
  position: fixed; inset: -20px;
  background-image: url('assets/bg-poster.jpg');
  background-size: cover; background-position: center;
  z-index: -2;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.bg-overlay {
  position: fixed; inset: 0;
  z-index: -1;
  transition: background 0.3s ease, opacity 0.3s ease;
}

/* HOME SCREEN: Clear image + Blue gradient */
body.home-active .bg-layer {
  filter: blur(0px);
  opacity: 1;
}
body.home-active .bg-overlay {
  background: linear-gradient(100deg, rgba(6,10,26,0.95) 0%, rgba(9,14,34,0.85) 38%, rgba(10,16,38,0.70) 68%, rgba(10,16,38,0.40) 100%);
  opacity: var(--bg-overlay-opacity);
}

/* CHAT SCREEN: Blurred image + 95% Opaque Dark/Grey Overlay */
body.chat-active .bg-layer {
  filter: blur(20px); 
  opacity: 1; /* Keeps the image visible so a little bit shines through */
}
body.chat-active .bg-overlay {
  /* This is 95% to 98% opaque black/grey, letting 2-5% of the blurred background peek through */
  background: linear-gradient(100deg, rgba(24,24,27,0.98) 0%, rgba(39,39,42,0.95) 100%);
  opacity: 1;
}
/* ========================================================= */

h1, h2, h3, .brand { font-family: 'Space Grotesk', sans-serif; }

::-webkit-scrollbar { width: 8px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 8px; transition: background 0.3s ease; }
*:hover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }

button, .icon-btn, .brand, .nav-item, .chat-item, .sidebar-label, .danger-item {
  font-family: inherit; cursor: pointer; user-select: none; -webkit-user-select: none;
}

.app { display: flex; height: 100vh; width: 100vw; }

/* ---------------- SIDEBAR (FLAWLESS COLLAPSE) ---------------- */
.sidebar {
  width: 280px; 
  flex-shrink: 0;
  background: rgba(19, 19, 20, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid rgba(255, 255, 255, 0.08); 
  display: flex; 
  flex-direction: column;
  padding: 22px 16px; 
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
  position: relative;
  box-shadow: 4px 0 30px rgba(0, 0, 0, 0.4); 
  z-index: 50;
}

.sidebar.collapsed { width: 76px; }

.fade-text {
  opacity: 1;
  white-space: nowrap; 
  transition: opacity 0.2s ease;
}
.sidebar.collapsed .fade-text {
  opacity: 0; 
  pointer-events: none;
}

.brand { 
  display: flex; align-items: center; justify-content: flex-start; 
  gap: 12px; padding: 0 5px 20px 5px; position: relative; 
  overflow: hidden; white-space: nowrap;
}
.brand .logo-dot {
  width: 34px; height: 34px; border-radius: 10px;
  background-image: url('assets/bg-logo.jpeg');
  background-size: cover; background-position: center;
  border: 1px solid var(--glass-border); flex-shrink: 0; position: relative; overflow: hidden;
}
.logo-dot i.overlay-icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(11, 18, 48, 0.85); backdrop-filter: blur(2px); color: var(--text); 
  font-size: 22px;
  opacity: 0; transition: opacity 0.2s ease;
}
.sidebar.collapsed .brand-text-wrap:hover .logo-dot i.overlay-icon { opacity: 1; }
.brand-text-wrap {
  display: flex; align-items: center; gap: 10px; color: var(--text); flex: 1;
  background: none; border: none; padding: 0; text-align: left;
}
.brand-text-wrap .fade-text { font-weight: 600; font-size: 17px; letter-spacing: .2px; }

.sidebar-toggle {
  background: transparent; border: none; color: var(--text-faint); 
  font-size: 24px; 
  padding: 4px; border-radius: 8px; transition: all 0.2s; position: absolute; right: 8px; top: -4px;
}
.sidebar-toggle:hover { background: var(--glass-strong); color: var(--text); }
.sidebar.collapsed .sidebar-toggle { opacity: 0; pointer-events: none; }

.newchat-btn, .nav-item, .danger-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 12px;
  width: 100%; 
  padding: 10px 8px;
  border-radius: 12px;
  background: transparent; border: none; text-align: left; 
  color: var(--text-dim); font-size: 14.5px; font-weight: 600;
  overflow: hidden; white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease;
}
.newchat-btn i, .nav-item i, .danger-item i {
  width: 28px;
  font-size: 22px;
  text-align: center; flex-shrink: 0;
}

.newchat-btn { 
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  color: var(--text); margin-bottom: 18px; height: 44px;
}
.newchat-btn:hover { background: rgba(255,255,255,0.20); }
.nav-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.nav-item:hover { background: var(--glass); color: var(--text); }
.nav-item.active { background: var(--glass-strong); color: #fff; border: 1px solid var(--glass-border); }
.danger-item { color: #ef4444; }
.danger-item i { color: #ef4444; }
.danger-item:hover { background: rgba(239, 68, 68, 0.15); }

.sidebar-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin: 14px 10px 8px 10px; font-weight: 600; 
  white-space: nowrap; transition: opacity 0.2s ease;
}
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding-right: 2px; }

.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .chat-list { display: none; }

.chat-item-wrapper { position: relative; display: flex; align-items: center; border-radius: var(--radius-sm); width: 100%; }
.chat-item-wrapper:hover { background: var(--glass); }

.chat-item {
  width: 100%; display: flex; align-items: center; justify-content: flex-start; gap: 8px;
  padding: 9px 34px 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13px; background: transparent; border: none;
  text-align: left; overflow: hidden; white-space: nowrap;
}
.chat-item-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.chat-pin-icon { font-size: 14px; color: var(--text-faint); margin-left: 4px; }
.chat-item.active { background: var(--glass-strong); color: var(--text); }

.menu-dots {
  background: transparent; border: none; color: var(--text-faint); font-size: 18px; width: 24px; height: 24px; 
  padding: 0; margin: 0; display: flex; align-items: center; justify-content: center; border-radius: 6px; position: absolute; right: 6px; 
  top: 50%; transform: translateY(-50%); display: none; z-index: 60; transition: background 0.2s, color 0.2s;
}
.chat-item-wrapper:hover .menu-dots { display: flex; }
.menu-dots:hover { color: var(--text); background: rgba(255,255,255,0.15); }
.chat-actions-menu {
  display: none; position: absolute; right: 28px; top: 10px; flex-direction: column;
  background: rgba(10, 15, 30, 0.95); backdrop-filter: blur(20px); border: 1px solid var(--glass-border); border-radius: 8px; padding: 4px;
  z-index: 100; box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}
.chat-actions-menu.show { display: flex; }
.action-btn { background: transparent; border: none; color: var(--text-dim); font-size: 13px; cursor: pointer; padding: 8px 12px; border-radius: 4px; text-align: left; display: flex; gap: 8px; align-items: center; }
.action-btn i { font-size: 15px; color: var(--text-dim); }
.action-btn:hover, .action-btn:hover i { background: var(--glass-strong); color: var(--text); }
.chat-empty { color: var(--text-faint); font-size: 12.5px; padding: 8px 10px; }

.sidebar-bottom { margin-top: auto; border-top: 1px solid var(--glass-border); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }

/* ---------------- MAIN ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; z-index: 10; }
#homeView { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px 30px 30px; overflow-y: auto; }
.hero { max-width: 800px; width: 100%; text-align: center; margin-bottom: 40px; }
.hero h1 { font-size: 38px; font-weight: 600; margin: 0 0 6px 0; letter-spacing: .2px; }
.hero p { color: var(--text-dim); font-size: 15px; margin: 0; }
.suggested-prompts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 750px; margin-bottom: 24px; }
.prompt-pill {
  display: flex; align-items: center; gap: 8px; background: var(--glass-strong); border: 1px solid var(--glass-border); color: var(--text-dim); padding: 10px 18px; border-radius: 20px; font-size: 13.5px; font-weight: 500; cursor: pointer; transition: all 0.2s; backdrop-filter: blur(10px);
}
.prompt-pill i { font-size: 16px; color: var(--text-dim); }
.prompt-pill:hover, .prompt-pill:hover i { background: rgba(255,255,255,0.15); color: var(--text); border-color: rgba(255,255,255,0.3); }

/* Input Elements */
.search-pill-container { width: 100%; max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; z-index: 20; position: relative; }
.search-pill {
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--glass-border);
  border-radius: 26px; padding: 12px 14px;
  backdrop-filter: blur(30px) saturate(150%); box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  transition: all 0.2s ease;
}
.normal-input-view { display: flex; align-items: flex-end; gap: 12px; width: 100%; }
.normal-input-view.hidden { display: none; }

.search-pill textarea {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font-size: 15px; font-family: inherit; line-height: 1.5;
  max-height: 200px; padding: 8px 0; overflow-y: hidden; cursor: text !important; user-select: text !important;
}
.search-pill textarea::placeholder { color: var(--text-faint); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: var(--text-dim); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; transition: all 0.2s; z-index: 25;
}
.icon-btn i { pointer-events: none; }
.icon-btn:hover { color: var(--text); background: var(--glass-strong); }
.send-btn { background: var(--text); color: #000; border: none; }
.send-btn i { color: #000; }
.send-btn:hover { background: var(--text-dim); color: #000; }
.mic-btn { color: var(--text-dim); }
.mic-btn:hover { color: var(--text); background: var(--glass-strong); }

/* ---------------- RECORDING & WAVEFORM ---------------- */
.recording-view {
  display: none; align-items: center; justify-content: space-between; width: 100%; gap: 10px; padding: 2px 0;
}
.recording-view.active { display: flex; }
.waveform-container {
  display: flex; align-items: center; justify-content: center; gap: 4px; flex: 1; height: 40px; overflow: hidden;
}
.waveform-bar {
  width: 4px; background: var(--text-dim); border-radius: 4px;
  animation: pulse-wave 1.2s ease-in-out infinite alternate;
}
@keyframes pulse-wave {
  0% { transform: scaleY(0.3); background: var(--text-faint); }
  50% { transform: scaleY(1.3); background: var(--text); }
  100% { transform: scaleY(0.6); background: var(--accent-blue); }
}
.stop-voice-btn { background: rgba(255, 255, 255, 0.08); border-radius: 50%; color: var(--text); }
.stop-voice-btn:hover { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

/* ---- Chat view ---- */
#chatView { flex: 1; display: none; flex-direction: column; min-height: 0; padding: 20px 0 18px 0; }

.messages { flex: 1; overflow-y: auto; padding: 10px 8% 20px 8%; display: flex; flex-direction: column; gap: 26px; }

/* =========================================================
   GENERIC CHAT LAYOUT 
========================================================= */
.msg { 
  max-width: 800px; 
  width: 100%; 
  align-self: center; 
  display: flex; 
  flex-direction: column; 
  gap: 6px; 
}

.msg-content { 
  line-height: 1.65; 
  white-space: pre-wrap; 
  word-wrap: break-word; 
  font-size: 16px; 
  transition: max-height 0.3s ease; 
}

.msg-content.clamp { max-height: 115px; overflow: hidden; display: block; }
.see-more-btn { background: transparent; border: none; color: #a4acc9; font-size: 13.5px; cursor: pointer; padding: 6px 0 0 0; text-align: left; font-weight: 600; display: inline-block; width: fit-content; }
.see-more-btn:hover { color: #ffffff; text-decoration: underline; }

/* USER BUBBLE (ROUND, ALIGNED RIGHT, MAX 75% WIDTH OF CONTAINER) */
.msg.user { 
  align-items: flex-end; 
}
.msg.user .bubble { 
  padding: 14px 20px; 
  border-radius: 24px; 
  background: var(--glass-strong); 
  border: 1px solid var(--glass-border); 
  color: #fff; 
  backdrop-filter: blur(10px); 
  max-width: 75%; 
  text-align: left; 
}

/* =========================================================
   AI TEXT LOGIC: NORMAL WEIGHT + STANDARD SIZE (EYE-FRIENDLY)
========================================================= */
.msg.assistant { align-items: flex-start; }

/* Standard size and normal weight to prevent eye strain */
.msg.assistant .msg-content {
  font-weight: 400; 
  font-size: 16px; 
  color: var(--text); 
}

/* AI HEADER */
.ai-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.ai-header .header-icon { width: 25px; height: 25px; border-radius: 60px; background-image: url('assets/bg-logo.jpeg'); background-size: cover; background-position: center; border: 0px solid var(--glass-border); }
.ai-header span { 
  font-size: 15px; 
  font-weight: 600; 
  color: var(--text); 
}
.ai-text { color: var(--text-dim); padding-left: 40px; max-width: 100%; }

/* ACTION BUTTONS PLACED DIRECTLY BELOW TEXT */
.ai-actions { 
  display: flex; 
  align-items: center; 
  gap: 2px; 
  padding-left: 40px; 
  margin-top: 10px; 
}
.ai-action-btn { background: transparent; border: none; color: var(--text-faint); font-size: 17px; cursor: pointer; padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.ai-action-btn:hover { color: var(--text); background: var(--glass-strong); }
.ai-action-btn[data-clicked="true"]:hover { background: transparent; color: var(--text-faint); cursor: default; }
/* ========================================================= */


/* TOAST */
.toast-container { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; z-index: 9999; }
.toast { background: rgba(11, 18, 48, 0.95); border: 1px solid var(--glass-border); color: var(--text); padding: 12px 24px; border-radius: 30px; font-size: 14px; font-weight: 500; opacity: 0; transform: translateY(20px); transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); backdrop-filter: blur(15px); box-shadow: 0 8px 30px rgba(0,0,0,0.4); display: flex; align-items: center; gap: 8px; }
.toast i { font-size: 16px; }
.toast.show { opacity: 1; transform: translateY(0); }
.typing-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); margin-right: 4px; animation: blink 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
.composer-wrap { padding: 14px 15% 0 15%; position: relative; z-index: 20; }

/* ---------------- ATTACHMENTS ---------------- */
.hidden-file-input { display: none; }

.attach-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--glass-strong); border: 1px solid var(--glass-border);
  border-radius: 16px; padding: 8px 12px; margin-bottom: 8px;
  max-width: 800px; width: 100%;
}
.attach-chip .attach-thumb {
  width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex-shrink: 0;
  background: rgba(255,255,255,0.08); display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--text-dim);
}
.attach-chip .attach-info { flex: 1; min-width: 0; }
.attach-chip .attach-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-chip .attach-status { font-size: 11.5px; color: var(--text-faint); }
.attach-chip .attach-remove { background: transparent; border: none; color: var(--text-faint); font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px; flex-shrink: 0; }
.attach-chip .attach-remove:hover { color: #ef4444; background: rgba(239,68,68,0.12); }

.msg-attach-tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  color: var(--text-dim); background: rgba(255,255,255,0.06); border: 1px solid var(--glass-border);
  padding: 4px 10px; border-radius: 12px; margin-bottom: 8px;
}

/* ---------------- CODE BLOCKS ---------------- */
.code-block {
  background: #0a0e1f; border: 1px solid var(--glass-border); border-radius: 12px;
  margin: 10px 0; overflow: hidden; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: rgba(255,255,255,0.04); border-bottom: 1px solid var(--glass-border);
  font-size: 12px; color: var(--text-faint); text-transform: lowercase; letter-spacing: .04em;
}
.code-copy-btn {
  display: flex; align-items: center; gap: 6px; background: transparent; border: none;
  color: var(--text-dim); font-size: 12px; font-family: inherit; cursor: pointer;
  padding: 4px 8px; border-radius: 6px; transition: all .15s ease;
}
.code-copy-btn:hover { color: var(--text); background: var(--glass-strong); }
.code-block pre { margin: 0; padding: 14px; overflow-x: auto; }
.code-block code { font-size: 13.5px; line-height: 1.6; color: #d9e0f5; white-space: pre; }
.inline-code {
  background: rgba(255,255,255,0.08); border: 1px solid var(--glass-border);
  padding: 1px 6px; border-radius: 5px; font-size: 0.9em;
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace; color: #ffcb8b;
}
.ai-text ul { margin: 6px 0; padding-left: 22px; }
.ai-text li { margin-bottom: 4px; }

/* ---------------- GENERATED IMAGES ---------------- */
.generated-image-wrap { max-width: 420px; }
.generated-image {
  width: 100%; border-radius: 14px; border: 1px solid var(--glass-border);
  display: block; margin-bottom: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.generated-image-caption { font-size: 13.5px; color: var(--text-dim); }
.generated-image-error { color: #f4a3a3; font-size: 14px; }

