/**
 * Issued – Custom styles (only what TW4 cannot do)
 */

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #8b5cf6;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #7c3aed;
}

/* --- Comic cover: dark scrim on hover (pseudo-element) --- */
.comic-cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 10;
}

.comic-card:hover .comic-cover::after {
  opacity: 1;
}

/* Desktop: show hover buttons on cover */
@media (hover: hover) {
  .comic-card:hover .comic-cover-btn {
    opacity: 1;
  }
}

/* Touch: always show edit button */
@media (hover: none) and (pointer: coarse) {
  .comic-cover-btn.comic-info-btn {
    opacity: 1;
  }
}

/* --- Progress bar (pseudo-element for fill) --- */
.progress-bar {
  position: relative;
  overflow: hidden;
  background: rgba(139, 92, 246, 0.1);
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: #7c3aed;
  transition: width 0.3s ease;
}

/* --- View toggle buttons (spread / cover-separate) --- */
.btn-view-active {
  background-color: #ede9fe;
  color: #7c3aed;
}

.btn-view-active:hover {
  background-color: #ddd6fe;
}

#btn-cover-sep:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Two-page spread layout --- */
.reader-pages {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  cursor: inherit;
  will-change: transform;
}

.reader-image-wrap.is-zoomed {
  cursor: grab;
  touch-action: none;
}

.reader-image-wrap.is-panning {
  cursor: grabbing;
}

@media (prefers-reduced-motion: reduce) {
  .reader-pages,
  .reader-controls,
  .reader-navigation,
  .reader-hints,
  .reader-secondary-actions {
    transition: none !important;
  }
}

.reader-pages.spread-mode {
  gap: 4px;
}

.reader-pages.spread-mode img {
  max-width: calc(50% - 2px);
  flex-shrink: 1;
}

/* --- Progress bar: clickable scrubber --- */
.reader-mobile-back,
.reader-mobile-heading,
.reader-page-separator,
.reader-actions-toggle,
.reader-mobile-action-heading,
.reader-mobile-action-label,
.reader-actions-backdrop,
.reader-mobile-hint {
  display: none;
}

.reader-secondary-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.reader-progress-wrap {
  cursor: pointer;
  padding: 8px 0;
  margin: -8px 0;
  touch-action: none;
}

.reader-progress-wrap:hover .progress-bar {
  height: 0.375rem;
}

/* --- Inline page-jump input --- */
#reader-page-num {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

#reader-page-input {
  width: 3.5rem;
  font-size: inherit;
  font-weight: 700;
  color: #7c3aed;
  background: transparent;
  border: none;
  border-bottom: 2px solid #7c3aed;
  outline: none;
  text-align: center;
  padding: 0;
  appearance: textfield;
  -moz-appearance: textfield;
}

#reader-page-input::-webkit-outer-spin-button,
#reader-page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* --- Fullscreen reader --- */
.reader:fullscreen,
.reader:-webkit-full-screen {
  position: relative;
}

.reader:fullscreen .reader-controls,
.reader:-webkit-full-screen .reader-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  margin-bottom: 0;
}

.reader:fullscreen .reader-navigation,
.reader:-webkit-full-screen .reader-navigation {
  position: absolute;
  bottom: 3.5rem;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 0;
}

.reader:fullscreen .reader-hints,
.reader:-webkit-full-screen .reader-hints {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  margin-top: 0;
}

.reader:fullscreen .reader-image-wrap,
.reader:-webkit-full-screen .reader-image-wrap {
  flex: 1;
  min-height: 0;
  margin: 0;
}

.reader:fullscreen .reader-image-wrap img,
.reader:-webkit-full-screen .reader-image-wrap img {
  max-height: 100%;
}

:fullscreen .reader-controls.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

:fullscreen .reader-navigation.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

:fullscreen .reader-hints.hidden {
  opacity: 0;
  pointer-events: none;
}

:fullscreen.cursor-hidden {
  cursor: none;
}

@media (max-width: 639px) {
  .reader-page {
    background: #f8fafc;
  }

  .reader-page .site-header {
    display: none;
  }

  .reader-page .site-main {
    width: 100%;
    max-width: none !important;
    padding: 0 !important;
  }

  .reader-page .reader {
    min-height: 100dvh;
    width: 100%;
  }

  .reader-page .reader-controls {
    margin: 0;
    padding: max(0.375rem, env(safe-area-inset-top)) 0.5rem 0.375rem;
    border-width: 0 0 1px;
    border-color: rgba(139, 92, 246, 0.16);
    border-radius: 0;
    box-shadow: 0 3px 12px rgb(15 23 42 / 0.1);
    background: rgb(255 255 255 / 0.94);
    z-index: 30;
  }

  .reader-page .reader-toolbar {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 92px;
    align-items: center;
    gap: 0.375rem;
  }

  .reader-mobile-back,
  .reader-actions-toggle {
    display: inline-flex;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    color: #4b5563;
    box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
    touch-action: manipulation;
  }

  .reader-mobile-back svg,
  .reader-actions-toggle svg {
    width: 20px;
    height: 20px;
  }

  .reader-page .reader-summary {
    min-width: 0;
  }

  .reader-desktop-heading {
    display: none;
  }

  .reader-mobile-heading {
    display: block;
    margin: 0;
    color: #111827;
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.1rem;
  }

  .reader-page-status {
    min-width: 0;
    gap: 0.5rem;
    line-height: 1rem;
  }

  .reader-page-counter {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.75rem;
  }

  .reader-page-label,
  .reader-page-of {
    display: none;
  }

  .reader-page-separator {
    display: inline;
    margin: 0 0.15rem;
    color: #9ca3af;
  }

  .reader-page .reader-progress-wrap {
    min-width: 2.5rem;
    max-width: none;
    padding: 6px 0;
    margin: -6px 0;
  }

  .reader-page .reader-progress-wrap .progress-bar,
  .reader-page .reader-progress-wrap:hover .progress-bar {
    height: 3px;
  }

  .reader-page #reader-page-input {
    width: 2.5rem;
  }

  .reader-primary-actions {
    display: grid;
    grid-template-columns: repeat(2, 44px);
    gap: 0.25rem;
  }

  .reader-page #fullscreen-toggle {
    width: 44px;
    height: 44px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgb(15 23 42 / 0.08);
  }

  .reader-secondary-actions {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    left: 0;
    z-index: 3;
    display: grid;
    gap: 0.875rem;
    max-height: calc(100dvh - 4.75rem - env(safe-area-inset-top));
    padding: 1rem;
    overflow-y: auto;
    visibility: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    background: rgb(255 255 255 / 0.98);
    box-shadow: 0 18px 40px rgb(15 23 42 / 0.22);
    opacity: 0;
    transform: translateY(-0.375rem);
    transition: opacity 160ms ease, transform 160ms ease, visibility 160ms;
    pointer-events: none;
  }

  .reader-controls.mobile-actions-open .reader-secondary-actions {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .reader-controls.mobile-actions-open .reader-actions-toggle {
    border-color: #c4b5fd;
    background: #ede9fe;
    color: #6d28d9;
  }

  .reader-controls.mobile-actions-open .reader-actions-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: block;
    padding: 0;
    border: 0;
    background: rgb(15 23 42 / 0.18);
    cursor: default;
  }

  .reader-tags-wrap {
    display: grid;
    gap: 0.5rem;
    margin: 0;
  }

  .reader-mobile-action-heading {
    display: block;
    color: #6b7280;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1rem;
    text-transform: uppercase;
  }

  .reader-tag-entry {
    width: 100%;
  }

  .reader-tag-entry #reader-tag-input {
    width: auto;
    min-width: 0;
    min-height: 44px;
    flex: 1;
    font-size: 0.875rem;
  }

  .reader-tag-entry #reader-tag-add {
    width: 44px;
    min-height: 44px;
    flex-shrink: 0;
    font-size: 1rem;
  }

  .reader-view-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .reader-view-actions button {
    width: 100%;
    height: 44px;
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 0 0.875rem;
    border: 1px solid #e5e7eb;
    box-shadow: none;
  }

  .reader-mobile-action-label {
    display: inline;
    overflow: hidden;
    font-size: 0.875rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reader-page .reader-image-wrap {
    min-height: 50vh;
    margin: 0;
    padding: 0 !important;
    border-radius: 0 !important;
    background: #111827;
    box-shadow: none !important;
  }

  .reader-page .reader-image-wrap img {
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .reader-page .reader-pages {
    width: fit-content;
    height: fit-content;
    max-width: 100%;
    max-height: 100%;
  }

  .reader-page .reader-pages.spread-mode {
    gap: 0;
  }

  .reader-page .reader-pages.spread-mode img {
    max-width: 50%;
  }

  .reader-page .reader-navigation {
    gap: 1rem;
    margin-top: 0.75rem;
  }

  .reader-page .reader-nav-btn {
    width: 48px;
    min-width: 48px;
    max-width: 48px !important;
    height: 48px;
    min-height: 48px;
    flex: 0 0 48px;
    gap: 0;
    padding: 0 !important;
    border-radius: 9999px;
  }

  .reader-page .reader-nav-label,
  .reader-desktop-hint {
    display: none;
  }

  .reader-mobile-hint {
    display: block;
  }

  .reader-page .reader-hints {
    margin-top: 0.625rem;
    padding: 0 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  }

  html[data-theme="dark"] .reader-page {
    background: #0f172a;
  }

  html[data-theme="dark"] .reader-page .reader-controls,
  html[data-theme="dark"] .reader-page .reader-secondary-actions {
    border-color: #374151;
    background: rgb(17 24 39 / 0.96);
  }

  html[data-theme="dark"] .reader-mobile-heading {
    color: #f9fafb;
  }

  html[data-theme="dark"] .reader-mobile-back,
  html[data-theme="dark"] .reader-actions-toggle,
  html[data-theme="dark"] .reader-page #fullscreen-toggle,
  html[data-theme="dark"] .reader-view-actions button {
    border-color: #4b5563;
    background: #1f2937;
    color: #e5e7eb;
  }

  html[data-theme="dark"] .reader-controls.mobile-actions-open .reader-actions-toggle {
    border-color: #7c3aed;
    background: #2e1065;
    color: #ddd6fe;
  }
}

/* --- Keyframes --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }

  100% {
    background-position: 1000px 0;
  }
}

@keyframes reader-spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 1000px 100%;
  animation: shimmer 2s infinite;
}

.reader-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border: 4px solid rgba(139, 92, 246, 0.2);
  border-top-color: #8b5cf6;
  border-radius: 50%;
  animation: reader-spin 0.8s linear infinite;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.reader-spinner.visible {
  opacity: 1;
}

/* --- Table view: meta chips with Lucide icons --- */
.comic-meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  color: #6b7280;
  position: relative;
  white-space: nowrap;
}

.comic-meta-icon {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  color: #9ca3af;
}

/* CSS tooltip via data-tooltip attribute */
.comic-meta-chip[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #f9fafb;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 50;
}

.comic-meta-chip[data-tooltip]::after {
  content: '';
  position: absolute;
  bottom: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: #1f2937;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 50;
}

.comic-meta-chip[data-tooltip]:hover::before,
.comic-meta-chip[data-tooltip]:hover::after {
  opacity: 1;
}

/* --- Table view --- */
.comics-table-wrap table {
  table-layout: auto;
}

.comic-thumb-zoom-wrap {
  overflow: hidden;
}

.comic-thumb-zoom {
  transition: transform 0.3s ease;
  transform-origin: left center;
  display: block;
}

.comic-table-row:hover .comic-thumb-zoom {
  transform: scale(1.6);
}

/* Touch: always show edit button in table rows */
@media (hover: none) and (pointer: coarse) {
  .comic-table-row .comic-info-btn {
    opacity: 1 !important;
  }
}

/* --- Folder preview (dynamic bg-image from JS) --- */
.folder-thumb {
  background-size: cover;
  background-position: center;
  background-color: #f3f4f6;
}

.folder-preview-single .folder-thumb-1 {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
}

.folder-preview-single .folder-thumb-2,
.folder-preview-single .folder-thumb-3,
.folder-preview-single .folder-thumb-4 {
  display: none;
}

/* --- Library display preferences --- */

html[data-layout-width="full"] .layout-container {
  max-width: none !important;
}

.cover-grid {
  --cover-min-width: 8rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--cover-min-width)), 1fr)) !important;
}

html[data-thumbnail-size="tiny"] .cover-grid {
  --cover-min-width: 4.75rem;
}

html[data-thumbnail-size="extra-small"] .cover-grid {
  --cover-min-width: 5.5rem;
}

html[data-thumbnail-size="small"] .cover-grid {
  --cover-min-width: 6.5rem;
}

html[data-thumbnail-size="large"] .cover-grid {
  --cover-min-width: 10rem;
}

html[data-thumbnail-size="extra-large"] .cover-grid {
  --cover-min-width: 12rem;
}

html[data-thumbnail-size="huge"] .cover-grid {
  --cover-min-width: 14rem;
}

@media (min-width: 640px) {
  .cover-grid {
    --cover-min-width: 11rem;
  }

  html[data-thumbnail-size="tiny"] .cover-grid {
    --cover-min-width: 5.5rem;
  }

  html[data-thumbnail-size="extra-small"] .cover-grid {
    --cover-min-width: 7rem;
  }

  html[data-thumbnail-size="small"] .cover-grid {
    --cover-min-width: 8.5rem;
  }

  html[data-thumbnail-size="large"] .cover-grid {
    --cover-min-width: 14rem;
  }

  html[data-thumbnail-size="extra-large"] .cover-grid {
    --cover-min-width: 18rem;
  }

  html[data-thumbnail-size="huge"] .cover-grid {
    --cover-min-width: 22rem;
  }
}

html[data-borderless="true"] .cover-grid {
  gap: 0 !important;
}

html[data-borderless="true"] .comic-card,
html[data-borderless="true"] .folder-card {
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  transform: none !important;
}

html[data-borderless="true"] .comic-card-details,
html[data-borderless="true"] .folder-card-details {
  display: none !important;
}

html[data-borderless="true"] .folder-preview-mosaic,
html[data-borderless="true"] .folder-preview-images,
html[data-borderless="true"] .folder-thumb {
  border-radius: 0 !important;
}

html[data-borderless="true"] .folder-preview-images {
  gap: 0 !important;
  padding: 0 !important;
}

.display-switch[aria-checked="true"] {
  background-color: #7c3aed;
}

.display-switch[aria-checked="true"] .display-switch-thumb {
  transform: translateX(1.25rem);
}

.display-option[aria-pressed="true"] {
  border-color: #a78bfa;
  background-color: #ede9fe;
  color: #6d28d9;
}

html[data-theme="dark"] .display-option[aria-pressed="true"] {
  border-color: #7c3aed !important;
  background-color: #2e1065 !important;
  color: #ddd6fe !important;
}

/* --- Color theme --- */
html[data-theme="dark"] {
  color-scheme: dark;
}

.theme-sun {
  display: none;
}

html[data-theme="dark"] .theme-moon {
  display: none;
}

html[data-theme="dark"] .theme-sun {
  display: block;
}

html[data-theme="dark"] body {
  background: linear-gradient(135deg, #111827 0%, #0f172a 48%, #1e1b4b 100%);
  color: #e5e7eb;
}

html[data-theme="dark"] header {
  background-color: rgb(17 24 39 / 0.88) !important;
  border-color: #312e81 !important;
}

html[data-theme="dark"] .bg-white {
  background-color: #1f2937 !important;
}

html[data-theme="dark"] .bg-white\/80,
html[data-theme="dark"] .bg-white\/90 {
  background-color: rgb(31 41 55 / 0.9) !important;
}

html[data-theme="dark"] .bg-gray-50,
html[data-theme="dark"] .bg-gray-100,
html[data-theme="dark"] .bg-violet-50 {
  background-color: #111827 !important;
}

html[data-theme="dark"] .bg-violet-100 {
  background-color: #312e81 !important;
}

html[data-theme="dark"] .text-gray-900,
html[data-theme="dark"] .text-gray-800,
html[data-theme="dark"] .text-gray-700 {
  color: #f3f4f6 !important;
}

html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .text-gray-500 {
  color: #d1d5db !important;
}

html[data-theme="dark"] .text-gray-400,
html[data-theme="dark"] .text-gray-300 {
  color: #9ca3af !important;
}

html[data-theme="dark"] .text-violet-600,
html[data-theme="dark"] .text-violet-700 {
  color: #c4b5fd !important;
}

html[data-theme="dark"] .border-gray-100,
html[data-theme="dark"] .border-gray-200,
html[data-theme="dark"] .border-violet-100,
html[data-theme="dark"] .border-violet-200 {
  border-color: #4b5563 !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background-color: #111827 !important;
  border-color: #4b5563 !important;
  color: #f9fafb !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #9ca3af;
}

html[data-theme="dark"] .hover\:bg-violet-50:hover,
html[data-theme="dark"] .hover\:bg-violet-50\/60:hover,
html[data-theme="dark"] .hover\:bg-violet-100:hover,
html[data-theme="dark"] .hover\:bg-gray-50:hover {
  background-color: #374151 !important;
}

html[data-theme="dark"] .hover\:bg-white:hover {
  background-color: #4b5563 !important;
}

html[data-theme="dark"] .hover\:text-violet-600:hover,
html[data-theme="dark"] .hover\:text-violet-700:hover,
html[data-theme="dark"] .hover\:text-violet-800:hover,
html[data-theme="dark"] .hover\:text-violet-900:hover {
  color: #ddd6fe !important;
}

html[data-theme="dark"] .folder-thumb {
  background-color: #111827;
}

html[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #1f2937 25%, #374151 50%, #1f2937 75%);
  background-size: 200% 100%;
}

html[data-theme="dark"] .swal2-popup {
  background-color: #1f2937;
  color: #f3f4f6;
}

html[data-theme="dark"] .swal2-title,
html[data-theme="dark"] .swal2-html-container {
  color: #f3f4f6;
}

@media (prefers-reduced-motion: no-preference) {
  body,
  header,
  .bg-white,
  .bg-white\/80,
  .bg-white\/90 {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  }
}
