:root {
  --bg-page: #f5f7fa;
  --bg-card: #ffffff;
  --bg-soft: #eef2f6;
  --text-main: #182026;
  --text-muted: #4a5568;
  --border: #d9e1ea;
  --primary: #0d7a5f;
  --primary-hover: #095c47;
  --primary-soft: #e6f5f0;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --purple: #6d28d9;
  --purple-soft: #ede9fe;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.embed-mode .topbar {
  display: none;
}

.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-pill {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-main);
  font-weight: 500;
  white-space: nowrap;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-restore {
  background: var(--amber-soft);
  color: #92400e;
  border-color: #fcd34d;
}

.btn-restore:hover:not(:disabled) {
  background: #fde68a;
  border-color: #f59e0b;
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--text-main);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-ghost {
  background: #ffffff;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--danger);
  border-color: #fca5a5;
}

.btn-lg {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
}

.auth-gate {
  padding: 40px 16px;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.auth-card p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 15px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.stat-card:hover {
  border-color: var(--primary);
}

.stat-highlight {
  border-color: #a7f3d0;
  background: #f0fdf8;
}

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

.stat-num {
  margin-top: 4px;
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
}

.tabs-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  min-height: 42px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn.active {
  background: var(--text-main);
  color: #ffffff;
  border-color: var(--text-main);
}

.taxonomy-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chip-row-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 34px;
}

.chip-list {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  min-width: 0;
  flex: 1 1 auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

.chip-btn {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

#channelChips .chip-btn.active {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #93c5fd;
}

#categoryChips .chip-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #6ee7b7;
}

.filter-bar {
  display: flex;
  gap: 10px;
  padding-top: 4px;
}

.search-input,
.grade-select,
.full-select {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 15px;
  outline: none;
}

.search-input {
  flex: 1 1 auto;
  min-width: 0;
}

.search-input:focus,
.grade-select:focus,
.full-select:focus {
  border-color: var(--primary);
}

.full-select {
  width: 100%;
}

.cards-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-grade-S {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-grade-A {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-grade-B,
.badge-grade-C {
  background: var(--bg-soft);
  color: var(--text-muted);
}

.badge-channel {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge-category {
  background: var(--purple-soft);
  color: var(--purple);
}

.badge-status {
  background: var(--bg-soft);
  color: var(--text-main);
}

.item-date {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: auto;
}

.item-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  overflow-wrap: anywhere;
}

.item-summary {
  margin: 0 0 10px;
  font-size: 15px;
  color: #2d3748;
  overflow-wrap: anywhere;
}

.item-target {
  font-size: 14px;
  color: var(--text-muted);
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}

.item-target strong {
  color: var(--text-main);
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-box {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* Drawer / Modal */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 50;
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
}

.drawer-panel {
  width: 100%;
  max-width: 600px;
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

.drawer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  flex-shrink: 0;
}

.drawer-header-text {
  min-width: 0;
}

.drawer-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.drawer-title {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.close-btn {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-main);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.drawer-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-box {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.detail-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.detail-text {
  margin: 0;
  font-size: 15px;
  color: var(--text-main);
  overflow-wrap: anywhere;
}

.detail-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.quotes-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #2d3748;
}

.custom-dir-toggle {
  margin-top: 10px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-main);
  cursor: pointer;
}

.new-project-box {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.65;
  color: #2d3748;
  max-height: 280px;
  overflow-y: auto;
}

.drawer-footer {
  position: sticky;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.drawer-footer .btn {
  flex: 1 1 auto;
}

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #182026;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
}

@media (max-width: 680px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-bar {
    flex-direction: column;
  }
  .card-actions .btn {
    flex: 1 1 calc(50% - 4px);
  }
}
