:root {
  --bg: #090d17;
  --bg-soft: #111827;
  --surface: rgba(16, 22, 36, 0.88);
  --surface-2: rgba(21, 28, 45, 0.9);
  --border: rgba(255, 255, 255, 0.12);
  --text: #e9edf7;
  --muted: #9ba7c2;
  --accent: #5d8cff;
  --accent-soft: rgba(93, 140, 255, 0.25);
  --danger: #ff6f7f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", "Poppins", sans-serif;
  background: radial-gradient(circle at top left, #1a2340 0%, var(--bg) 45%, #05070f 100%);
  color: var(--text);
}

.app-shell {
  width: 100vw;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr 340px;
  gap: 18px;
  padding: 18px;
}

.app-sidebar,
.app-main,
.app-docs {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.app-sidebar {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-block h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: 0.2s ease;
}

button:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.35rem;
  display: grid;
  place-items: center;
}

.ghost-btn {
  text-align: left;
  font-weight: 500;
}

.app-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-header h2 {
  margin: 0;
  font-size: 1.7rem;
}

.chat-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.chat-scroll {
  flex: 1;
  padding: 20px 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-scroll::-webkit-scrollbar,
.edit-doc-list::-webkit-scrollbar {
  width: 7px;
}

.chat-scroll::-webkit-scrollbar-thumb,
.edit-doc-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 20px;
}

.user-message,
.bot-message {
  max-width: min(76%, 620px);
  padding: 11px 14px;
  border-radius: 14px;
  line-height: 1.45;
  animation: fadeUp 0.2s ease;
}

.user-message {
  align-self: flex-end;
  background: linear-gradient(135deg, #3464d6, #2649a0);
}

.bot-message {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.chat-composer {
  margin: 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 8px 8px 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#userInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

#userInput::placeholder {
  color: var(--muted);
}

#sendBtn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #79a4ff, #4b79ed);
}

#sendBtn svg {
  width: 20px;
  height: 20px;
  transform: rotate(45deg);
}

.app-docs {
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.docs-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.docs-header-row h3 {
  margin: 0;
  font-size: 1.6rem;
}

.docs-subtitle {
  margin: 0;
  color: var(--muted);
}

.edit-doc-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 3px;
}

.edit-doc-item {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.edit-doc-item span {
  min-width: 0;
}

.edit-doc-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.edit-buttons {
  display: flex;
  gap: 6px;
}

.edit-btn,
.delete-btn {
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 0.8rem;
}

.edit-btn {
  background: var(--accent-soft);
}

.delete-btn {
  background: rgba(255, 111, 127, 0.16);
  border-color: rgba(255, 111, 127, 0.35);
}

.edit-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

#clearBtn {
  background: rgba(255, 111, 127, 0.18);
  border-color: rgba(255, 111, 127, 0.4);
}

.typing-indicator {
  display: none;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 14px;
  width: 60px;
  justify-content: space-around;
}

.typing-indicator span,
.typing span {
  width: 7px;
  height: 7px;
  background: #8db1ff;
  border-radius: 50%;
  animation: typingBlink 1.2s infinite ease-in-out;
}

.typing { display: flex; gap: 4px; }
.typing span:nth-child(2), .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3), .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBlink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1.05); }
}

.popup,
.about-popup {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(5, 8, 14, 0.74);
  backdrop-filter: blur(12px);
  z-index: 100;
}

.popup-content,
.about-box {
  width: min(92vw, 430px);
  background: rgba(15, 21, 34, 0.95);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.popup-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popup-content input,
.popup-content textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.popup-actions {
  display: flex;
  gap: 10px;
}

.popup-actions button {
  flex: 1;
}

.about-box {
  max-height: 85vh;
  overflow-y: auto;
  text-align: center;
}

.about-title { margin: 0 0 8px; }
.about-logo { width: 80px; border-radius: 14px; }
.about-desc, .about-version, .about-dev { color: var(--muted); }
.about-links-row { display: flex; gap: 10px; }
.about-links-row a {
  flex: 1;
  color: #a6c2ff;
  text-decoration: none;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.about-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
}

.changelog-box-inner {
  text-align: left;
}

#changelogBody {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  max-height: 50vh;
  overflow-y: auto;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(17, 24, 38, 0.95);
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s;
  z-index: 9999;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

#imgModal,
#pdfModal {
  display: none;
  position: fixed;
  inset: 0;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 99999;
}

#imgModalContent,
#pdfModalViewer {
  max-width: 90%;
  max-height: 90%;
  width: 90%;
  height: 90%;
  border-radius: 12px;
  border: none;
}

#helpBody {
  max-height: 65vh;
  overflow-y: auto;
}

#importLoader {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(420px, 86vw);
  background: rgba(13, 19, 31, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  z-index: 1000;
}

#importBar {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, #5f8fff, #80b5ff);
  width: 0;
  margin-bottom: 8px;
}

#editPopup { display: none !important; }

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
  }

  .app-docs {
    position: fixed;
    right: 18px;
    top: 18px;
    bottom: 18px;
    width: min(360px, calc(100vw - 36px));
    z-index: 40;
    transform: translateX(120%);
    transition: transform 0.25s ease;
  }

  .app-docs.open {
    transform: translateX(0);
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .app-sidebar {
    padding: 12px;
  }

  .sidebar-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .ghost-btn { text-align: center; }
  .chat-header { padding: 16px; }
  .chat-scroll { padding: 14px; }
}
