* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;
  --border-soft: rgba(15, 23, 42, .1);
  --border-mid: rgba(15, 23, 42, .18);
  --radius-md: 8px;
  --radius-lg: 12px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Menlo", "Consolas", monospace;
}

body {
  font-family: var(--font);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 34% 28% 38%;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  min-height: 0;
}

.chat-panel,
.results-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-panel {
  background: var(--bg-primary);
  border-right: .5px solid var(--border-soft);
}

.chat-header,
.results-header,
.preview-header {
  background: var(--bg-primary);
  border-bottom: .5px solid var(--border-soft);
  min-height: 61px;
  flex-shrink: 0;
}

.chat-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-icon {
  width: 32px;
  height: 32px;
  background: #1e293b;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-icon i {
  color: #fff;
  font-size: 16px;
}

.chat-header-text h1,
.results-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-text p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.messages {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  font-size: 13px;
  line-height: 1.55;
  max-width: 96%;
}

.msg.user {
  align-self: flex-end;
  background: #1e293b;
  color: #f1f5f9;
  padding: 10px 14px;
  border-radius: 14px 14px 4px 14px;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: .5px solid var(--border-soft);
  padding: 10px 14px;
  border-radius: 14px 14px 14px 4px;
}

.input-row {
  flex-shrink: 0;
  padding: 12px;
  border-top: .5px solid var(--border-soft);
  display: flex;
  gap: 8px;
  background: var(--bg-primary);
}

.input-row textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  height: 42px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font);
  border: .5px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
}

.input-row textarea:focus {
  border-color: #1e293b;
}

.send-btn {
  flex-shrink: 0;
  background: #1e293b;
  color: #fff;
  border: none;
  padding: 0 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
}

.send-btn:hover {
  background: #334155;
}

.filters-block {
  background: var(--bg-tertiary);
  border: .5px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  margin-bottom: 6px;
}

.filters-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.filters-json {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.results-panel {
  background: var(--bg-secondary);
  border-right: .5px solid var(--border-soft);
}

.results-header {
  padding: 14px 16px;
}

.results-header p {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.results-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
}

.empty-results {
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 10px;
}

.doc-card {
  background: var(--bg-primary);
  border: .5px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 10px;
  transition: border-color .15s, box-shadow .15s;
}

.doc-card:hover {
  border-color: var(--border-mid);
}

.doc-card.active {
  border-color: #1e293b;
  box-shadow: 0 0 0 1px rgba(30, 41, 59, .12);
}

.doc-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.35;
  word-break: break-word;
}

.doc-meta {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.35;
  word-break: break-word;
}

.doc-meta b {
  color: var(--text-primary);
  font-weight: 600;
}

.pages-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.pages-row {
  margin-top: 10px;
}

.page-btn {
  border: .5px solid var(--border-mid);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}

.page-btn:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

.page-btn.active {
  background: #1e293b;
  color: #ffffff;
  border-color: #1e293b;
}

.preview-panel {
  background: var(--bg-tertiary);
}

.preview-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-header > i {
  font-size: 16px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.preview-header-text {
  flex: 1;
  min-width: 0;
}

.preview-header-text .doc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-header-text .doc-path {
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 0;
}

.messages,
.results-list,
.preview-scroll {
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
}

.messages::-webkit-scrollbar,
.results-list::-webkit-scrollbar,
.preview-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.messages::-webkit-scrollbar-thumb,
.results-list::-webkit-scrollbar-thumb,
.preview-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb:hover,
.results-list::-webkit-scrollbar-thumb:hover,
.preview-scroll::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.image-stage {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.preview-img {
  max-width: 100%;
  max-height: calc(100vh - 150px);
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  border: .5px solid var(--border-soft);
  border-radius: var(--radius-md);
  transform-origin: top center;
}

.preview-scroll iframe {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 140px);
  border: none;
  border-radius: var(--radius-md);
  background: white;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: var(--text-tertiary);
}

.empty-state i {
  font-size: 36px;
  display: block;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 13px;
}

.loading-dot {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.loading-dot span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: bounce .9s infinite;
}

.loading-dot span:nth-child(2) {
  animation-delay: .15s;
}

.loading-dot span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-5px);
  }
}
