@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@400;600&family=Manrope:wght@400;600&display=swap");

:root {
  --ink: #1e2328;
  --muted: #5b6470;
  --bg: #f3f4f6;
  --card: #ffffff;
  --accent: #0e3a2f;
  --accent-2: #c8a028;
  --line: #e3e6ea;
  --panel: #f9fafb;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  font-family: "Manrope", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 10% 10%, #f7f8fa 0%, #f1f3f6 45%, #eef1f4 100%);
  color: var(--ink);
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 1440px;
  margin: 20px auto;
  padding: 22px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 48px rgba(20, 20, 20, 0.08);
  display: block;
}

.layout {
  display: block;
  width: 100%;
}

.main {
  min-width: 0;
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}

.top-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  background: #fbfcfe;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.top-menu.hidden {
  display: none;
}

.menu-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-sep {
  width: 1px;
  height: 20px;
  background: #e2e6ec;
  margin: 0 6px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, #1a5c47 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  letter-spacing: 1px;
}

.title {
  font-family: "Fraunces", "Georgia", serif;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.subtitle {
  font-size: 13px;
  color: var(--muted);
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: #f6f7f9;
  border: 1px solid #e6e9ee;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f8fb 100%);
  width: 100%;
}

.hero h1 {
  font-family: "Fraunces", "Georgia", serif;
  font-size: 36px;
  margin: 0 0 10px;
  letter-spacing: 0.2px;
}

.lead {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.main h2 {
  font-size: 20px;
  margin: 8px 0 12px;
  letter-spacing: 0.2px;
}

.main h3 {
  font-size: 15px;
  margin: 6px 0 10px;
  color: #2a2f36;
}

.hero-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.card {
  padding: 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

input, textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #d5dbe3;
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
}

input:focus, textarea:focus {
  outline: none;
  border-color: #9fb7ad;
  box-shadow: 0 0 0 3px rgba(14, 58, 47, 0.12);
}

button {
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(14, 58, 47, 0.18);
}

button:hover {
  background: #0b2f24;
  box-shadow: 0 6px 14px rgba(14, 58, 47, 0.2);
  transform: translateY(-1px);
}

.ghost {
  background: transparent;
  border: 1px solid #cfd6df;
  color: var(--accent);
}

.ghost:hover {
  background: #f3f5f8;
}

.primary {
  background: var(--accent);
}

.answer {
  padding: 12px;
  background: #f6f8fb;
  border: 1px solid #e1e6ee;
  border-radius: 10px;
  min-height: 60px;
  margin-bottom: 16px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  width: 100%;
}

.chat-stream {
  min-height: 60vh;
  max-height: 70vh;
  overflow: auto;
  padding: 10px;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  background: #fbfcfe;
}

.chat-message {
  margin: 10px 0;
  display: flex;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #e6e9ee;
  background: #ffffff;
}

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

.chat-message.user .chat-bubble {
  background: #e7f3ec;
  border-color: #cfe4d6;
}

.chat-message.assistant .chat-bubble {
  background: #ffffff;
}

.chat-side {
  padding: 8px;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  background: #fbfcfe;
  max-height: 70vh;
  overflow: auto;
}

.mobile-side {
  display: none;
}

.admin {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  background: #fbfcfe;
}

.admin-menu {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-tab {
  padding: 8px 10px;
  border-radius: 10px;
  background: #f2eadb;
  border: 1px solid #d8c9b1;
  color: #2a2a2a;
}

.admin-tab.active {
  background: #0f3b2e;
  color: #fff;
  border-color: #0f3b2e;
}

.admin-view {
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.admin-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #eef1f5;
}

.admin-row header {
  font-weight: 600;
}

.doc-item {
  padding: 8px 10px;
  border-bottom: 1px solid #eef1f5;
}

.doc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 8px 16px;
  align-items: start;
}

.doc-type {
  justify-self: end;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f1f3f6;
  border: 1px solid #d6dde6;
  color: #39414a;
}

.doc-item.active {
  background: #eef7f1;
  border-radius: 10px;
}

.chunk-item {
  padding: 8px 10px;
  border-bottom: 1px solid #eef1f5;
  font-size: 13px;
}

.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.small-btn {
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
}

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  margin-top: 12px;
  padding: 10px;
  background: #fff;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
}

.composer textarea {
  min-height: 44px;
}

.cite {
  color: #0f3b2e;
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
}

.cite-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1f3f6;
  border: 1px solid #d6dde6;
  margin: 0 4px;
  font-size: 12px;
}

.section + .section {
  margin-top: 8px;
}

.section {
  padding: 10px 12px;
  border: 1px solid #e6e9ee;
  border-radius: 10px;
  margin-bottom: 10px;
  background: #fbfcfe;
}

.section-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: #2a2a2a;
  font-size: 14px;
}

.section-body {
  color: #2b2f36;
  line-height: 1.55;
  font-size: 14px;
}

.cite {
  color: #0f3b2e;
  text-decoration: underline;
  font-weight: 600;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.item {
  padding: 6px 8px;
  border-bottom: 1px solid #eef1f5;
  cursor: pointer;
}

.saved-item {
  cursor: default;
}

.saved-item summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.saved-item summary::-webkit-details-marker {
  display: none;
}

.saved-body {
  margin-top: 8px;
}

.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.delete-btn {
  padding: 4px 8px;
  font-size: 11px;
  background: #f9ece8;
  border: 1px solid #f0cfc4;
  color: #7a2e22;
  border-radius: 8px;
}

.modal-card p {
  margin: 6px 0 14px;
}

#new-user-role {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #d8d0c0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.small {
  font-size: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

.hidden {
  display: none;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 16, 20, 0.45);
}

.modal-card {
  position: relative;
  z-index: 2;
  width: min(520px, 92vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
}

.modal-chunks {
  width: min(1000px, 96vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.chunks-list {
  overflow: auto;
  border: 1px solid #e6e9ee;
  border-radius: 12px;
  padding: 8px;
  background: #fbfcfe;
}

.global-loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 16, 20, 0.35);
  z-index: 1000;
}

.global-loader.hidden {
  display: none;
}

.loader-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #e6e9ee;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
}

.loader-text {
  font-weight: 600;
  color: #2a2f36;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #dbe3ec;
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.modal-close {
  background: #eee5d2;
  color: #222;
  margin-top: 8px;
}

.modal-pdf {
  width: min(1100px, 96vw);
  height: min(80vh, 900px);
  display: flex;
  flex-direction: column;
}

.pdf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.pdf-title {
  font-weight: 600;
  font-size: 14px;
}

.pdf-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#pdf-pages {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #d6dde6;
}

.pdf-frame {
  flex: 1;
  width: 100%;
  border: 1px solid #e1e6ee;
  border-radius: 10px;
}

.sources-panel {
  padding: 10px 12px;
  border: 1px solid #e6e9ee;
  border-radius: 10px;
  background: #fbfcfe;
  margin-top: 10px;
}

.source-item {
  margin-bottom: 8px;
}

.page-chip {
  display: inline-block;
  margin-right: 6px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #d6dde6;
  background: #f1f3f6;
  font-size: 12px;
  cursor: pointer;
}

.chunk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid #eef1f5;
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
  }
  .split {
    grid-template-columns: 1fr;
  }
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .chat-side {
    display: none;
  }
  .mobile-side {
    display: block;
    margin-top: 12px;
  }
  .top-menu {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 8px 10px;
  }
  .menu-item {
    white-space: nowrap;
  }
  .layout {
    grid-template-columns: 1fr;
  }
}
.item.active {
  background: #e9f3ea;
  border-radius: 8px;
  border: 1px solid #cfe3d2;
}

.assistant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.save-btn {
  padding: 4px 8px;
  border-radius: 8px;
  background: #f0e7d6;
  border: 1px solid #d8c9b1;
  color: #2a2a2a;
  font-size: 12px;
}
.menu-item {
  text-align: left;
  padding: 8px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: #2a2a2a;
  font-weight: 500;
}

.menu-item:hover {
  background: #f1f4f8;
}

.menu-item.active {
  background: #e7f3ec;
  border-color: #cfe4d6;
}

body:not(.logged-in) .top-menu {
  display: none;
}

.disclaimer {
  max-width: 1440px;
  margin: 0 auto 24px;
  padding: 10px 14px;
  font-size: 12px;
  color: #4b5563;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
}

@media (max-width: 900px) {
  .app {
    margin: 12px;
    padding: 18px;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .top-actions {
    width: 100%;
    justify-content: space-between;
  }
  .hero {
    grid-template-columns: 1fr;
  }
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .chat-stream {
    max-height: none;
  }
  .chat-side {
    max-height: none;
  }
  .composer {
    position: static;
    flex-direction: column;
  }
  .doc-grid {
    grid-template-columns: 1fr;
  }
  .doc-type {
    justify-self: start;
  }
}
