/* ══════════════════════════════════════════════════════
   library.css — 知萃 Library 知识库 UI
   风格: 深海蓝基底 + 纸感白卡 + 侧栏 + 卡片网格
   依赖: tokens.css (--z-* 设计令牌)
   ══════════════════════════════════════════════════════ */

@import url('tokens.css');

/* ─── Layout ──────────────────────────────────────── */

.library-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding-top: 80px;
}

/* ─── Sidebar ─────────────────────────────────────── */

.library-sidebar {
  width: 260px;
  min-width: 260px;
  padding: 20px 12px;
  border-right: 1px solid var(--z-border);
  overflow-y: auto;
  height: calc(100vh - 80px);
  position: sticky;
  top: 80px;
}

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

.sidebar-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--z-text-dim);
  padding: 8px 12px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-title .badge {
  background: var(--z-accent-bg-dim);
  color: var(--z-text-secondary);
  font-size: 0.65rem;
  padding: 1px 7px;
  border-radius: 10px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--z-radius-sm);
  color: var(--z-text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.sidebar-item:hover {
  background: var(--z-border-dim);
  color: var(--z-text-primary);
}

.sidebar-item.active {
  background: var(--z-accent-bg);
  color: var(--z-brand-primary);
}

.sidebar-item .item-count {
  margin-left: auto;
  color: var(--z-text-dim);
  font-size: 0.72rem;
}

.sidebar-item .item-icon {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
}

/* Garden tree */
.garden-tree-item {
  padding-left: 32px;
  font-size: 0.78rem;
}

/* Tag cloud */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 12px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  border: 1px solid transparent;
  white-space: nowrap;
}

.tag-chip:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.tag-chip.active {
  border-color: var(--z-brand-primary);
  box-shadow: 0 0 0 1px var(--z-brand-primary);
}

.tag-chip .tag-count {
  font-size: 0.62rem;
  opacity: 0.6;
  margin-left: 2px;
}

/* ─── Main Content ────────────────────────────────── */

.library-main {
  flex: 1;
  padding: 20px 28px;
  min-width: 0;
}

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

.library-header h1 {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--z-text-primary);
}

.library-header .result-count {
  font-size: 0.82rem;
  color: var(--z-text-dim);
}

/* Search bar */
.library-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--z-bg-surface);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  padding: 8px 14px;
  flex: 1;
  max-width: 480px;
}

.library-search-bar:focus-within {
  border-color: var(--z-brand-primary);
  box-shadow: var(--z-focus-ring);
}

.library-search-bar input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--z-text-primary);
  font-size: 0.85rem;
  font-family: var(--z-font-sans);
}

.library-search-bar input::placeholder {
  color: var(--z-text-dim);
}

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid var(--z-border);
  background: transparent;
  color: var(--z-text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  font-family: var(--z-font-sans);
}

.filter-btn:hover {
  border-color: var(--z-border-hover);
  color: var(--z-text-primary);
}

.filter-btn.active {
  background: var(--z-accent-bg);
  border-color: var(--z-brand-primary);
  color: var(--z-brand-primary);
}

/* View toggle */
.view-toggle {
  display: flex;
  gap: 2px;
  background: var(--z-bg-surface);
  border-radius: var(--z-radius-sm);
  padding: 2px;
}

.view-toggle button {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--z-text-dim);
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.82rem;
  transition: all var(--z-duration-hover) var(--z-ease-out);
}

.view-toggle button.active {
  background: var(--z-bg-surface-alt);
  color: var(--z-text-primary);
}

/* ─── Card Grid ───────────────────────────────────── */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.library-card {
  background: var(--z-bg-surface);
  border: 1px solid var(--z-border-dim);
  border-radius: var(--z-radius-md);
  overflow: hidden;
  transition: all var(--z-duration-normal) var(--z-ease-out);
  cursor: pointer;
}

.library-card:hover {
  border-color: var(--z-border-hover);
  transform: translateY(-2px);
  box-shadow: var(--z-shadow-card);
}

.card-thumbnail {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--z-bg-surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--z-text-dim);
  font-size: 0.75rem;
  overflow: hidden;
}

.card-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  padding: 14px 16px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--z-text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.card-source {
  font-size: 0.72rem;
  color: var(--z-text-dim);
  margin-bottom: 8px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 8px;
}

.card-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 0.65rem;
  color: var(--z-text-primary);
  line-height: 1.5;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--z-text-dim);
  padding-top: 8px;
  border-top: 1px solid var(--z-border-dim);
}

.card-footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.card-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
  border-radius: 4px;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  line-height: 1;
}

.card-action-btn:hover {
  transform: scale(1.15);
}

.card-action-btn.favorited {
  color: var(--z-danger);
}

/* ─── Empty State ─────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--z-text-dim);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--z-text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.82rem;
  max-width: 360px;
  margin: 0 auto;
}

/* ─── Loading State ───────────────────────────────── */

.library-loading {
  text-align: center;
  padding: 60px;
  color: var(--z-text-dim);
  font-size: 0.85rem;
}

.library-loading .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--z-border);
  border-top-color: var(--z-brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* ─── Pagination ──────────────────────────────────── */

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 24px;
  padding: 12px 0;
}

.pagination-btn {
  padding: 6px 12px;
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  background: var(--z-bg-surface);
  color: var(--z-text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  font-family: var(--z-font-sans);
}

.pagination-btn:hover {
  border-color: var(--z-border-hover);
  color: var(--z-text-primary);
}

.pagination-btn.active {
  background: var(--z-accent-bg);
  border-color: var(--z-brand-primary);
  color: var(--z-brand-primary);
}

.pagination-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ─── Detail Drawer ───────────────────────────────── */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--z-overlay);
  z-index: 200;
  display: none;
}

.drawer-overlay.open {
  display: block;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 500px;
  max-width: 90vw;
  height: 100vh;
  background: var(--z-bg-surface);
  border-left: 1px solid var(--z-border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform var(--z-duration-normal) var(--z-ease-out);
  overflow-y: auto;
  padding: 24px;
}

.drawer-panel.open {
  transform: translateX(0);
}

.drawer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--z-text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.drawer-close:hover {
  color: var(--z-text-primary);
  background: var(--z-border-dim);
}

.drawer-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--z-text-primary);
  margin-bottom: 16px;
  padding-right: 40px;
}

.drawer-section {
  margin-bottom: 20px;
}

.drawer-section h4 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--z-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

/* Tag input in drawer */
.tag-input-area {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px;
  background: var(--z-bg-base);
  border-radius: var(--z-radius-sm);
  border: 1px solid var(--z-border);
}

.tag-input-area input {
  flex: 1;
  min-width: 80px;
  background: none;
  border: none;
  outline: none;
  color: var(--z-text-primary);
  font-size: 0.82rem;
  font-family: var(--z-font-sans);
}

.tag-input-area input::placeholder {
  color: var(--z-text-dim);
}

/* ─── Modal (create collection etc.) ──────────────── */

.modal-sm {
  max-width: 420px;
}

.modal-sm .modal-card {
  padding: 28px 32px;
}

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

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--z-text-secondary);
  margin-bottom: 4px;
  font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--z-bg-base);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  color: var(--z-text-primary);
  font-size: 0.85rem;
  font-family: var(--z-font-sans);
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--z-brand-primary);
  box-shadow: var(--z-focus-ring);
}

.form-group textarea {
  min-height: 60px;
  resize: vertical;
}

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

.btn-primary {
  padding: 8px 20px;
  background: var(--z-gradient-cta);
  border: none;
  border-radius: var(--z-radius-sm);
  color: var(--z-text-on-cta);
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  transition: opacity var(--z-duration-hover) var(--z-ease-out);
  font-family: var(--z-font-sans);
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  padding: 8px 20px;
  background: transparent;
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  color: var(--z-text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--z-duration-hover) var(--z-ease-out);
  font-family: var(--z-font-sans);
}

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

/* ─── Responsive ──────────────────────────────────── */

/* Mobile sidebar toggle (hidden on desktop) */
.mobile-sidebar-toggle {
  display: none;
}

.mobile-sidebar-overlay {
  display: none;
}

@media (max-width: 768px) {
  /* Show hamburger */
  .mobile-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--z-border);
    border-radius: var(--z-radius-sm);
    background: var(--z-surface);
    color: var(--z-text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
  }
  .mobile-sidebar-toggle:hover {
    background: var(--z-border-dim);
  }

  /* Drawer sidebar */
  .library-sidebar {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 150;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 280px;
    height: 100vh;
    background: var(--z-surface);
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
  }
  .library-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Overlay */
  .mobile-sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 149;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }
  .mobile-sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .library-main {
    padding: 16px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .drawer-panel {
    width: 100%;
    max-width: 100vw;
    right: -100vw;
  }
}
