/* Custom font */
.font-serif-custom {
    font-family: 'Merriweather', serif !important;
}

/* Modal */
#preview-modal:empty {
    display: none;
}

.modal-backdrop {
    background: rgba(75, 85, 99, 0.65);
}

/* Loading indicators */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #6b7280;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

#loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -20px;
    margin-left: -20px;
    z-index: 10;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background-color: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Preview */
.preview-container {
    aspect-ratio: 1 / 1.414;
    background: #f9fafb;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    position: relative;
}

@media (max-width: 767px) {
    .preview-container {
        max-height: 65vh;
        width: 100%;
    }
}

@media (min-width: 768px) {
    .preview-container {
        max-height: calc(100vh - 12rem);
        height: auto;
    }
}

.preview-image-wrapper {
    aspect-ratio: 1 / 1.414;
    background: white;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.15s ease-in-out;
}

@media (max-width: 767px) {
    .preview-image {
        max-height: 65vh;
        max-width: 100vw;
    }
}

/* Page navigation */
.page-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #d1d5db;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
    .page-nav-btn:not(.hidden) {
        display: flex;
    }
}

.page-nav-btn:hover:not(:disabled) {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.page-nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-nav-btn.prev {
    left: -24px;
}

.page-nav-btn.next {
    right: -24px;
}

/* URL input scrollbar */
#url-input {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

#url-input::-webkit-scrollbar {
    display: none; /* Chrome/Safari/Opera */
}

/* HTMX indicators */
.htmx-indicator {
    display: none !important;
}

.htmx-request .htmx-indicator {
    display: block !important;
}

.htmx-request button[type="submit"] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* URL Input Rows */
.url-row {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.url-row:hover .drag-handle {
    opacity: 1;
}

.url-row .drag-handle {
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

/* Drag and drop */
.url-row.dragging {
    opacity: 0.5;
    transform: rotate(1deg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.drag-handle:active {
    cursor: grabbing !important;
}

.url-list-drop-target {
    background: rgba(34, 197, 94, 0.1);
    border: 2px dashed #22c55e;
    border-radius: 0.75rem;
}

/* Sortable.js classes */
.sortable-chosen {
    background: white !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25) !important;
    border: 2px solid #3b82f6 !important;
    transform: scale(1.02) rotate(2deg) !important;
    z-index: 1000 !important;
    opacity: 0.95 !important;
}

.sortable-ghost {
    opacity: 0.4;
    background: rgba(59, 130, 246, 0.05);
    border: 2px dashed #93c5fd !important;
}

.sortable-drag {
    opacity: 1 !important;
    background: white !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3) !important;
    border: 2px solid #3b82f6 !important;
}

/* Button hover effects */
.add-url-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#add-url-btn {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

#add-url-btn.hidden {
    opacity: 0;
    max-height: 0;
}

#add-url-btn:not(.hidden) {
    opacity: 1;
    max-height: 100px;
}

/* Smooth animations for showing/hiding elements */
#multi-url-help {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#multi-url-help.hidden {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
}

#multi-url-help:not(.hidden) {
    opacity: 1;
    max-height: 200px;
    overflow: visible;
}

#title-input-container {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#title-input-container:not(.hidden) {
    animation: fadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

#title-input-container.hidden {
    opacity: 0;
}

/* Title display/edit transitions */
#title-display,
#collection-title {
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#title-display.hidden,
#collection-title.hidden {
    opacity: 0;
}

/* URL list container transitions */
#url-list {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Smooth container resize */
#drop-zone {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus states */
input[name="urls[]"]:focus {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* Filled state styling */
input[name="urls[]"]:not(:placeholder-shown):not(:focus) {
    background-color: rgb(248 250 252 / var(--tw-bg-opacity, 1));
    border-color: rgb(226 232 240 / var(--tw-border-opacity, 1));
    font-size: 0.875rem; /* smaller text when filled */
    text-align: left;
    direction: ltr;
}

input[name="urls[]"]:not(:placeholder-shown):focus {
    background-color: white;
    border-color: #3b82f6;
    font-size: 1rem; /* normal text size when focused */
}

/* Reduce top margin for url-list when collection div is hidden */
#multi-url-help.hidden + #url-list {
    margin-top: 0;
}

/* Reduce spacing for add URL button */
#add-url-btn {
    padding-top: 1.5rem;
    margin-top: -0.66rem !important;
}

/* Smooth transitions for buttons */
.remove-btn,
#edit-title-btn,
#reset-button-container {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.remove-btn.hidden,
#edit-title-btn.hidden,
#reset-button-container.hidden {
    opacity: 0;
    transform: scale(0.8);
}

/* Submit button transition */
#submit-btn {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#submit-btn svg {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#submit-btn:hover:not(:disabled) svg {
    transform: rotate(-45deg);
}

/* Title overlay */
.title-overlay {
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.title-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.title-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

/* Hide input text when title is shown */
input[name="urls[]"].has-title {
    color: transparent;
}

input[name="urls[]"].has-title:focus {
    color: inherit;
}

/* Extracting state */
input[name="urls[]"].extracting {
    border-color: #3b82f6;
    animation: pulse-border 1.5s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% {
        border-color: #3b82f6;
        opacity: 1;
    }
    50% {
        border-color: #93c5fd;
        opacity: 0.8;
    }
}

/* Extraction success state */
input[name="urls[]"].extraction-success {
    background-color: #f9fafb;
    border-color: #d1d5db;
}

input[name="urls[]"].extraction-success:focus {
    background-color: white;
    border-color: #3b82f6;
}

input[name="urls[]"].extraction-success + .title-overlay {
    background-color: #f9fafb;
    border-color: #d1d5db;
}

input[name="urls[]"].extraction-success + .title-overlay:focus {
    background-color: white;
    border-color: #3b82f6;
}

/* Extraction failed state */
input[name="urls[]"].extraction-failed {
    border-color: #f87171 !important;
    border-width: 2px !important;
    background-color: white !important;
}

input[name="urls[]"].extraction-failed:hover {
    border-color: #fca5a5 !important;
}

input[name="urls[]"].extraction-failed:focus {
    border-color: #ef4444 !important;
    border-width: 2px !important;
    outline: none !important;
    ring: 0 !important;
    box-shadow: none !important;
    background-color: white !important;
}

/* Error overlay styling */
input[name="urls[]"].extraction-failed + .title-overlay {
    border-color: #f87171 !important;
    border-width: 2px !important;
}

input[name="urls[]"].extraction-failed + .title-overlay:hover {
    border-color: #fca5a5 !important;
}

/* Error message styling */
input[name="urls[]"].extraction-failed + .title-overlay .title {
    font-size: 0.8125rem !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
}

/* Error icon */
.error-icon {
    transition: opacity 0.2s;
}

.error-icon.hidden {
    opacity: 0;
}

.error-icon:not(.hidden) {
    opacity: 1;
}

/* Icon container */
.icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-container .favicon {
    transition: opacity 0.2s;
}

.icon-container .fallback-icon {
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity 0.2s;
}

.icon-container .fallback-icon.hidden {
    opacity: 0;
}

.icon-container .fallback-icon:not(.hidden) {
    opacity: 1;
}

/* Favicon loading */
.title-overlay .favicon {
    transition: opacity 0.2s;
}

/* Settings toggle */
#settings-chevron.rotate-180 {
    transform: rotate(180deg);
}

#settings-container {
    transition: opacity 0.2s ease-in-out, max-height 0.3s ease-in-out;
    overflow: hidden;
}

@media (max-width: 767px) {
    #settings-container:not(.hidden) {
        animation: fadeIn 0.2s ease-in-out;
    }
}
