@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --ink: #20243a;
  --muted: #7b8197;
  --line: #e7e9f2;
  --purple: #6856df;
  --purple-dark: #5140c5;
  --purple-soft: #f1efff;
  --bg: #f7f8fc;
  --white: #ffffff;
  --green: #22966e;
  --shadow: 0 10px 35px rgba(37, 38, 78, .055);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: .65;
  cursor: wait;
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 248px;
  min-width: 248px;
  padding: 27px 18px 20px;
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 8px 35px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, #8b7aff, #5b49d4);
  font-size: 24px;
  box-shadow: 0 7px 16px #6856df35;
}

.brand h1 {
  font: 800 18px "Manrope", sans-serif;
  margin: 0;
  letter-spacing: -.5px;
}

.brand p {
  margin: 3px 0 0;
  color: #989db0;
  font-size: 9px;
  letter-spacing: 1.2px;
  font-weight: 700;
}

.section-label,
.eyebrow {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #9a9eb0;
  font-weight: 700;
}

.section-label {
  padding: 0 12px;
  margin-bottom: 12px;
}

.nav-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  color: #777d93;
  border-radius: 11px;
  margin-bottom: 5px;
}

.nav-item span {
  font-size: 18px;
}

.nav-item.active {
  color: var(--purple);
  background: var(--purple-soft);
  font-weight: 700;
}

.sidebar-note {
  margin: auto 3px 22px;
  padding: 18px;
  background: linear-gradient(145deg, #f4f2ff, #fbfaff);
  border: 1px solid #e9e5ff;
  border-radius: 16px;
}

.note-icon {
  color: var(--purple);
  font-size: 22px;
}

.sidebar-note h3 {
  font: 700 14px "Manrope", sans-serif;
  margin: 11px 0 7px;
}

.sidebar-note p {
  color: #81869d;
  font-size: 12px;
  line-height: 1.65;
  margin: 0;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8a90a4;
  font-size: 11px;
  padding: 0 8px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #38b58a;
}

.footer-version {
  margin-left: auto;
  color: #b2b5c4;
}

.main-content {
  flex: 1;
  min-width: 0;
}

.topbar {
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 34px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar .eyebrow {
  margin: 0 0 5px;
}

.topbar h2 {
  font: 800 22px "Manrope", sans-serif;
  letter-spacing: -.7px;
  margin: 0;
}

.backend-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0fbf6;
  color: #398b70;
  border: 1px solid #d9f2e7;
  border-radius: 100px;
  padding: 9px 13px;
  font-size: 11px;
  font-weight: 700;
}

.workspace {
  max-width: 1480px;
  padding: 28px 34px 20px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(290px, .8fr);
  gap: 22px;
}

.chat-column,
.data-column {
  min-width: 0;
}

.intro-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--purple);
  background: var(--purple-soft);
  font-size: 22px;
  margin-bottom: 12px;
}

.upload-card,
.chat-card,
.data-card,
.login-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 17px;
  box-shadow: var(--shadow);
}

.upload-card {
  padding: 22px;
  margin-bottom: 20px;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 17px;
}

.card-heading h3,
.data-card h3 {
  margin: 0;
  font: 800 15px "Manrope", sans-serif;
}

.card-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dropzone {
  border: 1.5px dashed #d6d2f5;
  background: #fbfaff;
  border-radius: 13px;
  padding: 22px 15px 16px;
  text-align: center;
  transition: .2s;
}

.dropzone.dragover {
  background: #f0edff;
  border-color: var(--purple);
}

.dropzone.loaded {
  border-color: #9ad9c1;
  background: #f6fffb;
}

.upload-icon {
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #eeeaff;
  color: var(--purple);
  font-size: 24px;
}

.drop-title {
  font-weight: 700;
  margin: 0 0 5px;
}

.drop-subtitle {
  margin: 0 0 10px;
  color: #a1a5b5;
  font-size: 11px;
}

.file-info {
  color: #81869b;
  font-size: 11px;
  margin: 12px 0 0;
  overflow-wrap: anywhere;
}

.button {
  border: 0;
  border-radius: 9px;
  padding: 10px 15px;
  font-size: 12px;
  font-weight: 700;
  transition: .15s;
}

.button-secondary {
  background: #fff;
  border: 1px solid #dfdff0;
  color: #5d5c7b;
}

.button-secondary:hover {
  border-color: var(--purple);
  color: var(--purple);
}

.button-primary {
  background: var(--purple);
  color: white;
  box-shadow: 0 5px 12px #6856df2a;
}

.button-primary:hover {
  background: var(--purple-dark);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--purple);
  font-size: 11px;
  font-weight: 700;
  padding: 5px;
}

.sheet-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #a2a6b7;
  font-size: 9px;
  letter-spacing: 1px;
  font-weight: 700;
  margin: 19px 0 12px;
}

.sheet-divider::before,
.sheet-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.sheet-row {
  display: flex;
  gap: 8px;
}

.sheet-row input,
.question-form textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #e4e6ef;
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

.sheet-row input {
  font-size: 12px;
}

.sheet-row input:focus,
.question-form textarea:focus {
  border-color: #a9a0f1;
  box-shadow: 0 0 0 3px #6856df12;
}

.small-note {
  color: #a0a4b3;
  font-size: 10px;
  line-height: 1.5;
  margin: 9px 0 0;
}

.chat-card {
  padding: 22px;
}

.chat-heading {
  margin-bottom: 15px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 15px;
}

.chip {
  background: #faf9ff;
  border: 1px solid #e8e5fb;
  color: #7269b2;
  border-radius: 100px;
  padding: 8px 11px;
  font-size: 10px;
}

.chip:hover {
  background: var(--purple-soft);
  border-color: #c9c2fa;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 170px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 2px 15px;
}

.message {
  position: relative;
  max-width: 92%;
  border-radius: 13px;
  padding: 13px 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.assistant {
  align-self: flex-start;
  background: #f5f5fb;
  color: #454a61;
  border: 1px solid #ececf5;
}

.message.user {
  align-self: flex-end;
  background: var(--purple);
  color: white;
}

.message.error {
  color: #a53d4d;
  background: #fff3f4;
  border-color: #ffd9dd;
}

.copy-btn {
  display: block;
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: var(--purple);
  padding: 3px 0;
  font-size: 10px;
  font-weight: 700;
}

.typing {
  display: flex;
  gap: 5px;
  align-items: center;
  min-width: 56px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9b91e8;
  animation: pulse 1s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: .15s;
}

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

@keyframes pulse {
  0%, 60%, 100% {
    opacity: .35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.question-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border-top: 1px solid #f0f0f6;
  padding-top: 15px;
}

.question-form textarea {
  resize: vertical;
  min-height: 45px;
  max-height: 130px;
  font-size: 12px;
  line-height: 1.5;
}

.question-form .button {
  min-height: 43px;
  white-space: nowrap;
}

.question-form .button span {
  font-size: 16px;
  margin-left: 6px;
}

.status {
  min-height: 15px;
  margin: 9px 0 0;
  color: #8b91a4;
  font-size: 10px;
}

.status.error {
  color: #c34252;
}

.data-card {
  padding: 22px;
}

.data-card-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.data-card .eyebrow {
  margin: 0 0 7px;
}

.data-badge {
  padding: 5px 8px;
  background: #f1f2f7;
  border-radius: 7px;
  color: #959aab;
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: .6px;
}

.data-badge.ready {
  color: #20865f;
  background: #eaf8f1;
}

.data-info {
  color: #9095a8;
  font-size: 11px;
  line-height: 1.55;
  margin: 13px 0;
}

.extracted-data {
  max-height: 510px;
  min-height: 240px;
  overflow: auto;
  padding: 14px;
  border-radius: 11px;
  background: #fafbfe;
  border: 1px solid #eceef5;
  color: #5c6278;
  font: 11px/1.7 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.data-footnote {
  margin: 12px 0 0;
  font-size: 10px;
  line-height: 1.6;
  color: #a0a4b4;
}

.table-scroll {
  max-width: 100%;
  overflow: auto;
}

.result-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
  background: white;
}

.result-table th,
.result-table td {
  border: 1px solid #e6e8f0;
  padding: 9px 10px;
  text-align: left;
}

.result-table th {
  background: #f2f0ff;
  color: #5145a7;
  font-weight: 700;
}

.result-table tbody tr:nth-child(even) {
  background: #fafaff;
}

.backend-pill.warning {
  background: #fff8ec;
  color: #a86b12;
  border-color: #f6e3c1;
}

.backend-pill.warning .status-dot {
  background: #e3a43b;
}

.library-card {
  margin-bottom: 16px;
}

.library-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.library-item {
  display: flex;
  align-items: center;
  border: 1px solid #eceef5;
  border-radius: 10px;
  background: #fafbfe;
}

.library-item.active {
  border-color: #c9c2fa;
  background: var(--purple-soft);
}

.library-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 0;
  background: transparent;
  padding: 9px 11px;
  text-align: left;
  color: var(--ink);
}

.library-name {
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-meta {
  color: #9095a8;
  font-size: 10px;
}

.library-delete {
  border: 0;
  background: transparent;
  color: #b2b5c4;
  font-size: 18px;
  line-height: 1;
  padding: 6px 12px;
}

.library-delete:hover {
  color: #c34252;
}

.library-empty {
  margin-bottom: 0;
}

.message.not-found {
  background: #fffaf0;
  border-color: #f6e8c8;
}

.answer-table {
  margin-top: 10px;
  max-height: 260px;
  white-space: normal;
}

.source-excerpt {
  margin: 3px 0 0;
  color: #8a8fa3;
  font-size: 10.5px;
  line-height: 1.5;
}

a.nav-item {
  text-decoration: none;
}

a.nav-item:hover {
  color: var(--purple);
}

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

/* Public chat page */
.chat-page {
  max-width: 920px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
}

.chat-topbar {
  margin: 0 -20px 24px;
  min-height: 80px;
}

.chat-topbar .brand {
  padding: 0;
}

.chat-card-full {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-card-full .chat-messages {
  flex: 1;
  min-height: 320px;
  max-height: calc(100vh - 360px);
}

/* Admin sign in */
.login-card {
  max-width: 420px;
  margin: 70px auto 40px;
  padding: 30px;
}

.login-card h2 {
  font: 800 21px "Manrope", sans-serif;
  letter-spacing: -.6px;
  margin: 0 0 7px;
}

.login-card p {
  color: var(--muted);
  line-height: 1.6;
  margin: 0 0 18px;
}

.login-card form {
  display: flex;
  gap: 8px;
}

.login-card input {
  flex: 1;
  min-width: 0;
  border: 1px solid #e4e6ef;
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

.login-card input:focus {
  border-color: #a9a0f1;
  box-shadow: 0 0 0 3px #6856df12;
}

.page-footer {
  padding: 8px 34px 20px;
  text-align: center;
  color: #a0a4b4;
  font-size: 10px;
}

.page-footer span {
  padding: 0 5px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1080px) {
  .sidebar {
    width: 215px;
    min-width: 215px;
  }

  .workspace {
    padding: 24px 20px;
    grid-template-columns: minmax(0, 1.3fr) minmax(260px, .8fr);
    gap: 15px;
  }

  .topbar {
    padding: 18px 22px;
  }

  .question-form {
    flex-direction: column;
    align-items: stretch;
  }

  .question-form .button {
    align-self: flex-end;
  }
}

@media (max-width: 780px) {
  .sidebar {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 18px 14px;
  }

  .topbar {
    min-height: 80px;
    padding: 16px;
  }

  .topbar h2 {
    font-size: 19px;
  }

  .backend-pill {
    font-size: 0;
    padding: 10px;
  }

  .backend-pill .status-dot {
    width: 8px;
    height: 8px;
  }

  .chat-card-full .chat-messages {
    max-height: none;
  }

  .login-card {
    margin: 30px 14px;
    padding: 22px;
  }

  .upload-card,
  .chat-card,
  .data-card {
    padding: 17px;
  }

  .data-column {
    order: -1;
  }

  .extracted-data {
    min-height: 140px;
    max-height: 300px;
  }

  .page-footer {
    padding: 5px 14px 18px;
  }
}

@media (max-width: 430px) {
  .sheet-row {
    flex-direction: column;
  }

  .sheet-row .button {
    align-self: flex-start;
  }

  .card-heading h3,
  .data-card h3 {
    font-size: 14px;
  }

  .message {
    max-width: 100%;
  }

  .chat-heading {
    align-items: center;
  }
}