* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: #172033;
  background: #f6f7f9;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: #1d4ed8;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 24px;
  color: #fff;
  background: #111827;
}

.topbar a,
.topbar button {
  color: #fff;
}

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

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  min-height: auto;
}

.menu-toggle:focus {
  outline: none;
}

.brand {
  font-weight: 700;
}

nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.menu-icon {
  width: 16px;
  height: 16px;
  stroke-width: 2px;
  flex-shrink: 0;
}

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto;
}

.panel {
  padding: 24px;
  margin-bottom: 20px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.narrow {
  max-width: 420px;
  margin: 56px auto;
}

.stack,
.grid-form {
  display: grid;
  gap: 16px;
}

.grid-form {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

input,
select,
textarea,
button,
.button {
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

button,
.button {
  cursor: pointer;
  color: #fff;
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.secondary {
  color: #172033;
  background: #fff;
}

.danger {
  background: #b91c1c;
  border-color: #b91c1c;
}

.inline {
  display: inline;
}

.actions {
  display: flex;
  gap: 12px;
  align-items: end;
}

.section-heading {
  display: flex;
  gap: 12px;
  align-items: baseline;
}

.document-filters {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(140px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.document-list-filters {
  grid-template-columns: minmax(180px, 2fr) repeat(3, minmax(140px, 1fr)) auto;
}

.filter-actions {
  white-space: nowrap;
}

.category-create-form,
.category-edit-form {
  display: flex;
  gap: 12px;
  align-items: end;
}

.category-create-form {
  max-width: 560px;
}

.category-create-form label,
.category-edit-form input {
  flex: 1;
}

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

.document-table-scroll {
  padding-bottom: 10px;
  border-right: 2px solid #cbd5e1;
  border-left: 2px solid #cbd5e1;
  scrollbar-color: #64748b #e2e8f0;
  scrollbar-width: auto;
}

.document-table-scroll:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.document-table-scroll::-webkit-scrollbar {
  height: 14px;
}

.document-table-scroll::-webkit-scrollbar-track {
  background: #e2e8f0;
  border-radius: 999px;
}

.document-table-scroll::-webkit-scrollbar-thumb {
  background: #64748b;
  border: 3px solid #e2e8f0;
  border-radius: 999px;
}

.document-table {
  min-width: 1120px;
}

.document-table thead th {
  white-space: nowrap;
}

.document-name-cell {
  min-width: 240px;
  overflow-wrap: anywhere;
}

.document-title {
  padding-bottom: 8px;
  font-weight: 700;
}

.document-filename {
  padding-top: 8px;
  color: #64748b;
  border-top: 1px solid #cbd5e1;
}

.horizontal-scroll-hint {
  display: flex;
  width: fit-content;
  gap: 8px;
  align-items: center;
  padding: 7px 12px;
  margin: 0 0 8px;
  color: #334155;
  background: #f1f5f9;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
}

.horizontal-scroll-hint span {
  color: #1d4ed8;
  font-size: 20px;
  line-height: 1;
}

.file-thumbnail {
  position: relative;
  display: grid;
  width: 84px;
  height: 62px;
  overflow: hidden;
  place-items: center;
  color: #475569;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.file-thumbnail iframe {
  width: 168px;
  height: 124px;
  border: 0;
  pointer-events: none;
  transform: scale(0.5);
}

.file-extension {
  font-size: 13px;
  font-weight: 800;
}

.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}

.file-action-button {
  display: inline-flex;
  min-height: 34px;
  padding: 6px 12px;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

.file-action-button:hover {
  color: #fff;
  filter: brightness(0.92);
}

.file-action-button.view {
  background: #2563eb;
  border-color: #2563eb;
}

.file-action-button.download {
  background: #059669;
  border-color: #059669;
}

.file-action-button.edit {
  background: #7c3aed;
  border-color: #7c3aed;
  list-style: none;
}

.edit-popover {
  position: absolute;
  z-index: 5;
  display: grid;
  width: 320px;
  gap: 10px;
  padding: 16px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(15 23 42 / 18%);
}

.account-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.row-actions .danger {
  min-height: 34px;
  padding: 6px 10px;
}

.file-field {
  display: grid;
  gap: 6px;
}

.field-label {
  font-weight: 600;
}

.drop-zone {
  min-height: 132px;
  padding: 20px;
  place-content: center;
  text-align: center;
  border: 2px dashed #94a3b8;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.drop-zone:hover,
.drop-zone:focus-within,
.drop-zone.is-dragging {
  border-color: #1d4ed8;
  background: #eff6ff;
}

.drop-zone-title {
  color: #1e3a8a;
  font-weight: 700;
}

.drop-zone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.selected-files {
  padding-left: 20px;
  margin: 4px 0 0;
  color: #475569;
  font-size: 14px;
}

.status-help {
  padding-top: 14px;
  color: #64748b;
  font-size: 13px;
}

.status-help-title {
  margin: 0 0 6px;
  font-weight: 700;
}

.status-help dl {
  display: grid;
  gap: 4px;
  margin: 0;
}

.status-help dl > div {
  display: flex;
  gap: 8px;
}

.status-help dt {
  flex: 0 0 150px;
}

.status-help dd {
  margin: 0;
}

.status-label {
  display: inline-flex;
  min-height: 24px;
  padding: 3px 9px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.status-uploaded {
  color: #334155;
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.status-indexing {
  color: #854d0e;
  background: #fefce8;
  border-color: #fde68a;
}

.status-indexed {
  color: #166534;
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.status-failed {
  color: #991b1b;
  background: #fef2f2;
  border-color: #fecaca;
}

.status-deleted {
  color: #475569;
  background: #f8fafc;
  border-color: #d1d5db;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
}

.sidebar,
.chat-panel {
  padding: 20px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.history-item {
  display: block;
  padding: 10px 0;
  border-bottom: 1px solid #eef2f7;
}

.messages {
  display: grid;
  gap: 12px;
  min-height: 300px;
  margin-bottom: 16px;
}

.message {
  padding: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.message.user {
  background: #eff6ff;
}

.message.assistant {
  background: #f8fafc;
}

.message.pending {
  color: #64748b;
}

.message.failed {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.typing-indicator {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 24px;
}

.typing-indicator i {
  width: 7px;
  height: 7px;
  background: #64748b;
  border-radius: 50%;
  animation: typing-pulse 1.2s infinite ease-in-out;
}

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

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

@keyframes typing-pulse {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.role {
  margin-bottom: 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.content {
  line-height: 1.7;
}

.content > *:first-child {
  margin-top: 0;
}

.content > *:last-child {
  margin-bottom: 0;
}

.content p {
  margin: 0 0 12px;
}

.content ul,
.content ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.content li {
  margin-bottom: 4px;
}

.content li > p {
  margin: 0;
}

.content h1,
.content h2,
.content h3,
.content h4 {
  margin: 16px 0 8px;
  line-height: 1.4;
}

.content h1:first-child,
.content h2:first-child,
.content h3:first-child,
.content h4:first-child {
  margin-top: 0;
}

.content code {
  padding: 2px 5px;
  background: #eef2f7;
  border-radius: 4px;
  font-size: 0.9em;
}

.content pre {
  padding: 12px;
  margin: 0 0 12px;
  background: #eef2f7;
  border-radius: 6px;
}

.content pre code {
  padding: 0;
  background: none;
}

.content blockquote {
  padding-left: 12px;
  margin: 0 0 12px;
  color: #475569;
  border-left: 3px solid #cbd5e1;
}

.content table {
  margin-bottom: 12px;
}

.source-files {
  padding: 12px;
  margin-top: 14px;
  background: #fff;
  border: 1px solid #dbe3ee;
  border-radius: 6px;
}

.source-files-title {
  margin-bottom: 8px;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
}

.source-files ul {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.source-files li {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

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

.source-download {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 600;
}

.ask-form,
.filters {
  display: grid;
  gap: 10px;
}

.filters {
  grid-template-columns: 1fr 1fr auto;
}

.reference {
  padding: 12px;
  margin-top: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.error {
  color: #b91c1c;
}

.success {
  color: #166534;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  padding: 12px;
}

.auth-help {
  margin: 16px 0 0;
  text-align: center;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: #64748b;
}

.auth-divider::before,
.auth-divider::after {
  height: 1px;
  flex: 1;
  background: #cbd5e1;
  content: "";
}

.full-width {
  width: 100%;
}

.muted {
  color: #64748b;
}

@media (max-width: 780px) {
  .layout,
  .filters,
  .document-filters {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px;
  }

  .topbar-brand-row {
    width: 100%;
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  nav {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    gap: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
  }

  nav.open {
    max-height: 500px;
    opacity: 1;
    padding-top: 16px;
    padding-bottom: 8px;
    gap: 12px;
  }

  nav a {
    width: 100%;
    padding: 8px 0;
    border-bottom: 1px solid #1f2937;
  }

  nav form.inline {
    display: block;
    width: 100%;
  }

  nav form.inline button {
    width: 100%;
    text-align: center;
    margin-top: 8px;
  }

  .status-help dl > div {
    display: block;
  }
}

.initially-hidden { display: none; }
