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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
  background: #f0f2f5;
  color: #1a1a2e;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Search Panel ─────────────────────────────────── */

#search-panel {
  width: 30%;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #e2e5ea;
  box-shadow: 2px 0 8px rgba(0,0,0,0.04);
  z-index: 1;
}

header {
  padding: 24px 24px 20px;
  border-bottom: 1px solid #f0f2f5;
}

#header-title {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
  letter-spacing: -0.3px;
}

#header-sub {
  font-size: 12px;
  color: #8a93a2;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#search-box {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-bottom: 1px solid #f0f2f5;
  align-items: flex-end;
}

#question {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e2e5ea;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fafbfc;
  outline: none;
  transition: border-color 0.15s;
  resize: none;
  overflow: hidden;
  min-height: 40px;
  max-height: 160px;
  field-sizing: content;
}

#question:focus {
  border-color: #4361ee;
  background: #fff;
}

#question::placeholder {
  color: #b0b8c4;
}

#ask-btn {
  padding: 10px 18px;
  background: #4361ee;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

#ask-btn:hover {
  background: #3451d1;
}

#ask-btn:active {
  transform: scale(0.97);
}

#ask-btn:disabled {
  background: #b0b8c4;
  cursor: not-allowed;
  transform: none;
}

/* ── Results Area ─────────────────────────────────── */

#results {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 16px;
  color: #8a93a2;
}

#empty-icon {
  width: 48px;
  height: 48px;
  background: #f0f2f5;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #b0b8c4;
  margin-bottom: 14px;
}

#empty-state p {
  font-size: 14px;
  line-height: 1.6;
  max-width: 260px;
}

/* Loading */
#loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 32px 0;
  color: #8a93a2;
  font-size: 14px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #e2e5ea;
  border-top-color: #4361ee;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* Answer */
#answer-section {
  background: #f0faf0;
  border: 1.5px solid #c6e6c6;
  border-radius: 10px;
  padding: 14px 16px;
}

#answer-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #4a9a4a;
  margin-bottom: 8px;
}

#answer-text {
  font-size: 15px;
  line-height: 1.7;
  color: #2d3748;
  white-space: pre-wrap;
}

/* Sources */
#sources {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #f0f2f5;
}

#sources-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #8a93a2;
  margin-bottom: 10px;
}

#source-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: #f8f9fc;
  border: 1.5px solid #e2e5ea;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}

.source-chip:hover {
  border-color: #4361ee;
  background: #eef1fd;
}

.source-chip.active {
  border-color: #4361ee;
  background: #eef1fd;
}

.source-chip-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.source-chip-body {
  flex: 1;
  min-width: 0;
}

.source-chip-name {
  font-size: 13px;
  font-weight: 600;
  color: #4361ee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-chip-page {
  font-size: 12px;
  color: #8a93a2;
  margin-top: 1px;
}

.source-chip-snippet {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Viewer Panel ─────────────────────────────────── */

#viewer-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #e8eaed;
  overflow: hidden;
}

#viewer-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #8a93a2;
  gap: 12px;
}

#placeholder-icon {
  font-size: 48px;
  opacity: 0.4;
}

#viewer-placeholder p {
  font-size: 14px;
}

#pdf-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e2e5ea;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  gap: 16px;
  flex-shrink: 0;
}

#viewer-filename {
  font-size: 13px;
  font-weight: 500;
  color: #4a5568;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

#viewer-page-count {
  font-size: 12px;
  color: #8a93a2;
  white-space: nowrap;
  flex-shrink: 0;
}

#canvas-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 24px 24px 48px;
  background: #e8eaed;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Each rendered PDF page */
.pdf-page {
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  border-radius: 2px;
  background: #fff;
}

.pdf-page canvas {
  display: block;
}

/* Highlight overlay — absolutely positioned over the page canvas */
.pdf-highlight {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Loading placeholder before canvas renders */
.pdf-page-loading {
  width: 595px;
  height: 842px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b0b8c4;
  font-size: 13px;
}

/* ── Utility ─────────────────────────────────────── */

.hidden {
  display: none !important;
}
