/* ── Reset & Variables ────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #1a73e8;
  --primary-h: #1557b0;
  --surface:   #ffffff;
  --bg:        #f8f9fa;
  --border:    #dadce0;
  --text:      #202124;
  --text-sub:  #5f6368;
  --tag-bg:    #e8f0fe;
  --tag-color: #1a73e8;
  --radius:    8px;
  --shadow:    0 1px 6px rgba(32,33,36,.28);
}

body {
  font-family: "Google Sans", "Noto Sans TC", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 17px;
}

/* ── Header / Search Bar ──────────────────────────────── */
.search-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.search-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
  transition: box-shadow .2s;
}
.search-bar-wrap:focus-within { box-shadow: 0 1px 12px rgba(26,115,232,.3); border-color: var(--primary); }

.search-icon { width: 20px; height: 20px; color: var(--text-sub); flex-shrink: 0; }

#searchInput {
  flex: 1;
  border: none;
  outline: none;
  font-size: 17px;
  color: var(--text);
  background: transparent;
}

/* ── Buttons ──────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 7px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-sub);
  transition: background .15s;
}
.btn-ghost:hover:not(:disabled) { background: var(--tag-bg); color: var(--primary); }
.btn-ghost:disabled { opacity: .4; cursor: default; }

/* ── Main ─────────────────────────────────────────────── */
main {
  max-width: 800px;
  margin: 24px auto;
  padding: 0 16px 60px;
}

.hidden { display: none !important; }

/* ── Summary Card ─────────────────────────────────────── */
.summary-card {
  background: #e8f0fe;
  border: 1px solid #c5d8fd;
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.summary-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}
.summary-header svg { width: 18px; height: 18px; }

#summaryText { font-size: 17px; line-height: 1.4; color: var(--text); }

/* Markdown 渲染：段落、換行、粗體、項目列表 */
#summaryText p  { margin: 0 0 3px; }
#summaryText p:last-child { margin-bottom: 0; }
#summaryText strong { font-weight: 700; }
#summaryText ul {
  margin: 3px 0 5px 1.4em;
  padding: 0;
  list-style: disc;
}
#summaryText ul ul {
  margin: 2px 0 2px 1.4em;
  list-style: circle;
}
#summaryText ul ul ul {
  list-style: square;
}
#summaryText ul li { margin-bottom: 2px; line-height: 1.4; }

.citations {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.citation-chip {
  background: var(--surface);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.citation-chip:hover { background: var(--tag-bg); }

/* 摘要內 [1] [2] 等 inline reference 連結 */
.summary-ref-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.summary-ref-link:hover { text-decoration: underline; }

/* ── Results Meta ─────────────────────────────────────── */
.results-meta {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 12px;
}

/* ── Results List ─────────────────────────────────────── */
.results-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  transition: box-shadow .15s;
}
.result-item:hover { box-shadow: var(--shadow); }

.result-title {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  word-break: break-word;
  text-decoration: none;
}
.result-title:hover { text-decoration: underline; }

.result-tags {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.result-tag {
  background: var(--tag-bg);
  color: var(--tag-color);
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 8px;
}

/* ── Pagination (dropdown) ─────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 28px;
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.page-btn:hover:not(:disabled) { background: var(--tag-bg); }
.page-btn:disabled {
  opacity: .35;
  cursor: default;
}
.page-select {
  appearance: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  outline: none;
}
.page-select:focus { border-color: var(--primary); }
.page-label {
  font-size: 14px;
  color: var(--text-sub);
}

/* ── Status ───────────────────────────────────────────── */
.status-msg {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-sub);
  font-size: 15px;
}
.status-msg.error { color: #d93025; }

/* ── Modal ────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}

.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: min(92vw, 900px);
  height: min(88vh, 720px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#previewTitle {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-sub);
  line-height: 1;
  padding: 4px;
}

.modal-body {
  flex: 1;
  overflow: hidden;
}
#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Loading spinner ──────────────────────────────────── */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
