/*--------------------
Body
--------------------*/
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  overflow: hidden;
  background-color: #222;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: "Poppins", sans-serif;
}

/* ── Star canvas ─────────────────────────────────────────────── */
#star-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100% !important;
  height: 100% !important;
  z-index: 0;
  pointer-events: none;
}

/*--------------------
Chat
--------------------*/
.chat {
  backdrop-filter: blur(1vh);
  position: absolute;
  left: 50%;
  top: 50%;
  /* Mobile: cap layout width so visual (×1.5) stays within 88vw */
  width: min(37vh, calc(88vw / 1.5));
  height: 52vh;
  z-index: 4;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 1.5vh;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  transform: translate(-50%, -50%) scale(1.5);
  font-weight: normal;
  opacity: 0;
  transition: opacity 0.75s cubic-bezier(0.4, 0, 0.2, 1), height 0.35s ease;
}

.chat.visible {
  opacity: 1;
}



/*--------------------
Chat Title
--------------------*/
.chat-title {
  flex: 0 1 4.5vh;
  position: relative;
  z-index: 2;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  text-transform: uppercase;
  text-align: left;
  padding: 1vh 1vh 1vh 5vh;
  border-bottom: 0.12vh solid rgba(167, 130, 71, 0.22);
}
.chat-title h1, .chat-title h2 {
  font-weight: normal;
  font-size: 1vh;
  margin: 0;
  padding: 0;
  text-align: left;
  color: white;
}
.chat-title h2 {
  color: white;
  font-size: 0.8vh;
  letter-spacing: 0.1vh;
}
.chat-title .avatar {
  position: absolute;
  z-index: 1;
  top: 0.8vh;
  left: 0.9vh;
  border-radius: 3vh;
  width: 3.1vh;
  height: 3.1vh;
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: 0.2vh solid rgba(255, 255, 255, 0.3);
}
.chat-title .avatar img {
  width: 100%;
  height: auto;
}

/* History toggle button inside chat-title (right side) */
#history-toggle-btn {
  position: absolute;
  right: 1vh;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 228, 181, 0.12);
  border: 0.15vh solid rgba(255, 228, 181, 0.3);
  color: rgba(255, 228, 181, 0.7);
  border-radius: 0.7vh;
  width: 2.6vh;
  height: 2.6vh;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1vh;
  flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  z-index: 3;
}
#history-toggle-btn:hover {
  background: rgba(255, 228, 181, 0.25);
  border-color: moccasin;
  color: moccasin;
}
#history-toggle-btn.active {
  background: rgba(255, 228, 181, 0.28);
  border-color: moccasin;
  color: moccasin;
}

/*--------------------
History Drawer
--------------------*/
.history-drawer {
  flex: 0 0 auto;
  overflow: hidden;
  max-height: 22vh;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  opacity: 1;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 0.1vh solid rgba(255, 228, 181, 0.12);
  display: flex;
  flex-direction: column;
}

.history-drawer.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  border-bottom: none;
}

.history-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7vh 1vh 0.5vh;
  font-size: 0.8vh;
  color: rgba(255, 228, 181, 0.8);
  letter-spacing: 0.05vh;
  text-transform: uppercase;
  border-bottom: 0.1vh solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}
.history-drawer-header span {
  display: flex;
  align-items: center;
  gap: 0.4vh;
}
#history-clear-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.25);
  font-size: 0.85vh;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s ease;
  line-height: 1;
}
#history-clear-btn:hover {
  color: rgba(255, 80, 80, 0.7);
}

.history-list {
  overflow-y: auto;
  flex: 1 1 auto;
  padding: 0.4vh 0;
}
.history-list::-webkit-scrollbar { display: none; }
.history-list { scrollbar-width: none; }

.history-empty {
  font-size: 0.8vh;
  color: rgba(255, 255, 255, 0.3);
  text-align: center;
  padding: 1vh 0;
  font-weight: normal;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 0.5vh;
  padding: 0.35vh 1vh;
  font-size: 0.8vh;
  font-weight: normal;
  transition: background 0.15s ease;
  cursor: default;
}
.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.history-role {
  font-size: 0.65vh;
  text-transform: uppercase;
  letter-spacing: 0.05vh;
  flex-shrink: 0;
  width: 1.8vh;
  text-align: center;
  border-radius: 0.3vh;
  padding: 0.1vh 0.3vh;
}
.history-item--user .history-role {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
}
.history-item--assistant .history-role {
  background: rgba(255, 228, 181, 0.15);
  color: moccasin;
}
.history-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.6);
}
.history-source-count {
  font-size: 0.65vh;
  color: rgba(255, 228, 181, 0.55);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.2vh;
}
.history-time {
  font-size: 0.65vh;
  color: rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
}

/*--------------------
Streaming cursor
--------------------*/
.stream-cursor {
  display: inline-block;
  width: 0.5vh;
  height: 1.1vh;
  background: moccasin;
  border-radius: 0.1vh;
  margin-left: 0.15vh;
  vertical-align: text-bottom;
  opacity: 0.85;
  animation: cursor-blink 0.55s steps(1) infinite;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 0.85; }
  50%       { opacity: 0; }
}

/* While streaming, keep the bubble content as plain text (pre-wrap)
   so tokens append naturally without markdown interference */
.message.streaming .message-content {
  white-space: pre-wrap;
  word-break: break-word;
}
.message.streaming {
  border-left: 0.15vh solid rgba(130, 200, 255, 0.35);
  animation: bounce 500ms linear both, stream-pulse 2s ease-in-out infinite;
}
@keyframes stream-pulse {
  0%, 100% { border-left-color: rgba(130, 200, 255, 0.35); }
  50%       { border-left-color: rgba(130, 200, 255, 0.7); }
}

/*--------------------
Source Chips
--------------------*/
.source-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4vh;
  margin-top: 0.5vh;
}
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3vh;
  background: rgba(255, 228, 181, 0.1);
  border: 0.12vh solid rgba(255, 228, 181, 0.25);
  color: rgba(255, 228, 181, 0.8);
  border-radius: 0.5vh;
  padding: 0.2vh 0.6vh;
  font-size: 0.7vh;
  font-weight: normal;
  max-width: calc(100% - 1.4vh);
  overflow: hidden;
  cursor: default;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.source-chip .chip-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-chip:hover {
  background: rgba(255, 228, 181, 0.18);
  border-color: rgba(255, 228, 181, 0.5);
  color: moccasin;
}
.source-chip i {
  font-size: 0.65vh;
  flex-shrink: 0;
}
#upload-toggle-btn {
  background: rgba(255, 228, 181, 0.12);
  border: 0.15vh solid rgba(255, 228, 181, 0.3);
  color: rgba(255, 228, 181, 0.7);
  border-radius: 0.7vh;
  width: 2.6vh;
  height: 2.6vh;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1vh;
  flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
#upload-toggle-btn:hover {
  background: rgba(255, 228, 181, 0.25);
  border-color: moccasin;
  color: moccasin;
}
#upload-toggle-btn.active {
  background: rgba(255, 228, 181, 0.28);
  border-color: moccasin;
  color: moccasin;
}

/* Search indicator — sits above the AI reply, visually distinct from the response.
   !important needed to survive the bounce animation fill-mode and .message.new color:white */
.messages .message .search-indicator {
  display: block !important;
  font-size: 0.68vh !important;
  font-weight: normal !important;
  color: rgba(130, 200, 255, 0.8) !important;
  padding: 0 0 0.45vh 0;
  margin-bottom: 0.45vh;
  border-bottom: 0.1vh solid rgba(130, 200, 255, 0.18);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.5;
}

/* Links inside AI message text (rendered from markdown) */
.messages .message .message-content a {
  color: rgba(130, 200, 255, 0.9);
  text-decoration: underline;
  word-break: break-all;
  pointer-events: auto;
}
.messages .message .message-content a:hover {
  color: #a8d8ff;
}

/* Web source chips — clickable links */
.source-chip.web-chip {
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
}
.source-chip.web-chip:hover {
  background: rgba(130, 200, 255, 0.15);
  border-color: rgba(130, 200, 255, 0.45);
  color: #a8d8ff;
}
.source-chip.web-chip i {
  color: rgba(130, 200, 255, 0.65);
}

/*--------------------
Upload Panel (inside message-box, expands upward)
--------------------*/
.upload-panel {
  overflow: hidden;
  max-height: 22vh;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, padding 0.3s ease, margin-bottom 0.3s ease;
  opacity: 1;
  border-bottom: 0.1vh solid rgba(255, 228, 181, 0.15);
  padding: 1vh 0 0.8vh;
  margin-bottom: 0.7vh;
  display: flex;
  flex-direction: column;
  gap: 0.6vh;
}

.upload-panel.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0;
  margin-bottom: 0;
  pointer-events: none;
  border-bottom: none;
}

/* Drop Zone */
.drop-zone {
  border: 0.2vh dashed rgba(255, 228, 181, 0.4);
  border-radius: 1vh;
  padding: 1.2vh 1vh;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  background: rgba(255, 228, 181, 0.04);
  position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: moccasin;
  background: rgba(255, 228, 181, 0.1);
}

.drop-zone.drag-over .drop-icon {
  transform: translateY(-0.3vh) scale(1.15);
  color: moccasin;
}

.drop-zone-inner {
  pointer-events: none;
}

.drop-icon {
  font-size: 2.2vh;
  color: rgba(255, 228, 181, 0.6);
  display: block;
  margin-bottom: 0.4vh;
  transition: transform 0.2s ease, color 0.2s ease;
}

.drop-label {
  font-size: 0.85vh;
  color: rgba(255, 255, 255, 0.7);
  margin: 0 0 0.2vh;
  font-weight: normal;
}

.drop-browse {
  color: moccasin;
  text-decoration: underline;
  cursor: pointer;
  pointer-events: all;
}

.drop-hint {
  font-size: 0.75vh;
  color: rgba(255, 255, 255, 0.35);
  margin: 0;
  letter-spacing: 0.05vh;
  font-weight: normal;
}

/* File List */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.4vh;
  max-height: 7vh;
  overflow-y: auto;
}

.file-list::-webkit-scrollbar { display: none; }
.file-list { scrollbar-width: none; }

.file-item {
  display: flex;
  align-items: center;
  gap: 0.6vh;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 0.6vh;
  padding: 0.35vh 0.7vh;
  font-size: 0.8vh;
  color: rgba(255, 255, 255, 0.8);
  font-weight: normal;
  animation: bounce 350ms linear both;
}

.file-item .file-ext-badge {
  font-size: 0.65vh;
  background: rgba(255, 228, 181, 0.2);
  color: moccasin;
  border-radius: 0.4vh;
  padding: 0.1vh 0.4vh;
  text-transform: uppercase;
  letter-spacing: 0.04vh;
  flex-shrink: 0;
}

.file-item .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .file-size {
  font-size: 0.7vh;
  color: rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.file-item .file-remove {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  font-size: 0.8vh;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s ease;
}
.file-item .file-remove:hover {
  color: rgba(255, 80, 80, 0.8);
}

/* File item states */
.file-item.uploading .file-ext-badge {
  background: rgba(255, 228, 181, 0.1);
  color: rgba(255, 228, 181, 0.5);
}
.file-item.success .file-ext-badge {
  background: rgba(100, 200, 100, 0.2);
  color: #8dffb0;
}
.file-item.error .file-ext-badge {
  background: rgba(255, 80, 80, 0.2);
  color: #ff8d8d;
}

/* Upload Actions Row */
.upload-actions {
  display: flex;
  align-items: center;
  gap: 0.8vh;
}

.upload-submit-btn {
  background: rgba(255, 228, 181, 0.15);
  border: 0.15vh solid rgba(255, 228, 181, 0.4);
  color: moccasin;
  border-radius: 0.7vh;
  padding: 0.45vh 1.2vh;
  font-size: 0.8vh;
  font-family: "Poppins", sans-serif;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}
.upload-submit-btn:hover:not(:disabled) {
  background: rgba(255, 228, 181, 0.28);
  border-color: moccasin;
}
.upload-submit-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.upload-status {
  font-size: 0.75vh;
  color: rgba(255, 255, 255, 0.5);
  font-weight: normal;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-status.success {
  color: #8dffb0;
}
.upload-status.error {
  color: #ff8d8d;
}

/*--------------------
Messages
--------------------*/
.messages {
  flex: 1 1 auto;
  color: rgba(255, 255, 255, 0.5);
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  width: 100%;
  padding-left: 1vh;
  scroll-behavior: smooth;
  scrollbar-width: none;
}
.messages::-webkit-scrollbar {
  width: 0;
  display: none;
}
.messages .messages-content {
  width: 100%;
  min-height: 100%;
}
.messages .messages-content::after {
  content: '';
  display: table;
  clear: both;
}
.messages .message {
  clear: both;
  float: left;
  padding: 0.6vh 1vh 0.7vh;
  border-radius: 1vh 1vh 1vh 0;
  background: rgba(0,0,0, 0.2);
  margin: 0.8vh 0;
  font-size: 1.1vh;
  line-height: 1.4;
  margin-left: 3.5vh;
  position: relative;
  text-shadow: 0 0.1vh 1px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 4.5vh);
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.messages .message .timestamp {
  position: absolute;
  bottom: -1.5vh;
  font-size: 0.9vh;
  color: white;
}
.messages .message::before {
  content: "";
  position: absolute;
  bottom: -6px;
  border-top: 6px solid transparent;
  left: 0;
  border-right: 7px solid transparent;
  pointer-events: none;
}
.messages .message .avatar {
  position: absolute;
  z-index: 1;
  bottom: -1.5vh;
  left: -3.5vh;
  border-radius: 3vh;
  width: 3.1vh;
  height: 3.1vh;
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: 0.2vh solid rgba(255, 255, 255, 0.5);
}
.messages .message .avatar img {
  width: 100%;
  height: auto;
}
.messages .message.message-personal {
  float: right;
  color: #fff;
  text-align: right;
  background: rgba(0,0,0, 0.2);
  border-radius: 1vh 1vh 0 1vh;
  margin-left: 0;
  margin-right: 1vh;
  max-width: calc(100% - 4.5vh);
}
.messages .message.message-personal::before {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 5px solid transparent;
  border-top: 4px solid transparent;
  bottom: -4px;
  pointer-events: none;
}
.messages .message:last-child {
  margin-bottom: 2.4vh;
}

/* Markdown content inside AI messages */
.messages .message p {
  margin: 0 0 0.4vh;
}
.messages .message p:last-child {
  margin-bottom: 0;
}
.messages .message pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 0.5vh;
  padding: 0.5vh 0.7vh;
  font-size: 0.9vh;
  margin: 0.4vh 0 0;
  overflow-x: auto;
}
.messages .message code {
  font-size: 0.9vh;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 0.3vh;
  padding: 0 0.3vh;
}
.messages .message.new {
  color: white;
  transform: scale(0);
  transform-origin: 0 0;
  -webkit-animation: bounce 500ms linear both;
          animation: bounce 500ms linear both;
}
.messages .message.message-personal.new {
  transform-origin: 100% 100%;
}
.messages .message.loading::before {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  content: "";
  display: block;
  width: 0.3vh;
  height: 0.3vh;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  z-index: 2;
  margin-top: 0.4vh;
  -webkit-animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
          animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
  border: none;
  -webkit-animation-delay: 0.15s;
          animation-delay: 0.15s;
}
.messages .message.loading span {
  display: block;
  font-size: 0;
  width: 2vh;
  height: 1vh;
  position: relative;
}
.messages .message.loading span::before {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  content: "";
  display: block;
  width: 0.3vh;
  height: 0.3vh;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  z-index: 2;
  margin-top: 0.4vh;
  -webkit-animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
          animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
  margin-left: -0.7vh;
}
.messages .message.loading span::after {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  content: "";
  display: block;
  width: 0.3vh;
  height: 0.3vh;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  z-index: 2;
  margin-top: 0.4vh;
  -webkit-animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
          animation: ball 0.45s cubic-bezier(0, 0, 0.15, 1) alternate infinite;
  margin-left: 0.7vh;
  -webkit-animation-delay: 0.3s;
          animation-delay: 0.3s;
}

/*--------------------
Message Box
--------------------*/
.message-box {
  flex: 0 1 auto;
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  padding: 1vh;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 0.12vh solid rgba(167, 130, 71, 0.22);
}

/* Row: paperclip | textarea | send */
.message-input-row {
  display: flex;
  align-items: center;
  gap: 0.7vh;
  min-height: 2.6vh;
}

.message-box .message-input {
  background: none;
  border: none;
  outline: none !important;
  resize: none;
  color: white;
  font-size: 1vh;
  line-height: 1.5;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 0;
  /* single line to start; JS grows it */
  height: 1.5vh;
  max-height: 8vh;
  overflow-y: hidden;
  display: block;
  font-family: "Poppins", sans-serif;
  /* vertical centering inside the row handled by align-items: center on row */
}
.message-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

/* Send button — same shape & feel as attachment button */
.message-box .message-submit {
  background: rgba(255, 228, 181, 0.12);
  border: 0.15vh solid rgba(255, 228, 181, 0.3);
  color: rgba(255, 228, 181, 0.7);
  border-radius: 0.7vh;
  width: 2.6vh;
  height: 2.6vh;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1vh;
  flex-shrink: 0;
  outline: none !important;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  padding: 0;
}
.message-box .message-submit:hover {
  background: rgba(255, 228, 181, 0.25);
  border-color: moccasin;
  color: moccasin;
}

/*--------------------
Custom Scrollbar
--------------------*/
.mCSB_scrollTools {
  margin: 0.1vh -0.3vh 0.1vh 0;
  opacity: 0;
  width: 100%;
}

.mCSB_inside > .mCSB_container {
  margin-right: 0px;
  padding: 0 1vh;
}

.mCSB_scrollTools .mCSB_dragger .mCSB_dragger_bar {
  background-color: moccasin !important;
}

#mCSB_1_scrollbar_vertical {
  opacity: 0 !important;
}


/*--------------------
Bounce
--------------------*/
@-webkit-keyframes bounce {
  0% {
    transform: matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  4.7% {
    transform: matrix3d(0.45, 0, 0, 0, 0, 0.45, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  9.41% {
    transform: matrix3d(0.883, 0, 0, 0, 0, 0.883, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  14.11% {
    transform: matrix3d(1.141, 0, 0, 0, 0, 1.141, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  18.72% {
    transform: matrix3d(1.212, 0, 0, 0, 0, 1.212, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  24.32% {
    transform: matrix3d(1.151, 0, 0, 0, 0, 1.151, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  29.93% {
    transform: matrix3d(1.048, 0, 0, 0, 0, 1.048, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  35.54% {
    transform: matrix3d(0.979, 0, 0, 0, 0, 0.979, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  41.04% {
    transform: matrix3d(0.961, 0, 0, 0, 0, 0.961, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  52.15% {
    transform: matrix3d(0.991, 0, 0, 0, 0, 0.991, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  63.26% {
    transform: matrix3d(1.007, 0, 0, 0, 0, 1.007, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  85.49% {
    transform: matrix3d(0.999, 0, 0, 0, 0, 0.999, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  100% {
    transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
}
@keyframes bounce {
  0% {
    transform: matrix3d(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  4.7% {
    transform: matrix3d(0.45, 0, 0, 0, 0, 0.45, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  9.41% {
    transform: matrix3d(0.883, 0, 0, 0, 0, 0.883, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  14.11% {
    transform: matrix3d(1.141, 0, 0, 0, 0, 1.141, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  18.72% {
    transform: matrix3d(1.212, 0, 0, 0, 0, 1.212, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  24.32% {
    transform: matrix3d(1.151, 0, 0, 0, 0, 1.151, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  29.93% {
    transform: matrix3d(1.048, 0, 0, 0, 0, 1.048, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  35.54% {
    transform: matrix3d(0.979, 0, 0, 0, 0, 0.979, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  41.04% {
    transform: matrix3d(0.961, 0, 0, 0, 0, 0.961, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  52.15% {
    transform: matrix3d(0.991, 0, 0, 0, 0, 0.991, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  63.26% {
    transform: matrix3d(1.007, 0, 0, 0, 0, 1.007, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  85.49% {
    transform: matrix3d(0.999, 0, 0, 0, 0, 0.999, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
  100% {
    transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
  }
}
@-webkit-keyframes ball {
  from {
    transform: translateY(0) scaleY(0.8);
  }
  to {
    transform: translateY(-10px);
  }
}
@keyframes ball {
  from {
    transform: translateY(0) scaleY(0.8);
  }
  to {
    transform: translateY(-10px);
  }
}

/* LOADER */
/* LOADER */
/* LOADER */
/* LOADER */

#loader {
  position: fixed;
  inset: 0;
  backdrop-filter: blur(1vh);
  background-color: #222;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  pointer-events: all;
  transition:
    opacity 0.9s cubic-bezier(0.4, 0, 0.2, 1),
    backdrop-filter 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

#loader.fading {
  opacity: 0;
  backdrop-filter: blur(0px);
  pointer-events: none;
}

#loader.gone {
  display: none;
}

@keyframes loader {
  0% {
    left: -10vh;
  }
  100% {
    left: 110%;
  }
}

section {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 6px solid #a78247;
  overflow: hidden;
}

section:before,
section:after {
  content: "";
  display: block;
  position: absolute;
}

.trademark {
  font-size: 20px;
  color: #a78247;
  position: relative;
  top: 100%;
  text-align: center;
}

.wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1200px;
  height: 400px;
  border: 0;
  transform: translate(-50%, -50%);
  overflow: visible;
}

.wrapper .icon {
  position: relative;
  display: inline-block;
  width: 180px;
  height: 180px;
  margin: 20px 20px;
  border: 0;
  overflow: visible;
  top: calc(50% - 20px);
  left: calc(50% - 20px);
  transform: translate(-50%, -50%);
}

.wrapper .icon .moon,
.wrapper .icon .planetoid,
.wrapper .icon .planet {
  border-radius: 50%;
  background: #303030;
}

.icon_positioner {
  left: 50% !important;
  top: 50% !important;
  transform: translate(-50%, -50%) !important;
}

.wrapper .icon.icon2 .planetoid {
  top: 15%;
  right: 9%;
  width: 10%;
  height: 10%;
  overflow: visible;
  animation: icon2planetoid 5s linear 0s infinite;
}

.wrapper .icon.icon2 .planetoid:after {
  top: -35%;
  left: -35%;
  width: 1%;
  height: 1%;
  border: 3px solid #a78247;
  border-radius: 50%;
}

.wrapper .icon.icon2 .planet {
  top: 20%;
  left: 17%;
  width: 63%;
  height: 63%;
}

.wrapper .icon.icon2 .planet:after {
  top: 10%;
  left: 10%;
  width: 70%;
  height: 70%;
  border: 5px solid #a78247;
  border-radius: 50%;
  border-color: #a78247 transparent transparent transparent;
  transform: rotate(-50deg);
}

.wrapper .icon.icon2 .ring-planet {
  top: 40%;
  left: 10%;
  width: 77.5%;
  height: 25%;
  border-radius: 50%;
  border-color: transparent #a78247 #a78247 #a78247;
  transform: rotate(-17deg);
  animation: icon2ring 5s linear 0s alternate infinite;
}

@keyframes icon2planetoid {
  0% {
    top: 15%;
    left: 90%;
    transform: rotate(0deg);
    z-index: 0;
  }
  49% {
    top: 80%;
    left: 5%;
    transform: rotate(720deg);
    z-index: 0;
  }
  50% {
    top: 80%;
    left: 5%;
    transform: rotate(720deg);
    z-index: 1;
  }
  99% {
    top: 15%;
    left: 90%;
    transform: rotate(1440deg);
    z-index: 1;
  }
  100% {
    top: 15%;
    left: 90%;
    transform: rotate(1440deg);
    z-index: 0;
  }
}

@keyframes icon2ring {
  0% {
    transform: rotate(-10deg);
  }
  100% {
    transform: rotate(-30deg);
  }
}

/* CUSTOM ALERT MESSAGE */
/* CUSTOM ALERT MESSAGE */
/* CUSTOM ALERT MESSAGE */
/* CUSTOM ALERT MESSAGE */

#alert {
  transition: opacity 0.3s ease, visibility 0.3s ease;
  opacity: 1;
  visibility: visible;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  /* dark glass overlay behind the box */
  background-color: rgba(0, 0, 0, 0.55);
  width: 40vh;
  border-radius: 1.5vh;
  backdrop-filter: blur(0.5vh);
}

#alert.hidden {
  opacity: 0;
  visibility: hidden;
}

.alert-box {
  background: rgba(30, 30, 30, 0.85);
  border: 0.15vh solid rgba(255, 228, 181, 0.2);
  border-radius: 1.2vh;
  box-shadow: 0 0.8vh 2.5vh rgba(0, 0, 0, 0.5);
  overflow: hidden;
  font-family: "Poppins", sans-serif;
  z-index: 10000;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 1;
  transition: opacity 0.4s ease;
  width: 28vh;
}

#alert-message {
  background: rgba(255, 255, 255, 0.07) !important;
  padding: 1vh !important;
  color: rgba(255, 255, 255, 0.75) !important;
  text-align: center !important;
  border-radius: 0.8vh !important;
  font-size: 0.9vh;
  font-weight: normal;
}

#ok-btn {
  padding: 0.6vh 3vh;
  background: rgba(255, 228, 181, 0.15);
  border: 0.15vh solid rgba(255, 228, 181, 0.35);
  color: moccasin;
  border-radius: 0.7vh;
  cursor: pointer;
  font-family: "Poppins", sans-serif;
  font-size: 0.85vh;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#ok-btn:hover {
  background: rgba(255, 228, 181, 0.28);
  border-color: moccasin;
}

/* HIDDEN PROPERTY */
/* HIDDEN PROPERTY */
/* HIDDEN PROPERTY */
/* HIDDEN PROPERTY */

.hidden {
  opacity: 0;
  display: none;
  position: absolute;
  pointer-events: none;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

/*--------------------
AI Disclaimer
--------------------*/
.ai-disclaimer {
  position: fixed;
  bottom: 2vh;
  top: auto;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
  font-size: 0.72vh;
  font-weight: normal;
  color: rgba(255, 255, 255, 0.28);
  letter-spacing: 0.03vh;
  display: flex;
  align-items: center;
  gap: 0.4vh;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.75s cubic-bezier(0.4, 0, 0.2, 1) 0.15s, color 0.2s ease;
}

.ai-disclaimer.visible {
  opacity: 1;
}
.ai-disclaimer i {
  font-size: 0.7vh;
  color: rgba(255, 228, 181, 0.3);
}

/* ============================================================
   UNIFIED CONVERSATIONS DRAWER  (replaces sidebar + old drawer)
   ============================================================ */

/* ── Drawer container ────────────────────────────────────────── */
.history-drawer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 28vh;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity     0.3s  ease;
  opacity: 1;
  background: rgba(0, 0, 0, 0.18);
  border-bottom: 0.1vh solid rgba(255, 228, 181, 0.12);
}
.history-drawer.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  border-bottom: none;
}

/* ── Drawer header ───────────────────────────────────────────── */
.history-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7vh 1vh 0.5vh;
  font-size: 0.8vh;
  color: rgba(255, 228, 181, 0.8);
  letter-spacing: 0.05vh;
  text-transform: uppercase;
  border-bottom: 0.1vh solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}
.history-drawer-header span {
  display: flex;
  align-items: center;
  gap: 0.4vh;
}

/* header action buttons (new chat + delete all) */
.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4vh;
}
#new-chat-btn,
#delete-all-btn {
  background: none;
  border: 0.12vh solid rgba(255, 228, 181, 0.2);
  color: rgba(255, 228, 181, 0.45);
  border-radius: 0.45vh;
  width: 2.1vh;
  height: 2.1vh;
  font-size: 0.8vh;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  padding: 0;
}
#new-chat-btn:hover {
  color: moccasin;
  border-color: rgba(255, 228, 181, 0.55);
  background: rgba(255, 228, 181, 0.08);
}
#delete-all-btn:hover {
  color: rgba(255, 80, 80, 0.8);
  border-color: rgba(255, 80, 80, 0.4);
}

/* ── Conversation list ───────────────────────────────────────── */
.conv-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.3vh 0;
  min-height: 0;
}
.conv-list::-webkit-scrollbar { display: none; }
.conv-list { scrollbar-width: none; }

.conv-empty {
  font-size: 0.78vh;
  color: rgba(255, 255, 255, 0.28);
  text-align: center;
  padding: 1.2vh 1vh;
  font-weight: normal;
}

/* individual conversation row */
.conv-item {
  display: flex;
  align-items: center;
  gap: 0.45vh;
  padding: 0.45vh 1vh;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
}
.conv-item:hover  { background: rgba(255, 255, 255, 0.04); }
.conv-item.active { background: rgba(167, 130, 71, 0.14); }

.conv-item-icon {
  font-size: 0.75vh;
  color: rgba(255, 228, 181, 0.35);
  flex-shrink: 0;
}
.conv-item-title {
  flex: 1;
  min-width: 0;
  font-size: 0.78vh;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: normal;
}
.conv-item.active .conv-item-title { color: moccasin; }

.conv-item-date {
  font-size: 0.62vh;
  color: rgba(255, 255, 255, 0.22);
  flex-shrink: 0;
}
.conv-item-delete {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.12);
  font-size: 0.72vh;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
  line-height: 1;
}
.conv-item:hover .conv-item-delete { opacity: 1; }
.conv-item-delete:hover { color: rgba(255, 80, 80, 0.8); }

/* ── Auth footer ─────────────────────────────────────────────── */
.drawer-auth-footer {
  flex-shrink: 0;
  border-top: 0.1vh solid rgba(255, 228, 181, 0.1);
  padding: 0.6vh 1vh;
}
.drawer-auth-row {
  display: flex;
  align-items: center;
  gap: 0.5vh;
  font-size: 0.75vh;
  color: rgba(255, 255, 255, 0.38);
  font-weight: normal;
}
.drawer-auth-row i {
  font-size: 0.82vh;
  color: rgba(255, 228, 181, 0.38);
  flex-shrink: 0;
}

.hidden-auth { display: none !important; }

.drawer-login-link {
  margin-left: auto;
  color: moccasin;
  font-size: 0.72vh;
  text-decoration: none;
  border: 0.12vh solid rgba(255, 228, 181, 0.3);
  border-radius: 0.4vh;
  padding: 0.15vh 0.6vh;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}
.drawer-login-link:hover {
  background: rgba(255, 228, 181, 0.1);
  border-color: moccasin;
}

.drawer-username {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.55);
}
.drawer-logout-btn {
  margin-left: auto;
  background: none;
  border: 0.12vh solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.25);
  border-radius: 0.4vh;
  width: 1.9vh;
  height: 1.9vh;
  font-size: 0.72vh;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, border-color 0.2s ease;
  padding: 0;
}
.drawer-logout-btn:hover {
  color: rgba(255, 80, 80, 0.8);
  border-color: rgba(255, 80, 80, 0.4);
}

/* ============================================================
   RESPONSIVE — Mobile full-screen layout (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  /* No star canvas on mobile — save GPU, keep it clean */
  #star-canvas { display: none; }

  .chat {
    /* Fill the entire screen */
    position: fixed;
    top: 0; left: 0;
    /* zoom: 1.5 makes all internal vh-sized elements render at 1.5× without
       any overflow — unlike transform:scale(), zoom affects layout too */
    width: calc(100vw / 1.5);
    height: calc(100dvh / 1.5);
    /* Fallback for browsers without dvh */
    height: calc(100vh / 1.5);
    height: calc(100dvh / 1.5);
    border-radius: 0;
    transform: none;
    zoom: 1.5;
  }

  /* Hide disclaimer on mobile */
  .ai-disclaimer { display: none; }
}

/* ============================================================
   RESPONSIVE — Desktop wide layout (≥ 769px)
   ============================================================ */
@media (min-width: 769px) {
  .chat {
    /* Wider on desktop: visual width = min(50vw, 72vh) × 1.5 */
    width: min(50vw, 72vh);
    height: 54vh;
    /* Match auth project card aesthetic */
    border: 0.15vh solid rgba(167, 130, 71, 0.28);
    box-shadow: 0 1.5vh 4vh rgba(0, 0, 0, 0.6);
  }
}
/* ============================================================
   COMPANY ROW (in drawer, logged-in only)
   ============================================================ */
.company-row {
  display: flex;
  align-items: center;
  gap: 0.5vh;
  font-size: 0.75vh;
  color: rgba(255, 255, 255, 0.45);
  font-weight: normal;
  padding: 0.5vh 1vh;
  border-top: 0.1vh solid rgba(255, 228, 181, 0.08);
  flex-shrink: 0;
}
.company-row i {
  font-size: 0.78vh;
  color: rgba(255, 228, 181, 0.5);
  flex-shrink: 0;
}
#company-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 228, 181, 0.75);
}
.change-company-btn {
  background: none;
  border: none;
  color: rgba(255, 228, 181, 0.3);
  font-size: 0.7vh;
  cursor: pointer;
  padding: 0.1vh;
  flex-shrink: 0;
  transition: color 0.15s ease;
}
.change-company-btn:hover { color: moccasin; }

/* ============================================================
   COMPANY PICKER MODAL
   ============================================================ */
.company-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.25s ease;
}
.company-picker-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.company-picker-modal {
  background: rgba(18, 18, 28, 0.97);
  border: 1px solid rgba(167, 130, 71, 0.32);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.75);
  padding: 28px 24px;
  width: min(90vw, 400px);
  max-height: 80vh;
  overflow-y: auto;
  color: white;
  font-family: "Poppins", sans-serif;
}
.company-picker-modal::-webkit-scrollbar { display: none; }
.company-picker-modal { scrollbar-width: none; }

.company-picker-header {
  text-align: center;
  margin-bottom: 20px;
}
.company-picker-logo {
  width: 42px;
  height: 42px;
  margin: 0 auto 10px;
}
.company-picker-logo img { width: 100%; height: auto; }

.company-picker-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px;
  color: moccasin;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.company-picker-header p {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.42);
  margin: 0;
}

.company-list-modal {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.company-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.company-card:hover {
  border-color: rgba(167, 130, 71, 0.38);
  background: rgba(167, 130, 71, 0.07);
}
.company-card.suggested {
  border-color: rgba(167, 130, 71, 0.42);
  background: rgba(167, 130, 71, 0.09);
}

.company-card-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.company-card-icon {
  width: 34px;
  height: 34px;
  background: rgba(167, 130, 71, 0.14);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: rgba(255, 228, 181, 0.6);
  font-size: 13px;
}
.company-card-info { min-width: 0; }
.company-card-name {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.company-card-domain {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: 1px;
}
.company-card-badge {
  font-size: 9px;
  background: rgba(167, 130, 71, 0.18);
  color: moccasin;
  border: 1px solid rgba(167, 130, 71, 0.35);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
  letter-spacing: 0.04em;
  white-space: nowrap;
  align-self: flex-start;
  margin-top: 2px;
}

.company-select-btn {
  flex-shrink: 0;
  background: rgba(167, 130, 71, 0.14);
  border: 1px solid rgba(167, 130, 71, 0.38);
  color: moccasin;
  font-size: 10px;
  font-family: "Poppins", sans-serif;
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.company-select-btn:hover {
  background: rgba(167, 130, 71, 0.28);
  border-color: rgba(167, 130, 71, 0.65);
}
