/* ============================================
   SPODIC — Library Page
   Clean list with sections, search, collapse
   ============================================ */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg, #141414);
  color: var(--text, #e0e0e0);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.5;
  min-height: 100vh;
  padding-left: var(--nav-width, 56px);
}


/* --- Fixed Avatar (top-right) --- */
.avatar-fixed {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 150;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface, #1e1e1e);
  color: var(--text-muted, #6b6b6b);
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease-out, color 150ms ease-out;
}
.avatar-fixed:hover {
  background: var(--control-hover, rgba(255,255,255,0.08));
  color: var(--text, #e0e0e0);
}
.avatar-fixed.anon {
  background: var(--bg-secondary, #1e1e1e);
  border: 1px dashed var(--border, rgba(255,255,255,0.15));
  color: var(--text-secondary, #888);
  font-size: 0.75rem;
}
.avatar-fixed.anon:hover {
  border-color: var(--accent, #d63944);
  color: var(--accent, #d63944);
}


/* --- Account Dropdown --- */
.account-dropdown {
  position: fixed;
  top: 56px;
  right: 20px;
  min-width: 220px;
  background: var(--bg-surface, #1e1e1e);
  border: 1px solid var(--control-border, rgba(255,255,255,0.06));
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease-out;
  overflow: hidden;
}
.account-dropdown.open {
  opacity: 1;
  pointer-events: auto;
}

.dropdown-user {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--control-border, rgba(255,255,255,0.06));
}
.dropdown-user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text, #e0e0e0);
}
.dropdown-user-email {
  font-size: 0.75rem;
  color: var(--text-muted, #6b6b6b);
  margin-top: 1px;
}

.dropdown-items { padding: 6px 0; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 16px;
  background: none;
  border: none;
  color: var(--text, #e0e0e0);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease-out;
}
.dropdown-item:hover {
  background: var(--control-hover, rgba(255,255,255,0.08));
}
.dropdown-item.upgrade {
  color: var(--accent, #d63944);
}
.dropdown-divider {
  height: 1px;
  background: var(--control-border, rgba(255,255,255,0.06));
  margin: 4px 0;
}


/* --- Library Layout --- */
.library-content {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px;
  animation: fadeInUp 400ms ease-out forwards;
}


/* --- Library Header --- */
.library-header {
  margin-bottom: 32px;
}

.library-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text, #e0e0e0);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.library-search {
  position: relative;
}

.library-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle, #3a3a3a);
  pointer-events: none;
}

.library-search-input {
  display: block;
  width: 100%;
  padding: 10px 14px 10px 40px;
  background: var(--bg-input, #0f0f0f);
  border: 1px solid var(--control-border, rgba(255,255,255,0.06));
  border-radius: 10px;
  color: var(--text, #e0e0e0);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  outline: none;
  transition: border-color 150ms ease-out;
}
.library-search-input::placeholder {
  color: var(--text-subtle, #3a3a3a);
}
.library-search-input:focus {
  border-color: var(--accent, #d63944);
}


/* --- Section Headers --- */
.library-section {
  margin-bottom: 24px;
}

.library-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
  transition: opacity 150ms ease-out;
}
.library-section-header:hover {
  opacity: 0.8;
}

.library-section-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-subtle, #3a3a3a);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.library-section-count {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-subtle, #3a3a3a);
}

.library-section-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-subtle, #3a3a3a);
  transition: transform 200ms ease-out;
  flex-shrink: 0;
  margin-left: auto;
}
.library-section.collapsed .library-section-chevron {
  transform: rotate(-90deg);
}

.library-section-items {
  overflow: hidden;
  transition: max-height 300ms ease-out, opacity 200ms ease-out;
  max-height: 2000px;
  opacity: 1;
}
.library-section.collapsed .library-section-items {
  max-height: 0;
  opacity: 0;
}


/* --- Item Rows --- */
.library-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background 150ms ease-out;
  position: relative;
}
.library-item:hover {
  background: var(--control-hover, rgba(255,255,255,0.08));
}

/* Favourite star */
.library-item-star {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-subtle, #3a3a3a);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms ease-out;
}
.library-item-star:hover {
  color: var(--accent, #d63944);
}
.library-item-star.active {
  color: var(--accent, #d63944);
}
.library-item-star.active svg {
  fill: var(--accent, #d63944);
}

/* Info block */
.library-item-info {
  flex: 1;
  min-width: 0;
}

.library-item-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text, #e0e0e0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.library-item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted, #6b6b6b);
  margin-top: 2px;
}

.library-item-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-subtle, #3a3a3a);
  flex-shrink: 0;
}

/* File size */
.library-item-size {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: var(--text-subtle, #3a3a3a);
  min-width: 48px;
  text-align: right;
}

/* Mini progress bar */
.library-item-progress {
  width: 48px;
  height: 3px;
  border-radius: 2px;
  background: var(--control-border, rgba(255,255,255,0.06));
  flex-shrink: 0;
  overflow: hidden;
}
.library-item-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 300ms ease-out;
}
.library-item-progress-fill.reading {
  background: var(--accent, #d63944);
}
.library-item-progress-fill.completed {
  background: var(--success, #5a9a64);
}
.library-item-progress-fill.queued {
  background: var(--control-border, rgba(255,255,255,0.06));
}

/* Overflow button */
.library-item-overflow {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-subtle, #3a3a3a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 150ms ease-out, color 150ms ease-out, background 150ms ease-out;
}
.library-item:hover .library-item-overflow {
  opacity: 1;
}
.library-item-overflow:hover {
  color: var(--text, #e0e0e0);
  background: var(--control-active, rgba(255,255,255,0.12));
}


/* --- Overflow Menu --- */
.library-overflow-menu {
  position: fixed;
  min-width: 160px;
  background: var(--bg-surface, #1e1e1e);
  border: 1px solid var(--control-border, rgba(255,255,255,0.06));
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 300;
  overflow: hidden;
  padding: 4px 0;
}

.overflow-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  color: var(--text, #e0e0e0);
  font-size: 0.8125rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease-out;
}
.overflow-item:hover {
  background: var(--control-hover, rgba(255,255,255,0.08));
}
.overflow-item.overflow-danger {
  color: var(--error, #ca4754);
}
.overflow-item.overflow-danger:hover {
  background: rgba(202, 71, 84, 0.08);
}


/* --- Empty State --- */
.library-empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted, #6b6b6b);
}

.library-empty-icon {
  color: var(--text-subtle, #3a3a3a);
  margin-bottom: 16px;
}

.library-empty p {
  font-size: 0.9375rem;
  margin-bottom: 8px;
}

.library-empty-hint {
  font-size: 0.8125rem;
  color: var(--text-subtle, #3a3a3a);
}
.library-empty-hint a {
  color: var(--accent, #d63944);
  text-decoration: none;
}
.library-empty-hint a:hover {
  text-decoration: underline;
}


/* --- Confirm Delete Dialog --- */
.library-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 150ms ease;
}

.library-confirm-modal {
  background: var(--bg-surface, #1e1e1e);
  border: 1px solid var(--control-border, rgba(255,255,255,0.06));
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  animation: slideUp 200ms ease;
}

.library-confirm-modal h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text, #e0e0e0);
  margin-bottom: 8px;
}

.confirm-text {
  font-size: 0.8125rem;
  color: var(--text-muted, #6b6b6b);
  margin-bottom: 20px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.confirm-cancel {
  padding: 8px 16px;
  border: 1px solid var(--control-border, rgba(255,255,255,0.06));
  border-radius: 8px;
  background: none;
  color: var(--text, #e0e0e0);
  font-family: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 150ms ease-out;
}
.confirm-cancel:hover {
  background: var(--control-hover, rgba(255,255,255,0.08));
}

.confirm-delete {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--error, #ca4754);
  color: #fff;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 150ms ease-out;
}
.confirm-delete:hover {
  opacity: 0.9;
}


/* --- Animations --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* --- Responsive --- */
@media (max-width: 600px) {
  .library-content {
    padding: 24px 16px 48px;
  }

  .library-title {
    font-size: 1.25rem;
  }

  .library-item {
    padding: 10px 4px;
  }

  .library-item-size {
    display: none;
  }

  .library-item-overflow {
    opacity: 1;
  }

  .account-dropdown {
    right: 12px;
    min-width: 200px;
  }
}


/* --- Light theme adjustments --- */
[data-theme="paper"] .account-dropdown,
[data-theme="sakura"] .account-dropdown,
[data-theme="flower"] .account-dropdown,
[data-theme="paper"] .library-overflow-menu,
[data-theme="sakura"] .library-overflow-menu,
[data-theme="flower"] .library-overflow-menu,
[data-theme="paper"] .library-confirm-modal,
[data-theme="sakura"] .library-confirm-modal,
[data-theme="flower"] .library-confirm-modal {
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
