/**
 * Recent Topics with Images Extension for phpBB.
 *
 * @package     salvocortesiano.recenttopicsimage
 * @copyright   (c) 2025 Salvo Cortesiano
 * @license     GNU General Public License, version 2 (GPL-2.0)
 */

/* Container styles */
.recent-topics-container {
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.recent-topics-list {
    max-height: 500px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--rti-border, #ccc) #f0f0f0;
    background-color: var(--rti-content-bg, #fff);
    border-radius: 0 0 3px 3px;
    /* Assicuriamo che lo scorrimento sia per multipli di 4 righe */
    scroll-snap-type: y mandatory;
}

/* WebKit scrollbar styling */
.recent-topics-list::-webkit-scrollbar {
    width: 8px;
}

.recent-topics-list::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 4px;
}

.recent-topics-list::-webkit-scrollbar-thumb {
    background-color: var(--rti-border, #ccc);
    border-radius: 4px;
}

.recent-topics-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--rti-link, #aaa);
}

/* Topic item styles */
.recent-topic-item {
    display: flex;
    padding: 12px;
    border-bottom: 1px solid var(--rti-border, #eaeaea);
    transition: background-color 0.2s ease;
    /* Supporto per scroll-snap */
    scroll-snap-align: start;
    min-height: 125px; /* Altezza minima invece di altezza fissa */
    box-sizing: border-box; /* Assicuriamo che padding non influisca sull'altezza */
    color: var(--rti-content-text, #333333);
}

.recent-topic-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

.recent-topic-item:last-child {
    border-bottom: none;
}

.recent-topic-image {
    flex: 0 0 120px;
    margin-right: 15px;
    overflow: hidden;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.recent-topic-image img {
    width: calc(var(--recenttopicsimage-scale, 100%) * 1);
    height: calc(var(--recenttopicsimage-height, 80px) * var(--recenttopicsimage-scale-factor, 1));
    object-fit: cover;
    border-radius: 4px;
    transition: transform 0.3s ease, opacity 0.3s ease;
    margin: 0 auto;
    display: block;
}

.recent-topic-image:hover img {
    transform: scale(1.03);
}

/* Image Navigation Controls */
.topic-image-navigation {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    color: #fff;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.recent-topic-image:hover .topic-image-navigation {
    opacity: 1;
}

.topic-image-nav-prev,
.topic-image-nav-next {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 12px;
    border-radius: 3px;
    transition: background-color 0.3s ease;
}

.topic-image-nav-prev:hover,
.topic-image-nav-next:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.topic-image-counter {
    font-size: 11px;
    font-weight: bold;
}

/* Class for image transition */
.topic-image-changing {
    opacity: 0.5;
}

.recent-topic-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.recent-topic-title {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 5px;
    line-height: 1.3;
    position: relative;
}

.recent-topic-title a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--rti-link, #3f7fc0);
    transition: color 0.2s ease;
}

.recent-topic-title .topictitle.unread {
    font-weight: bold;
    color: var(--rti-content-text, #000);
}

.recent-topic-title .row-item-link {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

.recent-topic-title .row-item-link + a {
    position: relative;
    z-index: 2;
}

.recent-topic-title a:hover {
    color: var(--rti-link-hover, #1f5e9c);
    text-decoration: none;
}

.recent-topic-forum {
    font-size: 12px;
    margin-bottom: 5px;
    color: #666;
}

.recent-topic-forum a {
    color: #666;
    transition: color 0.2s ease;
}

.recent-topic-forum a:hover {
    color: #3f7fc0;
    text-decoration: none;
}

.recent-topic-details {
    font-size: 12px;
    color: #777;
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 5px;
}

.recent-topic-details span {
    margin-right: 15px;
    margin-bottom: 3px;
}

.recent-topic-details i {
    color: #aaa;
    margin-right: 3px;
}

.recent-topic-author {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-topic-replies {
    font-size: 12px;
    color: #777;
}

.recent-topic-replies i {
    color: #aaa;
    margin-right: 3px;
}

/* No topics message */
.no-topics-message {
    padding: 30px;
    text-align: center;
    color: #777;
    font-style: italic;
}

/* Responsive styles */
@media (max-width: 768px) {
    .recent-topic-item {
        flex-direction: column;
        padding: 15px;
        height: auto; /* Rimuove l'altezza fissa per dispositivi mobili */
        min-height: 250px; /* Altezza minima per evitare sovrapposizioni */
    }
    
    .recent-topic-image {
        flex: 0 0 auto;
        margin-right: 0;
        margin-bottom: 10px;
        width: 100%;
        max-height: 120px; /* Riduce l'altezza massima dell'immagine */
        position: relative;
    }
    
    .recent-topic-image img {
        width: 100%;
        height: auto;
        max-height: 120px;
    }
    
    .recent-topic-info {
        margin-top: 5px; /* Aggiunge spazio tra l'immagine e le informazioni */
        position: relative; /* Assicura che il testo rimanga al di sotto dell'immagine */
        width: 100%;
    }
    
    .recent-topic-title {
        font-size: 14px; /* Dimensione ridotta */
        margin-top: 5px;
        margin-bottom: 8px;
        clear: both; /* Assicura che il titolo inizi su una nuova riga */
    }
    
    .recent-topic-details {
        flex-direction: column;
        margin-bottom: 8px;
    }
    
    .recent-topic-details span {
        margin-right: 0;
        margin-bottom: 5px;
        line-height: 1.5;
        font-size: 11px; /* Testo più piccolo su dispositivi mobili */
    }
    
    /* Aumenta la dimensione della lista per contenere più contenuto */
    .recent-topics-list {
        max-height: 600px;
    }
    
    /* Rendere i tooltip più piccoli su mobile */
    .recent-topic-title a[data-tooltip]:hover::after,
    .recent-topic-title a[data-tooltip].tooltip-active::after {
        width: 200px;
        font-size: 11px;
        padding: 8px;
    }
}

/* When displayed in header */
.headerbar + .recent-topics-container {
    margin-top: 15px;
}

/* When displayed in index */
.forumbg + .recent-topics-container {
    margin-top: 15px;
}

/* Dark mode support - for phpBB themes with dark mode */
.darkmode .recent-topics-list,
.dark-mode .recent-topics-list,
[data-theme="dark"] .recent-topics-list {
    background-color: #2a2a2a;
}

.darkmode .recent-topic-item:hover,
.dark-mode .recent-topic-item:hover,
[data-theme="dark"] .recent-topic-item:hover {
    background-color: #333333;
}

.darkmode .recent-topic-item,
.dark-mode .recent-topic-item,
[data-theme="dark"] .recent-topic-item {
    border-color: #3a3a3a;
}

.darkmode .recent-topic-title a,
.dark-mode .recent-topic-title a,
[data-theme="dark"] .recent-topic-title a {
    color: #7cb2e8;
}

.darkmode .recent-topic-title a:hover,
.dark-mode .recent-topic-title a:hover,
[data-theme="dark"] .recent-topic-title a:hover {
    color: #9ccfff;
}

.darkmode .recent-topic-title .topictitle.unread,
.dark-mode .recent-topic-title .topictitle.unread,
[data-theme="dark"] .recent-topic-title .topictitle.unread {
    color: #ffffff;
    font-weight: bold;
}

.darkmode .recent-topic-forum a,
.dark-mode .recent-topic-forum a,
[data-theme="dark"] .recent-topic-forum a {
    color: #aaa;
}

.darkmode .recent-topic-details,
.dark-mode .recent-topic-details,
[data-theme="dark"] .recent-topic-details {
    color: #999;
}

.darkmode .recent-topics-list::-webkit-scrollbar-track,
.dark-mode .recent-topics-list::-webkit-scrollbar-track,
[data-theme="dark"] .recent-topics-list::-webkit-scrollbar-track {
    background: #333;
}

.darkmode .recent-topics-list::-webkit-scrollbar-thumb,
.dark-mode .recent-topics-list::-webkit-scrollbar-thumb,
[data-theme="dark"] .recent-topics-list::-webkit-scrollbar-thumb {
    background-color: #555;
}

/* Header bar */
.recent-topics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background-color: var(--rti-header-bg, var(--recenttopicsimage-header-color, #0099FF));
    border-radius: 3px 3px 0 0;
    color: var(--rti-header-text, #fff);
    height: 28px; /* Reduced height for slimmer header bar */
    overflow: hidden; /* Prevent content from overflowing */
    white-space: nowrap; /* Keep text on one line */
}

.recent-topics-header .header-title {
    font-weight: bold;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.recent-topics-header .header-actions {
    display: flex;
    align-items: center;
}

/* Ensure "Visualizzazioni" doesn't wrap */
.recent-topics-header .header-actions span {
    display: inline-block;
    white-space: nowrap;
}

/* Scroll controls */
.recent-topics-controls {
    display: flex;
    justify-content: flex-end;
    padding: 2px 10px;
    background-color: rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.recent-topics-controls button {
    background: none;
    border: none;
    margin-left: 5px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.recent-topics-controls button:hover {
    background-color: #e8e8e8;
}

.recent-topics-controls button:focus {
    outline: 2px solid #3f7fc0;
    outline-offset: 2px;
}

.recent-topics-controls button i {
    color: #777;
}

.recent-topics-controls button:hover i {
    color: #3f7fc0;
}

/* Accessibility focus */
.recent-topics-list:focus {
    outline: 2px solid #3f7fc0;
    outline-offset: -2px;
}

/* Tooltip styles */
.recent-topic-title a[data-tooltip] {
    position: relative;
}

/* Container style per i tooltip */
.recenttopics-tooltip {
    position: absolute;
    display: none;
    background-color: rgba(51, 51, 51, 0.95);
    color: #fff;
    padding: 10px;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    width: 280px;
    z-index: 999;
    font-weight: normal;
    font-size: 12px;
    line-height: 1.5;
    white-space: normal;
    pointer-events: none;
    max-height: 200px;
    overflow-y: auto;
    animation: fadeIn 0.3s ease;
}

/* Vecchio stile disabilitato per evitare doppi tooltip */
.recent-topic-title a[data-tooltip]:hover::after,
.recent-topic-title a[data-tooltip].tooltip-active::after {
    content: none; /* Disabilita il tooltip basato su ::after */
}

/* Tooltip animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive tooltip width */
@media (max-width: 480px) {
    /* Adatta il contenitore tooltip responsive */
    .recenttopics-tooltip {
        width: 220px;
        max-width: 90vw;
    }
    
    /* Ottimizzazioni aggiuntive per telefoni molto piccoli */
    .recent-topic-item {
        min-height: 200px; /* Altezza minima ridotta */
        padding: 10px;
    }
    
    .recent-topic-image {
        max-height: 100px;
    }
    
    .recent-topic-image img {
        max-height: 100px;
    }
    
    .recent-topic-title {
        font-size: 13px;
    }
    
    .recent-topic-details span {
        font-size: 10px;
        line-height: 1.3;
    }
    
    .recent-topics-header {
        padding: 3px 8px;
        height: 24px;
    }
    
    .recent-topics-header .header-title {
        font-size: 12px;
    }
}

/* Unread topic indicators */
.recent-topic-unread {
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: var(--rti-unread, #bd3d3d);
    border-radius: 50%;
    margin-right: 5px;
    position: relative;
    cursor: pointer;
    vertical-align: middle;
    transition: background-color 0.2s ease;
}

.recent-topic-unread:hover {
    background-color: var(--rti-highlight, #e74c3c);
}

.recent-topic-unread.dark-mode {
    background-color: var(--rti-unread, #ff5555);
}

.recent-topic-unread.dark-mode:hover {
    background-color: var(--rti-highlight, #ff7777);
}

.recent-topic-item-unread {
    background-color: rgba(var(--rti-highlight, 231, 76, 60), 0.03);
}

.darkmode .recent-topic-item-unread,
.dark-mode .recent-topic-item-unread,
[data-theme="dark"] .recent-topic-item-unread {
    background-color: rgba(255, 85, 85, 0.05);
}

.recent-topic-first-unread-link {
    display: none; /* Hide the actual link, but keep it in the DOM for JS access */
}

/* Dark mode for controls */
.darkmode .recent-topics-controls,
.dark-mode .recent-topics-controls,
[data-theme="dark"] .recent-topics-controls {
    background-color: #333;
    border-color: #3a3a3a;
}

.darkmode .recent-topics-controls button:hover,
.dark-mode .recent-topics-controls button:hover,
[data-theme="dark"] .recent-topics-controls button:hover {
    background-color: #444;
}

.darkmode .recent-topics-controls button i,
.dark-mode .recent-topics-controls button i,
[data-theme="dark"] .recent-topics-controls button i {
    color: #aaa;
}

.darkmode .recent-topics-controls button:hover i,
.dark-mode .recent-topics-controls button:hover i,
[data-theme="dark"] .recent-topics-controls button:hover i {
    color: #7cb2e8;
}

/* Dark mode for tooltips */
.darkmode .recenttopics-tooltip,
.dark-mode .recenttopics-tooltip,
[data-theme="dark"] .recenttopics-tooltip {
    background-color: rgba(30, 30, 30, 0.95);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
    color: #ddd;
}

/* Per compatibilità con temi che potrebbero ancora usare il vecchio selettore */
.darkmode .recent-topic-title a[data-tooltip]:hover::after,
.darkmode .recent-topic-title a[data-tooltip].tooltip-active::after,
.dark-mode .recent-topic-title a[data-tooltip]:hover::after,
.dark-mode .recent-topic-title a[data-tooltip].tooltip-active::after,
[data-theme="dark"] .recent-topic-title a[data-tooltip]:hover::after,
[data-theme="dark"] .recent-topic-title a[data-tooltip].tooltip-active::after {
    content: none;
}

/* Dark mode for image navigation */
.darkmode .topic-image-navigation,
.dark-mode .topic-image-navigation,
[data-theme="dark"] .topic-image-navigation {
    background: rgba(20, 20, 20, 0.7);
}

.darkmode .topic-image-nav-prev:hover,
.darkmode .topic-image-nav-next:hover,
.dark-mode .topic-image-nav-prev:hover,
.dark-mode .topic-image-nav-next:hover,
[data-theme="dark"] .topic-image-nav-prev:hover,
[data-theme="dark"] .topic-image-nav-next:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

/* Screen reader only class for accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* AJAX refresh animations */
.recent-topic-template {
    display: none;
}

.recent-topic-item-new {
    animation: newTopicHighlight 3s ease;
}

@keyframes newTopicHighlight {
    0% {
        background-color: rgba(63, 127, 192, 0.2);
        transform: translateY(-5px);
    }
    10% {
        transform: translateY(0);
    }
    70% {
        background-color: rgba(63, 127, 192, 0.1);
    }
    100% {
        background-color: transparent;
    }
}

/* Dark mode support for new item highlight */
.darkmode .recent-topic-item-new,
.dark-mode .recent-topic-item-new,
[data-theme="dark"] .recent-topic-item-new {
    animation: newTopicHighlightDark 3s ease;
}

@keyframes newTopicHighlightDark {
    0% {
        background-color: rgba(63, 127, 192, 0.25);
        transform: translateY(-5px);
    }
    10% {
        transform: translateY(0);
    }
    70% {
        background-color: rgba(63, 127, 192, 0.15);
    }
    100% {
        background-color: transparent;
    }
}
