:root {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.site-brand {
  font-weight: 600;
  font-size: 1.1rem;
}

.site-nav {
  display: flex;
  gap: 24px;
  background: #f9fbff;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.site-nav a {
  padding: 8px 16px;
  border-radius: 999px;
  color: var(--muted);
}

.site-nav a.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.page-body {
  padding: 24px;
  max-width: none;
  width: 100%;
  margin: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.small {
  padding: 8px 12px;
  font-size: 0.9rem;
}

.search-form,
.upload-form-single {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 16px 0;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 200px;
  flex: 1;
}

.field label,
.field span {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

input,
select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 1rem;
}

.tag-checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f9fafc;
}

.tag-pill {
  position: relative;
  display: inline-flex;
}

.tag-pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.tag-pill span {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
  background: #fff;
  transition: all 0.2s ease;
}

.tag-pill input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.flash {
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  color: var(--accent);
}

.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.paper-card {
  border: 2px solid rgba(15, 23, 42, 0.25);
  border-radius: 20px;
  padding: 18px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(245, 249, 255, 0.96));
  display: flex;
  flex-direction: column;
  gap: 0;
  transition: border 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  position: relative;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.2);
}

.paper-card:hover {
  border-color: rgba(37, 99, 235, 1);
  box-shadow: 0 18px 30px rgba(37, 99, 235, 0.18);
  transform: translateY(-3px);
}

.paper-card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.paper-card-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  padding-right: 40px;
}

.paper-category {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
}

.paper-date {
  color: var(--muted);
}

.paper-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.paper-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.paper-snippet {
  margin: 0;
  color: var(--text);
  line-height: 1.4;
  font-size: 0.95rem;
}

.paper-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.favorite-form {
  position: absolute;
  top: 12px;
  right: 12px;
  margin: 0;
  display: inline-flex;
}

.favorite-form.detail {
  position: static;
  top: auto;
  right: auto;
}

.favorite-toggle {
  width: 34px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: flex-start;
  justify-content: center;
}

.favorite-toggle span {
  display: block;
  position: relative;
  width: 18px;
  height: 26px;
  background: #e2e8f0;
  clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%);
  -webkit-clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%);
  box-shadow: inset 0 -2px 3px rgba(15, 23, 42, 0.15);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.favorite-toggle span::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 10px;
  border-radius: 2px;
  background: rgba(15, 23, 42, 0.25);
}

.favorite-toggle:hover span {
  background: #c7d2fe;
}

.favorite-toggle.active span {
  background: var(--accent);
  box-shadow: inset 0 -2px 4px rgba(15, 23, 42, 0.3);
}

.favorite-toggle.active span::after {
  background: #fff;
}

.tag {
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
}

.tag.muted {
  color: rgba(107, 114, 128, 0.7);
  background: transparent;
}

.tag.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tag-selector-field {
  min-width: 240px;
}

.tag-selector-summary {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.empty {
  color: var(--muted);
}

.search-form-wide {
  align-items: flex-end;
}

.search-results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.link-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.link-card:hover {
  border-color: var(--accent);
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.15);
  transform: translateY(-2px);
}

.link-card-title {
  font-weight: 600;
  font-size: 1rem;
}

.link-card-note {
  color: var(--muted);
  font-size: 0.9rem;
}

.link-card-url {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
}

.detail-panel {
  display: flex;
  gap: 24px;
  align-items: stretch;
  height: calc(100vh - 140px);
}

.detail-summary {
  flex: 1 1 65%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
}

.detail-summary .scroll-body {
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}

.detail-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 8px;
  background: #f3f6fb;
  border-radius: 999px;
  border: 1px solid var(--border);
  margin: 16px 0 0;
}

.tab-btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.15);
}

.tab-panels {
  margin-top: 16px;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-panel.active {
  display: flex;
}

.pdf-viewer {
  flex: 1 1 35%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 60vh;
  display: flex;
}

.pdf-viewer.resizable {
  resize: horizontal;
  overflow: auto;
  min-width: 320px;
  max-width: none;
}

.pdf-viewer iframe {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: none;
}

.detail-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.back-link {
  color: var(--accent);
  font-size: 0.9rem;
}

.detail-category {
  margin: 8px 0 4px;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
}

.detail-title {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.3;
}

.detail-meta,
.detail-authors {
  color: var(--muted);
  margin: 6px 0;
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: #f0f4ff;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn.danger {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.08);
}

.icon-btn.danger:hover {
  border-color: #ef4444;
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: #f9fafb;
}

.summary-heading {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 6px;
}

.summary-text {
  margin: 0;
  line-height: 1.4;
}

.tag-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.tag-form-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.tag-picker {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #f9fbff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.tag-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.tag-chip.muted {
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}

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

.tag-input-row .tag-input {
  flex: 1;
}

.tag-suggestions {
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tag-suggestions-title {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.tag-suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.tag-suggestion {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tag-suggestion.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.tag-editor {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tag-toggle-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.tag-form[hidden] {
  display: none;
}

.tag-form-actions {
  display: flex;
  justify-content: flex-end;
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.note-status[data-state="saving"] {
  color: var(--accent);
}

.note-status[data-state="error"] {
  color: #d14343;
}

.note-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 10px;
  background: #f9fafc;
}

.note-toolbar button {
  border: none;
  background: transparent;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.2s ease;
}

.note-toolbar button:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent);
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.note-editor {
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
  line-height: 1.5;
  overflow-y: auto;
}

.note-editor:focus {
  outline: 2px solid var(--accent-soft);
}

.note-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.note-form-actions {
  display: flex;
  justify-content: flex-end;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}

.chat-log {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
  overflow-y: auto;
  max-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  color: var(--muted);
  margin: 0;
}

.chat-bubble {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  background: #f9fbff;
}

.chat-bubble.user {
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.2);
}

.chat-role {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.chat-message {
  white-space: pre-wrap;
  line-height: 1.4;
}

.chat-form {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: #f9fafc;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font-size: 1rem;
  resize: vertical;
}

.chat-form textarea:disabled {
  background: #e5e7eb;
}

.chat-form-status {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 16px;
}

.chat-form-status[data-state="error"] {
  color: #d14343;
}

.chat-form-status[data-state="sending"] {
  color: var(--accent);
}

.chat-form-actions {
  display: flex;
  justify-content: flex-end;
}

.tag-modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 150;
}

.tag-modal.visible {
  opacity: 1;
  pointer-events: auto;
}

.tag-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.tag-modal-dialog {
  position: relative;
  width: min(640px, 90vw);
  max-height: 80vh;
  background: var(--panel);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.tag-modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tag-modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.icon-btn.ghost {
  background: transparent;
  border: none;
  color: var(--muted);
}

.tag-modal-body {
  padding: 20px 24px;
  overflow-y: auto;
}

.tag-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.tag-modal-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: #f9fafc;
}

.tag-modal-option input {
  margin: 0;
}

.tag-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tag-modal-footer .spacer {
  flex: 1;
}

.conversation-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.log-entry.user {
  background: var(--accent-soft);
}

.log-role {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

@media (max-width: 900px) {
  .detail-panel {
    flex-direction: column;
    height: auto;
  }
  .pdf-viewer {
    min-width: auto;
    resize: none;
  }
  .pdf-viewer iframe {
    min-height: 320px;
  }
}

.upload-progress {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.05em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.upload-progress.visible {
  opacity: 1;
  pointer-events: auto;
}

.loader {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 6px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
  margin-bottom: 12px;
}

.progress-title {
  margin: 12px 0 0;
  font-size: 1rem;
  text-align: center;
}

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