/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --primary-bg: #EEF2FF;
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --border-light: #F3F4F6;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.03);
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 260px;
  --header-h: 60px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  -webkit-text-size-adjust: 100%;
}

/* ===== Header ===== */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 6px; }

.hamburger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
}

.hamburger-btn:active {
  background: var(--bg);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 500px;
  margin: 0 auto;
}

.search-box {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--text-tertiary);
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 40px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  background: var(--bg);
  transition: all .2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.lang-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .2s;
}

.lang-btn.active {
  background: var(--primary);
  color: white;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .2s;
}

.btn-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
}

/* ===== Main Layout ===== */
.main-container {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  flex-shrink: 0;
}

.sidebar-section {
  padding: 8px 16px;
  margin-bottom: 4px;
}

.sidebar-section + .sidebar-section {
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-tertiary);
  letter-spacing: .8px;
  margin-bottom: 8px;
  padding: 0 8px;
}

.nav-list {
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all .15s;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.nav-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.nav-item.active .nav-count {
  background: var(--primary-light);
  color: white;
}

.tag-input-area {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding: 0 8px;
}

.tag-input-area input {
  flex: 1;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg);
}

.tag-input-area input:focus {
  outline: none;
  border-color: var(--primary);
}

.tag-input-area button {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}

.tag-input-area button:hover {
  background: var(--primary-dark);
}

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 24px;
  min-width: 0;
}

/* ===== Upload Zone ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  margin-bottom: 24px;
  background: var(--surface);
  transition: all .3s;
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-bg);
  transform: scale(1.005);
}

.upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-tertiary);
}

.upload-text {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-tertiary);
}

.btn-primary {
  padding: 8px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  margin-top: 4px;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-title {
  font-size: 18px;
  font-weight: 700;
}

.toolbar-count {
  font-size: 13px;
  color: var(--text-tertiary);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 12px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.select-control {
  height: 34px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.select-control:focus {
  outline: none;
  border-color: var(--primary);
}

.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 6px;
  padding: 2px;
}

.view-btn {
  width: 32px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all .2s;
}

.view-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Paper Cards (Grid) ===== */
.paper-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.paper-container.list-view {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.paper-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}

.paper-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--primary-light);
}

.list-view .paper-card {
  flex-direction: row;
  align-items: center;
  padding: 12px 16px;
  gap: 14px;
}

.paper-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.list-view .paper-card-header {
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
}

.paper-type-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.paper-type-badge.journal { background: #DBEAFE; color: #1E40AF; }
.paper-type-badge.conference { background: #DCFCE7; color: #166534; }
.paper-type-badge.thesis { background: #FEF3C7; color: #92400E; }
.paper-type-badge.book { background: #F3E8FF; color: #6B21A8; }
.paper-type-badge.other { background: #F3F4F6; color: #4B5563; }

.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-tertiary);
  transition: all .2s;
  flex-shrink: 0;
}

.star-btn.starred {
  color: var(--warning);
}

.paper-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-title-pair {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.paper-title-zh {
  font-size: 15px;
  color: var(--text);
}

.paper-title-en {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.list-view .paper-title-pair {
  flex: 1;
  min-width: 180px;
}

.paper-authors {
  font-size: 12px;
  color: var(--text-tertiary);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-brief {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 6px;
  border-left: 3px solid var(--primary-light);
}

.paper-brief-label {
  color: var(--primary);
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: baseline;
}

.list-view .paper-brief {
  flex: 1;
  max-width: 400px;
}

.paper-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.paper-tag {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 3px;
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
}

.species-tag {
  color: #166534;
  background: #DCFCE7;
}

.paper-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid var(--border-light);
}

.list-view .paper-footer {
  border-top: none;
  padding-top: 0;
  flex-shrink: 0;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.paper-field {
  display: flex;
  align-items: center;
  gap: 4px;
}

.paper-date {
  font-size: 11px;
}

/* ===== PDF Viewer ===== */
.paper-pdf-bar {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
}

.btn-view-pdf {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-view-pdf:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
}

.pdf-viewer-container {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
}

.pdf-viewer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.pdf-viewer-info {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.pdf-viewer-actions {
  display: flex;
  gap: 6px;
}

.btn-pdf-action {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}

.btn-pdf-action:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.pdf-viewer-iframe {
  width: 100%;
  height: 500px;
  border: none;
  background: #525659;
}

.pdf-viewer-loading {
  padding: 40px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* ===== Cloud Sync ===== */
.sync-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  transition: all .2s;
}

.sync-status-badge.syncing {
  background: #FEF3C7;
  color: #92400E;
}

.sync-status-badge.success {
  background: #DCFCE7;
  color: #166534;
}

.sync-status-badge.error {
  background: #FEE2E2;
  color: #991B1B;
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.sync-status-badge.syncing .sync-dot {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.sync-now-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.sync-now-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
}

.sync-now-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.settings-sync-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-secondary);
  margin-top: 8px;
}

.sync-toggle-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sync-toggle-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.sync-toggle-desc {
  font-size: 11px;
  color: var(--text-tertiary);
}

.sync-toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
}

.sync-toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.sync-toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 22px;
  transition: .3s;
}

.sync-toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: .3s;
}

.sync-toggle-switch input:checked + .sync-toggle-slider {
  background: var(--primary);
}

.sync-toggle-switch input:checked + .sync-toggle-slider:before {
  transform: translateX(18px);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

.empty-state svg {
  margin-bottom: 16px;
  color: var(--border);
}

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

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: none;
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 1;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  padding-right: 16px;
  line-height: 1.4;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: 6px;
  transition: all .2s;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-body {
  padding: 24px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

/* ===== Detail Modal ===== */
.detail-title-pair {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  background: #FAFAFF;
  line-height: 1.5;
  font-size: 14px;
  font-weight: 600;
}

.detail-title-label {
  display: block;
  margin-bottom: 3px;
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.type-evidence {
  padding: 8px 10px;
  margin: 0 0 20px;
  border-radius: 6px;
  background: #F9FAFB;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.5;
}

.type-evidence strong {
  color: var(--text);
}

.species-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.species-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.species-evidence {
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
  flex: 1;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
}

.detail-section {
  margin-bottom: 24px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-section-title::before {
  content: '';
  width: 3px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

.detail-brief {
  font-size: 14px;
  color: var(--text);
  background: var(--primary-bg);
  padding: 12px 16px;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
  line-height: 1.6;
}

.detail-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

.detail-keypoints {
  list-style: none;
  padding: 0;
}

.detail-keypoints li {
  padding: 6px 0 6px 20px;
  position: relative;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.detail-keypoints li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.detail-methods {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  padding: 14px;
  background: var(--bg);
  border-radius: 8px;
}

.detail-notes {
  width: 100%;
  min-height: 80px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}

.detail-notes:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn-secondary {
  padding: 7px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .2s;
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  padding: 7px 16px;
  border: 1px solid #FEE2E2;
  background: #FEF2F2;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--danger);
  transition: all .2s;
}

.btn-danger:hover {
  background: #FEE2E2;
}

.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  background: #FFF7ED;
  color: #C2410C;
  margin-left: 6px;
}

/* ===== Stats Modal ===== */
.stats-modal { max-width: 600px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.stats-breakdown {
  margin-top: 16px;
}

.stats-breakdown h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.stat-bar-label {
  width: 100px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.stat-bar-track {
  flex: 1;
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width .5s ease;
}

.stat-bar-count {
  width: 30px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ===== Processing Overlay ===== */
.processing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.processing-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 400px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}

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

#processingText {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
}

.processing-progress {
  width: 100%;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  width: 0%;
  transition: width .3s ease;
}

.processing-detail {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  max-width: 350px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .paper-container {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
  .sidebar { width: 220px; }
}

@media (max-width: 768px) {
  :root { --header-h: 56px; }

  .header { padding: 0 12px; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 82vw;
    height: 100vh;
    height: 100dvh;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    overflow-y: auto;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 290;
    opacity: 0;
    visibility: hidden;
    transition: opacity .28s ease, visibility .28s ease;
  }
  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }
  .hamburger-btn { display: flex; }
  .header-center { max-width: none; flex: 1; }
  .lang-switcher { display: none; }
  .api-mode-indicator { display: none; }
  .content { padding: 14px 12px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .paper-container { grid-template-columns: 1fr; }
  .upload-inner { padding: 32px 16px; }
  .logo-text { font-size: 16px; }
  .btn-icon { width: 38px; height: 38px; }
  .sync-now-btn { width: 38px; height: 38px; padding: 0; justify-content: center; }
  .sync-now-btn .sync-status-badge { display: none !important; }

  /* Modal full-screen on mobile */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }
  .modal-content {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
  }
  .modal-header {
    padding: 16px 18px;
    padding-top: calc(16px + env(safe-area-inset-top));
    border-radius: 0;
  }
  .modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .detail-modal, .settings-modal, .stats-modal { max-width: 100%; }
  .pdf-viewer-iframe { height: 60vh; height: 60dvh; }

  /* Toolbar */
  .toolbar { flex-wrap: wrap; gap: 10px; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar-right { justify-content: space-between; }

  /* Prevent iOS input auto-zoom */
  .search-box input,
  .settings-input,
  select.settings-input,
  .detail-notes,
  #newTagInput {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .logo svg { width: 24px; height: 24px; }
  .header-right { gap: 2px; }
  .header-center { padding: 0 4px; }
  .search-box input { height: 34px; font-size: 16px; }
  .btn-icon { width: 34px; height: 34px; }
  .sync-now-btn { width: 34px; height: 34px; }
  /* Hide less-used header buttons on narrow screens */
  #exportBtn, #importBtn { display: none; }
  .paper-card { padding: 14px; }
  .detail-actions { flex-direction: column; }
  .detail-actions button { width: 100%; }
  .pdf-viewer-toolbar { flex-direction: column; align-items: stretch; }
  .pdf-viewer-actions { justify-content: flex-end; }
}

@media (max-width: 360px) {
  .logo-text { display: none; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ===== Settings Modal ===== */
.settings-modal { max-width: 560px; }

.settings-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-light);
}

.settings-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-api-logo {
  font-size: 18px;
}

.api-status-badge {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 600;
  margin-left: auto;
  background: #FEF3C7;
  color: #92400E;
}

.api-status-badge.connected {
  background: #DCFCE7;
  color: #166534;
}

.api-status-badge.error {
  background: #FEE2E2;
  color: #991B1B;
}

.settings-form-group {
  margin-bottom: 14px;
}

.settings-form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.settings-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: all .2s;
}

.settings-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

select.settings-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.api-key-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.api-key-input-group .settings-input {
  padding-right: 36px;
}

.btn-toggle-pwd {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-toggle-pwd:hover {
  color: var(--text);
}

.settings-hint {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.settings-hint a {
  color: var(--primary);
  text-decoration: none;
}

.settings-hint a:hover {
  text-decoration: underline;
}

.settings-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-primary-sm {
  padding: 8px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}

.btn-primary-sm:hover {
  background: var(--primary-dark);
}

/* ===== Mode Radio Toggle ===== */
.settings-mode-toggle {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all .2s;
}

.mode-radio:hover {
  border-color: var(--primary-light);
}

.mode-radio:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.mode-radio input[type="radio"] {
  margin-top: 2px;
  accent-color: var(--primary);
  cursor: pointer;
}

.mode-radio-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-radio-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.mode-radio-desc {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* ===== Re-summarize Button ===== */
.btn-ai-resummarize {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border: 1px solid #DDD0FF;
  background: #F5F3FF;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--primary);
  transition: all .2s;
}

.btn-ai-resummarize:hover {
  background: var(--primary-bg);
  border-color: var(--primary);
}

.btn-ai-resummarize:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== API Mode Indicator in Header ===== */
.api-mode-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-tertiary);
}

.api-mode-indicator.ai {
  background: #F5F3FF;
  color: var(--primary);
}

.api-mode-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.api-mode-indicator.ai .api-mode-dot {
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
