/**
 * Tiles CSS
 * 
 * Styles for link tiles display
 * 
 * ADDED: Obsolete badge styling
 * FIXED: Added touch-action for iPad/iOS optimization
 */

/* Tile Container */
.tiles-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
    /* FIXED: Prevent tiles from stretching to fill container when few items */
    align-content: start;
    /* FIXED: Optimize touch scrolling on iOS */
    -webkit-overflow-scrolling: touch;
}

/* Individual Tile */
.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-height: 120px;
    max-height: 160px; /* FIXED: Consistent fixed height regardless of tile count */
    height: 140px; /* FIXED: Default fixed height for consistency */
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    overflow: visible; /* FIXED: Allow dropdown menu to extend beyond tile boundaries */
    /* FIXED: Eliminate 300ms tap delay on iOS and improve touch responsiveness */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
    user-select: none; /* Prevent text selection on touch */
    -webkit-user-select: none;
}

.tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Obsolete tile styling */
.tile.tile-obsolete {
    opacity: 0.7;
    border: 2px dashed #dc3545;
}

.tile.tile-obsolete:hover {
    opacity: 0.85;
}

/* Obsolete badge */
.tile-obsolete-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background-color: #dc3545;
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 3px;
    z-index: 5;
}

.tile-obsolete-badge i {
    font-size: 0.6rem;
}

/* Tile Icon */
.tile-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    /* FIXED: Prevent touch interference with icon */
    pointer-events: none;
}

.tile-icon img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 4px;
}

.tile-icon i {
    font-size: 32px;
    opacity: 0.9;
}

.tile-icon i.hidden {
    display: none;
}

/* Tile Name */
.tile-name {
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
    max-height: 2.4em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    /* FIXED: Prevent touch interference with text */
    pointer-events: none;
}

/* Tile Tooltip (description on hover) */
.tile-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    max-width: 200px;
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    pointer-events: none;
}

.tile:hover .tile-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Tile Favorite Star */
.tile-favorite {
    position: absolute;
    top: 8px;
    right: 8px;
    color: #FFD700;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    /* FIXED: Prevent touch interference */
    pointer-events: none;
}

/* Tile Tags */
.tile-tags {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
    /* FIXED: Prevent touch interference */
    pointer-events: none;
}

.tile-tag {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    color: white;
    opacity: 0.9;
}

/* Tile Actions Menu */
.tile-actions {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 10;
    /* FIXED: Allow touch events on actions */
    pointer-events: auto;
}

/* FIXED: Lift tile above siblings when menu is open */
.tile.menu-open {
    z-index: 1000;
}

.tile-menu-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    color: inherit;
    /* FIXED: Optimize touch interaction */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* On touch devices, always show menu button */
@media (hover: none) {
    .tile-menu-btn {
        opacity: 0.8;
    }
}

.tile:hover .tile-menu-btn {
    opacity: 1;
}

.tile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.tile-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    display: none;
    z-index: 9999; /* FIXED: High z-index to appear above all other tiles */
}

.tile-menu.active {
    display: block;
}

.tile-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    text-align: left;
    transition: background 0.2s;
    /* FIXED: Optimize touch interaction */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tile-menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.tile-menu-item:last-child {
    border-radius: 0 0 8px 8px;
}

.tile-menu-item:hover {
    background: #f5f5f5;
}

/* FIXED: Better touch feedback for menu items on touch devices */
@media (hover: none) {
    .tile-menu-item:active {
        background: #e0e0e0;
    }
}

.tile-menu-item.danger {
    color: #dc3545;
}

.tile-menu-item.danger:hover {
    background: #fff5f5;
}

.tile-menu-item i {
    width: 16px;
    text-align: center;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px;
    text-align: center;
    color: #666;
}

.empty-state i {
    font-size: 64px;
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state h3 {
    margin: 0 0 8px;
    font-weight: 500;
}

.empty-state p {
    margin: 0;
    color: #999;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .tiles-container {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 12px;
        padding: 12px;
    }
    
    .tile {
        padding: 12px;
        min-height: 100px;
        max-height: 130px; /* FIXED: Consistent height on mobile */
        height: 115px; /* FIXED: Fixed height on mobile */
    }
    
    .tile-icon img,
    .tile-icon i {
        width: 24px;
        height: 24px;
        font-size: 24px;
    }
    
    .tile-name {
        font-size: 0.85rem;
    }
    
    .tile-obsolete-badge {
        font-size: 0.55rem;
        padding: 1px 4px;
    }
}
