:root {
  --bg: #08101d;
  --bg-soft: #0d1830;
  --panel: rgba(12, 22, 43, 0.72);
  --panel-strong: rgba(10, 18, 36, 0.95);
  --text: #ebf4ff;
  --muted: #95abc8;
  --line: rgba(116, 170, 255, 0.24);
  --accent: #1dd8ff;
  --accent-strong: #00b7e8;
  --user: rgba(21, 140, 255, 0.28);
  --assistant: rgba(35, 72, 128, 0.34);
  --glow: 0 0 0 1px rgba(81, 179, 255, 0.22), 0 18px 48px rgba(5, 14, 30, 0.62);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 12%, rgba(52, 236, 255, 0.2) 0%, transparent 36%),
    radial-gradient(circle at 85% 84%, rgba(43, 125, 255, 0.28) 0%, transparent 34%),
    linear-gradient(160deg, #040816 0%, #08101d 42%, #0a1530 100%);
  overflow: hidden;
}

.background-shape {
  position: fixed;
  border-radius: 999px;
  z-index: 0;
  filter: blur(8px);
}

.shape-a {
  width: 420px;
  height: 420px;
  left: -130px;
  bottom: -160px;
  background: radial-gradient(circle, rgba(23, 214, 255, 0.8) 0%, rgba(23, 214, 255, 0.06) 65%);
  opacity: 0.45;
}

.shape-b {
  width: 340px;
  height: 340px;
  right: -100px;
  top: 20px;
  background: radial-gradient(circle, rgba(111, 121, 255, 0.7) 0%, rgba(111, 121, 255, 0.08) 68%);
  opacity: 0.5;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 320px;
  gap: 1rem;
  height: 100vh;
  padding: 1rem;
}

.app-shell--locked {
  display: none;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.auth-card {
  width: min(92vw, 420px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--glow);
  padding: 1.1rem;
  text-align: center;
}

.auth-card h2 {
  margin: 0.28rem 0 0.5rem;
  font-family: "Orbitron", "Archivo", sans-serif;
}

.auth-desc {
  margin: 0 0 0.85rem;
  color: #c4daf5;
  font-size: 0.92rem;
}

.auth-status {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

#google-login-btn {
  display: inline-flex;
  justify-content: center;
}

.left-rail,
.right-rail,
.chat-column {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--glow);
}

.left-rail,
.right-rail {
  padding: 1rem;
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.brand h1,
.chat-header h2 {
  margin: 0;
  font-family: "Orbitron", "Archivo", sans-serif;
  line-height: 1.15;
}

.brand h1 {
  font-size: 1.12rem;
  letter-spacing: 0.04em;
  color: #dff5ff;
}

.brand-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #9ff6ff 0%, #27ceff 60%, #0f4f9f 100%);
  box-shadow: 0 0 18px rgba(29, 216, 255, 0.8);
}

.brand-label,
.section-title,
.eyebrow {
  margin: 0;
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.new-chat-btn,
.quick-btn,
.ghost-btn,
.send-btn,
.recent-chat-btn {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.new-chat-btn {
  width: 100%;
  display: inline-block;
  text-align: center;
  border-radius: 12px;
  padding: 0.72rem 0.92rem;
  font-weight: 700;
  color: #041225;
  background: linear-gradient(135deg, #86f8ff 0%, #1dd8ff 45%, #27a6ff 100%);
  box-shadow: 0 8px 22px rgba(16, 163, 255, 0.4);
  text-decoration: none;
}

.admin-link-btn {
  margin-top: 0.5rem;
  background: linear-gradient(135deg, #c6d7ff 0%, #94b7ff 45%, #779fff 100%);
}

.rail-section {
  margin-top: 1.2rem;
}

.quick-list,
.recent-list,
.source-list,
.tips-list {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
  display: grid;
  gap: 0.55rem;
}

.quick-btn,
.recent-chat-btn {
  width: 100%;
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: #d9ebff;
  background: rgba(16, 31, 57, 0.78);
}

.quick-btn:hover,
.recent-chat-btn:hover {
  border-color: rgba(137, 213, 255, 0.6);
  background: rgba(23, 43, 76, 0.95);
}

.recent-chat-btn.active {
  border-color: rgba(130, 237, 255, 0.9);
  background: linear-gradient(120deg, rgba(24, 68, 117, 0.9) 0%, rgba(14, 44, 89, 0.95) 100%);
}

.recent-chat-item {
  list-style: none;
}

.recent-chat-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.42rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(16, 31, 57, 0.78);
  padding: 0.4rem 0.45rem 0.4rem 0.65rem;
}

.recent-chat-card:hover {
  border-color: rgba(137, 213, 255, 0.6);
  background: rgba(23, 43, 76, 0.95);
}

.recent-chat-card.active {
  border-color: rgba(130, 237, 255, 0.9);
  background: linear-gradient(120deg, rgba(24, 68, 117, 0.9) 0%, rgba(14, 44, 89, 0.95) 100%);
}

.recent-chat-title-btn {
  border: 0;
  background: transparent;
  color: #d9ebff;
  text-align: left;
  font: inherit;
  width: 100%;
  cursor: pointer;
  padding: 0.2rem 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-chat-title-input {
  display: none;
  width: 100%;
  border: 1px solid rgba(116, 170, 255, 0.42);
  background: rgba(9, 20, 40, 0.88);
  color: #eaf4ff;
  border-radius: 7px;
  font: inherit;
  padding: 0.24rem 0.4rem;
}

.recent-chat-card.is-editing .recent-chat-title-btn {
  display: none;
}

.recent-chat-card.is-editing .recent-chat-title-input {
  display: block;
}

.recent-chat-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.recent-chat-rename-btn,
.recent-chat-delete-btn {
  border: 1px solid rgba(116, 170, 255, 0.28);
  background: rgba(12, 24, 46, 0.88);
  color: #a6bad6;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 26px;
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.recent-chat-rename-btn:hover {
  border-color: rgba(120, 196, 255, 0.7);
  color: #dff5ff;
  background: rgba(39, 112, 184, 0.35);
}

.recent-chat-delete-btn:hover {
  border-color: rgba(255, 154, 154, 0.65);
  color: #ffd8d8;
  background: rgba(91, 28, 36, 0.82);
}

.source-list li,
.tips-list li {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  background: rgba(13, 27, 51, 0.86);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.muted {
  opacity: 0.95;
}

.chat-column {
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 1rem;
  min-height: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  font-size: 1.03rem;
  max-width: 46ch;
  color: #d9e9ff;
  letter-spacing: 0.02em;
}

.ghost-btn {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(14, 28, 52, 0.88);
  color: var(--text);
  padding: 0.45rem 0.75rem;
}

.mobile-menu-btn {
  display: none;
}

.mobile-chat-title {
  display: none;
}

.message-feed {
  overflow: auto;
  overflow-x: hidden;
  padding: 1rem 0.1rem;
  display: grid;
  align-content: start;
  gap: 0.95rem;
}

.message-row {
  display: flex;
  gap: 0.65rem;
  opacity: 0;
  transform: translateY(8px);
  animation: rise 260ms ease forwards;
}

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #2f5485;
  flex: 0 0 auto;
  border: 1px solid rgba(163, 217, 255, 0.35);
}

.message-row.user .avatar {
  background: linear-gradient(135deg, #22e0ff 0%, #2f8cff 100%);
  order: 2;
}

.message-row.assistant .avatar {
  background: linear-gradient(135deg, #7e89ff 0%, #6d3dff 100%);
}

.message-row.user {
  justify-content: flex-end;
}

.bubble-wrap {
  min-width: 0;
  display: inline-flex;
  flex-direction: column;
  width: fit-content;
  max-width: calc(100% - 42px);
}

.message-row.user .bubble-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-row.assistant .bubble-wrap {
  align-items: flex-start;
}

.who {
  margin: 0 0 0.2rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.bubble {
  display: inline-block;
  max-width: min(75ch, 100%);
  margin: 0;
  padding: 0.72rem 0.86rem;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
  font-size: 0.93rem;
  border: 1px solid var(--line);
  background: var(--assistant);
  color: #eaf4ff;
}

.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 0.25rem 0 0.35rem;
  line-height: 1.3;
  font-weight: 700;
}

.bubble h1 {
  font-size: 1rem;
}

.bubble h2 {
  font-size: 0.96rem;
}

.bubble h3 {
  font-size: 0.92rem;
}

.bubble ul {
  margin: 0.15rem 0 0.35rem;
  padding-left: 1.15rem;
}

.bubble li {
  margin: 0.1rem 0;
}

.bubble code {
  background: rgba(10, 20, 40, 0.7);
  border: 1px solid rgba(116, 170, 255, 0.28);
  border-radius: 6px;
  padding: 0.04rem 0.32rem;
  font-size: 0.88em;
}

.bubble pre {
  margin: 0.3rem 0;
  padding: 0.5rem 0.6rem;
  border-radius: 9px;
  overflow-x: auto;
  border: 1px solid rgba(116, 170, 255, 0.28);
  background: rgba(10, 20, 40, 0.72);
}

.bubble pre code {
  border: 0;
  padding: 0;
  background: transparent;
}

.bubble a {
  color: #8eeaff;
  text-decoration: underline;
}

.message-row.user .bubble {
  background: var(--user);
  border-color: rgba(74, 192, 255, 0.5);
}

.time {
  margin: 0.28rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.feedback-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
  margin-top: 0.12rem;
  align-self: flex-end;
}

.feedback-btn {
  border: 1px solid rgba(160, 176, 199, 0.35);
  background: rgba(70, 83, 104, 0.25);
  color: #8da2bf;
  border-radius: 999px;
  width: 28px;
  height: 28px;
  line-height: 24px;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.feedback-btn:hover {
  background: rgba(39, 112, 184, 0.35);
  color: #dff5ff;
  border-color: rgba(120, 196, 255, 0.7);
}

.feedback-btn.is-selected-up {
  background: rgba(46, 158, 86, 0.35);
  color: #defbe6;
  border-color: rgba(126, 235, 163, 0.7);
}

.feedback-btn.is-selected-down {
  background: rgba(170, 74, 74, 0.36);
  color: #ffe1e1;
  border-color: rgba(255, 153, 153, 0.7);
}

.message-row.typing .bubble {
  min-width: 56px;
  display: inline-flex;
  align-items: center;
  gap: 0.26rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #98d8ff;
  display: inline-block;
  animation: typing-bounce 1.15s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer {
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}

.composer textarea {
  width: 100%;
  resize: none;
  min-height: 56px;
  max-height: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--panel-strong);
}

.composer textarea::placeholder {
  color: #7f99bb;
}

.mode-switch {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.28rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 36, 0.94);
}

.mode-switch.compact {
  margin-top: 0;
  width: auto;
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: 0.2rem;
  padding: 0.18rem;
  border-radius: 999px;
}

.mode-switch.compact.footer-center {
  justify-self: center;
}

.mode-option {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.45rem 0.52rem;
  background: rgba(12, 24, 46, 0.72);
  color: #8fa9cb;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease, transform 120ms ease;
}

.mode-switch.compact .mode-option {
  font-size: 0.72rem;
  padding: 0.26rem 0.52rem;
  border-radius: 999px;
  min-width: 52px;
}

.mode-option:hover {
  border-color: rgba(110, 189, 255, 0.45);
  color: #cae7ff;
}

.mode-option.is-active {
  color: #041225;
  border-color: rgba(153, 242, 255, 0.9);
  background: linear-gradient(135deg, #84f7ff 0%, #1dd8ff 45%, #1fa8ff 100%);
  box-shadow: 0 8px 20px rgba(20, 151, 255, 0.36);
}

.mode-option:active {
  transform: translateY(1px);
}

.composer-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 0.65rem;
  gap: 0.5rem;
}

#status-text {
  font-size: 0.82rem;
  color: var(--muted);
  justify-self: start;
}

.send-btn {
  border-radius: 10px;
  background: linear-gradient(135deg, #7cf2ff 0%, #12caff 52%, #3a8dff 100%);
  color: #041225;
  font-weight: 700;
  padding: 0.52rem 0.95rem;
  justify-self: end;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.right-rail {
  display: grid;
  align-content: start;
  gap: 0.9rem;
}

.side-overlay {
  display: none;
}

.context-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: rgba(12, 24, 48, 0.84);
}

.upload-form {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.5rem;
}

#file-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  color: var(--text);
  background: rgba(10, 18, 36, 0.92);
}

#file-add-btn {
  width: 100%;
}

.upload-status {
  margin: 0.55rem 0 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.uploaded-file-list {
  list-style: none;
  padding: 0;
  margin: 0.6rem 0 0;
  display: grid;
  gap: 0.45rem;
  max-height: 180px;
  overflow: auto;
}

.uploaded-file-list li {
  padding: 0.46rem 0.58rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(10, 18, 36, 0.8);
  font-size: 0.82rem;
  color: #d8ebff;
}

.uploaded-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.uploaded-file-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.uploaded-file-delete-btn {
  border: 1px solid rgba(255, 128, 150, 0.4);
  background: rgba(77, 20, 36, 0.65);
  color: #ffd7df;
  width: 24px;
  height: 24px;
  line-height: 20px;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 18px;
  padding: 0;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

.pill {
  font-size: 0.78rem;
  color: #ccf7ff;
  background: rgba(41, 128, 191, 0.36);
  border: 1px solid rgba(107, 209, 255, 0.34);
  border-radius: 999px;
  padding: 0.3rem 0.55rem;
}

.btn {
  border: 1px solid rgba(116, 170, 255, 0.3);
  background: rgba(16, 31, 57, 0.92);
  color: #eaf3ff;
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.btn.ghost {
  background: rgba(14, 28, 52, 0.88);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 85;
  display: grid;
  place-items: center;
  background: rgba(6, 12, 24, 0.58);
  backdrop-filter: blur(2px);
  padding: 1rem;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: min(92vw, 620px);
  border: 1px solid rgba(116, 170, 255, 0.32);
  border-radius: 14px;
  padding: 1rem;
  background: rgba(13, 24, 46, 0.95);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
}

.modal-card h3 {
  margin: 0 0 0.45rem;
}

.modal-card p {
  margin: 0;
  color: #c5dbf5;
  line-height: 1.45;
}

.modal-actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
}

@media (max-width: 1100px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    position: fixed;
    inset: 0;
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .chat-column {
    order: 1;
    min-height: 0;
    height: 100%;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding:
      calc(env(safe-area-inset-top, 0px) + 0.65rem)
      0.75rem
      calc(env(safe-area-inset-bottom, 0px) + 0.55rem);
  }

  .message-feed {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .bubble {
    font-size: 0.88rem;
    line-height: 1.4;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-self: center;
  }

  .chat-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    min-height: 44px;
    padding-bottom: 0.65rem;
  }

  .chat-header .header-copy {
    display: none;
  }

  .mobile-chat-title {
    display: block;
    justify-self: center;
    font-family: "Orbitron", "Archivo", sans-serif;
    font-size: 0.95rem;
    letter-spacing: 0.03em;
    color: #dff5ff;
  }

  .left-rail {
    position: fixed;
    top: 0;
    left: 0;
    width: min(86vw, 360px);
    height: 100%;
    padding-top: calc(env(safe-area-inset-top, 0px) + 1rem);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    z-index: 40;
    transform: translateX(-104%);
    transition: transform 220ms ease;
    border-radius: 0 16px 16px 0;
    border-left: 0;
  }

  .right-rail {
    display: none;
  }

  .side-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 9, 18, 0.46);
    backdrop-filter: blur(1px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
    z-index: 30;
  }

  body.menu-open .left-rail {
    transform: translateX(0);
  }

  body.menu-open .side-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}
