/* =====================================================
   Skelbimai – pasirinktiniai stiliai
   Tailwind CSS papildymas (CDN režimas)
   ===================================================== */

/* --- Baziniai --- */
*,
*::before,
*::after {
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Slinkties juostos stilius */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }
.dark ::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* --- Tipografija --- */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* --- HTMX indikatorius --- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline-flex; }

/* --- Nuotraukų galerija (CSS Scroll Snap) --- */
.gallery-scroll {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
}

.gallery-scroll::-webkit-scrollbar { display: none; }

.gallery-scroll .gallery-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
}

/* --- Swiper papildymai --- */
.swiper-button-next,
.swiper-button-prev {
    color: #ffffff !important;
    background: rgba(0,0,0,0.4);
    width: 40px !important;
    height: 40px !important;
    border-radius: 50%;
    backdrop-filter: blur(4px);
}

.swiper-button-next::after,
.swiper-button-prev::after {
    font-size: 16px !important;
    font-weight: bold;
}

.swiper-pagination-bullet-active {
    background: #4f46e5 !important;
}

/* --- Nuotraukų įkėlimo zona --- */
.upload-zone {
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-zone.drag-over {
    background: #eef2ff;
}

.dark .upload-zone.drag-over {
    background: #1e1b4b;
}

/* Nuotraukų peržiūra */
.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}

.image-preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: grab;
    transition: border-color 0.15s;
}

.image-preview-item:hover {
    border-color: #4f46e5;
}

.image-preview-item.dragging {
    opacity: 0.5;
    border-color: #4f46e5;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.image-preview-item:hover .remove-btn { opacity: 1; }

.image-preview-item .main-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(79, 70, 229, 0.9);
    color: white;
}

/* --- Žemėlapio konteineris --- */
.map-container {
    width: 100%;
    height: 300px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    isolation: isolate;
}

/* Leaflet žemėlapio wrapper – sukuria atskirą stacking context,
   kad Leaflet z-index reikšmės (iki 1000) neliptų ant header (z-1001) */
#listing-map,
[id$="-map"],
.leaflet-container {
    position: relative;
    z-index: 0;
}

.dark .map-container {
    border-color: #374151;
}

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

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

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideDown {
    from { opacity: 0; max-height: 0; }
    to { opacity: 1; max-height: 500px; }
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.animate-fade-in { animation: fadeIn 0.3s ease-out forwards; }
.animate-fade-in-up { animation: fadeInUp 0.4s ease-out forwards; }
.animate-slide-in-right { animation: slideInRight 0.3s ease-out forwards; }
.animate-slide-down { animation: slideDown 0.3s ease-out forwards; }
.animate-pulse-soft { animation: pulse-soft 2s infinite; }

.skeleton {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: skeleton 1.5s infinite;
    border-radius: 6px;
}

.dark .skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    background-size: 200% 100%;
}

/* Stagger animacija kortelėms */
.listing-card { animation: fadeInUp 0.4s ease-out backwards; }
.listing-card:nth-child(1) { animation-delay: 0.00s; }
.listing-card:nth-child(2) { animation-delay: 0.05s; }
.listing-card:nth-child(3) { animation-delay: 0.10s; }
.listing-card:nth-child(4) { animation-delay: 0.15s; }
.listing-card:nth-child(5) { animation-delay: 0.20s; }
.listing-card:nth-child(6) { animation-delay: 0.25s; }
.listing-card:nth-child(7) { animation-delay: 0.30s; }
.listing-card:nth-child(8) { animation-delay: 0.35s; }

/* --- Modalas --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: fadeInUp 0.2s ease-out;
}

.dark .modal-content {
    background: #1f2937;
    border: 1px solid #374151;
}

/* --- Flash pranešimai --- */
.flash-message {
    animation: slideInRight 0.3s ease-out, fadeIn 0.3s ease-out 4.5s reverse forwards;
}

/* --- Responsive lentelės --- */
@media (max-width: 768px) {
    .responsive-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .responsive-table table {
        min-width: 600px;
    }

    .responsive-table th,
    .responsive-table td {
        white-space: nowrap;
    }
}

/* --- Dalinimosi mygtukai (fiksuota šoninė juosta) --- */

/* --- Back to top mygtukas --- */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #4f46e5;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    z-index: 40;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.back-to-top:hover {
    transform: translateY(-2px);
}

/* --- Slapukų juosta --- */
.cookie-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    animation: fadeInUp 0.4s ease-out;
}

/* --- Žvaigždučių reitingas (boost) --- */
.star-rating {
    display: inline-flex;
    gap: 2px;
}

.star-rating .star {
    cursor: pointer;
    transition: color 0.15s, transform 0.1s;
}

.star-rating .star:hover {
    transform: scale(1.2);
}

.star-rating .star.active {
    color: #f59e0b;
}

.star-rating .star.inactive {
    color: #d1d5db;
}

/* --- Spausdinimo stiliai --- */
@media print {
    header, footer, nav,
    .no-print, .back-to-top,
    .cookie-bar, .flash-message,
    button[type="submit"] {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    a { color: #000; text-decoration: underline; }
    a[href]::after { content: " (" attr(href) ")"; font-size: 10pt; color: #666; }

    .listing-detail img { max-width: 100%; page-break-inside: avoid; }
    .listing-detail { max-width: 100%; padding: 0; }
}

/* --- Focus stiliai prieinamumui --- */
:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* --- Paveikslėlių lazy loading placeholder --- */
img[loading="lazy"] {
    background: #f1f5f9;
}

.dark img[loading="lazy"] {
    background: #1e293b;
}

/* --- Breadcrumbs --- */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: #6b7280;
    flex-wrap: wrap;
}

.breadcrumbs a {
    color: #6b7280;
    transition: color 0.15s;
}

.breadcrumbs a:hover {
    color: #4f46e5;
}

.breadcrumbs .separator {
    color: #d1d5db;
}

.dark .breadcrumbs .separator {
    color: #4b5563;
}

/* --- Pasirinkimų automatinis stulpelių išdėstymas --- */
.opt-cols-auto {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0.375rem;
}
.opt-cols-auto-img {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
    gap: 0.75rem;
}
.dark .opt-cols-auto,
.dark .opt-cols-auto-img {
    /* paveldimi tinklelio stiliai tinka dark režimui */
}

/* --- Boost paryškinimas --- */
.listing-card.highlighted {
    border-color: #f59e0b;
    box-shadow: 0 0 0 1px #f59e0b, 0 4px 12px rgba(245, 158, 11, 0.15);
}

/* --- Toast pranešimas --- */
.toast {
    position: fixed;
    bottom: 80px;
    right: 24px;
    z-index: 60;
    padding: 12px 20px;
    border-radius: 10px;
    color: white;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideInRight 0.3s ease-out;
}

.toast.success { background: #059669; }
.toast.error { background: #dc2626; }
.toast.info { background: #4f46e5; }

/* --- Kategorijų blokai (pagrindinis puslapis) --- */
.categ-block + .categ-block {
    /* Vidinė linija tarp blokų tame pačiame stulpelyje */
}

@media (min-width: 768px) {
    .categ-block:nth-child(odd) {
        padding-right: 1.25rem;
        border-right: 1px solid #e5e7eb;
    }
    .dark .categ-block:nth-child(odd) {
        border-right-color: #374151;
    }
    .categ-block:nth-child(even) {
        padding-left: 1.25rem;
    }
}
